mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 18:51:11 +00:00
Implement lazy highlighting of search results
This commit is contained in:
parent
d4dcc1be13
commit
89f8ebe0cf
2 changed files with 37 additions and 19 deletions
|
@ -516,6 +516,7 @@ class Column (object):
|
||||||
label_header = None
|
label_header = None
|
||||||
get_modify_func = None
|
get_modify_func = None
|
||||||
get_data_func = None
|
get_data_func = None
|
||||||
|
get_row_data_func = None
|
||||||
get_sort_func = None
|
get_sort_func = None
|
||||||
|
|
||||||
def __init__ (self):
|
def __init__ (self):
|
||||||
|
@ -563,6 +564,12 @@ class TextColumn (SizedColumn):
|
||||||
else:
|
else:
|
||||||
cell_data_func = data_func
|
cell_data_func = data_func
|
||||||
column.set_cell_data_func (cell, cell_data_func)
|
column.set_cell_data_func (cell, cell_data_func)
|
||||||
|
elif self.get_row_data_func:
|
||||||
|
data_func = self.get_row_data_func ()
|
||||||
|
assert data_func
|
||||||
|
def cell_data_func (column, cell, model, tree_iter):
|
||||||
|
data_func (cell.props, model[tree_iter])
|
||||||
|
column.set_cell_data_func (cell, cell_data_func)
|
||||||
elif not self.get_modify_func:
|
elif not self.get_modify_func:
|
||||||
column.add_attribute (cell, "text", self.id)
|
column.add_attribute (cell, "text", self.id)
|
||||||
else:
|
else:
|
||||||
|
@ -765,27 +772,29 @@ class MessageColumn (TextColumn):
|
||||||
|
|
||||||
def __init__ (self, *a, **kw):
|
def __init__ (self, *a, **kw):
|
||||||
|
|
||||||
self.highlight = {}
|
self.highlighters = {}
|
||||||
|
|
||||||
TextColumn.__init__ (self, *a, **kw)
|
TextColumn.__init__ (self, *a, **kw)
|
||||||
|
|
||||||
def get_data_func (self):
|
def get_row_data_func (self):
|
||||||
|
|
||||||
from pango import AttrList, AttrBackground, AttrForeground
|
from pango import AttrList, AttrBackground, AttrForeground
|
||||||
highlight = self.highlight
|
highlighters = self.highlighters
|
||||||
|
id_ = self.id
|
||||||
|
|
||||||
def message_data_func (props, value, path):
|
def message_data_func (props, row):
|
||||||
|
|
||||||
line_index = path[0]
|
props.text = row[id_]
|
||||||
props.text = value
|
for highlighter in highlighters.values ():
|
||||||
if line_index in highlight:
|
ranges = highlighter (row)
|
||||||
start, end = highlight[line_index]
|
if not ranges:
|
||||||
attrlist = AttrList ()
|
props.attributes = None
|
||||||
attrlist.insert (AttrBackground (0, 0, 65535, start, end))
|
else:
|
||||||
attrlist.insert (AttrForeground (65535, 65535, 65535, start, end))
|
attrlist = AttrList ()
|
||||||
props.attributes = attrlist
|
for start, end in ranges:
|
||||||
else:
|
attrlist.insert (AttrBackground (0, 0, 65535, start, end))
|
||||||
props.attributes = None
|
attrlist.insert (AttrForeground (65535, 65535, 65535, start, end))
|
||||||
|
props.attributes = attrlist
|
||||||
|
|
||||||
return message_data_func
|
return message_data_func
|
||||||
|
|
||||||
|
|
|
@ -220,6 +220,11 @@ class FindBarFeature (FeatureBase):
|
||||||
self.bar.show ()
|
self.bar.show ()
|
||||||
self.bar.entry.grab_focus ()
|
self.bar.entry.grab_focus ()
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
column = self.window.column_manager.find_item (name = "message")
|
||||||
|
del column.highlighters[self]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
self.bar.hide ()
|
self.bar.hide ()
|
||||||
|
|
||||||
def handle_goto_previous_search_result_action_activate (self, action):
|
def handle_goto_previous_search_result_action_activate (self, action):
|
||||||
|
@ -270,6 +275,9 @@ class FindBarFeature (FeatureBase):
|
||||||
self.operation = SearchOperation (model, search_string, start_position = start_path[0])
|
self.operation = SearchOperation (model, search_string, start_position = start_path[0])
|
||||||
self.sentinel.run_for (self.operation)
|
self.sentinel.run_for (self.operation)
|
||||||
|
|
||||||
|
column = self.window.column_manager.find_item (name = "message")
|
||||||
|
column.highlighters[self] = self.operation.match_func
|
||||||
|
|
||||||
def handle_match_found (self, model, tree_iter):
|
def handle_match_found (self, model, tree_iter):
|
||||||
|
|
||||||
line_index = model.get_path (tree_iter)[0]
|
line_index = model.get_path (tree_iter)[0]
|
||||||
|
@ -307,19 +315,20 @@ class FindBarFeature (FeatureBase):
|
||||||
start_path, end_path = self.log_view.get_visible_range ()
|
start_path, end_path = self.log_view.get_visible_range ()
|
||||||
start_index, end_index = start_path[0], end_path[0]
|
start_index, end_index = start_path[0], end_path[0]
|
||||||
|
|
||||||
|
# Update highlighting. FIXME: Probably not needed/can be done better.
|
||||||
for line_index in new_matches:
|
for line_index in new_matches:
|
||||||
path = (line_index,)
|
path = (line_index,)
|
||||||
tree_iter = model.get_iter (path)
|
tree_iter = model.get_iter (path)
|
||||||
row = model[tree_iter]
|
|
||||||
ranges = match_func (row)
|
|
||||||
column.highlight[line_index] = ranges[0]
|
|
||||||
if line_index >= start_index and line_index <= end_index:
|
if line_index >= start_index and line_index <= end_index:
|
||||||
model.row_changed (path, tree_iter)
|
model.row_changed (path, tree_iter)
|
||||||
|
|
||||||
def clear_results (self):
|
def clear_results (self):
|
||||||
|
|
||||||
column = self.window.column_manager.find_item (name = "message")
|
try:
|
||||||
column.highlight.clear ()
|
column = self.window.column_manager.find_item (name = "message")
|
||||||
|
del column.highlighters[self]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
model = self.log_view.props.model
|
model = self.log_view.props.model
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue