From dd20e16383a9d1bea048d58581e19a7adb5196cc Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Fri, 17 Sep 2010 23:26:04 -0700 Subject: [PATCH] Simplify/clarify enabling of individual devices. --- src/ui/dialog/input.cpp | 78 ++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/src/ui/dialog/input.cpp b/src/ui/dialog/input.cpp index 92a54affb..e7d61e415 100644 --- a/src/ui/dialog/input.cpp +++ b/src/ui/dialog/input.cpp @@ -331,12 +331,14 @@ namespace Dialog { class DeviceModelColumns : public Gtk::TreeModel::ColumnRecord { public: + Gtk::TreeModelColumn toggler; + Gtk::TreeModelColumn expander; Gtk::TreeModelColumn description; - Gtk::TreeModelColumn< Glib::RefPtr > thumbnail; + Gtk::TreeModelColumn > thumbnail; Gtk::TreeModelColumn > device; Gtk::TreeModelColumn mode; - DeviceModelColumns() { add(description); add(thumbnail); add(device); add(mode); } + DeviceModelColumns() { add(toggler), add(expander), add(description); add(thumbnail); add(device); add(mode); } }; static std::map &getModeToString() @@ -390,6 +392,9 @@ private: static void commitCellModeChange(Glib::ustring const &path, Glib::ustring const &newText, Glib::RefPtr store); static void setModeCellString(Gtk::CellRenderer *rndr, Gtk::TreeIter const &iter); + static void commitCellStateChange(Glib::ustring const &path, Glib::RefPtr store); + static void setCellStateToggle(Gtk::CellRenderer *rndr, Gtk::TreeIter const &iter); + void saveSettings(); void useExtToggled(); @@ -806,24 +811,39 @@ InputDialogImpl::ConfPanel::ConfPanel() : row = *(poppers->append()); row[foo.one] = getModeToString()[Gdk::MODE_WINDOW]; - Gtk::CellRendererCombo *rendr = new Gtk::CellRendererCombo(); - rendr->property_model().set_value(poppers); - rendr->property_text_column().set_value(0); - rendr->property_has_entry() = false; - //Add the TreeView's view columns: + { + Gtk::CellRendererToggle *rendr = new Gtk::CellRendererToggle(); + Gtk::TreeViewColumn *col = new Gtk::TreeViewColumn("xx", *rendr); + if (col) { + tree.append_column(*col); + col->set_cell_data_func(*rendr, sigc::ptr_fun(setCellStateToggle)); + rendr->signal_toggled().connect(sigc::bind(sigc::ptr_fun(commitCellStateChange), store)); + } + } + + int expPos = tree.append_column("", getCols().expander); + tree.append_column("I", getCols().thumbnail); tree.append_column("Bar", getCols().description); - Gtk::TreeViewColumn *col = new Gtk::TreeViewColumn("X", *rendr); - if (col) { - tree.append_column(*col); - col->set_cell_data_func(*rendr, sigc::ptr_fun(setModeCellString)); - rendr->signal_edited().connect(sigc::bind(sigc::ptr_fun(commitCellModeChange), store)); - rendr->property_editable() = true; + + { + Gtk::CellRendererCombo *rendr = new Gtk::CellRendererCombo(); + rendr->property_model().set_value(poppers); + rendr->property_text_column().set_value(0); + rendr->property_has_entry() = false; + Gtk::TreeViewColumn *col = new Gtk::TreeViewColumn("X", *rendr); + if (col) { + tree.append_column(*col); + col->set_cell_data_func(*rendr, sigc::ptr_fun(setModeCellString)); + rendr->signal_edited().connect(sigc::bind(sigc::ptr_fun(commitCellModeChange), store)); + rendr->property_editable() = true; + } } tree.set_enable_tree_lines(); tree.set_headers_visible(false); + tree.set_expander_column( *tree.get_column(expPos - 1) ); setupTree( store, tabletIter ); @@ -874,6 +894,38 @@ void InputDialogImpl::ConfPanel::commitCellModeChange(Glib::ustring const &path, } } +void InputDialogImpl::ConfPanel::setCellStateToggle(Gtk::CellRenderer *rndr, Gtk::TreeIter const &iter) +{ + if (iter) { + Gtk::CellRendererToggle *toggle = dynamic_cast(rndr); + if (toggle) { + Glib::RefPtr dev = (*iter)[getCols().device]; + if (dev) { + Gdk::InputMode mode = (*iter)[getCols().mode]; + toggle->set_active(mode != Gdk::MODE_DISABLED); + } else { + toggle->set_active(false); + } + } + } +} + +void InputDialogImpl::ConfPanel::commitCellStateChange(Glib::ustring const &path, Glib::RefPtr store) +{ + Gtk::TreeIter iter = store->get_iter(path); + if (iter) { + Glib::RefPtr dev = (*iter)[getCols().device]; + if (dev) { + Gdk::InputMode mode = (*iter)[getCols().mode]; + if (mode == Gdk::MODE_DISABLED) { + Inkscape::DeviceManager::getManager().setMode( dev->getId(), Gdk::MODE_SCREEN ); + } else { + Inkscape::DeviceManager::getManager().setMode( dev->getId(), Gdk::MODE_DISABLED ); + } + } + } +} + void InputDialogImpl::ConfPanel::saveSettings() { Inkscape::DeviceManager::getManager().saveConfig(); -- 2.30.2