TreeView help
- From: "Amadeus W. M." <amadeus84 cablespeed com>
- To: gtkmm-list gnome org
- Subject: TreeView help
- Date: Sat, 12 Nov 2005 21:09:48 -0500
This is my first take at a TreeView, and I tried to figure it out on my
own from the docs, but I must resort once again to the community.
I have a bunch of files which I want to load and display in a TreeView
using a ListStore. I can do that, and do something to a selected row, ONLY
in SELECTION_SINGLE mode. In SELECTION_MULTIPLE, I'm trying to pass a
callback to select_foreach() but it never gets called. Please see
tree_path_action() below, and the constructor of the main window.
In fact, I don't even understand very well how multiple selection works.
The user does Ctrl+Button1 on each item it wants, then what? When does
select_foreach() get called? When does gtk (or X?) that the user is done
picking items, and that the action on each item must be triggered?
I got the whole multiple selection wrong, haven't I?
The model is trivial:
class ColsModel : public Gtk::TreeModel::ColumnRecord
{
public:
ColsModel() { add(name); }
Gtk::TreeModelColumn<string> name;
};
// Main window class is
class DisplayWindow : public DisplayWindow_glade
{
public:
// read the names of the items from command line.
DisplayWindow(int beg, int end, char * infiles[]);
~DisplayWindow() {}
private:
typedef Glib::RefPtr<Gtk::TreeSelection> selection_t;
typedef Gtk::TreeModel::Row row_t;
typedef Gtk::TreeModel::Path path_t;
ColsModel colmodel_;
Glib::RefPtr<Gtk::ListStore> SelStore_;
Glib::RefPtr<Gtk::TreeSelection> Selection_;
void on_selection_changed();
// more callbacks
void tree_iter_action(const Gtk::TreeModel::iterator& row);
void tree_path_action(const Gtk::TreeModel::Path & row);
};
// In the constructor:
DisplayWindow::DisplayWindow(int beg, int end, char * infiles[])
{
// Create store (StoreList) for the TreeView item selector
// according to ColsModel.
SelStore_= Gtk::ListStore::create(colmodel_);
ItemSelector->set_model(SelStore_);
// Selection.
selection_t Selection_=ItemSelector->get_selection();
Selection_->set_mode(Gtk::SELECTION_MULTIPLE);
Selection_->signal_changed().connect(
sigc::mem_fun(*this, &DisplayWindow::on_selection_changed));
// What to do with a multiple selection.
Selection_->selected_foreach_path(
sigc::mem_fun(*this, &DisplayWindow::tree_path_action) );
// Fill the item selector with file names.
row_t row;
while(beg<end){
row = *(SelStore_->append());
row[colmodel_.name]=string(infiles[beg++]);
}
ItemSelector->append_column("File", colmodel_.name);
}
// Callbacks:
void DisplayWindow::on_selection_changed()
{
cerr << __FUNCTION__ << ": " << __LINE__ << endl;
}
// Coming in, is the selected row, which we must act upon.
void DisplayWindow::tree_iter_action(const Gtk::TreeModel::iterator& iter)
{
row_t row=*iter;
Gtk::TreeModelColumn<string> name;
string rowname;
//Do something with the row.
cerr << __FUNCTION__ << ": " << __LINE__ << endl;
// row[name];
rowname = iter->get_value(name);
cerr << rowname << endl;
// cerr << row[name] << endl;
}
void DisplayWindow::tree_path_action(const Gtk::TreeModel::Path & row)
{
cerr << __FUNCTION__ << ": " << __LINE__ << endl;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]