Give content menu on both main control and timeline. Fix silly bug on updating edito...
authorCarl Hetherington <cth@carlh.net>
Fri, 19 Jul 2013 18:54:35 +0000 (19:54 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 19 Jul 2013 18:54:35 +0000 (19:54 +0100)
src/wx/content_menu.cc [new file with mode: 0644]
src/wx/content_menu.h [new file with mode: 0644]
src/wx/film_editor.cc
src/wx/film_editor.h
src/wx/timeline.cc
src/wx/timeline.h
src/wx/wscript

diff --git a/src/wx/content_menu.cc b/src/wx/content_menu.cc
new file mode 100644 (file)
index 0000000..6f10503
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <wx/wx.h>
+#include "lib/film.h"
+#include "content_menu.h"
+#include "repeat_dialog.h"
+
+using std::cout;
+using boost::shared_ptr;
+
+enum {
+       ID_repeat,
+       ID_remove
+};
+
+ContentMenu::ContentMenu (shared_ptr<Film> f, wxWindow* p)
+       : _menu (new wxMenu)
+       , _film (f)
+       , _parent (p)
+{
+       _menu->Append (ID_repeat, _("Repeat..."));
+       _menu->AppendSeparator ();
+       _menu->Append (ID_remove, _("Remove"));
+
+       _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, &ContentMenu::repeat, this, ID_repeat);
+       _parent->Bind (wxEVT_COMMAND_MENU_SELECTED, &ContentMenu::remove, this, ID_remove);
+}
+
+ContentMenu::~ContentMenu ()
+{
+       delete _menu;
+}
+
+void
+ContentMenu::popup (ContentList c, wxPoint p)
+{
+       _content = c;
+       _parent->PopupMenu (_menu, p);
+}
+
+void
+ContentMenu::repeat (wxCommandEvent &)
+{
+       if (_content.empty ()) {
+               return;
+       }
+               
+       RepeatDialog d (_parent);
+       d.ShowModal ();
+
+       shared_ptr<const Film> film = _film.lock ();
+       if (!film) {
+               return;
+       }
+
+       film->playlist()->repeat (_content, d.number ());
+       d.Destroy ();
+
+       _content.clear ();
+}
+
+void
+ContentMenu::remove (wxCommandEvent &)
+{
+       if (_content.empty ()) {
+               return;
+       }
+
+       shared_ptr<const Film> film = _film.lock ();
+       if (!film) {
+               return;
+       }
+
+       film->playlist()->remove (_content);
+
+       _content.clear ();
+}
+
diff --git a/src/wx/content_menu.h b/src/wx/content_menu.h
new file mode 100644 (file)
index 0000000..127fbea
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef DCPOMATIC_CONTENT_MENU_H
+#define DCPOMATIC_CONTENT_MENU_H
+
+#include <wx/wx.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+#include "lib/types.h"
+
+class Film;
+
+class ContentMenu
+{
+public:
+       ContentMenu (boost::shared_ptr<Film>, wxWindow *);
+       ~ContentMenu ();
+
+       void popup (ContentList, wxPoint);
+
+private:
+       void repeat (wxCommandEvent &);
+       void remove (wxCommandEvent &);
+       
+       wxMenu* _menu;
+       boost::weak_ptr<Film> _film;
+       wxWindow* _parent;
+       ContentList _content;
+};
+
+#endif
index 33f5603a486bff092eea17b1d40811ab07bb81bc..c2351ed25b196eaeeb20785958a92453b79537d2 100644 (file)
@@ -69,6 +69,7 @@ using boost::lexical_cast;
 /** @param f Film to edit */
 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        : wxPanel (parent)
+       , _menu (f, this)
        , _generally_sensitive (true)
        , _audio_dialog (0)
        , _timeline_dialog (0)
@@ -211,6 +212,7 @@ FilmEditor::connect_to_widgets ()
        _ratio->Connect                  (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::ratio_changed), 0, this);
        _content->Connect                (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED,   wxListEventHandler    (FilmEditor::content_selection_changed), 0, this);
        _content->Connect                (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler    (FilmEditor::content_selection_changed), 0, this);
+       _content->Connect                (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,wxListEventHandler    (FilmEditor::content_right_click), 0, this);
        _content_add->Connect            (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
        _content_remove->Connect         (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
        _content_timeline->Connect       (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_timeline_clicked), 0, this);
@@ -689,6 +691,10 @@ FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
        }
 
        shared_ptr<Content> content = weak_content.lock ();
+       if (content != selected_content ()) {
+               return;
+       }
+       
        shared_ptr<VideoContent> video_content;
        shared_ptr<AudioContent> audio_content;
        shared_ptr<SubtitleContent> subtitle_content;
@@ -1516,3 +1522,11 @@ FilmEditor::sequence_video_changed (wxCommandEvent &)
 {
        _film->set_sequence_video (_sequence_video->GetValue ());
 }
+
+void
+FilmEditor::content_right_click (wxListEvent& ev)
+{
+       ContentList cl;
+       cl.push_back (selected_content ());
+       _menu.popup (cl, ev.GetPoint ());
+}
index 7347ab1a6326d6c2c75b849de2eb8f4d260fcf32..9501bbd7cbb0d82f0da896b567c9273b58af3427 100644 (file)
@@ -27,6 +27,7 @@
 #include <wx/collpane.h>
 #include <boost/signals2.hpp>
 #include "lib/film.h"
