From 1084a12e8a204f87b02aca0d21aad2054656f917 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 31 Jan 2009 16:31:15 +0000 Subject: [PATCH] Added theme icons support, and a New Window menu command --- src/gui/window-manager.cpp | 73 +++++++++++++++++++------- src/gui/window-manager.hpp | 28 +++++++++- src/gui/workspace/actions.cpp | 10 ++++ src/gui/workspace/actions.hpp | 1 + src/gui/workspace/workspace-window.cpp | 2 + 5 files changed, 94 insertions(+), 20 deletions(-) diff --git a/src/gui/window-manager.cpp b/src/gui/window-manager.cpp index c227d4b5d..663ac3002 100644 --- a/src/gui/window-manager.cpp +++ b/src/gui/window-manager.cpp @@ -93,6 +93,8 @@ WindowManager::register_stock_items() add_stock_icon_set(factory, "panel-timeline", "panel_timeline", _("_Timeline")); add_stock_icon_set(factory, "panel-viewer", "panel_viewer", _("_Viewer")); + add_stock_icon_set(factory, "window-new", "new_window", _("New _Window")); + add_stock_icon_set(factory, "tool-arrow", "tool_arrow", _("_Arrow")); add_stock_icon_set(factory, "tool-i-beam", "tool_i_beam", _("_I-Beam")); @@ -144,14 +146,19 @@ WindowManager::add_stock_icon_set( bool WindowManager::add_stock_icon(Gtk::IconSet &icon_set, const Glib::ustring& icon_name, Gtk::IconSize size, bool wildcard) -{ +{ + // Try the icon theme + if(add_theme_icon_source(icon_set, icon_name, size, wildcard)) + return true; + // Try the ~/.lumiera/icons folder - if(add_stock_icon_source(icon_set, ustring::compose("%1/%2", + if(add_non_theme_icon_source(icon_set, ustring::compose("%1/%2", GtkLumiera::get_home_data_path(), ustring("icons")), icon_name, size, wildcard)) return true; - if(add_stock_icon_source( + // Try the local directory + if(add_non_theme_icon_source( icon_set, get_current_dir(), icon_name, size, wildcard)) return true; @@ -159,38 +166,68 @@ WindowManager::add_stock_icon(Gtk::IconSet &icon_set, } bool -WindowManager::add_stock_icon_source(Gtk::IconSet &icon_set, - const Glib::ustring& base_dir, const Glib::ustring& icon_name, - Gtk::IconSize size, bool wildcard) +WindowManager::add_theme_icon_source(Gtk::IconSet &icon_set, + const Glib::ustring& icon_name, Gtk::IconSize size, bool wildcard) { - ustring path; - Gtk::IconSource source; - + // Get the size int width = 0, height = 0; if(!IconSize::lookup(size, width, height)) return false; + REQUIRE(width > 0); + + // Try to load the icon + RefPtr theme = Gtk::IconTheme::get_default(); + REQUIRE(theme); + const IconInfo info = theme->lookup_icon(icon_name, width, + (IconLookupFlags)0); + if(info) + { + const ustring path(info.get_filename()); + if(add_stock_icon_from_path(path, icon_set, size, wildcard)) + return true; + } + + return false; +} + +bool +WindowManager::add_non_theme_icon_source(Gtk::IconSet &icon_set, + const Glib::ustring& base_dir, const Glib::ustring& icon_name, + Gtk::IconSize size, bool wildcard) +{ + // Get the size + int width = 0, height = 0; + if(!IconSize::lookup(size, width, height)) + return false; + REQUIRE(width > 0); + + // Try to load the icon + const ustring path(ustring::compose("%1/%2x%3/%4.png", + base_dir, width, height, icon_name)); + return add_stock_icon_from_path(path, icon_set, size, wildcard); +} + +bool +WindowManager::add_stock_icon_from_path(Glib::ustring path, + Gtk::IconSet &icon_set, Gtk::IconSize size, bool wildcard) +{ + Gtk::IconSource source; try - { - ustring path = ustring::compose("%1/%2x%3/%4.png", - base_dir, width, height, icon_name); - - INFO(gui, "Attempting to load icon: %s", path.c_str()); - + { // This throws an exception if the file is not found: source.set_pixbuf(Gdk::Pixbuf::create_from_file(path)); } catch(const Glib::Exception& ex) { - INFO(gui, "Failed to load icon: %s", path.c_str()); return false; } - + source.set_size(size); source.set_size_wildcarded(wildcard); icon_set.add_source(source); - + return true; } diff --git a/src/gui/window-manager.hpp b/src/gui/window-manager.hpp index 64783d250..66fd4b71f 100644 --- a/src/gui/window-manager.hpp +++ b/src/gui/window-manager.hpp @@ -103,9 +103,21 @@ private: **/ static bool add_stock_icon(Gtk::IconSet &icon_set, const Glib::ustring& icon_name, Gtk::IconSize size, bool wildcard); + + /** + * Loads an icon from a the icon theme + * @param icon_set The icon set to add the icon to. + * @param icon_name The name of the icon to load. + * @param size The size of the icon to load. + * @param wildcard This value is set to true if this icon is + * wildcarded. + * @return Returns true if the icon was loaded successfully. + **/ + static bool add_theme_icon_source(Gtk::IconSet &icon_set, + const Glib::ustring& icon_name, Gtk::IconSize size, bool wildcard); /** - * Loads an icon from a specific path and adds it to an icon set. + * Loads an icon from a non theme set. * @param icon_set The icon set to add the icon to. * @param base_dir The root icons directory to load from. * @param icon_name The file name of the icon to load. @@ -114,9 +126,21 @@ private: * wildcarded. * @return Returns true if the icon was loaded successfully. **/ - static bool add_stock_icon_source(Gtk::IconSet &icon_set, + static bool add_non_theme_icon_source(Gtk::IconSet &icon_set, const Glib::ustring& base_dir, const Glib::ustring& icon_name, Gtk::IconSize size, bool wildcard); + + /** + * Loads an icon from a specific path and adds it to an icon set. + * @param path The path to load from. + * @param icon_set The icon set to add the icon to. + * @param size The size of the icon to load. + * @param wildcard This value is set to true if this icon is + * wildcarded. + * @return Returns true if the icon was loaded successfully. + **/ + static bool add_stock_icon_from_path(Glib::ustring path, + Gtk::IconSet &icon_set, Gtk::IconSize size, bool wildcard); public: diff --git a/src/gui/workspace/actions.cpp b/src/gui/workspace/actions.cpp index 4ed0a18a3..fa89310d5 100644 --- a/src/gui/workspace/actions.cpp +++ b/src/gui/workspace/actions.cpp @@ -88,6 +88,10 @@ Actions::Actions(WorkspaceWindow &workspace_window) : sigc::mem_fun(*this, &Actions::on_menu_view_viewer)); actionGroup->add(viewerPanelAction); + actionGroup->add(Action::create("ViewNewWindow", + Gtk::StockID("new_window")), + sigc::mem_fun(*this, &Actions::on_menu_view_new_window)); + // Sequence Menu actionGroup->add(Action::create("SequenceMenu", _("_Sequence"))); actionGroup->add(Action::create("SequenceAdd", _("_Add...")), @@ -181,6 +185,12 @@ Actions::on_menu_view_viewer() workspaceWindow.viewerPanel->show(viewerPanelAction->get_active()); } +void +Actions::on_menu_view_new_window() +{ + g_message("New Window"); +} + /* ===== Sequence Menu Event Handlers ===== */ void diff --git a/src/gui/workspace/actions.hpp b/src/gui/workspace/actions.hpp index a11b58cfd..eb995fc02 100644 --- a/src/gui/workspace/actions.hpp +++ b/src/gui/workspace/actions.hpp @@ -69,6 +69,7 @@ private: void on_menu_view_resources(); void on_menu_view_timeline(); void on_menu_view_viewer(); + void on_menu_view_new_window(); void on_menu_sequence_add(); diff --git a/src/gui/workspace/workspace-window.cpp b/src/gui/workspace/workspace-window.cpp index 0fe2d8377..d79008367 100644 --- a/src/gui/workspace/workspace-window.cpp +++ b/src/gui/workspace/workspace-window.cpp @@ -120,6 +120,8 @@ WorkspaceWindow::create_ui() " " " " " " + " " + " " " " " " " "