X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftools%2Fdcpomatic_playlist.cc;h=4a4407b02c60e4464ece8153b8b12d53eff504ef;hb=986a681d008c432f68a4ff67d44e7a019ceab1a5;hp=9eada8b3820968807aea9297d772c342545d4328;hpb=baed0f37f3cb3375f39b8d44f01eadb8796eb0d5;p=dcpomatic.git
diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc
index 9eada8b38..4a4407b02 100644
--- a/src/tools/dcpomatic_playlist.cc
+++ b/src/tools/dcpomatic_playlist.cc
@@ -106,6 +106,7 @@ public:
PlaylistList (wxPanel* parent, ContentStore* content_store)
: _sizer (new wxBoxSizer(wxVERTICAL))
, _content_store (content_store)
+ , _parent(parent)
{
auto label = new wxStaticText (parent, wxID_ANY, wxEmptyString);
label->SetLabelMarkup (_("Playlists"));
@@ -136,6 +137,8 @@ public:
_list->Bind (wxEVT_COMMAND_LIST_ITEM_DESELECTED, bind(&PlaylistList::selection_changed, this));
_new->Bind (wxEVT_BUTTON, bind(&PlaylistList::new_playlist, this));
_delete->Bind (wxEVT_BUTTON, bind(&PlaylistList::delete_playlist, this));
+
+ setup_sensitivity();
}
wxSizer* sizer ()
@@ -155,6 +158,11 @@ public:
boost::signals2::signal)> Edit;
private:
+ void setup_sensitivity()
+ {
+ _delete->Enable(static_cast(selected()));
+ }
+
void add_playlist_to_view (shared_ptr playlist)
{
wxListItem item;
@@ -176,7 +184,9 @@ private:
return;
}
- if (change == SignalSPL::Change::NAME) {
+ switch (change) {
+ case SignalSPL::Change::NAME:
+ {
int N = 0;
for (auto i: _playlists) {
if (i == playlist) {
@@ -184,6 +194,13 @@ private:
}
++N;
}
+ break;
+ }
+ case SignalSPL::Change::CONTENT:
+ if (auto dir = Config::instance()->player_playlist_directory()) {
+ playlist->write(*dir / (playlist->id() + ".xml"));
+ }
+ break;
}
}
@@ -211,16 +228,32 @@ private:
void new_playlist ()
{
+ auto dir = Config::instance()->player_playlist_directory();
+ if (!dir) {
+ error_dialog(_parent, _("No playlist folder is specified in preferences. Please set one and then try again."));
+ return;
+ }
+
shared_ptr spl (new SignalSPL(wx_to_std(_("New Playlist"))));
add_playlist_to_model (spl);
add_playlist_to_view (spl);
_list->SetItemState (_list->GetItemCount() - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}
- void delete_playlist ()
+ boost::optional 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;
}
@@ -229,11 +262,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());
+ Edit(shared_ptr());
}
void selection_changed ()
@@ -244,6 +277,8 @@ private:
} else {
Edit (_playlists[selected]);
}
+
+ setup_sensitivity();
}
wxBoxSizer* _sizer;
@@ -252,6 +287,7 @@ private:
wxButton* _delete;
vector> _playlists;
ContentStore* _content_store;
+ wxWindow* _parent;
};
@@ -314,6 +350,8 @@ public:
_down->Bind (wxEVT_BUTTON, bind(&PlaylistContent::down_clicked, this));
_add->Bind (wxEVT_BUTTON, bind(&PlaylistContent::add_clicked, this));
_remove->Bind (wxEVT_BUTTON, bind(&PlaylistContent::remove_clicked, this));
+
+ setup_sensitivity();
}
wxSizer* sizer ()
@@ -402,9 +440,7 @@ private:
DCPOMATIC_ASSERT (_playlist);
- auto tmp = (*_playlist)[s];
- (*_playlist)[s] = (*_playlist)[s-1];
- (*_playlist)[s-1] = tmp;
+ _playlist->swap(s, s - 1);
set_item (s - 1, (*_playlist)[s-1]);
set_item (s, (*_playlist)[s]);
@@ -419,9 +455,7 @@ private:
DCPOMATIC_ASSERT (_playlist);
- auto tmp = (*_playlist)[s];
- (*_playlist)[s] = (*_playlist)[s+1];
- (*_playlist)[s+1] = tmp;
+ _playlist->swap(s, s + 1);
set_item (s + 1, (*_playlist)[s+1]);
set_item (s, (*_playlist)[s]);
@@ -479,8 +513,6 @@ public:
_playlist_list->Edit.connect (bind(&DOMFrame::change_playlist, this, _1));
- _playlist_content->set (_playlist_list->first_playlist());
-
Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
@@ -522,12 +554,9 @@ private:
void save_playlist (shared_ptr playlist)
{
- auto dir = Config::instance()->player_playlist_directory();
- if (!dir) {
- error_dialog (this, _("No playlist folder is specified in preferences. Please set one and then try again."));
- return;
+ if (auto dir = Config::instance()->player_playlist_directory()) {
+ playlist->write(*dir / (playlist->id() + ".xml"));
}
- playlist->write (*dir / (playlist->id() + ".xml"));
}
void setup_menu (wxMenuBar* m)