[Debtags-commits] [svn] r2040 - in debtags-edit/1.2: . src

Enrico Zini enrico at alioth.debian.org
Wed Nov 1 01:55:45 CET 2006


Author: enrico
Date: Wed Nov  1 01:55:44 2006
New Revision: 2040

Added:
   debtags-edit/1.2/src/TagsetList.h
Modified:
   debtags-edit/1.2/   (props changed)
   debtags-edit/1.2/src/Makefile.am
   debtags-edit/1.2/src/TagEditor.cc
   debtags-edit/1.2/src/TagEditor.h
Log:
 r3586 at viaza:  enrico | 2006-11-01 01:55:13 +0100
 Extracted all common tagset-in-a-treeview infrastructure into TagsetEditor


Modified: debtags-edit/1.2/src/Makefile.am
==============================================================================
--- debtags-edit/1.2/src/Makefile.am	(original)
+++ debtags-edit/1.2/src/Makefile.am	Wed Nov  1 01:55:44 2006
@@ -20,4 +20,4 @@
 
 INCLUDES = $(LIBEPT_CFLAGS) $(GTKMM_CFLAGS)
 
-EXTRA_DIST = AddButtons.h DebtagsDocument.h DebtagsEditOptions.h DebtagsEditor.h Environment.h FilterPanel.h Mutex.h PatchReview.h RelatedPanel.h TagEditor.h TagMenu.h TagMenu.tcc TagSelector.h Thread.h
+EXTRA_DIST = AddButtons.h DebtagsDocument.h DebtagsEditOptions.h DebtagsEditor.h Environment.h FilterPanel.h Mutex.h PatchReview.h RelatedPanel.h TagEditor.h TagMenu.h TagMenu.tcc TagSelector.h TagsetList.h Thread.h

Modified: debtags-edit/1.2/src/TagEditor.cc
==============================================================================
--- debtags-edit/1.2/src/TagEditor.cc	(original)
+++ debtags-edit/1.2/src/TagEditor.cc	Wed Nov  1 01:55:44 2006
@@ -32,6 +32,65 @@
 using namespace wibble::operators;
 
 template<class DOC>
+bool TagEditor<DOC>::TagList::fillMenu(const Tag& tag, const std::set<Tag>& selected)
+{
+	if (tag == Tag())
+		return false;
+
+	if (selected.size() < 2)
+	{
+#if 0
+		this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Select this tag",
+					sigc::bind< Tag >(
+						sigc::mem_fun(*this, &TagEditor<DOC>::do_signal_select_tag), tag)));
+#endif
+		this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Delete this tag",
+					sigc::bind< Tag >(
+						sigc::mem_fun(te, &TagEditor<DOC>::on_del_from_selection), tag)));
+	}
+	else
+	{
+#if 0
+		// TODO: build the tag set with all the selected tags
+		this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Merge",
+					sigc::mem_fun(*this, &ItemList::do_signal_request_tagset_merge)));
+		this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Intersect",
+					sigc::mem_fun(*this, &ItemList::do_signal_request_tagset_intersect)));
+#endif
+	}
+#if 0
+	this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Copy to other panel",
+				sigc::mem_fun(*this, &ItemList::do_signal_request_item_copy)));
+	this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Move to other panel",
+				sigc::mem_fun(*this, &ItemList::do_signal_request_item_move)));
+#endif
+
+#if 0
+	TagMenu<TagcollDocument<string> >* addMenu = new TagMenu<TagcollDocument<string> >();
+	addMenu->set_manage();
+	addMenu->populateUnselected(doc, ts);
+	string stag = tag;
+	addMenu->signal_selected().connect(
+				sigc::mem_fun(*this, &ItemList::on_add_tag));
+	itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("_Add...", *addMenu));
+#endif	
+
+#if 0
+	if (!ts.empty())
+	{
+		itemPopup.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
+		for (TagSet::const_iterator i = ts.begin();
+				i != ts.end(); i++)
+			itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Remove " + i->fullname(),
+				sigc::bind<Tag>(
+					sigc::mem_fun(*this, &ItemList::on_remove_tag), *i)));
+	}
+#endif
+
+	return true;
+}
+
+template<class DOC>
 void TagEditor<DOC>::do_add_tag(Tag tag)
 {
 	_signal_add_tag.emit(tag);
@@ -143,113 +202,13 @@
 }
 
 template<class DOC>
