[Aptitude-devel] [PATCH 4 of 4] Use EditColumns column itself as Expander column. This will both cleanup the

Luca Bruno lethalman88 at gmail.com
Fri Dec 26 12:26:49 UTC 2008


# HG changeset patch
# User Luca Bruno <lethalman88 at gmail.com>
# Date 1230294303 -3600
# Node ID 506cb036cd55fb703cc19de42f15ef39b5a27bd7
# Parent  4f97dfb9045fcef4dd668bc2833fd0c0e2d6736c
Use EditColumns column itself as Expander column. This will both cleanup the
code and remove extra unused space in treeviews (like Dependencies).
	* src/gtk/info.cc (InfoTab::disp_package): removed expander
references
	* src/gtk/entityview.cc
	(EntityView::EditColumnsDialog::hidden_property, set_hidden,
	get_hidden): added
	(EntityView::EditColumnsDialog::add_column_to_list): return if col
	has been hidden
	(EntityView::column_drop_handler): enforce "..." column to be the
	first
	(EntityView::init): removed Expander column, hide EditColumns in the
	columns editor for real
	(EntityView::set_model): cleaned up has_expandable_rows trick

	* src/gtk/entityview.h (EntityView::get_expander_column): removed
	(EntityView::EditColumns): column added

diff --git a/src/gtk/entityview.cc b/src/gtk/entityview.cc
--- a/src/gtk/entityview.cc
+++ b/src/gtk/entityview.cc
@@ -181,6 +181,7 @@
   {
     static const Glib::Quark description_property;
     static const Glib::Quark edit_name_property;
+    static const Glib::Quark hidden_property;
 
     static void ustring_destroy_notify(gpointer data)
     {
@@ -260,6 +261,36 @@
     }
 
 
+    /** \brief Do not add the column to the editor.
+     *
+     *  The column will not be displayed in the "edit columns" dialog box.
+     *
+     *  \param col            The column to modify.
+     *  \param hidden         true to hide the column from the columns editor, false otherwise.
+     */
+    static void set_hidden(Gtk::TreeViewColumn *col,
+                           bool hidden)
+    {
+      col->set_data(hidden_property, reinterpret_cast<gpointer>(hidden));
+    }
+
+    /** \brief Retrieve the hiding of a column that was set by set_hidden(),
+     *  and false otherwise.
+     *
+     *  \param col  The column whose description should be retrieved.
+     *
+     *  \return The hiding of col, if one was set using
+     *  set_hidden(), and false otherwise.
+     */
+    static bool get_hidden(Gtk::TreeViewColumn *col)
+    {
+      gpointer rval = col->get_data(hidden_property);
+
+      if(rval == NULL)
+	return false;
+      else
+	return reinterpret_cast<glong>(rval);
+    }
 
     class ModelColumns : public Gtk::TreeModel::ColumnRecord
     {
@@ -386,6 +417,9 @@
      */
     void add_column_to_list(Gtk::TreeViewColumn * col) const
     {
+      if (get_hidden(col))
+        return;
+
       Glib::ustring name = get_edit_name(col);
       if(name.empty())
 	name = col->get_title();
@@ -427,6 +461,7 @@
 
   const Glib::Quark EntityView::EditColumnsDialog::description_property("aptitude-visible-columns-editor-column-description-property");
   const Glib::Quark EntityView::EditColumnsDialog::edit_name_property("aptitude-visible-columns-editor-column-edit-name-property");
+  const Glib::Quark EntityView::EditColumnsDialog::hidden_property("aptitude-visible-columns-editor-column-hidden-property");
 
   // \todo Perhaps "Edit Columns..." should be available without going
   // through the menu, so it's useful in tabs that have more than one
@@ -489,20 +524,13 @@
     cache_reloaded.connect(sigc::mem_fun(*this, &EntityView::on_cache_reloaded));
 
     {
-      Gtk::TreeViewColumn *EditColumnsColumn = new Gtk::TreeViewColumn("...");
-      EditColumnsColumn->signal_clicked().connect(sigc::mem_fun(*this, &EntityView::show_edit_columns_dialog));
-      EditColumnsColumn->set_clickable(true);
+      EditColumns = manage(new Gtk::TreeViewColumn("..."));
+      EditColumns->signal_clicked().connect(sigc::mem_fun(*this, &EntityView::show_edit_columns_dialog));
+      EditColumns->set_clickable(true);
       // Don't let the properties of this column be edited.
-      EditColumnsDialog::set_edit_name(EditColumnsColumn, "");
-      tree->append_column(*EditColumnsColumn);
+      EditColumnsDialog::set_hidden(EditColumns, true);
+      tree->append_column(*EditColumns);
     }
-
-    // Put in a dummy column for the expanders, so everything else
-    // lines up.
-    Expander = manage(new Gtk::TreeViewColumn(""));
-    setup_column_properties(Expander, 24);
-    Expander->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
-    tree->append_column(*Expander);
 
     {
       // \todo should the selected status icon have a dropdown menu?
@@ -779,7 +807,7 @@
 				       Gtk::TreeViewColumn *next_column)
   {
     // Ensure that the expander column is always first.
-    if(column == Expander || next_column == Expander)
+    if(column == EditColumns || next_column == EditColumns)
       return false;
 
     return true;
@@ -824,13 +852,6 @@
 			    sigc::mem_fun(this, &EntityView::compare_rows_by_version));
 
     revstore.clear();
-    bool has_expandable_rows = false;
-    model->foreach_iter(sigc::bind(sigc::ptr_fun(post_process_model),
-				   model,
-				   get_columns(),
-				   get_reverse_store(),
-				   &has_expandable_rows));
-    Expander->set_visible(has_expandable_rows);
     get_treeview()->set_model(model);
   }
 }
diff --git a/src/gtk/entityview.h b/src/gtk/entityview.h
--- a/src/gtk/entityview.h
+++ b/src/gtk/entityview.h
@@ -179,7 +179,7 @@
       void on_cache_closed();
       void on_cache_reloaded();
 
-      Gtk::TreeViewColumn * Expander;
+      Gtk::TreeViewColumn * EditColumns;
       Gtk::TreeViewColumn * Status;
       Gtk::TreeViewColumn * AutomaticallyInstalled;
       Gtk::TreeViewColumn * Name;
@@ -256,7 +256,6 @@
       void refresh_view(const std::set<pkgCache::PkgIterator> *changed_packages);
       EntityTreeView * get_treeview() const { return tree; };
       const EntityColumns * get_columns() const { return &cols; };
-      Gtk::TreeViewColumn *get_expander_column() const { return Expander; }
       Gtk::TreeViewColumn *get_status_column() const { return Status; }
       Gtk::TreeViewColumn *get_name_column() const { return Name; }
       Gtk::TreeViewColumn *get_version_column() const { return Version; }
diff --git a/src/gtk/info.cc b/src/gtk/info.cc
--- a/src/gtk/info.cc
+++ b/src/gtk/info.cc
@@ -657,7 +657,6 @@
     pDependsView = ref_ptr<EntityView>(new EntityView(get_xml(), "main_info_dependsview",
 						      _("Package information: dependency list")));
     pDependsView->set_model(make_depends_tree(pDependsView->get_columns(), ver));
-    pDependsView->get_expander_column()->set_fixed_width(48);
     pDependsView->get_name_column()->set_fixed_width(280);
     pDependsView->get_automatically_installed_column()->set_visible(false);
     Gtk::TreeModel::Children dependsChildren = pDependsView->get_treeview()->get_model()->children();



More information about the Aptitude-devel mailing list