diff --git a/livesupport/src/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h b/livesupport/src/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h index ac2d03a16..a45827c72 100644 --- a/livesupport/src/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h +++ b/livesupport/src/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h @@ -143,6 +143,15 @@ class ZebraTreeView : public Gtk::TreeView signalCellEdited().emit(path, columnId, newText); } + /** + * Renumber the rows after they have changed. + * + * This is called from the onRowInserted(), onRowDeleted() and + * onRowsReordered() signal handlers. + */ + void + renumberRows(void) throw (); + protected: @@ -154,6 +163,42 @@ class ZebraTreeView : public Gtk::TreeView int, const Glib::ustring &> signalCellEditedObject; + /** + * Event handler for the row_inserted signal. + * + * @param path a path pointing to the inserted row. + * @param iter an iterator pointing to the inserted row. + */ + void + onRowInserted(const Gtk::TreeModel::Path & path, + const Gtk::TreeModel::iterator & iter) + throw (); + + /** + * Event handler for the row_deleted signal. + * + * @param path points to the previous location of the deleted row. + */ + void + onRowDeleted(const Gtk::TreeModel::Path & path) throw (); + + /** + * Event handler for the rows_reordered signal. + * + * @param path points to the tree node whose children have been + * reordered. + * @param iter points to the node whose children have been + * reordered, or 0 if the depth of path is 0. + * @param mapping an array of integers mapping the current position + * of each child to its old position before the + * re-ordering, i.e. mapping[newpos] = oldpos. + */ + void + onRowsReordered(const Gtk::TreeModel::Path & path, + const Gtk::TreeModel::iterator& iter, + int* mapping) + throw (); + public: /** diff --git a/livesupport/src/modules/widgets/src/ZebraTreeView.cxx b/livesupport/src/modules/widgets/src/ZebraTreeView.cxx index 81e9ab9d1..a70b4b92a 100644 --- a/livesupport/src/modules/widgets/src/ZebraTreeView.cxx +++ b/livesupport/src/modules/widgets/src/ZebraTreeView.cxx @@ -62,6 +62,12 @@ ZebraTreeView :: ZebraTreeView(Glib::RefPtr treeModel) throw () : Gtk::TreeView(treeModel) { + treeModel->signal_row_inserted().connect(sigc::mem_fun(*this, + &ZebraTreeView::onRowInserted)); + treeModel->signal_row_deleted().connect(sigc::mem_fun(*this, + &ZebraTreeView::onRowDeleted)); + treeModel->signal_rows_reordered().connect(sigc::mem_fun(*this, + &ZebraTreeView::onRowsReordered)); } @@ -434,3 +440,62 @@ ZebraTreeView :: removeItem(const Gtk::TreeModel::iterator & iter) treeModel->erase(iter); } + + +/*------------------------------------------------------------------------------ + * Event handler for the row_inserted signal. + *----------------------------------------------------------------------------*/ +void +ZebraTreeView :: onRowInserted(const Gtk::TreeModel::Path & path, + const Gtk::TreeModel::iterator & iter) + throw () +{ + renumberRows(); + columns_autosize(); +} + + +/*------------------------------------------------------------------------------ + * Event handler for the row_deleted signal. + *----------------------------------------------------------------------------*/ +void +ZebraTreeView :: onRowDeleted(const Gtk::TreeModel::Path & path) + throw () +{ + renumberRows(); + columns_autosize(); +} + + +/*------------------------------------------------------------------------------ + * Event handler for the rows_reordered signal. + *----------------------------------------------------------------------------*/ +void +ZebraTreeView :: onRowsReordered(const Gtk::TreeModel::Path & path, + const Gtk::TreeModel::iterator & iter, + int* mapping) + throw () +{ + renumberRows(); +} + + +/*------------------------------------------------------------------------------ + * Renumber the rows after they have changed. + *----------------------------------------------------------------------------*/ +void +ZebraTreeView :: renumberRows(void) throw () +{ + Glib::RefPtr treeModel = get_model(); + ZebraTreeModelColumnRecord modelColumns; + int rowNumber = 0; + Gtk::TreeModel::iterator iter; + + for (iter = treeModel->children().begin(); + iter != treeModel->children().end(); ++iter) { + Gtk::TreeRow row = *iter; + row[modelColumns.rowNumberColumn] = rowNumber; + ++rowNumber; + } +} + diff --git a/livesupport/src/products/gLiveSupport/src/LiveModeWindow.cxx b/livesupport/src/products/gLiveSupport/src/LiveModeWindow.cxx index d955c13f6..a8ab4005f 100644 --- a/livesupport/src/products/gLiveSupport/src/LiveModeWindow.cxx +++ b/livesupport/src/products/gLiveSupport/src/LiveModeWindow.cxx @@ -88,13 +88,10 @@ LiveModeWindow :: LiveModeWindow (Ptr::Ref gLiveSupport, // Create the tree model: treeModel = Gtk::ListStore::create(modelColumns); - treeModel->signal_rows_reordered().connect(sigc::mem_fun(*this, - &LiveModeWindow::onRowsReordered)); - treeModel->signal_row_deleted().connect(sigc::mem_fun(*this, - &LiveModeWindow::onRowDeleted)); // ... and the tree view: treeView = Gtk::manage(wf->createTreeView(treeModel)); + treeView->set_reorderable(true); treeView->set_headers_visible(false); treeView->set_enable_search(false); @@ -262,13 +259,6 @@ LiveModeWindow :: popTop(void) throw () treeModel->erase(iter); } - for (iter = treeModel->children().begin(); - iter != treeModel->children().end(); ++iter) { - Gtk::TreeRow row = *iter; - int rowNumber = row[modelColumns.rowNumberColumn]; - row[modelColumns.rowNumberColumn] = --rowNumber; - } - return playable; } diff --git a/livesupport/src/products/gLiveSupport/src/LiveModeWindow.h b/livesupport/src/products/gLiveSupport/src/LiveModeWindow.h index fe87158d2..ed71ff42e 100644 --- a/livesupport/src/products/gLiveSupport/src/LiveModeWindow.h +++ b/livesupport/src/products/gLiveSupport/src/LiveModeWindow.h @@ -191,29 +191,6 @@ class LiveModeWindow : public WhiteWindow, public LocalizedObject bool onKeyPressed(GdkEventKey * event) throw (); - /** - * Signal handler for the "rows reordered" event. - */ - void - onRowsReordered(const Gtk::TreeModel::Path & path, - const Gtk::TreeModel::iterator& iter, - int* newToOldMapping) - throw () - { -// std::cerr << "rows changed: " << path.to_string() << "; " -// << "iter: " << (iter ? "true" : "false") << "\n"; - } - - /** - * Signal handler for the "row deleted" event. - */ - void - onRowDeleted(const Gtk::TreeModel::Path & path) throw () - { -// std::cerr << "rows deleted: " << path.to_string() << ";\n"; - treeView->columns_autosize(); - } - /** * Function to catch the event of the close button being pressed. */