Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nested searches on namespace view #228

Merged
merged 2 commits into from Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions gaphor/diagram/profiles/stereotypepage.py
Expand Up @@ -18,6 +18,7 @@ def create_stereotype_tree_view(model, toggle_stereotype, set_slot_value):
Model, for which tree view is created.
"""
tree_view = Gtk.TreeView.new_with_model(model)
tree_view.set_search_column(-1)

# Stereotype/Attributes
col = Gtk.TreeViewColumn.new()
Expand Down
1 change: 1 addition & 0 deletions gaphor/diagram/propertypages.py
Expand Up @@ -344,6 +344,7 @@ def create_tree_view(model, names, tip="", ro_cols=None):
ro_cols = set()

tree_view = Gtk.TreeView(model=model)
tree_view.set_search_column(-1)

n = model.get_n_columns() - 1
for name, i in zip(names, list(range(n))):
Expand Down
31 changes: 24 additions & 7 deletions gaphor/ui/namespace.py
Expand Up @@ -67,13 +67,6 @@ def __init__(self, model, factory):
self.set_property("headers-visible", False)
self.set_property("search-column", 0)

def search_func(model, column, key, iter, data=None):
assert column == 0
element = model.get_value(iter, column)
if element.name:
return not element.name.startswith(key)

self.set_search_equal_func(search_func)
selection = self.get_selection()
selection.set_mode(Gtk.SelectionMode.BROWSE)
column = Gtk.TreeViewColumn.new()
Expand Down Expand Up @@ -310,10 +303,34 @@ def sort_func(model, iter_a, iter_b, userdata):
return 1
return -1

def search_func(model, column, key, rowiter):
# Note that this function returns `False` for a match!
assert column == 0
row = model[rowiter]
matched = False

# Search in child rows. If any element in the underlaying
# tree matches, it will expand.
for inner in row.iterchildren():
child = list(inner)[column]
if not search_func(model, column, key, inner.iter):
view.expand_to_path(row.path)
matched = True

element = list(row)[column]
if element.name and key.lower() in element.name.lower():
matched = True
elif not matched:
view.collapse_row(row.path)

return not matched # False means match found!

sorted_model.set_sort_func(0, sort_func, None)
sorted_model.set_sort_column_id(0, Gtk.SortType.ASCENDING)

view = NamespaceView(sorted_model, self.element_factory)
view.set_search_equal_func(search_func)

scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
Expand Down