run bundle fixup code for all platforms
[ardour.git] / gtk2_ardour / route_group_dialog.cc
index 4bcc26a35a47be5544be7de85ab3eb0b0fc46e20..9f50d7a3f653fc031d4cb34d5b9f638e301b1949 100644 (file)
 
 #include <gtkmm/table.h>
 #include <gtkmm/stock.h>
-#include <gtkmm2ext/window_title.h>
+#include <gtkmm/messagedialog.h>
 #include "ardour/route_group.h"
+#include "ardour/session.h"
 #include "route_group_dialog.h"
 #include "i18n.h"
 #include <iostream>
 
 using namespace Gtk;
-using namespace Gtkmm2ext;
 using namespace ARDOUR;
 using namespace std;
-
-RouteGroupDialog::RouteGroupDialog (RouteGroup* g, StockID const & s)
-       : ArdourDialog (_("route group dialog")),
-         _group (g),
-         _active (_("Active")),
-         _gain (_("Gain")),
-         _relative (_("Relative")),
-         _mute (_("Muting")),
-         _solo (_("Soloing")),
-         _rec_enable (_("Record enable")),
-         _select (_("Selection")),
-         _edit (_("Editing"))
+using namespace PBD;
+
+RouteGroupDialog::RouteGroupDialog (RouteGroup* g, bool creating_new)
+       : ArdourDialog (_("Route Group"))
+       , _group (g)
+       , _initial_name (g->name ())
+       , _active (_("Active"))
+       , _gain (_("Gain"))
+       , _relative (_("Relative"))
+       , _mute (_("Muting"))
+       , _solo (_("Soloing"))
+       , _rec_enable (_("Record enable"))
+       , _select (_("Selection"))
+       , _edit (_("Editing"))
+       , _route_active (_("Route active state"))
 {
        set_modal (true);
        set_skip_taskbar_hint (true);
@@ -48,10 +51,6 @@ RouteGroupDialog::RouteGroupDialog (RouteGroup* g, StockID const & s)
        set_position (Gtk::WIN_POS_MOUSE);
        set_name (N_("RouteGroupDialog"));
 
-       WindowTitle title (Glib::get_application_name());
-       title += _("Route group");
-       set_title(title.get_string());
-
        VBox* vbox = manage (new VBox);
        Gtk::Label* l;
 
@@ -79,13 +78,27 @@ RouteGroupDialog::RouteGroupDialog (RouteGroup* g, StockID const & s)
        _name.set_text (_group->name ());
        _active.set_active (_group->is_active ());
 
-       _gain.set_active (_group->property (RouteGroup::Gain));
+       _name.signal_activate ().connect (sigc::bind (sigc::mem_fun (*this, &Dialog::response), RESPONSE_OK));
+
+       _gain.set_active (_group->is_gain());
        _relative.set_active (_group->is_relative());
-       _mute.set_active (_group->property (RouteGroup::Mute));
-       _solo.set_active (_group->property (RouteGroup::Solo));
-       _rec_enable.set_active (_group->property (RouteGroup::RecEnable));
-       _select.set_active (_group->property (RouteGroup::Select));
-       _edit.set_active (_group->property (RouteGroup::Edit));
+       _mute.set_active (_group->is_mute());
+       _solo.set_active (_group->is_solo());
+       _rec_enable.set_active (_group->is_recenable());
+       _select.set_active (_group->is_select());
+       _edit.set_active (_group->is_edit());
+       _route_active.set_active (_group->is_route_active());
+
+       _name.signal_changed().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _active.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _gain.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _relative.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _mute.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _solo.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _rec_enable.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _select.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _edit.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
+       _route_active.signal_toggled().connect (sigc::mem_fun (*this, &RouteGroupDialog::update));
 
        gain_toggled ();
 
@@ -109,38 +122,76 @@ RouteGroupDialog::RouteGroupDialog (RouteGroup* g, StockID const & s)
        table->attach (_rec_enable, 1, 3, 5, 6, Gtk::FILL, Gtk::FILL, 0, 0);
        table->attach (_select, 1, 3, 6, 7, Gtk::FILL, Gtk::FILL, 0, 0);
        table->attach (_edit, 1, 3, 7, 8, Gtk::FILL, Gtk::FILL, 0, 0);
+       table->attach (_route_active, 1, 3, 8, 9, Gtk::FILL, Gtk::FILL, 0, 0);
 
        options_box->pack_start (*table, false, true);
        vbox->pack_start (*options_box, false, true);
 
        get_vbox()->pack_start (*vbox, false, false);
 
-       _gain.signal_toggled().connect(mem_fun (*this, &RouteGroupDialog::gain_toggled));
-
-       add_button (Stock::CANCEL, RESPONSE_CANCEL);
-       add_button (s, RESPONSE_OK);
+       _gain.signal_toggled().connect(sigc::mem_fun (*this, &RouteGroupDialog::gain_toggled));
 
+       if (creating_new) {
+               add_button (Stock::CANCEL, RESPONSE_CANCEL);
+               add_button (Stock::NEW, RESPONSE_OK);
+               set_default_response (RESPONSE_OK);
+       } else {
+               add_button (Stock::CLOSE, RESPONSE_CLOSE);
+               set_default_response (RESPONSE_CLOSE);
+       }
+       
        show_all_children ();
 }
 
