BizHawk/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs

102 lines
2.5 KiB
C#
Raw Normal View History

2011-07-04 01:57:18 +00:00
using System;
using System.Windows.Forms;
2014-01-16 13:47:04 +00:00
using System.ComponentModel;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
2011-07-04 01:57:18 +00:00
{
public partial class EditCommentsForm : Form
{
private IMovie _selectedMovie;
2014-01-16 13:47:04 +00:00
private String _lastHeaderClicked;
private Boolean _sortReverse;
public EditCommentsForm()
{
InitializeComponent();
_lastHeaderClicked = "";
_sortReverse = false;
}
2011-07-04 01:57:18 +00:00
2014-01-16 13:47:04 +00:00
private void OnColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
SortColumn(CommentGrid.Columns[e.ColumnIndex]);
}
private void SortColumn(DataGridViewColumn e)
{
ListSortDirection _direction;
DataGridViewColumn _column = e;
if (_lastHeaderClicked != _column.Name)
{
_sortReverse = false;
}
if (!_sortReverse)
{
_direction = ListSortDirection.Ascending;
}
else
{
_direction = ListSortDirection.Descending;
}
CommentGrid.Sort(_column, _direction);
_lastHeaderClicked = _column.Name;
_sortReverse = !_sortReverse;
CommentGrid.Refresh();
}
2011-07-04 01:57:18 +00:00
private void EditCommentsForm_Load(object sender, EventArgs e)
{
if (Global.MovieSession.ReadOnly)
2011-07-04 01:57:18 +00:00
{
CommentGrid.Columns[0].ReadOnly = true;
Text = "View Comments";
}
if (CommentGrid.Rows.Count > 8)
{
var x = Height + ((CommentGrid.Rows.Count - 8) * 21);
Height = x < 600 ? x : 600;
}
2011-07-04 01:57:18 +00:00
}
private void Cancel_Click(object sender, EventArgs e)
{
2013-04-15 02:14:14 +00:00
Close();
2011-07-04 01:57:18 +00:00
}
private void OK_Click(object sender, EventArgs e)
{
if (!Global.MovieSession.ReadOnly)
2011-07-04 01:57:18 +00:00
{
_selectedMovie.Header.Comments.Clear();
for (int i = 0; i < CommentGrid.Rows.Count - 1; i++)
{
var c = CommentGrid.Rows[i].Cells[0];
_selectedMovie.Header.Comments.Add("comment " + c.Value);
}
_selectedMovie.Save();
2011-07-04 01:57:18 +00:00
}
2013-04-15 02:14:14 +00:00
Close();
2011-07-04 01:57:18 +00:00
}
public void GetMovie(IMovie m)
2011-07-04 01:57:18 +00:00
{
_selectedMovie = m;
if (m.Header.Comments.Count == 0) return;
for (int i = 0; i < m.Header.Comments.Count; i++)
2011-07-04 01:57:18 +00:00
{
var str = m.Header.Comments[i];
if (str.Length >= 7 && str.Substring(0, 7) == "comment")
{
str = str.Remove(0, 7);
}
CommentGrid.Rows.Add();
var c = CommentGrid.Rows[i].Cells[0];
c.Value = str;
2011-07-04 01:57:18 +00:00
}
}
}
}