Save / restore settings from the editor region list context menu.
authorCarl Hetherington <carl@carlh.net>
Sun, 19 Sep 2010 02:18:59 +0000 (02:18 +0000)
committerCarl Hetherington <carl@carlh.net>
Sun, 19 Sep 2010 02:18:59 +0000 (02:18 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7804 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.cc
gtk2_ardour/editor_actions.cc
gtk2_ardour/editor_regions.cc
gtk2_ardour/editor_regions.h

index 9c431fdd2c1d148f944882e1282d68402fecd236..a91a0572e442ebd2512baa5d75ff911a901eee38 100644 (file)
@@ -2559,6 +2559,7 @@ Editor::set_state (const XMLNode& node, int /*version*/)
        XMLNodeList children = node.children ();
        for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
                selection->set_state (**i, Stateful::current_state_version);
+               _regions->set_state (**i);
        }
 
        return 0;
@@ -2648,6 +2649,7 @@ Editor::get_state ()
        node->add_property (X_("editor-list-page"), buf);
 
        node->add_child_nocopy (selection->get_state ());
+       node->add_child_nocopy (_regions->get_state ());
        
        return *node;
 }
index e8eeb4d5727f03ebdaa8f5f7e0fdea037e1b55c2..0814bd37ff9c28e082215ba8cdd71e056a3e965f 100644 (file)
@@ -841,7 +841,7 @@ Editor::register_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::write_sensitive_actions.push_back (act);
 
-       act = ActionManager::register_action (editor_actions, X_("addExternalAudioToRegionList"), _("Import to Region List"), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportAsRegion));
+       act = ActionManager::register_action (editor_actions, X_("addExternalAudioToRegionList"), _("Import to Region List..."), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportAsRegion));
        ActionManager::session_sensitive_actions.push_back (act);
        ActionManager::write_sensitive_actions.push_back (act);
 
index 4d51c2539dcc75a917f8992ae778c65a6e789e7c..a87cc6ac8e74dd31cf3187f6c04692671927b971 100644 (file)
@@ -493,16 +493,15 @@ EditorRegions::redisplay ()
 
        bool tree_expanded = false;
 