-bool TagEditor<DOC>::on_event_from_list(GdkEvent* e)
-{
-	if (e->type == GDK_BUTTON_PRESS && e->button.button == 3)
-	{
-		Gtk::TreeModel::Path path;
-		Gtk::TreeViewColumn* column;
-		int cell_x, cell_y;
-		if (itemList.get_path_at_pos(
-				(int)e->button.x, (int)e->button.y,
-				path, column,
-				cell_x, cell_y))
-		{
-			// Clicked on an item
-			debug("Cell %d, %d\n", cell_x, cell_y);
-
-			Gtk::TreeModel::Row row = *itemListModel->get_iter(path);
-			Tag tag = row[itemListModelColumns.tag];
-			
-			debug("Tag: %s\n", tag.fullname().c_str());
-
-			Glib::RefPtr<Gtk::TreeSelection> sel = itemList.get_selection();
-			int rows = sel->count_selected_rows();
-
-			this->itemPopup.items().clear();
-
-			debug("%d selected rows\n");
-
-			if (rows == 1)
-			{
-#if 0
-				this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Select this tag",
-							sigc::bind< Tag >(
-								sigc::mem_fun(*this, &TagEditor<DOC>::do_signal_select_tag), tag)));
-#endif
-				this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Delete this tag",
-							sigc::bind< Tag >(
-								sigc::mem_fun(*this, &TagEditor<DOC>::on_del_from_selection), tag)));
-			}
-			else
-			{
-#if 0
-				// TODO: build the tag set with all the selected tags
-				this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Merge",
-							sigc::mem_fun(*this, &ItemList::do_signal_request_tagset_merge)));
-				this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Intersect",
-							sigc::mem_fun(*this, &ItemList::do_signal_request_tagset_intersect)));
-#endif
-			}
-#if 0
-			this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Copy to other panel",
-						sigc::mem_fun(*this, &ItemList::do_signal_request_item_copy)));
-			this->itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Move to other panel",
-						sigc::mem_fun(*this, &ItemList::do_signal_request_item_move)));
-#endif
-
-#if 0
-			TagMenu<TagcollDocument<string> >* addMenu = new TagMenu<TagcollDocument<string> >();
-			addMenu->set_manage();
-			addMenu->populateUnselected(doc, ts);
-			string stag = tag;
-			addMenu->signal_selected().connect(
-						sigc::mem_fun(*this, &ItemList::on_add_tag));
-			itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("_Add...", *addMenu));
-#endif	
-
-#if 0
-			if (!ts.empty())
-			{
-				itemPopup.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
-				for (TagSet::const_iterator i = ts.begin();
-						i != ts.end(); i++)
-					itemPopup.items().push_back(Gtk::Menu_Helpers::MenuElem("Remove " + i->fullname(),
-						sigc::bind<Tag>(
-							sigc::mem_fun(*this, &ItemList::on_remove_tag), *i)));
-			}
-#endif
-
-			this->itemPopup.popup(e->button.button, e->button.time);
-
-			return true;
-		} else {
-			// Clicked outside
-			warning("itemList.get_path_at_pos failed\n");
-			return false;
-		}
-	}
-	return false;
-}
-
-template<class DOC>
 TagEditor<DOC>::TagEditor(DOC& doc)
