diff --git a/src/gui/panels/panel.cpp b/src/gui/panels/panel.cpp index 81dbf9092..814845113 100644 --- a/src/gui/panels/panel.cpp +++ b/src/gui/panels/panel.cpp @@ -21,27 +21,38 @@ * *****************************************************/ #include "panel.hpp" +#include "../gtk-lumiera.hpp" namespace lumiera { namespace gui { namespace panels { -Panel::Panel(const gchar *name, const gchar *long_name, GdlDockItemBehavior behavior) +Panel::Panel(const gchar *name, const gchar *long_name, + GdlDockItemBehavior behavior) { - dock_item = (GdlDockItem*)gdl_dock_item_new (name, long_name, behavior); + dock_item = (GdlDockItem*)gdl_dock_item_new ( + name, long_name, behavior); internal_setup(); + + ENSURE(dock_item != NULL); } Panel::Panel(const gchar *name, const gchar *long_name, const gchar *stock_id, GdlDockItemBehavior behavior) { - dock_item = (GdlDockItem*)gdl_dock_item_new_with_stock (name, long_name, stock_id, behavior); + dock_item = (GdlDockItem*)gdl_dock_item_new_with_stock ( + name, long_name, stock_id, behavior); + g_object_ref(dock_item); internal_setup(); + + ENSURE(dock_item != NULL); } Panel::~Panel() { - #warning Im not sure that dock_item is freed - is it self deleting? + REQUIRE(dock_item != NULL); + g_object_unref(dock_item); + dock_item = NULL; } GdlDockItem* @@ -53,6 +64,7 @@ Panel::get_dock_item() const void Panel::show(bool show) { + REQUIRE(dock_item != NULL); if(show) gdl_dock_item_show_item (dock_item); else gdl_dock_item_hide_item (dock_item); } @@ -60,12 +72,17 @@ Panel::show(bool show) bool Panel::is_shown() const { + REQUIRE(dock_item != NULL); return GTK_WIDGET_VISIBLE((GtkWidget*)dock_item); } void Panel::internal_setup() { + REQUIRE(dock_item != NULL); + REQUIRE(gobj() != NULL); + + gdl_dock_item_hide_grip(dock_item); gtk_container_add ((GtkContainer*)dock_item, (GtkWidget*)gobj()); gtk_widget_show ((GtkWidget*)dock_item); } diff --git a/src/gui/workspace/actions.cpp b/src/gui/workspace/actions.cpp index 2e8df4277..1cabe1c1f 100644 --- a/src/gui/workspace/actions.cpp +++ b/src/gui/workspace/actions.cpp @@ -28,200 +28,208 @@ using namespace Gtk; using namespace Glib; +using namespace sigc; using namespace lumiera::gui; namespace lumiera { namespace gui { namespace workspace { - Actions::Actions(WorkspaceWindow &workspace_window) : - workspaceWindow(workspace_window) +Actions::Actions(WorkspaceWindow &workspace_window) : + workspaceWindow(workspace_window), + is_updating_action_state(false) +{ + register_stock_items(); + + workspace_window.signal_show ().connect_notify(mem_fun(this, &Actions::update_action_state)); + + //----- 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)); + actionGroup->add(Action::create("FileOpenProject", Stock::OPEN, _("_Open Project...")), + sigc::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)); + actionGroup->add(Action::create("FileQuit", Stock::QUIT), + sigc::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)); + actionGroup->add(Action::create("EditPaste", Stock::PASTE), + sigc::mem_fun(*this, &Actions::on_menu_others)); + actionGroup->add(Action::create("EditPreferences", Stock::PREFERENCES), + sigc::mem_fun(*this, &Actions::on_menu_edit_preferences)); + + // View Menu + actionGroup->add(Action::create("ViewMenu", _("_View"))); + + assetsPanelAction = ToggleAction::create("ViewAssets", Gtk::StockID("assets_panel")); + assetsPanelAction->signal_toggled().connect( + sigc::mem_fun(*this, &Actions::on_menu_view_assets)); + actionGroup->add(assetsPanelAction); + + timelinePanelAction = ToggleAction::create("ViewTimeline", Gtk::StockID("timeline_panel")); + timelinePanelAction->signal_toggled().connect( + sigc::mem_fun(*this, &Actions::on_menu_view_timeline)); + actionGroup->add(timelinePanelAction); + + viewerPanelAction = ToggleAction::create("ViewViewer", Gtk::StockID("viewer_panel")); + viewerPanelAction->signal_toggled().connect( + sigc::mem_fun(*this, &Actions::on_menu_view_viewer)); + actionGroup->add(viewerPanelAction); + + // Help Menu + actionGroup->add(Action::create("HelpMenu", _("_Help")) ); + actionGroup->add(Action::create("HelpAbout", Stock::ABOUT), + sigc::mem_fun(*this, &Actions::on_menu_help_about) ); +} + +void +Actions::register_stock_items() +{ + RefPtr factory = IconFactory::create(); + add_stock_item(factory, "assets-panel.png", "assets_panel", _("_Assets")); + add_stock_item(factory, "timeline-panel.png", "timeline_panel", _("_Timeline")); + add_stock_item(factory, "viewer-panel.png", "viewer_panel", _("_Viewer")); + factory->add_default(); //Add factory to list of factories. +} + +void +Actions::add_stock_item(const Glib::RefPtr& factory, + const Glib::ustring& filepath, + const Glib::ustring& id, const Glib::ustring& label) +{ + Gtk::IconSource source; + try { - register_stock_items(); - - 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)); - actionGroup->add(Action::create("FileOpenProject", Stock::OPEN, _("_Open Project...")), - sigc::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)); - actionGroup->add(Action::create("FileQuit", Stock::QUIT), - sigc::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)); - actionGroup->add(Action::create("EditPaste", Stock::PASTE), - sigc::mem_fun(*this, &Actions::on_menu_others)); - actionGroup->add(Action::create("EditPreferences", Stock::PREFERENCES), - sigc::mem_fun(*this, &Actions::on_menu_edit_preferences)); - - // View Menu - actionGroup->add(Action::create("ViewMenu", _("_View"))); - - assetsPanelAction = ToggleAction::create("ViewAssets", Gtk::StockID("assets_panel")); - assetsPanelAction->signal_toggled().connect( - sigc::mem_fun(*this, &Actions::on_menu_view_assets)); - actionGroup->add(assetsPanelAction); - - timelinePanelAction = ToggleAction::create("ViewTimeline", Gtk::StockID("timeline_panel")); - timelinePanelAction->signal_toggled().connect( - sigc::mem_fun(*this, &Actions::on_menu_view_timeline)); - actionGroup->add(timelinePanelAction); - - viewerPanelAction = ToggleAction::create("ViewViewer", Gtk::StockID("viewer_panel")); - viewerPanelAction->signal_toggled().connect( - sigc::mem_fun(*this, &Actions::on_menu_view_viewer)); - actionGroup->add(viewerPanelAction); - - // Help Menu - actionGroup->add(Action::create("HelpMenu", _("_Help")) ); - actionGroup->add(Action::create("HelpAbout", Stock::ABOUT), - sigc::mem_fun(*this, &Actions::on_menu_help_about) ); - - // Refresh the UI state - update_action_state(); + //This throws an exception if the file is not found: + source.set_pixbuf( Gdk::Pixbuf::create_from_file(filepath) ); + } + catch(const Glib::Exception& ex) + { + g_message(ex.what().c_str()); } - void - Actions::register_stock_items() - { - RefPtr factory = IconFactory::create(); - add_stock_item(factory, "assets-panel.png", "assets_panel", _("_Assets")); - add_stock_item(factory, "timeline-panel.png", "timeline_panel", _("_Timeline")); - add_stock_item(factory, "viewer-panel.png", "viewer_panel", _("_Viewer")); - factory->add_default(); //Add factory to list of factories. - } + source.set_size(Gtk::ICON_SIZE_SMALL_TOOLBAR); + source.set_size_wildcarded(); //Icon may be scaled. - void - Actions::add_stock_item(const Glib::RefPtr& factory, - const Glib::ustring& filepath, - const Glib::ustring& id, const Glib::ustring& label) - { - Gtk::IconSource source; - try - { - //This throws an exception if the file is not found: - source.set_pixbuf( Gdk::Pixbuf::create_from_file(filepath) ); - } - catch(const Glib::Exception& ex) - { - g_message(ex.what().c_str()); - } + Gtk::IconSet icon_set; + icon_set.add_source(source); //More than one source per set is allowed. - source.set_size(Gtk::ICON_SIZE_SMALL_TOOLBAR); - source.set_size_wildcarded(); //Icon may be scaled. + const Gtk::StockID stock_id(id); + factory->add(stock_id, icon_set); + Gtk::Stock::add(Gtk::StockItem(stock_id, label)); +} - Gtk::IconSet icon_set; - icon_set.add_source(source); //More than one source per set is allowed. +void +Actions::update_action_state() +{ + REQUIRE(workspaceWindow.assets_panel); + REQUIRE(workspaceWindow.timeline_panel); + REQUIRE(workspaceWindow.viewer_panel); + + is_updating_action_state = true; + assetsPanelAction->set_active(workspaceWindow.assets_panel->is_shown()); + timelinePanelAction->set_active(workspaceWindow.timeline_panel->is_shown()); + viewerPanelAction->set_active(workspaceWindow.viewer_panel->is_shown()); + is_updating_action_state = false; +} - const Gtk::StockID stock_id(id); - factory->add(stock_id, icon_set); - Gtk::Stock::add(Gtk::StockItem(stock_id, label)); - } +/* ===== File Menu Event Handlers ===== */ - void - Actions::update_action_state() - { - assetsPanelAction->set_active(workspaceWindow.assets_panel.is_shown()); - timelinePanelAction->set_active(workspaceWindow.timeline_panel.is_shown()); - viewerPanelAction->set_active(workspaceWindow.viewer_panel.is_shown()); - } +void +Actions::on_menu_file_new_project() +{ + g_message("A File|New menu item was selecteda."); +} - /* ===== File Menu Event Handlers ===== */ +void +Actions::on_menu_file_open_project() +{ + g_message("A File|Open menu item was selecteda."); +} - void - Actions::on_menu_file_new_project() - { - g_message("A File|New menu item was selecteda."); - } +void +Actions::on_menu_file_render() +{ + dialogs::Render dialog(workspaceWindow); + dialog.run(); +} - void - Actions::on_menu_file_open_project() - { - g_message("A File|Open menu item was selecteda."); - } +void +Actions::on_menu_file_quit() +{ + workspaceWindow.hide(); // Closes the main window to stop the Gtk::Main::run(). +} - void - Actions::on_menu_file_render() - { - dialogs::Render dialog(workspaceWindow); - dialog.run(); - } +/* ===== Edit Menu Event Handlers ===== */ - void - Actions::on_menu_file_quit() - { - workspaceWindow.hide(); // Closes the main window to stop the Gtk::Main::run(). - } +void +Actions::on_menu_edit_preferences() +{ + dialogs::PreferencesDialog dialog(workspaceWindow); + dialog.run(); +} - /* ===== Edit Menu Event Handlers ===== */ +/* ===== View Menu Event Handlers ===== */ - void - Actions::on_menu_edit_preferences() - { - dialogs::PreferencesDialog dialog(workspaceWindow); - dialog.run(); - } +void +Actions::on_menu_view_assets() +{ + if(!is_updating_action_state) + workspaceWindow.assets_panel->show(assetsPanelAction->get_active()); +} - /* ===== View Menu Event Handlers ===== */ +void +Actions::on_menu_view_timeline() +{ + if(!is_updating_action_state) + workspaceWindow.timeline_panel->show(timelinePanelAction->get_active()); +} - void - Actions::on_menu_view_assets() - { - workspaceWindow.assets_panel.show(!workspaceWindow.assets_panel.is_shown()); - update_action_state(); - } +void +Actions::on_menu_view_viewer() +{ + if(!is_updating_action_state) + workspaceWindow.viewer_panel->show(viewerPanelAction->get_active()); +} - void - Actions::on_menu_view_timeline() - { - workspaceWindow.timeline_panel.show(!workspaceWindow.timeline_panel.is_shown()); - update_action_state(); - } +void +Actions::on_menu_help_about() +{ + // Configure the about dialog + AboutDialog dialog; + + //dialog.set_program_name(AppTitle); + dialog.set_version(AppVersion); + //dialog.set_version(Appconfig::get("version")); + dialog.set_copyright(AppCopyright); + dialog.set_website(AppWebsite); + dialog.set_authors(StringArrayHandle(AppAuthors, + sizeof(AppAuthors) / sizeof(gchar*), + OWNERSHIP_NONE)); - void - Actions::on_menu_view_viewer() - { - workspaceWindow.viewer_panel.show(!workspaceWindow.viewer_panel.is_shown()); - update_action_state(); - } - - void - Actions::on_menu_help_about() - { - // Configure the about dialog - AboutDialog dialog; - - //dialog.set_program_name(AppTitle); - dialog.set_version(AppVersion); - //dialog.set_version(Appconfig::get("version")); - dialog.set_copyright(AppCopyright); - dialog.set_website(AppWebsite); - dialog.set_authors(StringArrayHandle(AppAuthors, - sizeof(AppAuthors) / sizeof(gchar*), - OWNERSHIP_NONE)); - - dialog.set_transient_for(workspaceWindow); - - // Show the about dialog - dialog.run(); - } + dialog.set_transient_for(workspaceWindow); + + // Show the about dialog + dialog.run(); +} - //----- Temporary junk - void - Actions::on_menu_others() - { - g_message("A menu item was selected."); - } +//----- Temporary junk +void +Actions::on_menu_others() +{ + g_message("A menu item was selected."); +} } // namespace workspace } // namespace gui diff --git a/src/gui/workspace/actions.hpp b/src/gui/workspace/actions.hpp index 891ae7757..235ae29ef 100644 --- a/src/gui/workspace/actions.hpp +++ b/src/gui/workspace/actions.hpp @@ -93,6 +93,10 @@ class WorkspaceWindow; Glib::RefPtr assetsPanelAction; Glib::RefPtr timelinePanelAction; Glib::RefPtr viewerPanelAction; + + /* ===== Internals ===== */ + private: + bool is_updating_action_state; friend class WorkspaceWindow; }; diff --git a/src/gui/workspace/workspace-window.cpp b/src/gui/workspace/workspace-window.cpp index 56724fbc2..1bab85431 100644 --- a/src/gui/workspace/workspace-window.cpp +++ b/src/gui/workspace/workspace-window.cpp @@ -47,7 +47,7 @@ WorkspaceWindow::WorkspaceWindow(Project *source_project) : actions(*this) { REQUIRE(source_project != NULL); - + layout = NULL; create_ui(); @@ -60,7 +60,7 @@ WorkspaceWindow::~WorkspaceWindow() void WorkspaceWindow::create_ui() - { + { //----- Configure the Window -----// set_title(AppTitle); set_default_size(1024, 768); @@ -127,8 +127,13 @@ WorkspaceWindow::create_ui() ASSERT(toolbar != NULL); toolbar->set_toolbar_style(TOOLBAR_ICONS); base_container.pack_start(*toolbar, Gtk::PACK_SHRINK); + + //----- Create the Panels -----// + assets_panel = Glib::RefPtr(new AssetsPanel()); + viewer_panel = Glib::RefPtr(new ViewerPanel()); + timeline_panel = Glib::RefPtr(new TimelinePanel()); - //----- Create the dock -----// + //----- Create the Dock -----// dock = Glib::wrap(gdl_dock_new()); layout = gdl_dock_layout_new((GdlDock*)dock->gobj()); @@ -139,15 +144,15 @@ WorkspaceWindow::create_ui() dock_container.pack_end(*dock, PACK_EXPAND_WIDGET); base_container.pack_start(dock_container, PACK_EXPAND_WIDGET); - gdl_dock_add_item ((GdlDock*)dock->gobj(), assets_panel.get_dock_item(), GDL_DOCK_LEFT); - gdl_dock_add_item ((GdlDock*)dock->gobj(), viewer_panel.get_dock_item(), GDL_DOCK_RIGHT); - gdl_dock_add_item ((GdlDock*)dock->gobj(), timeline_panel.get_dock_item(), GDL_DOCK_BOTTOM); + gdl_dock_add_item ((GdlDock*)dock->gobj(), assets_panel->get_dock_item(), GDL_DOCK_LEFT); + gdl_dock_add_item ((GdlDock*)dock->gobj(), viewer_panel->get_dock_item(), GDL_DOCK_RIGHT); + gdl_dock_add_item ((GdlDock*)dock->gobj(), timeline_panel->get_dock_item(), GDL_DOCK_BOTTOM); // Manually dock and move around some of the items - gdl_dock_item_dock_to (timeline_panel.get_dock_item(), assets_panel.get_dock_item(), - GDL_DOCK_BOTTOM, -1); - gdl_dock_item_dock_to (viewer_panel.get_dock_item(), assets_panel.get_dock_item(), - GDL_DOCK_RIGHT, -1); + gdl_dock_item_dock_to (timeline_panel->get_dock_item(), + assets_panel->get_dock_item(), GDL_DOCK_BOTTOM, -1); + gdl_dock_item_dock_to (viewer_panel->get_dock_item(), + assets_panel->get_dock_item(), GDL_DOCK_RIGHT, -1); show_all_children(); diff --git a/src/gui/workspace/workspace-window.hpp b/src/gui/workspace/workspace-window.hpp index 70d1a04e4..86e3dd68a 100644 --- a/src/gui/workspace/workspace-window.hpp +++ b/src/gui/workspace/workspace-window.hpp @@ -77,9 +77,9 @@ namespace workspace { /* ===== Panels ===== */ private: - AssetsPanel assets_panel; - ViewerPanel viewer_panel; - TimelinePanel timeline_panel; + Glib::RefPtr assets_panel; + Glib::RefPtr viewer_panel; + Glib::RefPtr timeline_panel; /* ===== Helpers ===== */ private: