Check for playlist directory on new playlist, rather than save.
[dcpomatic.git] / src / tools / dcpomatic_playlist.cc
index 835582c091d88ceef49f547c8f8a119af99ed8af..4a4407b02c60e4464ece8153b8b12d53eff504ef 100644 (file)
@@ -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 (_("<b>Playlists</b>"));
@@ -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<void (shared_ptr<SignalSPL>)> Edit;
 
 private:
+       void setup_sensitivity()
+       {
+               _delete->Enable(static_cast<bool>(selected()));
+       }
+
        void add_playlist_to_view (shared_ptr<const SignalSPL> playlist)
        {
                wxListItem item;
@@ -220,6 +228,12 @@ 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<SignalSPL> spl (new SignalSPL(wx_to_std(_("New Playlist"))));
                add_playlist_to_model (spl);
                add_playlist_to_view (spl);
@@ -263,6 +277,8 @@ private:
                } else {
                        Edit (_playlists[selected]);
                }
+
+               setup_sensitivity();
        }
 
        wxBoxSizer* _sizer;
@@ -271,6 +287,7 @@ private:
        wxButton* _delete;
        vector<shared_ptr<SignalSPL>> _playlists;
        ContentStore* _content_store;
+       wxWindow* _parent;
 };
 
 
@@ -537,12 +554,9 @@ private:
 
        void save_playlist (shared_ptr<SignalSPL> 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)