Skip to content

Commit

Permalink
Allow editing subtitles and comments from PlayMovie
Browse files Browse the repository at this point in the history
also resolve a TODO in regards to TasMovie disposing
  • Loading branch information
Morilli committed Jun 10, 2024
1 parent efc6674 commit 0165b5f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public partial class EditCommentsForm : Form
private readonly bool _readOnly;
private string _lastHeaderClicked;
private bool _sortReverse;
private readonly bool _dispose;

public EditCommentsForm(IMovie movie, bool readOnly)
public EditCommentsForm(IMovie movie, bool readOnly, bool disposeOnClose = false)
{
_movie = movie;
_readOnly = readOnly;
_lastHeaderClicked = "";
_sortReverse = false;
_dispose = disposeOnClose;

InitializeComponent();
Icon = Properties.Resources.TAStudioIcon;
Expand Down Expand Up @@ -99,5 +101,13 @@ private void SortColumn(DataGridViewColumn e)
_sortReverse = !_sortReverse;
CommentGrid.Refresh();
}

private void OnClosed(object sender, FormClosedEventArgs e)
{
if (_dispose && _movie is ITasMovie tasMovie)
{
tasMovie.Dispose();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ public partial class EditSubtitlesForm : Form, IDialogParent

private readonly IMovie _selectedMovie;
private readonly bool _readOnly;
private readonly bool _dispose;

public IDialogController DialogController { get; }

public EditSubtitlesForm(IDialogController dialogController, IMovie movie, PathEntryCollection pathEntries, bool readOnly)
public EditSubtitlesForm(IDialogController dialogController, IMovie movie, PathEntryCollection pathEntries, bool readOnly, bool disposeOnClose = false)
{
_pathEntries = pathEntries;
_selectedMovie = movie;
_readOnly = readOnly;
_dispose = disposeOnClose;
DialogController = dialogController;
InitializeComponent();
Icon = Properties.Resources.TAStudioIcon;
Expand Down Expand Up @@ -271,5 +273,13 @@ private void SubGrid_CellContentClick(object sender, DataGridViewCellEventArgs e
}
}
}

private void OnClosed(object sender, FormClosedEventArgs e)
{
if (_dispose && _selectedMovie is ITasMovie tasMovie)
{
tasMovie.Dispose();
}
}
}
}
6 changes: 2 additions & 4 deletions src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,7 @@ private void CommentsBtn_Click(object sender, EventArgs e)
// TODO this will allocate unnecessary memory when this movie is a TasMovie due to TasStateManager
var movie = _movieSession.Get(_movieList[MovieView.SelectedIndices[0]].Filename);
movie.Load();
// TODO movie should be disposed if movie is ITasMovie
var form = new EditCommentsForm(movie, _movieSession.ReadOnly);
var form = new EditCommentsForm(movie, readOnly: false, disposeOnClose: true);
form.Show();
}
}
Expand All @@ -539,8 +538,7 @@ private void SubtitlesBtn_Click(object sender, EventArgs e)
// TODO this will allocate unnecessary memory when this movie is a TasMovie due to TasStateManager
var movie = _movieSession.Get(_movieList[MovieView.SelectedIndices[0]].Filename);
movie.Load();
// TODO movie should be disposed if movie is ITasMovie
var form = new EditSubtitlesForm(DialogController, movie, _config.PathEntries, readOnly: true);
var form = new EditSubtitlesForm(DialogController, movie, _config.PathEntries, readOnly: false, disposeOnClose: true);
form.Show();
}
}
Expand Down

0 comments on commit 0165b5f

Please sign in to comment.