Commit c1eaa76f authored by Marinus Schraal's avatar Marinus Schraal

searchbar: Make manager a property of FilterView

Making the manager a property saves us passing it to init.
parent f8ddb362
......@@ -163,23 +163,21 @@ class FilterView(Gtk.TreeView):
),
}
manager = GObject.Property(type=GObject.GObject)
def __repr__(self):
return '<FilterView>'
@log
def __init__(self, manager):
def __init__(self):
super().__init__()
self._manager = manager
self._model = Gtk.ListStore.new([
GObject.TYPE_STRING, # ID
GObject.TYPE_STRING, # NAME
GObject.TYPE_STRING, # TEXT
])
self._manager.fill_in_values(self._model)
self.set_activate_on_single_click(True)
self.set_headers_visible(False)
self.set_enable_search(False)
......@@ -211,19 +209,26 @@ class FilterView(Gtk.TreeView):
col.set_cell_data_func(
self._text_renderer, self._head_visible, False)
self.connect('notify::manager', self._on_manager_changed)
self.show()
@log
def _on_manager_changed(self, klass, value, data=None):
if value is not None:
self.props.manager.fill_in_values(self._model)
@log
def _row_activated(self, view, path, col):
id_ = self._model[self._model.get_iter(path)][BaseModelColumns.ID]
self.emit('selection-changed', self._manager, id_)
self._manager.entry.emit('changed')
self.emit('selection-changed', self.props.manager, id_)
self.props.manager.entry.emit('changed')
@log
def _render_radio(self, col, cell, model, iter_):
id_ = model[iter_][BaseModelColumns.ID]
cell.set_active(self._manager.active == id_)
cell.set_active(self.props.manager.active == id_)
@classmethod
@log
......@@ -269,7 +274,8 @@ class DropDown(Gtk.Revealer):
def initialize_filters(self, searchbar):
self._source_manager = SourceManager(
'source', _("Sources"), searchbar._search_entry)
_source_filter = FilterView(self._source_manager)
_source_filter = FilterView()
_source_filter.manager = self._source_manager
_source_filter.connect('selection-changed', self._on_selection_changed)
self._grid.add(_source_filter)
......@@ -278,7 +284,8 @@ class DropDown(Gtk.Revealer):
self.search_manager = BaseManager(
'search', _("Match"), searchbar._search_entry)
self._search_filter = FilterView(self.search_manager)
self._search_filter = FilterView()
self._search_filter.manager = self.search_manager
self._search_filter.connect(
'selection-changed', self._on_selection_changed)
self._grid.add(self._search_filter)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment