From d1ede5d14574fe06e49e2fa3054c4ece7aab9b38 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 21 Jul 2018 17:34:37 +0200 Subject: Working on themes --- src/helper/icon-loader.cpp | 24 +++++++++++- src/helper/icon-loader.h | 5 ++- src/inkscape.cpp | 2 +- src/io/resource.cpp | 69 +++++++++++++++++++++++++++++++++- src/io/resource.h | 13 +++++++ src/preferences-skeleton.h | 2 +- src/ui/dialog/inkscape-preferences.cpp | 12 +++--- src/ui/dialog/inkscape-preferences.h | 2 +- src/ui/interface.cpp | 2 +- 9 files changed, 116 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/helper/icon-loader.cpp b/src/helper/icon-loader.cpp index b19b19582..3a7d459b3 100644 --- a/src/helper/icon-loader.cpp +++ b/src/helper/icon-loader.cpp @@ -21,6 +21,7 @@ #include "widgets/toolbox.h" #include #include +#include Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, gint size) { @@ -45,7 +46,10 @@ Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, gint size) icon_name = "preferences-system"; } sp_svg_write_color(colornamed, sizeof(colornamed), prefs->getInt("/theme/symbolicColor", - 0x000000ff)); Gdk::RGBA color; color.set(colornamed); Gtk::IconInfo iconinfo = + 0x000000ff)); + Gdk::RGBA color; + color.set(colornamed); + Gtk::IconInfo iconinfo = iconTheme->lookup_icon(icon_name + Glib::ustring("-symbolic"), size, Gtk::ICON_LOOKUP_FORCE_SIZE); if (bool(iconinfo)) { @@ -119,6 +123,24 @@ Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_size) return image; } +std::pair, Gdk::RGBA > sp_set_radioaction_icon(Gtk::RadioAction::Group group, Glib::ustring icon_name, Glib::ustring label, Glib::ustring tooltip) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/theme/symbolicIcons", false)) { + icon_name = icon_name + Glib::ustring("-symbolic"); + } + + Glib::RefPtr action = + Gtk::RadioAction::create_with_icon_name (group, "Anonymous", icon_name.c_str(), label.c_str(), tooltip.c_str()); + Gtk::ToolItem* item = action->create_tool_item(); + Gdk::RGBA color; + gchar colornamed[64]; + sp_svg_write_color(colornamed, sizeof(colornamed), prefs->getInt("/theme/symbolicColor", + 0x000000ff)); + color.set(colornamed); + return std::make_pair(action, color); +} + /* Local Variables: mode:c++ diff --git a/src/helper/icon-loader.h b/src/helper/icon-loader.h index 5b6af546f..ef7dbd110 100644 --- a/src/helper/icon-loader.h +++ b/src/helper/icon-loader.h @@ -12,6 +12,9 @@ */ #include #include +#include +#include +#include Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, gint size); Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size); @@ -21,5 +24,5 @@ Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gint size); Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_sice); Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_sice); Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_sice); - +std::pair,Gdk::RGBA > sp_set_radioaction_icon(Gtk::RadioAction::Group group, Glib::ustring icon_name, Glib::ustring label, Glib::ustring tooltip); #endif // SEEN_INK_STOCK_ITEMS_H diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 2fb11444e..59f503bf7 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -479,7 +479,7 @@ Application::Application(const char* argv, bool use_gui) : /* Load the preferences and menus */ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - g_object_set (gtk_settings_get_default (), "gtk-theme-name", prefs->getString("/theme/theme").c_str(), NULL); + g_object_set (gtk_settings_get_default (), "gtk-theme-name", prefs->getString("/theme/gtkTheme").c_str(), NULL); g_object_set (gtk_settings_get_default (), "gtk-application-prefer-dark-theme", prefs->getBool("/theme/darkTheme", false), NULL); InkErrorHandler* handler = new InkErrorHandler(use_gui); prefs->setErrorHandler(handler); diff --git a/src/io/resource.cpp b/src/io/resource.cpp index f8cf9fce4..127b92b76 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -213,7 +213,6 @@ Glib::ustring get_filename(Glib::ustring path, Glib::ustring filename) * * domain - Optional domain (overload), will check return domains if not. * type - The type of files, e.g. TEMPLATES - * path - Instead of Domain and Type, specify the path to get the files from. * extensions - A list of extensions to return, e.g. xml, svg * exclusions - A list of names to exclude e.g. default.xml */ @@ -225,6 +224,7 @@ std::vector get_filenames(Type type, std::vector ex get_filenames_from_path(ret, get_path_ustring(CREATE, type), extensions, exclusions); return ret; } + std::vector get_filenames(Domain domain, Type type, std::vector extensions, std::vector exclusions) { std::vector ret; @@ -238,10 +238,41 @@ std::vector get_filenames(Glib::ustring path, std::vector get_foldernames(Type type, std::vector exclusions) +{ + std::vector ret; + get_foldernames_from_path(ret, get_path_ustring(USER, type), exclusions); + get_foldernames_from_path(ret, get_path_ustring(SYSTEM, type), exclusions); + get_foldernames_from_path(ret, get_path_ustring(CREATE, type), exclusions); + return ret; +} + +std::vector get_foldernames(Domain domain, Type type, std::vector exclusions) +{ + std::vector ret; + get_foldernames_from_path(ret, get_path_ustring(domain, type), exclusions); + return ret; +} +std::vector get_foldernames(Glib::ustring path, std::vector exclusions) +{ + std::vector ret; + get_foldernames_from_path(ret, path, exclusions); + return ret; +} + + /* * Get all the files from a specific path and any sub-dirs, populating &files vector * - * &files - Output list to populate, will be opoulated with full paths + * &files - Output list to populate, will be poulated with full paths * path - The directory to parse, will add nothing if directory doesn't exist * extensions - Only add files with these extensions, they must be duplicated * exclusions - Exclude files that exactly match these names. @@ -280,6 +311,40 @@ void get_filenames_from_path(std::vector &files, Glib::ustring pa } } +/* + * Get all the files from a specific path and any sub-dirs, populating &files vector + * + * &folders - Output list to populate, will be poulated with full paths + * path - The directory to parse, will add nothing if directory doesn't exist + * exclusions - Exclude files that exactly match these names. + */ +void get_foldernames_from_path(std::vector &folders, Glib::ustring path, std::vector exclusions) +{ + if(!Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) { + return; + } + + Glib::Dir dir(path); + std::string file = dir.read_name(); + while (!file.empty()){ + // If not extensions are specified, don't reject ANY files. + bool reject = false; + + // Reject any file which matches the exclusions. + for (auto &exc: exclusions) { + reject |= Glib::str_has_prefix(file, exc); + } + + // Reject any filename which isn't a regular file + Glib::ustring filename = Glib::build_filename(path, file); + + if(Glib::file_test(filename, Glib::FILE_TEST_IS_DIR) && !reject) { + folders.push_back(filename); + } + file = dir.read_name(); + } +} + /** * Get, or guess, or decide the location where the preferences.xml diff --git a/src/io/resource.h b/src/io/resource.h index dae43ec8f..f70e55447 100644 --- a/src/io/resource.h +++ b/src/io/resource.h @@ -79,11 +79,24 @@ std::vector get_filenames(Glib::ustring path, std::vector extensions={}, std::vector exclusions={}); +std::vector get_foldernames(Type type, + std::vector exclusions={}); + +std::vector get_foldernames(Domain domain, Type type, + std::vector exclusions={}); + +std::vector get_foldernames(Glib::ustring path, + std::vector exclusions={}); + void get_filenames_from_path(std::vector &files, Glib::ustring path, std::vector extensions={}, std::vector exclusions={}); +void get_foldernames_from_path(std::vector &files, + Glib::ustring path, + std::vector exclusions={}); + char *profile_path(const char *filename); char *homedir_path(const char *filename); diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index 2bff8d634..2a6083e55 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -73,7 +73,7 @@ static char const preferences_skeleton[] = " inkscape:window-height=\"480\" />\n" " \n" " \n" +" gtkTheme=\"Adwaita\" iconTheme=\"hicolor\" symbolicIcons=\"0\" darkTheme=\"0\" symbolicColor=\"0x000000ff\" >\n" " \n" "\n" " labels; std::vector values; for(auto &filename: files) { @@ -836,6 +832,8 @@ void InkscapePreferences::initPageUI() labels.push_back(filename); values.push_back(filename); } + labels.erase(unique(labels.begin(), labels.end()), labels.end()); + values.erase(unique(values.begin(), values.end()), values.end()); _icon_theme.init("/theme/iconTheme", labels, values, "hicolor"); _page_theme.add_line(false, _("Change icon theme:"), _icon_theme, "", "", false); } diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index f705d8e29..d172687fa 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -240,7 +240,7 @@ protected: UI::Widget::PrefCheckButton _t_node_delete_preserves_shape; UI::Widget::PrefColorPicker _t_node_pathoutline_color; - UI::Widget::PrefCombo _theme; + UI::Widget::PrefCombo _gtk_theme; UI::Widget::PrefCombo _icon_theme; UI::Widget::PrefCheckButton _dark_theme; UI::Widget::PrefCheckButton _symbolic_icons; diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 9f5d2d38c..89f2c3d8a 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -269,7 +269,7 @@ sp_ui_reload() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int window_geometry = prefs->getInt("/options/savewindowgeometry/value", PREFS_WINDOW_GEOMETRY_NONE); - g_object_set (gtk_settings_get_default (), "gtk-theme-name", prefs->getString("/theme/theme").c_str(), NULL); + g_object_set (gtk_settings_get_default (), "gtk-theme-name", prefs->getString("/theme/gtkTheme").c_str(), NULL); g_object_set (gtk_settings_get_default (), "gtk-application-prefer-dark-theme", prefs->getBool("/theme/darkTheme", false), NULL); prefs->setInt("/options/savewindowgeometry/value", PREFS_WINDOW_GEOMETRY_LAST); prefs->save(); -- cgit v1.2.3