diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-12-01 20:12:56 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-12-01 20:12:56 +0100 |
| commit | 05fff51f80d5a2d5728fd40472d1c1e0f9e00300 (patch) | |
| tree | 447e76ee731aeb1a2bace9881399d1f1b1f74477 | |
| parent | 7709de3a8d94aa00e01d7f86504cab7a5c77e564 (diff) | |
Extract selected().
| -rw-r--r-- | src/tools/dcpomatic_playlist.cc | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 05dea1f33..835582c09 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -226,10 +226,20 @@ private: _list->SetItemState (_list->GetItemCount() - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } - void delete_playlist () + boost::optional<int> selected() const { - long int selected = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + long int selected = _list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (selected < 0 || selected >= int(_playlists.size())) { + return {}; + } + + return selected; + } + + void delete_playlist () + { + auto index = selected(); + if (!index) { return; } @@ -238,11 +248,11 @@ private: return; } - boost::filesystem::remove (*dir / (_playlists[selected]->id() + ".xml")); - _list->DeleteItem (selected); - _playlists.erase (_playlists.begin() + selected); + boost::filesystem::remove(*dir / (_playlists[*index]->id() + ".xml")); + _list->DeleteItem(*index); + _playlists.erase(_playlists.begin() + *index); - Edit (shared_ptr<SignalSPL>()); + Edit(shared_ptr<SignalSPL>()); } void selection_changed () |
