add nascent poly-phonic pressure to automation menu for MIDI tracks
[ardour.git] / gtk2_ardour / color_theme_manager.cc
index c3d0765726ae88626cfbd1ffe4d099eacb0b49c9..be0278ef9b4746779f0552f879c2511aba708b43 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000-2007 Paul Davis
+    Copyright (C) 2000-2016 Paul Davis
 
     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
 
 #include "pbd/gstdio_compat.h"
 
-#include <gtkmm/stock.h>
-#include <gtkmm/settings.h>
-
-#include "gtkmm2ext/gtk_ui.h"
 #include "gtkmm2ext/cell_renderer_color_selector.h"
 #include "gtkmm2ext/utils.h"
 
-#include "pbd/file_utils.h"
 #include "pbd/compose.h"
+#include "pbd/file_utils.h"
+#include "pbd/replace_all.h"
 
 #include "ardour/filesystem_paths.h"
 #include "ardour/profile.h"
@@ -49,7 +46,7 @@
 #include "ui_config.h"
 #include "utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace Gtk;
@@ -62,7 +59,56 @@ ColorThemeManager::ColorThemeManager ()
        , palette_viewport (*palette_scroller.get_hadjustment(), *palette_scroller.get_vadjustment())
        , palette_group (0)
        , palette_window (0)
+       , color_theme_label (_("Color Theme"))
 {
+       set_spacing (12);
+
+       std::map<string,string> color_themes;
+
+       get_color_themes (color_themes);
+
+       if (color_themes.size() > 1) {
+               theme_list = TreeStore::create (color_theme_columns);
+
+               TreeModel::iterator selected_iter = theme_list->children().end();
+
+               for (std::map<string,string>::iterator c = color_themes.begin(); c != color_themes.end(); ++c) {
+                       TreeModel::Row row;
+
+                       row = *(theme_list->append());
+                       row[color_theme_columns.name] = c->first;
+
+                       string color_file_name = c->second;
+
+                       row[color_theme_columns.path] = color_file_name;
+
+                       /* match second (path; really basename) since that is
+                          what we store/restore.
+                       */
+
+                       if (UIConfiguration::instance().get_color_file() == color_file_name) {
+                               selected_iter = row;
+                       }
+               }
+
+               color_theme_dropdown.set_model (theme_list);
+               color_theme_dropdown.pack_start (color_theme_columns.name);
+
+               if (selected_iter != theme_list->children().end()) {
+                       color_theme_dropdown.set_active (selected_iter);
+               }
+
+               Gtk::HBox* hbox = Gtk::manage (new Gtk::HBox());
+               Gtk::Alignment* align = Gtk::manage (new Gtk::Alignment);
+               align->set (0, 0.5);
+               align->add (color_theme_dropdown);
+               hbox->set_spacing (6);
+               hbox->pack_start (color_theme_label, false, false);
+               hbox->pack_start (*align, true, true);
+               pack_start (*hbox, PACK_SHRINK);
+               hbox->show_all ();
+       }
+
        reset_button.signal_clicked().connect (sigc::mem_fun (*this, &ColorThemeManager::reset_canvas_colors));
 
        /* Now the alias list */
@@ -89,7 +135,7 @@ ColorThemeManager::ColorThemeManager ()
 
        palette_group = initialize_palette_canvas (*palette_viewport.canvas());
        palette_viewport.signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ColorThemeManager::palette_canvas_allocated), palette_group, palette_viewport.canvas(),
-                                                                    sigc::mem_fun (*this, &ColorThemeManager::palette_event)));
+                                                                    sigc::mem_fun (*this, &ColorThemeManager::palette_event)));
        palette_scroller.add (palette_viewport);
 
        modifier_scroller.add (modifier_vbox);
@@ -100,9 +146,15 @@ ColorThemeManager::ColorThemeManager ()
 
        notebook.set_size_request (400, 400);
 
-       set_spacing (12);
-       pack_start (reset_button, false, false);
        pack_start (notebook, true, true);
+       pack_start (reset_button, false, false);
+
+       color_dialog.get_colorsel()->set_has_opacity_control (true);
+       color_dialog.get_colorsel()->set_has_palette (true);
+       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));
+
+       color_theme_dropdown.signal_changed().connect (sigc::mem_fun (*this, &ColorThemeManager::on_color_theme_changed));
 
        /* no need to call setup_palette() here, it will be done when its size is allocated */
        setup_aliases ();
@@ -171,7 +223,9 @@ ColorThemeManager::reset_canvas_colors()
        string cfile;
        string basename;
 
-       basename = UIConfiguration::instance().color_file_name (true, true, true);
+       /* look for a versioned user-owned color file, and try to rename it */
+
+       basename = UIConfiguration::instance().color_file_name (true, true);
 
        if (find_file (ardour_config_search_path(), basename, cfile)) {
                string backup = cfile + string (X_(".old"));
@@ -179,7 +233,7 @@ ColorThemeManager::reset_canvas_colors()
                /* don't really care if it fails */
        }
 
-       UIConfiguration::instance().load_defaults();
+       UIConfiguration::instance().load_color_theme (false);
        UIConfiguration::instance().save_state ();
 }
 
@@ -551,3 +605,18 @@ ColorThemeManager::tip_widget()
 {
        return reset_button; /* XXX need a better widget for this purpose */
 }
+
+void
+ColorThemeManager::on_color_theme_changed ()
+{
+       Gtk::TreeModel::iterator iter = color_theme_dropdown.get_active();
+
+       if (iter) {
+               Gtk::TreeModel::Row row = *iter;
+
+               if (row) {
+                       string new_theme = row[color_theme_columns.path];
+                       UIConfiguration::instance().set_color_file (new_theme);
+               }
+       }
+}