-int
+/** @return true if the route group edit was cancelled, otherwise false */
+bool
 RouteGroupDialog::do_run ()
 {
-       int const r = run ();
-
-       if (r == Gtk::RESPONSE_OK) {
-               _group->set_property (RouteGroup::Gain, _gain.get_active ());
-               _group->set_property (RouteGroup::Mute, _mute.get_active ());
-               _group->set_property (RouteGroup::Solo, _solo.get_active ());
-               _group->set_property (RouteGroup::RecEnable, _rec_enable.get_active ());
-               _group->set_property (RouteGroup::Select, _select.get_active ());
-               _group->set_property (RouteGroup::Edit, _edit.get_active ());
-               _group->set_name (_name.get_text ()); // This emits changed signal
-               _group->set_active (_active.get_active (), this);
-               _group->set_relative (_relative.get_active(), this);
+       while (1) {
+               int const r = run ();
+               if (r == Gtk::RESPONSE_CANCEL) {
+                       /* cancel, so just bail now */
+                       return Gtk::RESPONSE_CANCEL;
+               }
+
+               if (unique_name ()) {
+                       /* not cancelled and the name is ok, so all is well */
+                       return false;
+               }
+       
+               _group->set_name (_initial_name);
+               MessageDialog msg (
+                       _("A route group of this name already exists.  Please use a different name."),
+                       false,
+                       Gtk::MESSAGE_ERROR,
+                       Gtk::BUTTONS_OK,
+                       true
+                       );
+               
+               msg.run ();
        }
 
-       return r;
+       /* NOTREACHED */
+       return false;
+}
+
+void
+RouteGroupDialog::update ()
+{
+       PropertyList plist;
+
+       plist.add (Properties::gain, _gain.get_active());
+       plist.add (Properties::recenable, _rec_enable.get_active());
+       plist.add (Properties::mute, _mute.get_active());
+       plist.add (Properties::solo, _solo.get_active ());
+       plist.add (Properties::select, _select.get_active());
+       plist.add (Properties::edit, _edit.get_active());
+       plist.add (Properties::route_active, _route_active.get_active());
+       plist.add (Properties::relative, _relative.get_active());
+       plist.add (Properties::active, _active.get_active());
+       plist.add (Properties::name, string (_name.get_text()));
+
+       _group->apply_changes (plist);
 }
 
 void
@@ -149,3 +200,15 @@ RouteGroupDialog::gain_toggled ()
        _relative.set_sensitive (_gain.get_active ());
 }
 
+/** @return true if the current group's name is unique accross the session */
+bool
+RouteGroupDialog::unique_name () const
+{
+       list<RouteGroup*> route_groups = _group->session().route_groups ();
+       list<RouteGroup*>::iterator i = route_groups.begin ();
+       while (i != route_groups.end() && ((*i)->name() != _name.get_text() || *i == _group)) {
+               ++i;
+       }
+
+       return (i == route_groups.end ());
+}