-       if (_toggle_full_action && _toggle_full_action->get_active()) {   //If the list was expanded prior to rebuilding,
-               tree_expanded = true;                                                                                                                           //expand it again afterwards
+       /* If the list was expanded prior to rebuilding, expand it again afterwards */
+       if (toggle_full_action()->get_active()) {
+               tree_expanded = true;
        }
 
        _display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
        _model->clear ();
 
-       /* now add everything we have, via a temporary list used to help with
-               sorting.
-       */
+       /* now add everything we have, via a temporary list used to help with sorting */
 
        tmp_region_list.clear();
 
@@ -874,39 +873,22 @@ EditorRegions::populate_row (boost::shared_ptr<Region> region, TreeModel::Row co
 }
 
 void
-EditorRegions::build_menu ()
+EditorRegions::toggle_show_auto_regions ()
 {
-       _menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
-
-       /* now grab specific menu items that we need */
-
-       Glib::RefPtr<Action> act;
-
-       _hide_action = ActionManager::get_action (X_("RegionList"), X_("rlHide"));
-       _show_action = ActionManager::get_action (X_("RegionList"), X_("rlShow"));
-
-       act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
-       if (act) {
-               _toggle_full_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
-       }
-
-       act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
-       if (act) {
-               _toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
-       }
+       _show_automatic_regions = toggle_show_auto_regions_action()->get_active();
+       redisplay ();
 }
 
 void
-EditorRegions::toggle_show_auto_regions ()
+EditorRegions::toggle_full ()
 {
-       _show_automatic_regions = _toggle_show_auto_regions_action->get_active();
-       redisplay ();
+       set_full (toggle_full_action()->get_active ());
 }
 
 void
-EditorRegions::toggle_full ()
+EditorRegions::set_full (bool f)
 {
-       if (_toggle_full_action->get_active()) {
+       if (f) {
                _display.expand_all ();
        } else {
                _display.collapse_all ();
@@ -917,7 +899,7 @@ void
 EditorRegions::show_context_menu (int button, int time)
 {
        if (_menu == 0) {
-               build_menu ();
+               _menu = dynamic_cast<Menu*> (ActionManager::get_widget ("/RegionListMenu"));
        }
 
        if (_display.get_selection()->count_selected_rows() > 0) {
@@ -944,8 +926,8 @@ EditorRegions::show_context_menu (int button, int time)
                }
        }
 
-       _hide_action->set_sensitive (have_shown);
-       _show_action->set_sensitive (have_hidden);
+       hide_action()->set_sensitive (have_shown);
+       show_action()->set_sensitive (have_hidden);
 
        _menu->popup (button, time);
 }
@@ -1292,3 +1274,140 @@ EditorRegions::opaque_changed (std::string const & path)
        }
 
 }
+
+XMLNode &
+EditorRegions::get_state () const
+{
+       XMLNode* node = new XMLNode (X_("RegionList"));
+
+       node->add_property (X_("sort-type"), enum_2_string (_sort_type));
+
+       RefPtr<Action> act = ActionManager::get_action (X_("RegionList"), X_("SortAscending"));
+       bool const ascending = RefPtr<RadioAction>::cast_dynamic(act)->get_active ();
+       node->add_property (X_("sort-ascending"), ascending ? "yes" : "no");
+       node->add_property (X_("show-all"), toggle_full_action()->get_active() ? "yes" : "no");
+       node->add_property (X_("show-automatic-regions"), _show_automatic_regions ? "yes" : "no");
+
+       return *node;
+}
+               
+void
+EditorRegions::set_state (const XMLNode & node)
+{
+       if (node.name() != X_("RegionList")) {
+               return;
+       }
+
+       XMLProperty const * p = node.property (X_("sort-type"));
+       if (p) {
+               Editing::RegionListSortType const t = static_cast<Editing::RegionListSortType> (string_2_enum (p->value(), _sort_type));
+               reset_sort_type (t, true);
+               RefPtr<RadioAction> ract = sort_type_action (t);
+               ract->set_active ();
+       }
+
+       p = node.property (X_("sort-ascending"));
+       if (p) {
+               bool const a = string_is_affirmative (p->value ());
+               reset_sort_direction (a);
+               RefPtr<Action> act;
+               if (a) {
+                       act = ActionManager::get_action (X_("RegionList"), X_("SortAscending"));
+               } else {
+                       act = ActionManager::get_action (X_("RegionList"), X_("SortDescending"));
+               }
+
+               RefPtr<RadioAction>::cast_dynamic(act)->set_active ();
+       }
+
+       p = node.property (X_("show-all"));
+       if (p) {
+               bool const s = string_is_affirmative (p->value ());
+               set_full (s);
+               toggle_full_action()->set_active (s);
+       }
+
+       p = node.property (X_("show-automatic-regions"));
+       if (p) {
+               bool const s = string_is_affirmative (p->value ());
+               _show_automatic_regions = s;
+               redisplay ();
+               toggle_show_auto_regions_action()->set_active (s);
+       }
+}
+
+RefPtr<RadioAction>
+EditorRegions::sort_type_action (Editing::RegionListSortType t) const
+{
+       const char* action = 0;
+
+       switch (t) {
+       case Editing::ByName:
+               action = X_("SortByRegionName");
+               break;
+       case Editing::ByLength:
+               action = X_("SortByRegionLength");
+               break;
+       case Editing::ByPosition:
+               action = X_("SortByRegionPosition");
+               break;
+       case Editing::ByTimestamp:
+               action = X_("SortByRegionTimestamp");
+               break;
+       case Editing::ByStartInFile:
+               action = X_("SortByRegionStartinFile");
+               break;
+       case Editing::ByEndInFile:
+               action = X_("SortByRegionEndinFile");
+               break;
+       case Editing::BySourceFileName:
+               action = X_("SortBySourceFileName");
+               break;
+       case Editing::BySourceFileLength:
+               action = X_("SortBySourceFileLength");
+               break;
+       case Editing::BySourceFileCreationDate:
+               action = X_("SortBySourceFileCreationDate");
+               break;
+       case Editing::BySourceFileFS:
+               action = X_("SortBySourceFilesystem");
+               break;
+       default:
+               fatal << string_compose (_("programming error: %1: %2"), "EditorRegions: impossible sort type", (int) t) << endmsg;
+               /*NOTREACHED*/
+       }
+
+       RefPtr<Action> act = ActionManager::get_action (X_("RegionList"), action);
+       assert (act);
+
+       return RefPtr<RadioAction>::cast_dynamic (act);
+}
+
+RefPtr<Action>
+EditorRegions::hide_action () const
+{
+       return ActionManager::get_action (X_("RegionList"), X_("rlHide"));
+       
+}
+
+RefPtr<Action>
+EditorRegions::show_action () const
+{
+       return ActionManager::get_action (X_("RegionList"), X_("rlShow"));
+}
+
+RefPtr<ToggleAction>
+EditorRegions::toggle_full_action () const
+{
+       Glib::RefPtr<Action> act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
+       assert (act);
+       return Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+}
+
+RefPtr<ToggleAction>
+EditorRegions::toggle_show_auto_regions_action () const
+{
+       Glib::RefPtr<Action> act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
+       assert (act);
+       return Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+}
index c4b5c8f3f1fbc5ca0775cc6bd78396adb9b3a2c2..e6f473ff3d4a4de3bd5ef0650c57bada7b9252b0 100644 (file)
@@ -63,6 +63,9 @@ public:
                _display.get_selection()->unselect_all ();
        }
 
+       XMLNode& get_state () const;
+       void set_state (const XMLNode &);
+
 private:
 
        struct Columns : public Gtk::TreeModel::ColumnRecord {
@@ -119,7 +122,6 @@ private:
 
        bool key_press (GdkEventKey *);
        bool button_press (GdkEventButton *);
-       void build_menu ();
        void show_context_menu (int button, int time);
 
        int sorter (Gtk::TreeModel::iterator, Gtk::TreeModel::iterator);
@@ -137,15 +139,19 @@ private:
                Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
                );
 
+       Glib::RefPtr<Gtk::RadioAction> sort_type_action (Editing::RegionListSortType) const;
+       void set_full (bool);
+
+       Glib::RefPtr<Gtk::Action> hide_action () const;
+       Glib::RefPtr<Gtk::Action> show_action () const;
+       Glib::RefPtr<Gtk::ToggleAction> toggle_full_action () const;
+       Glib::RefPtr<Gtk::ToggleAction> toggle_show_auto_regions_action () const;
+       
        Gtk::Menu* _menu;
        Gtk::ScrolledWindow _scroller;
        Gtk::Frame _frame;
        Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
        Glib::RefPtr<Gtk::TreeStore> _model;
-       Glib::RefPtr<Gtk::Action> _hide_action; ///< the action for our Hide menu option
-       Glib::RefPtr<Gtk::Action> _show_action; ///< the action for our Show menu option
-       Glib::RefPtr<Gtk::ToggleAction> _toggle_full_action;
-       Glib::RefPtr<Gtk::ToggleAction> _toggle_show_auto_regions_action;
        bool _show_automatic_regions;
        Editing::RegionListSortType _sort_type;
        bool _no_redisplay;