Extract save_playlist().
[dcpomatic.git] / src / tools / dcpomatic_playlist.cc
index 3e3bd02669cc8e359c855126608b66a69e551d08..636a50f8ab9d6a3daafd36e564ba8d2ef65c871e 100644 (file)
@@ -59,6 +59,16 @@ using namespace boost::placeholders;
 #endif
 
 
+static
+void
+save_playlist(shared_ptr<const SPL> playlist)
+{
+       if (auto dir = Config::instance()->player_playlist_directory()) {
+               playlist->write(*dir / (playlist->id() + ".xml"));
+       }
+}
+
+
 class ContentDialog : public wxDialog, public ContentStore
 {
 public:
@@ -106,6 +116,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>"));
@@ -196,9 +207,7 @@ private:
                        break;
                }
                case SignalSPL::Change::CONTENT:
-                       if (auto dir = Config::instance()->player_playlist_directory()) {
-                               playlist->write(*dir / (playlist->id() + ".xml"));
-                       }
+                       save_playlist(playlist);
                        break;
                }
        }
@@ -227,6 +236,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);
@@ -280,6 +295,7 @@ private:
        wxButton* _delete;
        vector<shared_ptr<SignalSPL>> _playlists;
        ContentStore* _content_store;
+       wxWindow* _parent;
 };
 
 
@@ -544,16 +560,6 @@ private:
                _playlist_content->set (playlist);
        }
 
-       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;
-               }
-               playlist->write (*dir / (playlist->id() + ".xml"));
-       }
-
        void setup_menu (wxMenuBar* m)
        {
                auto file = new wxMenu;