[meld/deprecation-cleanup: 46/48] ui.bufferselectors: Absorb FilteredListSelector
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/deprecation-cleanup: 46/48] ui.bufferselectors: Absorb FilteredListSelector
- Date: Sun, 2 Dec 2018 02:46:00 +0000 (UTC)
commit 1d7275e63e89e4cbf6853c2e82b5a5b9ace42875
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Dec 2 10:58:58 2018 +1000
ui.bufferselectors: Absorb FilteredListSelector
It was mostly separate because of the template hack. Now it seems
reasonable to have all this logic together.
meld/ui/bufferselectors.py | 70 +++++++++++++++++++++++++++++++++++++++++++++-
meld/ui/listselector.py | 67 --------------------------------------------
2 files changed, 69 insertions(+), 68 deletions(-)
---
diff --git a/meld/ui/bufferselectors.py b/meld/ui/bufferselectors.py
index 2e9b8deb..73250306 100644
--- a/meld/ui/bufferselectors.py
+++ b/meld/ui/bufferselectors.py
@@ -5,13 +5,81 @@ from gi.repository import GtkSource
from meld.conf import _
from meld.ui._gtktemplate import Template
-from meld.ui.listselector import FilteredListSelector
# TODO: Current pygobject support for templates excludes subclassing of
# templated classes, which is why we have two near-identical UI files
# here, and why we can't subclass Gtk.Grid directly in
# FilteredListSelector.
+
+class FilteredListSelector:
+
+ # FilteredListSelector was intially based on gedit's
+ # GeditHighlightModeSelector
+ # Copyright (C) 2013 - Ignacio Casal Quinteiro
+ # Python translation and adaptations
+ # Copyright (C) 2015, 2017 Kai Willadsen <kai willadsen gmail com>
+
+ __gtype_name__ = 'FilteredListSelector'
+
+ NAME_COLUMN, VALUE_COLUMN = 0, 1
+
+ def __init__(self):
+ super().__init__()
+ self.init_template()
+
+ self.treeview_selection = self.treeview.get_selection()
+ # FIXME: Should be able to access as a template child, but can't.
+ self.listfilter = self.treeview.get_model()
+ self.liststore = self.listfilter.get_model()
+
+ self.populate_model()
+ self.filter_string = ''
+ self.entry.connect('changed', self.on_entry_changed)
+ self.listfilter.set_visible_func(self.name_filter)
+
+ self.entry.connect('activate', self.on_activate)
+ self.treeview.connect('row-activated', self.on_activate)
+
+ def populate_model(self):
+ raise NotImplementedError
+
+ def select_value(self, value):
+ if not value:
+ return
+
+ new_value_getter = getattr(value, self.value_accessor)
+ for row in self.liststore:
+ row_value = row[self.VALUE_COLUMN]
+ if not row_value:
+ continue
+ old_value_getter = getattr(row_value, self.value_accessor)
+ if old_value_getter() != new_value_getter():
+ continue
+ self.treeview_selection.select_path(row.path)
+ self.treeview.scroll_to_cell(row.path, None, True, 0.5, 0)
+
+ def name_filter(self, model, it, *args):
+ if not self.filter_string:
+ return True
+ name = model.get_value(it, self.NAME_COLUMN).lower()
+ return self.filter_string.lower() in name
+
+ def on_entry_changed(self, entry):
+ self.filter_string = entry.get_text()
+ self.listfilter.refilter()
+ first = self.listfilter.get_iter_first()
+ if first:
+ self.treeview_selection.select_iter(first)
+
+ def on_activate(self, *args):
+ model, it = self.treeview_selection.get_selected()
+ if not it:
+ return
+ value = model.get_value(it, self.VALUE_COLUMN)
+ self.emit(self.change_signal_name, value)
+
+
# The subclassing here is weird; the Selector must directly subclass
# Gtk.Grid; we can't do this on the FilteredListSelector. Likewise, the
# Template.Child attributes must be per-class, because of how they're
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]