-	: doc(doc)
+	: doc(doc), itemList(doc, *this)
 {
 	// Add the TreeView, inside a ScrolledWindow
 	scrolledItemList.add(itemList);
 	// Only show the scrollbars when they are necessary:
 	scrolledItemList.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
-
-	// Create the Tree model
-	itemListModel = Gtk::ListStore::create(itemListModelColumns);
-	itemList.set_model(itemListModel);
-	itemList.add_events(Gdk::BUTTON_PRESS_MASK);
-	itemList.signal_event().connect(sigc::mem_fun(*this, &TagEditor<DOC>::on_event_from_list));
-
-	// Add the view columns
-	itemList.append_column("Tag", itemListModelColumns.desc);
-
 	pack_start(scrolledItemList, true, true);
 
 	Gtk::HBox* hbox = manage(new Gtk::HBox());
@@ -294,34 +253,7 @@
 
 	std::set<Tag> _selected = doc.currentTags();
 
-#if 0
-	if (doc.current() == typename DOC::Package())
-	{
-		table = new Gtk::Table(1, 1);
-		tableBox.pack_start(*table);
-		Gtk::Label* l = manage(new Gtk::Label("No package currently selected"));
-		table->attach(*l, 1, 2, 1, 2, Gtk::SHRINK);
-		table->show();
-		table->show_all_children(true);
-		return;
-	}
-#endif
-
-	itemListModel->clear();
-	cerr << "Adding" << endl;
-    for (typename std::set<Tag>::const_iterator i = _selected.begin(); i != _selected.end(); i++)
-	{
-		if (*i != Tag())
-		{
-			cerr << "Add: " << i->fullname() << endl;
-			Gtk::TreeModel::Row row;
-			row = *(itemListModel->append());
-			row[itemListModelColumns.tag] = *i;
-			row[itemListModelColumns.desc] =
-				"[" + i->fullname() + "] " +
-				i->facet().shortDescription() + " :: " + i->shortDescription();
-		}
-	}
+	itemList.display(_selected);
 
 	buttonAdd->set_sensitive(doc.current() != Package());
 	buttonAddD->set_sensitive(doc.current() != Package());

Modified: debtags-edit/1.2/src/TagEditor.h
==============================================================================
--- debtags-edit/1.2/src/TagEditor.h	(original)
+++ debtags-edit/1.2/src/TagEditor.h	Wed Nov  1 01:55:44 2006
@@ -27,6 +27,7 @@
 #include <gtkmm/treeview.h>
 #include <gtkmm/liststore.h>
 #include <gtkmm/menu.h>
+#include "TagsetList.h"
 
 template<class DOC>
 class TagEditor : public Gtk::VBox
@@ -42,30 +43,34 @@
 	typedef SigC::Signal1<void, Tag> type_signal_remove_tag;
 
 protected:
+	class TagList : public TagsetList<DOC>
+	{
+	protected:
+		// Format the tag description from a tag
+		virtual std::string format(const Tag& tag)
+		{
+			return "[" + tag.fullname() + "] " +
+					tag.facet().shortDescription() + " :: " + tag.shortDescription();
+		}
+
+		virtual bool fillMenu(const Tag& tag, const std::set<Tag>& selected);
+
+		DOC& doc;
+		TagEditor<DOC>& te;
+
+	public:
+		TagList(DOC& doc, TagEditor<DOC>& te) : doc(doc), te(te) {}
+	};
+
 	DOC& doc;
 	
-	Gtk::Menu itemPopup;
-
-	Gtk::TreeView itemList;
+	TagList itemList;
 	Gtk::ScrolledWindow scrolledItemList;
-	Glib::RefPtr<Gtk::ListStore> itemListModel;
 
 	Gtk::Widget* buttonAdd;
 	Gtk::Widget* buttonAddR;
 	Gtk::Widget* buttonAddD;
 
-	// Tree model columns
-	class ItemListModelColumns : public Gtk::TreeModel::ColumnRecord
-	{
-	public:
-		ItemListModelColumns() { add(tag); add(desc); }
-
-		Gtk::TreeModelColumn<Tag> tag;
-		Gtk::TreeModelColumn<Glib::ustring> desc;
-	};
-
-	ItemListModelColumns itemListModelColumns;
-
 	//type_signal_changed _signal_changed;
 	type_signal_add_tag _signal_add_tag;
 	type_signal_remove_tag _signal_remove_tag;
@@ -76,7 +81,6 @@
 	bool on_tag_popup_event(GdkEvent* e, Tag tag);
 	void on_add_to_selection(Tag tag);
 	void on_del_from_selection(Tag tag);
-	bool on_event_from_list(GdkEvent* e);
 
 	void on_changed();
 



More information about the Debtags-commits mailing list