From 303a6f2ce4f9b0b1b5ea771ea187404478ec9607 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Wed, 15 Apr 2009 20:12:06 +0100 Subject: [PATCH] Modify Panel hiding for PanelManager compatibility --- src/gui/panels/panel.cpp | 47 +++++++++++++++++++++++++++-- src/gui/panels/panel.hpp | 35 +++++++++++++++++++++ src/gui/workspace/panel-manager.cpp | 45 +++++++++++++++++++-------- src/gui/workspace/panel-manager.hpp | 8 +++++ 4 files changed, 121 insertions(+), 14 deletions(-) diff --git a/src/gui/panels/panel.cpp b/src/gui/panels/panel.cpp index bf1816205..962c4f8b3 100644 --- a/src/gui/panels/panel.cpp +++ b/src/gui/panels/panel.cpp @@ -36,6 +36,7 @@ Panel::Panel(workspace::PanelManager &panel_manager, const gchar *stock_id) : panelManager(panel_manager), dockItem(dock_item), + hide_panel_handler_id(0), panelBar(*this, stock_id) { REQUIRE(dockItem); @@ -56,6 +57,10 @@ Panel::Panel(workspace::PanelManager &panel_manager, gtk_container_add ((GtkContainer*)dockItem, (GtkWidget*)gobj()); gtk_widget_show ((GtkWidget*)dockItem); + + // Connect the signals + hide_panel_handler_id = g_signal_connect (GTK_OBJECT(dockItem), + "hide", G_CALLBACK(on_item_hidden), this); } Panel::~Panel() @@ -67,6 +72,10 @@ Panel::~Panel() gdl_dock_item_get_grip(dockItem)); gtk_container_remove (GTK_CONTAINER(grip), ((Widget&)panelBar).gobj()); + + // Detach the signals + g_signal_handler_disconnect( + GTK_OBJECT(dockItem), hide_panel_handler_id); // Unref the dock item g_object_unref(dockItem); @@ -88,10 +97,24 @@ Panel::show(bool show) } bool -Panel::is_locked() const +Panel::is_shown() const { REQUIRE(dockItem != NULL); - return !GDL_DOCK_ITEM_NOT_LOCKED(dockItem); + return GTK_WIDGET_VISIBLE((GtkWidget*)dockItem); +} + +void +Panel::iconify() +{ + REQUIRE(dockItem != NULL); + gdl_dock_item_iconify_item(dockItem); +} + +bool +Panel::is_iconified() const +{ + REQUIRE(dockItem != NULL); + return GDL_DOCK_ITEM_ICONIFIED(dockItem); } void @@ -102,6 +125,13 @@ Panel::lock(bool lock) else gdl_dock_item_unlock (dockItem); } +bool +Panel::is_locked() const +{ + REQUIRE(dockItem != NULL); + return !GDL_DOCK_ITEM_NOT_LOCKED(dockItem); +} + workspace::PanelManager& Panel::get_panel_manager() { @@ -126,5 +156,18 @@ Panel::get_controller() return panelManager.get_workspace_window().get_controller(); } +sigc::signal& +Panel::signal_hide_panel() +{ + return hidePanelSignal; +} + +void +Panel::on_item_hidden(GdlDockItem*, Panel *panel) +{ + REQUIRE(panel); + panel->hidePanelSignal(); +} + } // namespace panels } // namespace gui diff --git a/src/gui/panels/panel.hpp b/src/gui/panels/panel.hpp index 89559be3b..6234c2a13 100644 --- a/src/gui/panels/panel.hpp +++ b/src/gui/panels/panel.hpp @@ -81,6 +81,16 @@ public: */ bool is_shown() const; + /** + * Iconifys the panel. + **/ + void iconify(); + + /** + * Returns true if the panel is currently iconified. + **/ + bool is_iconified() const; + /** * Locks or unlocks the panel. * @param show A value of true will lock the panel, false will unlock @@ -98,6 +108,13 @@ public: **/ workspace::PanelManager& get_panel_manager(); +public: + + /** + * A signal that fires when the dock item is hidden. + **/ + sigc::signal& signal_hide_panel(); + protected: /** @@ -114,6 +131,14 @@ protected: * Returns a reference to the controller **/ controller::Controller& get_controller(); + +private: + + /** + * An event handler for when dockItem is hidden. + * @param func_data A pointer to the panel that owns dock_item + **/ + static void on_item_hidden(GdlDockItem*, Panel *panel); protected: @@ -128,6 +153,16 @@ protected: **/ GdlDockItem* dockItem; + /** + * A signal that fires when the dock item is hidden. + **/ + sigc::signal hidePanelSignal; + + /** + * The id of the hide panel handler. + **/ + gulong hide_panel_handler_id; + /** * The panel bar to attach to the panel grip. **/ diff --git a/src/gui/workspace/panel-manager.cpp b/src/gui/workspace/panel-manager.cpp index a038b3a8c..c0c186ca4 100644 --- a/src/gui/workspace/panel-manager.cpp +++ b/src/gui/workspace/panel-manager.cpp @@ -130,6 +130,8 @@ PanelManager::show_panel(const int description_index) const shared_ptr panel = *i; if(get_panel_type(panel.get()) == description_index) { + panel->show(); + GdlDockItem *dock_item = panel->get_dock_item(); ENSURE(dock_item); gdl_dock_object_present(GDL_DOCK_OBJECT(dock_item), NULL); @@ -141,9 +143,6 @@ PanelManager::show_panel(const int description_index) 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); @@ -174,8 +173,6 @@ void PanelManager::switch_panel(panels::Panel &old_panel, shared_ptr new_panel( panelDescriptionList[description_index].create(*this, dock_item)); g_object_unref(dock_item); - - panels.push_back(new_panel); } void @@ -186,9 +183,6 @@ PanelManager::split_panel(panels::Panel &panel, const int index = get_panel_type(&panel); shared_ptr new_panel = create_panel_by_index(index); - // Add it to the list - panels.push_back(new_panel); - // Dock the panel GdlDockPlacement placement = GDL_DOCK_NONE; switch(split_direction) @@ -245,10 +239,6 @@ PanelManager::create_panels() timelinePanel->get_dock_item(), GDL_DOCK_BOTTOM); gdl_dock_add_item(dock, viewerPanel->get_dock_item(), GDL_DOCK_RIGHT); - - panels.push_back(timelinePanel); - panels.push_back(viewerPanel); - panels.push_back(resourcesPanel); } int @@ -287,6 +277,13 @@ PanelManager::create_panel_by_index(const int index) ENSURE(panel); panel->show_all(); + // Connect event handlers + panel->signal_hide_panel().connect(bind( + mem_fun(*this, &PanelManager::on_panel_shown), panel)); + + // Add the panel to the list + panels.push_back(panel); + return panel; } @@ -315,5 +312,29 @@ PanelManager::get_panel_type(panels::Panel *panel) const return -1; } +void +PanelManager::on_panel_shown(boost::weak_ptr panel_ptr) +{ + if(panel_ptr.expired()) + return; + + shared_ptr panel(panel_ptr); + REQUIRE(panel); + + if(panel->is_shown() || panel->is_iconified()) + return; + + // Release the panel + list< boost::shared_ptr >::iterator i; + for(i = panels.begin(); i != panels.end(); i++) + { + if((*i) == panel) + { + panels.erase(i); + break; + } + } +} + } // namespace workspace } // namespace gui diff --git a/src/gui/workspace/panel-manager.hpp b/src/gui/workspace/panel-manager.hpp index d5da3ab98..af684688d 100644 --- a/src/gui/workspace/panel-manager.hpp +++ b/src/gui/workspace/panel-manager.hpp @@ -165,6 +165,14 @@ private: * if no description was found for this type. **/ int get_panel_type(panels::Panel *panel) const; + +private: + + /** + * An event handler for when the panel is shown or hidden. + * @param panel_ptr A weak pointer to the panel that was hidden. + **/ + void on_panel_shown(boost::weak_ptr panel_ptr); private: