enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / color_theme_manager.cc
index b7dc9b303ac8de6c4987ee16e17b95e6176574f4..e038493c96ce57216317a8625d237293fd1dcd95 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
@@ -27,8 +27,9 @@
 #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"
@@ -45,7 +46,7 @@
 #include "ui_config.h"
 #include "utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace Gtk;
@@ -70,19 +71,30 @@ ColorThemeManager::ColorThemeManager ()
                theme_list = TreeStore::create (color_theme_columns);
 
                TreeModel::iterator selected_iter = theme_list->children().end();
+               const bool running_from_source = running_from_source_tree();
 
                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;
-                       row[color_theme_columns.path] = c->second;
+
+                       string color_file_name = c->second;
+
+                       if (running_from_source) {
+                               /* color themes from within the source tree are
+                                  suffixed by "-PROGRAM-NAME" (lowercased)
+                               */
+                               replace_all (color_file_name, string_compose ("-%1", downcase (PROGRAM_NAME)), "");
+                       }
+
+                       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() == c->second) {
+                       if (UIConfiguration::instance().get_color_file() == color_file_name) {
                                selected_iter = row;
                        }
                }
@@ -131,7 +143,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);
@@ -219,7 +231,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, false, true);
 
        if (find_file (ardour_config_search_path(), basename, cfile)) {
                string backup = cfile + string (X_(".old"));
@@ -227,7 +241,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 ();
 }
 
@@ -614,4 +628,3 @@ ColorThemeManager::on_color_theme_changed ()
                }
        }
 }
-