mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 09:40:37 +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
|
||||
get_modify_func = None
|
||||
get_data_func = None
|
||||
get_row_data_func = None
|
||||
get_sort_func = None
|
||||
|
||||
def __init__ (self):
|
||||
|
@ -563,6 +564,12 @@ class TextColumn (SizedColumn):
|
|||
else:
|
||||
cell_data_func = 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:
|
||||
column.add_attribute (cell, "text", self.id)
|
||||
else:
|
||||
|
@ -765,27 +772,29 @@ class MessageColumn (TextColumn):
|
|||
|
||||
def __init__ (self, *a, **kw):
|
||||
|
||||
self.highlight = {}
|
||||
self.highlighters = {}
|
||||
|
||||
TextColumn.__init__ (self, *a, **kw)
|
||||
|
||||
def get_data_func (self):
|
||||
def get_row_data_func (self):
|
||||
|
||||
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 = value
|
||||
if line_index in highlight:
|
||||
start, end = highlight[line_index]
|
||||
attrlist = AttrList ()
|
||||
attrlist.insert (AttrBackground (0, 0, 65535, start, end))
|
||||
attrlist.insert (AttrForeground (65535, 65535, 65535, start, end))
|
||||
props.attributes = attrlist
|
||||
else:
|
||||
props.attributes = None
|
||||
props.text = row[id_]
|
||||
for highlighter in highlighters.values ():
|
||||
ranges = highlighter (row)
|
||||
if not ranges:
|
||||
props.attributes = None
|
||||
else:
|
||||
attrlist = AttrList ()
|
||||
for start, end in ranges:
|
||||
attrlist.insert (AttrBackground (0, 0, 65535, start, end))
|
||||
attrlist.insert (AttrForeground (65535, 65535, 65535, start, end))
|
||||
props.attributes = attrlist
|
||||
|
||||
return message_data_func
|
||||
|
||||
|
|
|
@ -220,6 +220,11 @@ class FindBarFeature (FeatureBase):
|
|||
self.bar.show ()
|
||||
self.bar.entry.grab_focus ()
|
||||
else:
|
||||
try:
|
||||
column = self.window.column_manager.find_item (name = "message")
|
||||
del column.highlighters[self]
|
||||
except KeyError:
|
||||
pass
|
||||
self.bar.hide ()
|
||||
|
||||
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.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):
|
||||
|
||||
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_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:
|
||||
path = (line_index,)
|
||||
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:
|
||||
model.row_changed (path, tree_iter)
|
||||
|
||||
def clear_results (self):
|
||||
|
||||
column = self.window.column_manager.find_item (name = "message")
|
||||
column.highlight.clear ()
|
||||
try:
|
||||
column = self.window.column_manager.find_item (name = "message")
|
||||
del column.highlighters[self]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
model = self.log_view.props.model
|
||||
|
||||
|
|
Loading…
Reference in a new issue