summaryrefslogtreecommitdiff
path: root/src/gtk
diff options
context:
space:
mode:
authorDaniel Burrows <Daniel Burrows Daniel_Burrows@alumni.brown.edu>2010-05-17 19:18:23 -0700
committerDaniel Burrows <Daniel Burrows Daniel_Burrows@alumni.brown.edu>2010-05-17 19:18:23 -0700
commit3f926ba8c2b51c0b6082636ed6bfa403a99c70bb (patch)
treeacf3c2ad972bc33b5ae4f04b2d839b67946558e7 /src/gtk
parent1f6cf8e47030ccab0f9a7799cc24ace8a5bc7dd2 (diff)
downloadaptitude-3f926ba8c2b51c0b6082636ed6bfa403a99c70bb.tar.gz
Add scaffolding to the tab_info structure to make it easy to create siblings of the current tab.
I envision some tabs being created in multiple areas; their sub-tabs should be siblings. Having this code centralized avoids any need to store backlinks manually from other parts of the program. (I hope)
Diffstat (limited to 'src/gtk')
-rw-r--r--src/gtk/toplevel/model.cc38
-rw-r--r--src/gtk/toplevel/model.h14
2 files changed, 51 insertions, 1 deletions
diff --git a/src/gtk/toplevel/model.cc b/src/gtk/toplevel/model.cc
index 8a4e3339..091d412b 100644
--- a/src/gtk/toplevel/model.cc
+++ b/src/gtk/toplevel/model.cc
@@ -19,14 +19,18 @@
#include "model.h"
+#include <loggers.h>
+
#include <cwidget/generic/util/bool_accumulate.h>
#include <boost/enable_shared_from_this.hpp>
+#include <boost/weak_ptr.hpp>
#include <generic/util/dynamic_set_impl.h>
#include <gtkmm/window.h>
+using aptitude::Loggers;
using aptitude::util::dynamic_set;
using aptitude::util::dynamic_set_impl;
using aptitude::util::enumerator;
@@ -101,8 +105,14 @@ namespace gui
{
// Arrange for the tab to be dropped from the set when it's
// closed.
-
tab->connect_closed(sigc::mem_fun(*this, &area_info_impl::tab_closed));
+
+ tab->set_parent_area(shared_from_this());
+ }
+
+ void tab_removed(const boost::shared_ptr<tab_info> &tab)
+ {
+ tab->set_parent_area(boost::shared_ptr<area_info>());
}
void tab_closed(const boost::shared_ptr<tab_info> &tab)
@@ -122,6 +132,9 @@ namespace gui
{
tabs->connect_inserted(sigc::mem_fun(*this,
&area_info_impl::tab_inserted));
+
+ tabs->connect_removed(sigc::mem_fun(*this,
+ &area_info_impl::tab_removed));
}
std::string get_name() { return name; }
@@ -153,6 +166,8 @@ namespace gui
bool active;
+ boost::weak_ptr<area_info> parent_area_weak;
+
sigc::signal<void, boost::shared_ptr<tab_info>, std::string, Gtk::Window *> signal_tooltip_changed;
sigc::signal<void, boost::shared_ptr<tab_info>, aptitude::util::progress_info> signal_progress_changed;
sigc::signal<void, boost::shared_ptr<tab_info> > signal_activate_tab;
@@ -178,6 +193,27 @@ namespace gui
delete tooltip_window;
}
+ void set_parent_area(const boost::shared_ptr<area_info> &parent_area)
+ {
+ if(parent_area_weak.lock().get() != NULL &&
+ parent_area.get() != NULL)
+ LOG_ERROR(Loggers::getAptitudeGtkToplevel(),
+ "Parent area for the tab " << name << " set twice.");
+ else
+ parent_area_weak = parent_area;
+ }
+
+ void add_sibling(const boost::shared_ptr<tab_info> &sibling)
+ {
+ boost::shared_ptr<area_info> parent_area = parent_area_weak.lock();
+
+ if(parent_area.get() != NULL)
+ parent_area->get_tabs()->insert(sibling);
+ else
+ LOG_ERROR(Loggers::getAptitudeGtkToplevel(),
+ "Can't add a sibling to a tab with no parent.");
+ }
+
std::string get_name() { return name; }
void get_tooltip(std::string &out_tooltip_text,
diff --git a/src/gtk/toplevel/model.h b/src/gtk/toplevel/model.h
index c50ec053..cd8ec424 100644
--- a/src/gtk/toplevel/model.h
+++ b/src/gtk/toplevel/model.h
@@ -278,6 +278,12 @@ namespace gui
*/
virtual void activate() = 0;
+ /** \brief Add the given tab to the same area as this tab.
+ *
+ * If no parent area is stored, logs an error and does nothing.
+ */
+ virtual void add_sibling(const boost::shared_ptr<tab_info> &sibling) = 0;
+
/** \brief Signals */
// @{
@@ -321,6 +327,14 @@ namespace gui
*/
virtual sigc::connection
connect_closed(const sigc::slot<void, boost::shared_ptr<tab_info> > &slot) = 0;
+
+ /** \brief Set the area that this tab is stored in.
+ *
+ * Should only be invoked by area_info. If the area is set to
+ * a non-NULL value when it already has a non-NULL value, the
+ * new setting is discarded and an error is logged.
+ */
+ virtual void set_parent_area(const boost::shared_ptr<area_info> &area) = 0;
};
/** \brief Create a new tab_info.