diff --git a/src/gui/workspace/actions.cpp b/src/gui/workspace/actions.cpp index 8ee8fc9b6..38cc5588b 100644 --- a/src/gui/workspace/actions.cpp +++ b/src/gui/workspace/actions.cpp @@ -31,6 +31,8 @@ #include "../model/project.hpp" +#include "include/logging.h" + using namespace Gtk; using namespace Glib; using namespace sigc; @@ -44,72 +46,161 @@ Actions::Actions(WorkspaceWindow &workspace_window) : is_updating_action_state(false) { workspace_window.signal_show ().connect_notify(mem_fun(this, &Actions::update_action_state)); +} +void +Actions::populate_main_actions(RefPtr uiManager) +{ + REQUIRE(uiManager); + //----- Create the Action Group -----// actionGroup = ActionGroup::create(); // File menu actionGroup->add(Action::create("FileMenu", _("_File"))); actionGroup->add(Action::create("FileNewProject", Stock::NEW, _("_New Project...")), - sigc::mem_fun(*this, &Actions::on_menu_file_new_project)); + mem_fun(*this, &Actions::on_menu_file_new_project)); actionGroup->add(Action::create("FileOpenProject", Stock::OPEN, _("_Open Project...")), - sigc::mem_fun(*this, &Actions::on_menu_file_open_project)); + mem_fun(*this, &Actions::on_menu_file_open_project)); actionGroup->add(Action::create("FileRender", _("_Render...")), - Gtk::AccelKey("R"), - sigc::mem_fun(*this, &Actions::on_menu_file_render)); + AccelKey("R"), + mem_fun(*this, &Actions::on_menu_file_render)); actionGroup->add(Action::create("FileQuit", Stock::QUIT), - sigc::mem_fun(*this, &Actions::on_menu_file_quit)); + mem_fun(*this, &Actions::on_menu_file_quit)); // Edit menu actionGroup->add(Action::create("EditMenu", _("_Edit"))); actionGroup->add(Action::create("EditCopy", Stock::COPY), - sigc::mem_fun(*this, &Actions::on_menu_others)); + mem_fun(*this, &Actions::on_menu_others)); actionGroup->add(Action::create("EditPaste", Stock::PASTE), - sigc::mem_fun(*this, &Actions::on_menu_others)); + mem_fun(*this, &Actions::on_menu_others)); actionGroup->add(Action::create("EditPreferences", Stock::PREFERENCES), - sigc::mem_fun(*this, &Actions::on_menu_edit_preferences)); + mem_fun(*this, &Actions::on_menu_edit_preferences)); // View Menu actionGroup->add(Action::create("ViewMenu", _("_View"))); assetsPanelAction = ToggleAction::create("ViewResources", - Gtk::StockID("panel_resources")); + StockID("panel_resources")); assetsPanelAction->signal_toggled().connect( - sigc::mem_fun(*this, &Actions::on_menu_view_resources)); + mem_fun(*this, &Actions::on_menu_view_resources)); actionGroup->add(assetsPanelAction); timelinePanelAction = ToggleAction::create("ViewTimeline", - Gtk::StockID("panel_timeline")); + StockID("panel_timeline")); timelinePanelAction->signal_toggled().connect( - sigc::mem_fun(*this, &Actions::on_menu_view_timeline)); + mem_fun(*this, &Actions::on_menu_view_timeline)); actionGroup->add(timelinePanelAction); viewerPanelAction = ToggleAction::create("ViewViewer", - Gtk::StockID("panel_viewer")); + StockID("panel_viewer")); viewerPanelAction->signal_toggled().connect( - sigc::mem_fun(*this, &Actions::on_menu_view_viewer)); + mem_fun(*this, &Actions::on_menu_view_viewer)); actionGroup->add(viewerPanelAction); // Sequence Menu actionGroup->add(Action::create("SequenceMenu", _("_Sequence"))); actionGroup->add(Action::create("SequenceAdd", _("_Add...")), - sigc::mem_fun(*this, &Actions::on_menu_sequence_add)); + mem_fun(*this, &Actions::on_menu_sequence_add)); // Track Menu actionGroup->add(Action::create("TrackMenu", _("_Track"))); actionGroup->add(Action::create("TrackAdd", _("_Add...")), - sigc::mem_fun(*this, &Actions::on_menu_track_add)); + mem_fun(*this, &Actions::on_menu_track_add)); // Window Menu actionGroup->add(Action::create("WindowMenu", _("_Window"))); actionGroup->add(Action::create("WindowNewWindow", - Gtk::StockID("new_window")), - sigc::mem_fun(*this, &Actions::on_menu_window_new_window)); + StockID("new_window")), + mem_fun(*this, &Actions::on_menu_window_new_window)); + actionGroup->add(Action::create("WindowShowPanel", _("_Show Panel"))); // Help Menu actionGroup->add(Action::create("HelpMenu", _("_Help")) ); actionGroup->add(Action::create("HelpAbout", Stock::ABOUT), - sigc::mem_fun(*this, &Actions::on_menu_help_about) ); + mem_fun(*this, &Actions::on_menu_help_about) ); + + uiManager->insert_action_group(actionGroup); + + //----- Create the UI layout -----// + Glib::ustring ui_info = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + + try + { + uiManager->add_ui_from_string(ui_info); + } + catch(const Glib::Error& ex) + { + ERROR(gui, "Building menus failed: %s", ex.what().data()); + return; + } + + //----- Add Extra Actions -----// + populate_show_panel_actions(uiManager); +} + +void +Actions::populate_show_panel_actions(RefPtr uiManager) +{ + const int count = PanelManager::get_panel_description_count(); + + RefPtr actionGroup = ActionGroup::create(); + for(int i = 0; i < count; i++) + { + const gchar *stock_id = PanelManager::get_panel_stock_id(i); + const ustring name = ustring::compose("Panel%1", i); + actionGroup->add(Action::create(name, StockID(stock_id)), + bind(mem_fun(*this, &Actions::on_menu_show_panel), i)); + } + + uiManager->insert_action_group(actionGroup); + + for(int i = 0; i < count; i++) + { + const ustring name = ustring::compose("Panel%1", i); + uiManager->add_ui(uiManager->new_merge_id(), + "/MenuBar/WindowMenu/WindowShowPanel", name, name); + } } void @@ -215,8 +306,15 @@ Actions::on_menu_track_add() void Actions::on_menu_window_new_window() { - application().get_window_manager().new_window(workspaceWindow.project, - workspaceWindow.controller); + application().get_window_manager().new_window( + workspaceWindow.get_project(), + workspaceWindow.get_controller()); +} + +void +Actions::on_menu_show_panel(int panel_index) +{ + workspaceWindow.get_panel_manager().show_panel(panel_index); } /* ===== Help Menu Event Handlers ===== */ diff --git a/src/gui/workspace/actions.hpp b/src/gui/workspace/actions.hpp index 668c71975..c6e843832 100644 --- a/src/gui/workspace/actions.hpp +++ b/src/gui/workspace/actions.hpp @@ -42,11 +42,29 @@ class WorkspaceWindow; */ class Actions { -private: +public: + /** + * Constructor + * @param workspace_window The owner workspace window. + **/ Actions(WorkspaceWindow &workspace_window); + + /** + * Populates a uiManager with the main set of actions. + * @param uiManager A pointer to the uiManager to populate. + **/ + void populate_main_actions(Glib::RefPtr uiManager); /* ===== Internals ===== */ private: + + /** + * Populates a uiManager with actions for the Show Panel menu. + * @param uiManager A pointer to the uiManager to populate. + **/ + void populate_show_panel_actions( + Glib::RefPtr uiManager); + /** * Updates the state of the menu/toolbar actions * to reflect the current state of the workspace */ @@ -75,6 +93,7 @@ private: void on_menu_track_add(); void on_menu_window_new_window(); + void on_menu_show_panel(int panel_index); void on_menu_help_about(); @@ -93,8 +112,6 @@ private: /* ===== Internals ===== */ private: bool is_updating_action_state; - - friend class WorkspaceWindow; }; } // namespace workspace diff --git a/src/gui/workspace/panel-manager.cpp b/src/gui/workspace/panel-manager.cpp index faa1068da..b40eb8d04 100644 --- a/src/gui/workspace/panel-manager.cpp +++ b/src/gui/workspace/panel-manager.cpp @@ -120,6 +120,21 @@ PanelManager::get_workspace_window() return workspaceWindow; } +void +PanelManager::show_panel(const int description_index) +{ + // Create the new panel + shared_ptr new_panel = + create_panel_by_index(description_index); + + // Add it to the list + panels.push_back(new_panel); + + // Dock the item + gdl_dock_add_item(dock, new_panel->get_dock_item(), + GDL_DOCK_FLOATING); +} + void PanelManager::switch_panel(panels::Panel &old_panel, const int description_index) { @@ -193,6 +208,13 @@ PanelManager::get_panel_stock_id(int index) return panelDescriptionList[index].get_stock_id(); } +const char* +PanelManager::get_panel_title(int index) +{ + REQUIRE(index >= 0 && index < get_panel_description_count()); + return panelDescriptionList[index].get_title(); +} + void PanelManager::create_panels() { diff --git a/src/gui/workspace/panel-manager.hpp b/src/gui/workspace/panel-manager.hpp index 354c11fdf..d5da3ab98 100644 --- a/src/gui/workspace/panel-manager.hpp +++ b/src/gui/workspace/panel-manager.hpp @@ -82,6 +82,12 @@ public: **/ WorkspaceWindow& get_workspace_window(); + /** + * Shows a panel given a description index. + * @param description_index The index of the panel type to show. + **/ + void show_panel(const int description_index); + /** * Switches a panel from one type to another, without touching the * underlying GdlDockItem. @@ -108,11 +114,18 @@ public: static int get_panel_description_count(); /** - * Gets a panel description. + * Gets a panel description's stock id. * @param index The index of the panel to retrieve. * @return Returns the stock id of a panel at this index. **/ static const gchar* get_panel_stock_id(const int index); + + /** + * Gets a panel description's title. + * @param index The index of the panel to retrieve. + * @return Returns the title of a panel at this index. + **/ + static const char* get_panel_title(int index); private: diff --git a/src/gui/workspace/workspace-window.cpp b/src/gui/workspace/workspace-window.cpp index b940ccad3..6f6243783 100644 --- a/src/gui/workspace/workspace-window.cpp +++ b/src/gui/workspace/workspace-window.cpp @@ -37,6 +37,7 @@ #include "include/logging.h" using namespace Gtk; +using namespace Glib; using namespace gui::model; using namespace gui::controller; @@ -87,62 +88,9 @@ WorkspaceWindow::create_ui() add(baseContainer); uiManager = Gtk::UIManager::create(); - uiManager->insert_action_group(actions.actionGroup); - + actions.populate_main_actions(uiManager); add_accel_group(uiManager->get_accel_group()); - //Layout the actions in a menubar and toolbar: - Glib::ustring ui_info = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; - - try - { - uiManager->add_ui_from_string(ui_info); - } - catch(const Glib::Error& ex) - { - NOBUG_ERROR(gui, "Building menus failed: %s", ex.what().data()); - return; - } - //----- Set up the Menu Bar -----// Gtk::Widget* menu_bar = uiManager->get_widget("/MenuBar"); REQUIRE(menu_bar != NULL); @@ -172,6 +120,7 @@ WorkspaceWindow::create_ui() show_all_children(); } + } // namespace workspace } // namespace gui diff --git a/src/gui/workspace/workspace-window.hpp b/src/gui/workspace/workspace-window.hpp index 866fb872c..b00b009a6 100644 --- a/src/gui/workspace/workspace-window.hpp +++ b/src/gui/workspace/workspace-window.hpp @@ -97,8 +97,6 @@ private: * The instantiation of the actions helper class, which * registers and handles user action events */ Actions actions; - - friend class Actions; }; } // namespace workspace