NOOP, remove trailing tabs/whitespace.
[ardour.git] / gtk2_ardour / theme_manager.cc
index 58a22508ec87976512f42bc5a9828258a997e49b..3d1a1f8952d0ba359cb34570ccfca665ba839e08 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "fix_carbon.h"
 
+#include <pbd/gstdio_compat.h>
+
 #include <gtkmm/stock.h>
 #include <gtkmm/settings.h>
 
@@ -45,8 +47,7 @@
 #include "ardour_dialog.h"
 #include "theme_manager.h"
 #include "rgb_macros.h"
-#include "ardour_ui.h"
-#include "global_signals.h"
+#include "ui_config.h"
 #include "utils.h"
 
 #include "i18n.h"
@@ -57,10 +58,6 @@ using namespace PBD;
 using namespace ARDOUR;
 using namespace ARDOUR_UI_UTILS;
 
-namespace ARDOUR_UI_UTILS {
-       sigc::signal<void> ColorsChanged;
-}
-
 ThemeManager::ThemeManager()
         : dark_button (_("Dark Theme"))
        , light_button (_("Light Theme"))
@@ -74,22 +71,23 @@ ThemeManager::ThemeManager()
        , timeline_item_gradient_depth (0, 1.0, 0.05)
        , timeline_item_gradient_depth_label (_("Timeline item gradient depth"))
        , all_dialogs (_("All floating windows are dialogs"))
+       , transients_follow_front (_("Transient windows follow front window."))
        , icon_set_label (_("Icon Set"))
        , palette_viewport (*palette_scroller.get_hadjustment(), *palette_scroller.get_vadjustment())
        , palette_group (0)
        , palette_window (0)
 {
        /* Now the alias list */
-       
+
        alias_list = TreeStore::create (alias_columns);
        alias_display.set_model (alias_list);
        alias_display.append_column (_("Object"), alias_columns.name);
-       
+
        Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
        TreeViewColumn* color_column = manage (new TreeViewColumn (_("Color"), *color_renderer));
        color_column->add_attribute (color_renderer->property_color(), alias_columns.color);
        alias_display.append_column (*color_column);
-       
+
        alias_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
        alias_display.get_column (0)->set_expand (true);
        alias_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
@@ -103,7 +101,7 @@ ThemeManager::ThemeManager()
        alias_scroller.add (alias_display);
 
        /* various buttons */
-       
+
        RadioButton::Group group = dark_button.get_group();
        light_button.set_group(group);
        theme_selection_hbox.set_homogeneous(false);
@@ -111,10 +109,13 @@ ThemeManager::ThemeManager()
        theme_selection_hbox.pack_start (light_button);
 
        set_homogeneous (false);
+#if 0 // disable light/dark theme choice. until the 'light theme gets some attention.
        pack_start (theme_selection_hbox, PACK_SHRINK);
+#endif
        pack_start (reset_button, PACK_SHRINK);
 #ifndef __APPLE__
        pack_start (all_dialogs, PACK_SHRINK);
+       pack_start (transients_follow_front, PACK_SHRINK);
 #endif
        pack_start (flat_buttons, PACK_SHRINK);
        pack_start (blink_rec_button, PACK_SHRINK);
@@ -127,7 +128,7 @@ ThemeManager::ThemeManager()
 
        if (icon_sets.size() > 1) {
                Gtkmm2ext::set_popdown_strings (icon_set_dropdown, icon_sets);
-               icon_set_dropdown.set_active_text (ARDOUR_UI::config()->get_icon_set());
+               icon_set_dropdown.set_active_text (UIConfiguration::instance().get_icon_set());
 
                hbox = Gtk::manage (new Gtk::HBox());
                hbox->set_spacing (6);
@@ -136,7 +137,7 @@ ThemeManager::ThemeManager()
                pack_start (*hbox, PACK_SHRINK);
        }
 
-       
+
        hbox = Gtk::manage (new Gtk::HBox());
        hbox->set_spacing (6);
        hbox->pack_start (waveform_gradient_depth, true, true);
@@ -155,25 +156,22 @@ ThemeManager::ThemeManager()
        palette_scroller.add (palette_viewport);
 
        modifier_scroller.add (modifier_vbox);
-       
+
        notebook.append_page (alias_scroller, _("Items"));
        notebook.append_page (palette_scroller, _("Palette"));
        notebook.append_page (modifier_scroller, _("Transparency"));
-       
+
        pack_start (notebook);
 
        show_all ();
 
        waveform_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
        timeline_item_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
-       
+
        color_dialog.get_colorsel()->set_has_opacity_control (true);
        color_dialog.get_colorsel()->set_has_palette (true);
-       
-       flat_buttons.set_active (ARDOUR_UI::config()->get_flat_buttons());
-       blink_rec_button.set_active (ARDOUR_UI::config()->get_blink_rec_arm());
-       region_color_button.set_active (ARDOUR_UI::config()->get_color_regions_using_track_color());
-       show_clipping_button.set_active (ARDOUR_UI::config()->get_show_waveform_clipping());
+
+       set_ui_to_state();
 
        color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
        color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
@@ -187,19 +185,23 @@ ThemeManager::ThemeManager()
        waveform_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_waveform_gradient_depth_change));
        timeline_item_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_timeline_item_gradient_depth_change));
        all_dialogs.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_all_dialogs_toggled));
