swaroop: fix phantom entries when loading/saving playlists.
[dcpomatic.git] / src / tools / dcpomatic_playlist.cc
index bee920501ca32c918953de8aa736bd5ab4db0fcd..0b8f935b3aaf0d8dc02ba1b3e7dcd0599b092e10 100644 (file)
@@ -21,6 +21,7 @@
 #include "../wx/wx_util.h"
 #include "../wx/wx_signal_manager.h"
 #include "../wx/content_view.h"
+#include "../wx/dcpomatic_button.h"
 #include "../lib/util.h"
 #include "../lib/config.h"
 #include "../lib/cross.h"
@@ -44,7 +45,7 @@ using boost::dynamic_pointer_cast;
 class ContentDialog : public wxDialog, public ContentStore
 {
 public:
-       ContentDialog (wxWindow* parent, weak_ptr<Film> film)
+       ContentDialog (wxWindow* parent)
                : wxDialog (parent, wxID_ANY, _("Add content"), wxDefaultPosition, wxSize(800, 640))
                , _content_view (new ContentView(this))
        {
@@ -82,9 +83,7 @@ class DOMFrame : public wxFrame
 public:
        explicit DOMFrame (wxString const & title)
                : wxFrame (0, -1, title)
-               /* XXX: this is a bit of a hack, but we need it to be able to use the Content class hierarchy */
-               , _film (new Film(optional<boost::filesystem::path>()))
-               , _content_dialog (new ContentDialog(this, _film))
+               , _content_dialog (new ContentDialog(this))
        {
                /* Use a panel as the only child of the Frame so that we avoid
                   the dark-grey background on Windows.
@@ -162,7 +161,6 @@ private:
                item.SetId (_list->GetItemCount());
                long const N = _list->InsertItem (item);
                set_item (N, e);
-               _playlist.add (e);
        }
 
        void selection_changed ()
@@ -231,7 +229,9 @@ private:
                if (r == wxID_OK) {
                        shared_ptr<Content> content = _content_dialog->selected ();
                        if (content) {
-                               add (SPLEntry(content));
+                               SPLEntry e (content);
+                               add (e);
+                               _playlist.add (e);
                        }
                }
        }
@@ -294,7 +294,9 @@ private:
                wxFileDialog* d = new wxFileDialog (this, _("Select playlist file"), default_dir, wxEmptyString, wxT("XML files (*.xml)|*.xml"));
                if (d->ShowModal() == wxID_OK) {
                        _list->DeleteAllItems ();
-                       if (!_playlist.read (wx_to_std(d->GetPath()), _content_dialog)) {
+                       _playlist.read (wx_to_std(d->GetPath()), _content_dialog);
+                       if (!_playlist.missing()) {
+                               _list->DeleteAllItems ();
                                BOOST_FOREACH (SPLEntry i, _playlist.get()) {
                                        add (i);
                                }
@@ -311,7 +313,6 @@ private:
        wxButton* _remove;
        wxButton* _save;
        wxButton* _load;
-       boost::shared_ptr<Film> _film;
        SPL _playlist;
        ContentDialog* _content_dialog;