made the rows in the Live Mode window drag'n'drop reorderable

This commit is contained in:
fgerlits 2006-02-01 17:04:51 +00:00
parent bbcc7bf2ca
commit e21440dff2
4 changed files with 111 additions and 34 deletions

View file

@ -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:
/**

View file

@ -62,6 +62,12 @@ ZebraTreeView :: ZebraTreeView(Glib::RefPtr<Gtk::TreeModel> 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<Gtk::TreeModel> 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;
}
}

View file

@ -88,13 +88,10 @@ LiveModeWindow :: LiveModeWindow (Ptr<GLiveSupport>::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;
}

View file

@ -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.
*/