summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>2016-07-26 07:42:54 +0200
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>2016-07-26 08:02:40 +0200
commit37dc4bd8a7039bfad6e8e6b014aace49a21f6f76 (patch)
tree5a4b95589a8010179295b417eb4918f2e22b4d09
parent43e20fd3e8d008873ab8e88569df793ed21760d6 (diff)
Factor out and simplify the search by components in options tree
-rw-r--r--gtk2_ardour/option_editor.cc116
-rw-r--r--gtk2_ardour/option_editor.h2
2 files changed, 42 insertions, 76 deletions
diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc
index f19babaae4..9a21e600a0 100644
--- a/gtk2_ardour/option_editor.cc
+++ b/gtk2_ardour/option_editor.cc
@@ -533,99 +533,63 @@ OptionEditor::treeview_row_selected ()
}
}
-void
-OptionEditor::add_path_to_treeview (std::string const & pn, Gtk::Widget& widget)
+TreeModel::iterator
+OptionEditor::find_path_in_treemodel (std::string const & pn, bool create_missing)
{
- option_treeview.set_model (Glib::RefPtr<TreeStore>());
-
- if (pn.find ('/') == std::string::npos) {
- /* new top level item in tree */
-
- TreeModel::iterator new_row = option_tree->append ();
- TreeModel::Row row = *new_row;
- row[option_columns.name] = pn;
- row[option_columns.widget] = &widget;
-
- } else {
-
- /* find parent */
-
- /* split page name, which is actually a path, into each
- * component
- */
-
- std::vector<std::string> components;
- split (pn, components, '/');
-
- /* start with top level children */
-
- typedef Gtk::TreeModel::Children type_children; //minimise code length.
- type_children children = option_tree->children();
-
- /* foreach path component ... */
-
- for (std::vector<std::string>::const_iterator s = components.begin(); s != components.end(); ) {
-
- bool component_found = false;
-
- type_children::iterator iter;
-
- /* look through the children at this level */
+ /* split page name, which is actually a path, into each component */
- for (iter = children.begin(); iter != children.end(); ++iter) {
- Gtk::TreeModel::Row row = *iter;
+ std::vector<std::string> components;
+ split (pn, components, '/');
- std::string row_name = row[option_columns.name];
- if (row_name == (*s)) {
+ /* start with top level children */
- /* found it */
+ TreeModel::Children children = option_tree->children();
+ TreeModel::iterator iter;
- component_found = true;
+ /* foreach path component ... */
- /* reset children to point to
- * the children of this row
- */
+ for (std::vector<std::string>::const_iterator s = components.begin(); s != components.end(); ++s) {
- children = row.children();
- break;
- }
+ for (iter = children.begin(); iter != children.end(); ++iter) {
+ TreeModel::Row row = *iter;
+ const std::string row_name = row[option_columns.name];
+ if (row_name == (*s)) {
+ break;
}
+ }
- if (!component_found) {
-
- /* missing component. If it is the last
- * one, append a real page. Otherwise
- * just put an entry in the tree model
- * since it is a navigational/sorting
- * component.
- */
-
- TreeModel::iterator new_row = option_tree->append (children);
- TreeModel::Row row = *new_row;
+ if (iter == children.end()) {
+ /* the current component is missing; bail out or create it */
+ if (!create_missing) {
+ return option_tree->get_iter(TreeModel::Path(""));
+ } else {
+ iter = option_tree->append (children);
+ TreeModel::Row row = *iter;
row[option_columns.name] = *s;
+ row[option_columns.widget] = 0;
+ }
+ }
- ++s;
+ /* from now on, iter points to a valid row, either the one we found or a new one */
+ /* set children to the row's children to continue searching */
+ children = (*iter)->children ();
- if (s == components.end()) {
- row[option_columns.widget] = &widget;
- } else {
- row[option_columns.widget] = 0;
- }
+ }
- children = row.children ();
+ return iter;
+}
- } else {
+void
+OptionEditor::add_path_to_treeview (std::string const & pn, Gtk::Widget& widget)
+{
+ option_treeview.set_model (Glib::RefPtr<TreeStore>());
- /* component found, just move on to the
- * next one. children has already been
- * reset appropriately.
- */
+ TreeModel::iterator row_iter = find_path_in_treemodel(pn, true);
- ++s;
- }
- }
+ assert(row_iter);
- }
+ TreeModel::Row row = *row_iter;
+ row[option_columns.widget] = &widget;
option_treeview.set_model (option_tree);
option_treeview.expand_all ();
diff --git a/gtk2_ardour/option_editor.h b/gtk2_ardour/option_editor.h
index 53c6712878..b5d44d577c 100644
--- a/gtk2_ardour/option_editor.h
+++ b/gtk2_ardour/option_editor.h
@@ -723,6 +723,8 @@ private:
std::map<std::string, OptionEditorPage*> _pages;
void add_path_to_treeview (std::string const &, Gtk::Widget&);
+ Gtk::TreeModel::iterator find_path_in_treemodel (std::string const & pn,
+ bool create_missing = false);
void treeview_row_selected ();
};