+#include "content_menu.h"
 
 class wxNotebook;
 class wxListCtrl;
@@ -97,6 +98,7 @@ private:
        void dcp_audio_channels_changed (wxCommandEvent &);
        void dcp_resolution_changed (wxCommandEvent &);
        void sequence_video_changed (wxCommandEvent &);
+       void content_right_click (wxListEvent &);
 
        /* Handle changes to the model */
        void film_changed (Film::Property);
@@ -173,6 +175,8 @@ private:
        Timecode* _length;
        wxChoice* _dcp_resolution;
 
+       ContentMenu _menu;
+
        std::vector<Ratio const *> _ratios;
 
        bool _generally_sensitive;
index c7276a081991656d68248343c87bd12910b9eced..7227fcffc2ab598edc81cc34cd6ab0e6f5680210 100644 (file)
@@ -25,7 +25,6 @@
 #include "film_editor.h"
 #include "timeline.h"
 #include "wx_util.h"
-#include "repeat_dialog.h"
 
 using std::list;
 using std::cout;
@@ -320,11 +319,6 @@ private:
        int _y;
 };
 
-enum {
-       ID_repeat,
-       ID_remove
-};
-
 Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
        , _film_editor (ed)
@@ -335,7 +329,7 @@ Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film)
        , _left_down (false)
        , _down_view_start (0)
        , _first_move (false)
-       , _menu (0)
+       , _menu (film, this)
 {
 #ifndef __WXOSX__
        SetDoubleBuffered (true);
@@ -348,9 +342,6 @@ Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film)
        Connect (wxID_ANY, wxEVT_MOTION, wxMouseEventHandler (Timeline::mouse_moved), 0, this);
        Connect (wxID_ANY, wxEVT_SIZE, wxSizeEventHandler (Timeline::resized), 0, this);
 
-       Connect (ID_repeat, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Timeline::repeat), 0, this);
-       Connect (ID_remove, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Timeline::remove), 0, this);
-
        playlist_changed ();
 
        SetMinSize (wxSize (640, tracks() * track_height() + 96));
@@ -572,14 +563,7 @@ Timeline::right_down (wxMouseEvent& ev)
                cv->set_selected (true);
        }
 
-       if (!_menu) {
-               _menu = new wxMenu;
-               _menu->Append (ID_repeat, _("Repeat..."));
-               _menu->AppendSeparator ();
-               _menu->Append (ID_remove, _("Remove"));
-       }
-
-       PopupMenu (_menu, ev.GetPosition ());
+       _menu.popup (selected_content (), ev.GetPosition ());
 }
 
 void
@@ -634,42 +618,6 @@ Timeline::clear_selection ()
        }
 }
 
-void
-Timeline::repeat (wxCommandEvent &)
-{
-       ContentList sel = selected_content ();
-       if (sel.empty ()) {
-               return;
-       }
-               
-       RepeatDialog d (this);
-       d.ShowModal ();
-
-       shared_ptr<const Film> film = _film.lock ();
-       if (!film) {
-               return;
-       }
-
-       film->playlist()->repeat (sel, d.number ());
-       d.Destroy ();
-}
-
-void
-Timeline::remove (wxCommandEvent &)
-{
-       ContentList sel = selected_content ();
-       if (sel.empty ()) {
-               return;
-       }
-
-       shared_ptr<const Film> film = _film.lock ();
-       if (!film) {
-               return;
-       }
-
-       film->playlist()->remove (sel);
-}
-
 Timeline::ContentViewList
 Timeline::selected_views () const
 {
index 48eaa9d762250bbde17d12797f6b4147f679c9f2..6f5c2ef3b925a286d410d7799f5e1c736638da2e 100644 (file)
@@ -23,6 +23,7 @@
 #include <wx/wx.h>
 #include "lib/util.h"
 #include "lib/rect.h"
+#include "content_menu.h"
 
 class Film;
 class View;
@@ -75,9 +76,6 @@ private:
        void set_start_from_event (wxMouseEvent &);
        void clear_selection ();
 
-       void repeat (wxCommandEvent &);
-       void remove (wxCommandEvent &);
-
        typedef std::vector<boost::shared_ptr<View> > ViewList;
        typedef std::vector<boost::shared_ptr<ContentView> > ContentViewList;
 
@@ -96,7 +94,7 @@ private:
        boost::shared_ptr<ContentView> _down_view;
        Time _down_view_start;
        bool _first_move;
-       wxMenu* _menu;
+       ContentMenu _menu;
 
        boost::signals2::scoped_connection _playlist_connection;
 };
index 09ce0218db1fc1b63d1b31019214c94486f83d42..a6af05bc4f66bceb8fcf2c77875538652073647c 100644 (file)
@@ -9,6 +9,7 @@ sources = """
           audio_mapping_view.cc
           audio_plot.cc
           config_dialog.cc
+          content_menu.cc
           dci_metadata_dialog.cc
           dir_picker_ctrl.cc
           film_editor.cc