+       transients_follow_front.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_transients_follow_front_toggled));
        icon_set_dropdown.signal_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_icon_set_changed));
 
-       Gtkmm2ext::UI::instance()->set_tip (all_dialogs, 
+       Gtkmm2ext::UI::instance()->set_tip (all_dialogs,
                                            string_compose (_("Mark all floating windows to be type \"Dialog\" rather than using \"Utility\" for some.\n"
                                                              "This may help with some window managers. This requires a restart of %1 to take effect"),
                                                            PROGRAM_NAME));
+       Gtkmm2ext::UI::instance()->set_tip (transients_follow_front,
+                                           string_compose (_("Make transient windows follow the front window when toggling between the editor and mixer.\n"
+                                                             "This requires a restart of %1 to take effect"), PROGRAM_NAME));
 
        set_size_request (-1, 400);
        /* no need to call setup_palette() here, it will be done when its size is allocated */
        setup_aliases ();
        setup_modifiers ();
-       
-       ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &ThemeManager::colors_changed));
+
+       UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ThemeManager::colors_changed));
 }
 
 ThemeManager::~ThemeManager()
@@ -209,12 +211,12 @@ ThemeManager::~ThemeManager()
 void
 ThemeManager::setup_modifiers ()
 {
-       UIConfiguration* uic (ARDOUR_UI::config());
+       UIConfiguration* uic (&UIConfiguration::instance());
        UIConfiguration::Modifiers& modifiers (uic->modifiers);
        Gtk::HBox* mod_hbox;
        Gtk::Label* mod_label;
        Gtk::HScale* mod_scale;
-       
+
        Gtkmm2ext::container_clear (modifier_vbox);
 
        for (UIConfiguration::Modifiers::const_iterator m = modifiers.begin(); m != modifiers.end(); ++m) {
@@ -229,7 +231,7 @@ ThemeManager::setup_modifiers ()
                mod_label = manage (new Label (m->first));
                mod_label->set_alignment (1.0, 0.5);
                mod_label->set_size_request (150, -1); /* 150 pixels should be enough for anyone */
-               
+
                mod_hbox->pack_start (*mod_label, false, true, 12);
                mod_hbox->pack_start (*mod_scale, true, true);
 
@@ -244,18 +246,18 @@ void
 ThemeManager::modifier_edited (Gtk::Range* range, string name)
 {
        using namespace ArdourCanvas;
-       
+
        double alpha = range->get_value();
        SVAModifier svam (SVAModifier::Assign, -1.0, -1.0, alpha);
-       ARDOUR_UI::config()->set_modifier (name, svam);
+       UIConfiguration::instance().set_modifier (name, svam);
 }
 
 void
 ThemeManager::colors_changed ()
 {
        setup_palette ();
-       setup_aliases ();       
-       setup_modifiers ();     
+       setup_aliases ();
+       setup_modifiers ();
 }
 
 int
@@ -267,7 +269,7 @@ ThemeManager::save (string /*path*/)
 void
 ThemeManager::on_flat_buttons_toggled ()
 {
-       ARDOUR_UI::config()->set_flat_buttons (flat_buttons.get_active());
+       UIConfiguration::instance().set_flat_buttons (flat_buttons.get_active());
        ArdourButton::set_flat_buttons (flat_buttons.get_active());
        /* force a redraw */
        gtk_rc_reset_styles (gtk_settings_get_default());
@@ -276,26 +278,34 @@ ThemeManager::on_flat_buttons_toggled ()
 void
 ThemeManager::on_blink_rec_arm_toggled ()
 {
-       ARDOUR_UI::config()->set_blink_rec_arm (blink_rec_button.get_active());
-       ARDOUR::Config->ParameterChanged("blink-rec-arm");
+       UIConfiguration::instance().set_blink_rec_arm (blink_rec_button.get_active());
+       UIConfiguration::instance().ParameterChanged("blink-rec-arm");
 }
 
 void
 ThemeManager::on_region_color_toggled ()
 {
-       ARDOUR_UI::config()->set_color_regions_using_track_color (region_color_button.get_active());
+       UIConfiguration::instance().set_color_regions_using_track_color (region_color_button.get_active());
 }
 
 void
 ThemeManager::on_show_clip_toggled ()
 {
-       ARDOUR_UI::config()->set_show_waveform_clipping (show_clipping_button.get_active());
+       UIConfiguration::instance().set_show_waveform_clipping (show_clipping_button.get_active());
+       // "show-waveform-clipping" was a session config key
+       ArdourCanvas::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
 }
 
 void
 ThemeManager::on_all_dialogs_toggled ()
 {
-       ARDOUR_UI::config()->set_all_floating_windows_are_dialogs (all_dialogs.get_active());
+       UIConfiguration::instance().set_all_floating_windows_are_dialogs (all_dialogs.get_active());
+}
+
+void
+ThemeManager::on_transients_follow_front_toggled ()
+{
+       UIConfiguration::instance().set_transients_follow_front (transients_follow_front.get_active());
 }
 
 void
@@ -303,7 +313,7 @@ ThemeManager::on_waveform_gradient_depth_change ()
 {
        double v = waveform_gradient_depth.get_value();
 
-       ARDOUR_UI::config()->set_waveform_gradient_depth (v);
+       UIConfiguration::instance().set_waveform_gradient_depth (v);
        ArdourCanvas::WaveView::set_global_gradient_depth (v);
 }
 
@@ -312,14 +322,14 @@ ThemeManager::on_timeline_item_gradient_depth_change ()
 {
        double v = timeline_item_gradient_depth.get_value();
 
-       ARDOUR_UI::config()->set_timeline_item_gradient_depth (v);
+       UIConfiguration::instance().set_timeline_item_gradient_depth (v);
 }
 
 void
 ThemeManager::on_icon_set_changed ()
 {
        string new_set = icon_set_dropdown.get_active_text();
-       ARDOUR_UI::config()->set_icon_set (new_set);
+       UIConfiguration::instance().set_icon_set (new_set);
 }
 
 void
@@ -327,8 +337,8 @@ ThemeManager::on_dark_theme_button_toggled()
 {
        if (!dark_button.get_active()) return;
 
-       UIConfiguration* uic (ARDOUR_UI::config());
-       
+       UIConfiguration* uic (&UIConfiguration::instance());
+
         uic->set_color_file("dark");
 }
 
@@ -337,16 +347,57 @@ ThemeManager::on_light_theme_button_toggled()
 {
        if (!light_button.get_active()) return;
 
-       UIConfiguration* uic (ARDOUR_UI::config());
-       
+       UIConfiguration* uic (&UIConfiguration::instance());
+
         uic->set_color_file("light");
 }
 
+void
+ThemeManager::set_ui_to_state()
+{
+       /* there is no way these values can change individually
+        * by themselves (w/o user-interaction)
+        * hence a common combined update function suffices
+        */
+
+       if (UIConfiguration::instance().get_color_file() == "light") {
+               light_button.set_active(true);
+       } else {
+               dark_button.set_active(true);
+       }
+
+       /* there is no need to block signal handlers, here,
+        * all elements check if the value has changed and ignore NOOPs
+        */
+       all_dialogs.set_active (UIConfiguration::instance().get_all_floating_windows_are_dialogs());
+       transients_follow_front.set_active (UIConfiguration::instance().get_transients_follow_front());
+       flat_buttons.set_active (UIConfiguration::instance().get_flat_buttons());
+       blink_rec_button.set_active (UIConfiguration::instance().get_blink_rec_arm());
+       region_color_button.set_active (UIConfiguration::instance().get_color_regions_using_track_color());
+       show_clipping_button.set_active (UIConfiguration::instance().get_show_waveform_clipping());
+       waveform_gradient_depth.set_value(UIConfiguration::instance().get_waveform_gradient_depth());
+       timeline_item_gradient_depth.set_value(UIConfiguration::instance().get_timeline_item_gradient_depth());
+}
+
 void
 ThemeManager::reset_canvas_colors()
 {
-       ARDOUR_UI::config()->load_defaults();
-       ARDOUR_UI::config()->save_state ();
+       string cfile;
+       string basename;
+
+       basename = "my-";
+       basename += UIConfiguration::instance().get_color_file();
+       basename += ".colors";
+
+       if (find_file (ardour_config_search_path(), basename, cfile)) {
+               string backup = cfile + string (X_(".old"));
+               g_rename (cfile.c_str(), backup.c_str());
+               /* don't really care if it fails */
+       }
+
+       UIConfiguration::instance().load_defaults();
+       UIConfiguration::instance().save_state ();
+       set_ui_to_state();
 }
 
 ArdourCanvas::Container*
@@ -358,7 +409,7 @@ ThemeManager::initialize_palette_canvas (ArdourCanvas::Canvas& canvas)
        canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 0.0));
 
        /* bi-directional scroll group */
-       
+
        ScrollGroup* scroll_group = new ScrollGroup (canvas.root(), ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
        canvas.add_scroller (*scroll_group);
 
@@ -401,14 +452,14 @@ ThemeManager::build_palette_canvas (ArdourCanvas::Canvas& canvas, ArdourCanvas::
 
        /* we want the colors sorted by hue, with their name */
 
-       UIConfiguration::Colors& colors (ARDOUR_UI::config()->colors);
+       UIConfiguration::Colors& colors (UIConfiguration::instance().colors);
        vector<NamedColor> nc;
        for (UIConfiguration::Colors::const_iterator x = colors.begin(); x != colors.end(); ++x) {
                nc.push_back (NamedColor (x->first, HSV (x->second)));
        }
        SortByHue sorter;
        sort (nc.begin(), nc.end(), sorter);
-       
+
        const uint32_t color_limit = nc.size();
        const double box_size = 20.0;
        const double width = canvas.width();
@@ -417,9 +468,9 @@ ThemeManager::build_palette_canvas (ArdourCanvas::Canvas& canvas, ArdourCanvas::
        uint32_t color_num = 0;
 
        /* clear existing rects and delete them */
-       
+
        group.clear (true);
-       
+
        for (uint32_t y = 0; y < height - box_size && color_num < color_limit; y += box_size) {
                for (uint32_t x = 0; x < width - box_size && color_num < color_limit; x += box_size) {
                        ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (&group, ArdourCanvas::Rect (x, y, x + box_size, y + box_size));
@@ -442,7 +493,7 @@ ThemeManager::build_palette_canvas (ArdourCanvas::Canvas& canvas, ArdourCanvas::
 void
 ThemeManager::palette_size_request (Gtk::Requisition* req)
 {
-       uint32_t ncolors = ARDOUR_UI::config()->colors.size();
+       uint32_t ncolors = UIConfiguration::instance().colors.size();
        const int box_size = 20;
 
        double c = sqrt ((double)ncolors);
@@ -450,7 +501,7 @@ ThemeManager::palette_size_request (Gtk::Requisition* req)
        req->height = (int) floor (c * box_size);
 
        /* add overflow row if necessary */
-       
+
        if (fmod (ncolors, c) != 0.0) {
                req->height += box_size;
        }
@@ -480,7 +531,7 @@ ThemeManager::edit_palette_color (std::string name)
 {
        using namespace ArdourCanvas;
        double r,g, b, a;
-       UIConfiguration* uic (ARDOUR_UI::config());
+       UIConfiguration* uic (&UIConfiguration::instance());
        ArdourCanvas::Color c = uic->color (name);
        Gdk::Color gdkcolor;
 
@@ -503,8 +554,8 @@ ThemeManager::palette_color_response (int result, std::string name)
        using namespace ArdourCanvas;
 
        color_dialog_connection.disconnect ();
-       
-       UIConfiguration* uic (ARDOUR_UI::config());
+
+       UIConfiguration* uic (&UIConfiguration::instance());
        Gdk::Color gdkcolor;
        double r,g, b, a;
 
@@ -516,10 +567,10 @@ ThemeManager::palette_color_response (int result, std::string name)
                r = gdkcolor.get_red_p();
                g = gdkcolor.get_green_p();
                b = gdkcolor.get_blue_p();
-               
+
                uic->set_color (name, rgba_to_color (r, g, b, a));
                break;
-               
+
        default:
                break;
        }
@@ -532,7 +583,7 @@ ThemeManager::alias_palette_event (GdkEvent* ev, string new_alias, string target
 {
        switch (ev->type) {
        case GDK_BUTTON_RELEASE:
-               ARDOUR_UI::config()->set_alias (target_name, new_alias);
+               UIConfiguration::instance().set_alias (target_name, new_alias);
                return true;
                break;
        default:
@@ -553,7 +604,7 @@ ThemeManager::alias_palette_response (int response, std::string target_name, std
 
        case GTK_RESPONSE_REJECT:
                /* revert choice */
-               ARDOUR_UI::config()->set_alias (target_name, old_alias);
+               UIConfiguration::instance().set_alias (target_name, old_alias);
                break;
 
        default:
@@ -567,7 +618,7 @@ ThemeManager::alias_palette_response (int response, std::string target_name, std
 void
 ThemeManager::choose_color_from_palette (string const & name)
 {
-       UIConfiguration* uic (ARDOUR_UI::config());
+       UIConfiguration* uic (&UIConfiguration::instance());
        UIConfiguration::ColorAliases::iterator i = uic->color_aliases.find (name);
 
        if (i == uic->color_aliases.end()) {
@@ -579,14 +630,14 @@ ThemeManager::choose_color_from_palette (string const & name)
        palette_window = new ArdourDialog (_("Color Palette"));
        palette_window->add_button (Stock::CANCEL, RESPONSE_REJECT); /* using CANCEL causes confusion if dialog is closed via CloseAllDialogs */
        palette_window->add_button (Stock::OK, RESPONSE_OK);
-       
+
        ArdourCanvas::GtkCanvas* canvas = new ArdourCanvas::GtkCanvas ();
        ArdourCanvas::Container* group = initialize_palette_canvas (*canvas);
-       
+
        canvas->signal_size_request().connect (sigc::mem_fun (*this, &ThemeManager::palette_size_request));
        canvas->signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), group, canvas,
                                                            sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_event), name)));
-       
+
        palette_window->get_vbox()->pack_start (*canvas);
        palette_window->show_all ();
 
@@ -600,8 +651,8 @@ void
 ThemeManager::setup_aliases ()
 {
        using namespace ArdourCanvas;
-       
-       UIConfiguration* uic (ARDOUR_UI::config());
+
+       UIConfiguration* uic (&UIConfiguration::instance());
        UIConfiguration::ColorAliases& aliases (uic->color_aliases);
 
        alias_list->clear ();
@@ -614,7 +665,7 @@ ThemeManager::setup_aliases ()
                if ((colon = i->first.find (':')) != string::npos) {
 
                        /* this is supposed to be a child node, so find the
-                        * parent 
+                        * parent
                         */
 
                        string parent = i->first.substr (0, colon);
@@ -632,7 +683,7 @@ ThemeManager::setup_aliases ()
                                row = *(alias_list->append());
                                row[alias_columns.name] = parent;
                                row[alias_columns.alias] = "";
-                               
+
                                /* now add the child as a child of this one */
 
                                row = *(alias_list->insert (row->children().end()));