mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
Add ranged line omission feature
This commit is contained in:
parent
cb6d082f19
commit
8108907e5f
3 changed files with 128 additions and 7 deletions
|
@ -387,10 +387,62 @@ class FilteredLogModel (LogModelBase):
|
|||
self.line_offsets[:] = (offset for row, offset in enum
|
||||
if func (row))
|
||||
|
||||
def parent_line_index (self, line_index):
|
||||
|
||||
return line_index # FIXME
|
||||
|
||||
class Filter (object):
|
||||
|
||||
pass
|
||||
|
||||
class SubRange (object):
|
||||
|
||||
def __init__ (self, l, start, end):
|
||||
|
||||
if start > end:
|
||||
raise ValueError ("need start <= end")
|
||||
|
||||
self.l = l
|
||||
self.start = start
|
||||
self.end = end
|
||||
|
||||
def __getitem__ (self, i):
|
||||
|
||||
return self.l[i + self.start]
|
||||
|
||||
def __len__ (self):
|
||||
|
||||
return self.end - self.start
|
||||
|
||||
def __iter__ (self):
|
||||
|
||||
l = self.l
|
||||
i = self.start
|
||||
while i <= self.end:
|
||||
yield l[i]
|
||||
|
||||
class RangeFilteredLogModel (FilteredLogModel):
|
||||
|
||||
def __init__ (self, lazy_log_model):
|
||||
|
||||
FilteredLogModel.__init__ (self, lazy_log_model)
|
||||
|
||||
self.line_index_range = None
|
||||
|
||||
def set_range (self, start_index, last_index):
|
||||
|
||||
self.line_index_range = (start_index, last_index,)
|
||||
self.line_offsets = SubRange (self.parent_model.line_offsets,
|
||||
start_index, last_index)
|
||||
self.line_levels = SubRange (self.parent_model.line_levels,
|
||||
start_index, last_index)
|
||||
|
||||
def parent_line_index (self, line_index):
|
||||
|
||||
start_index = self.line_index_range[0]
|
||||
|
||||
return line_index + start_index
|
||||
|
||||
class DebugLevelFilter (Filter):
|
||||
|
||||
def __init__ (self, debug_level):
|
||||
|
@ -979,10 +1031,14 @@ class Window (object):
|
|||
self.actions.reload_file.props.sensitive = False
|
||||
|
||||
group = gtk.ActionGroup ("RowActions")
|
||||
group.add_actions ([("edit-copy-line", gtk.STOCK_COPY, _("Copy line"), "<Ctrl>C"),
|
||||
group.add_actions ([("omit-before-line", None, _("Omit lines before this one")),
|
||||
("omit-after-line", None, _("Omit lines after this one")),
|
||||
("show-hidden-lines", None, _("Show omitted lines")),
|
||||
("edit-copy-line", gtk.STOCK_COPY, _("Copy line"), "<Ctrl>C"),
|
||||
("edit-copy-message", gtk.STOCK_COPY, _("Copy message")),
|
||||
("filter-out-higher-levels", None, _("Filter out higher debug levels"))])
|
||||
self.actions.add_group (group)
|
||||
self.actions.show_hidden_lines.props.sensitive = False
|
||||
|
||||
self.actions.add_group (self.column_manager.action_group)
|
||||
|
||||
|
@ -1034,6 +1090,7 @@ class Window (object):
|
|||
|
||||
for action_name in ("new-window", "open-file", "reload-file",
|
||||
"close-window", "cancel-load",
|
||||
"omit-before-line", "omit-after-line", "show-hidden-lines",
|
||||
"edit-copy-line", "edit-copy-message",
|
||||
"filter-out-higher-levels",
|
||||
"show-about",):
|
||||
|
@ -1137,6 +1194,51 @@ class Window (object):
|
|||
|
||||
self.close ()
|
||||
|
||||
def handle_omit_after_line_action_activate (self, action):
|
||||
|
||||
first_index = self.log_filter.parent_line_index (0)
|
||||
try:
|
||||
filtered_line_index = self.get_active_line_index ()
|
||||
except ValueError:
|
||||
return
|
||||
last_index = self.log_filter.parent_line_index (filtered_line_index)
|
||||
|
||||
self.logger.info ("omitting lines after %i (abs %i), first line is abs %i",
|
||||
filtered_line_index,
|
||||
last_index,
|
||||
first_index)
|
||||
|
||||
self.log_filter = RangeFilteredLogModel (self.log_model)
|
||||
self.log_filter.set_range (first_index, last_index + 1)
|
||||
self.log_view.props.model = self.log_filter
|
||||
self.actions.show_hidden_lines.props.sensitive = True
|
||||
|
||||
def handle_omit_before_line_action_activate (self, action):
|
||||
|
||||
try:
|
||||
filtered_line_index = self.get_active_line_index ()
|
||||
except ValueError:
|
||||
return
|
||||
first_index = self.log_filter.parent_line_index (filtered_line_index)
|
||||
last_index = self.log_filter.parent_line_index (len (self.log_filter) - 1)
|
||||
|
||||
self.logger.info ("omitting lines before %i (abs %i), last line is abs %i",
|
||||
filtered_line_index,
|
||||
first_index,
|
||||
last_index)
|
||||
|
||||
self.log_filter = RangeFilteredLogModel (self.log_model)
|
||||
self.log_filter.set_range (first_index, last_index)
|
||||
self.log_view.props.model = self.log_filter
|
||||
self.actions.show_hidden_lines.props.sensitive = True
|
||||
|
||||
def handle_show_hidden_lines_action_activate (self, action):
|
||||
|
||||
self.logger.info ("restoring model filter to show all lines")
|
||||
self.log_filter = FilteredLogModel (self.log_model)
|
||||
self.log_view.props.model = self.log_filter
|
||||
self.actions.show_hidden_lines.props.sensitive = False
|
||||
|
||||
def handle_edit_copy_line_action_activate (self, action):
|
||||
|
||||
line_index = self.get_active_line_index ()
|
||||
|
|
|
@ -647,8 +647,14 @@ class TimelineFeature (FeatureBase):
|
|||
action.connect ("toggled", handler)
|
||||
action.props.active = self.state.shown
|
||||
|
||||
handler = self.handle_log_view_notify_model
|
||||
self.notify_model_id = self.log_view.connect ("notify::model", handler)
|
||||
|
||||
def handle_detach_window (self, window):
|
||||
|
||||
self.log_view.disconnect (self.notify_model_id)
|
||||
self.log_view = None
|
||||
|
||||
window.ui_manager.remove_ui (self.merge_id)
|
||||
self.merge_id = None
|
||||
|
||||
|
@ -659,7 +665,22 @@ class TimelineFeature (FeatureBase):
|
|||
|
||||
def handle_attach_log_file (self, window, log_file):
|
||||
|
||||
model = window.log_filter
|
||||
pass
|
||||
|
||||
def handle_detach_log_file (self, window, log_file):
|
||||
|
||||
self.timeline.clear ()
|
||||
self.vtimeline.clear ()
|
||||
|
||||
def handle_log_view_notify_model (self, view, gparam):
|
||||
|
||||
model = view.props.model
|
||||
|
||||
if model is None:
|
||||
self.timeline.clear ()
|
||||
self.vtimeline.clear ()
|
||||
return
|
||||
|
||||
self.timeline.update (model)
|
||||
|
||||
# Need to dispatch these idly with a low priority to avoid triggering a
|
||||
|
@ -670,11 +691,6 @@ class TimelineFeature (FeatureBase):
|
|||
return False
|
||||
gobject.idle_add (idle_update, priority = gobject.PRIORITY_LOW)
|
||||
|
||||
def handle_detach_log_file (self, window, log_file):
|
||||
|
||||
self.timeline.clear ()
|
||||
self.vtimeline.clear ()
|
||||
|
||||
def update_timeline_position (self):
|
||||
|
||||
model = self.log_view.props.model
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
</menu>
|
||||
<placeholder name="ViewMenuAdditions"/>
|
||||
<separator/>
|
||||
<menuitem name="ViewContextMenuOmitBefore" action="omit-before-line"/>
|
||||
<menuitem name="ViewContextMenuOmitAfter" action="omit-after-line"/>
|
||||
<menuitem name="ViewContextMenuShowHidden" action="show-hidden-lines"/>
|
||||
<menuitem name="ViewContextMenuCopyMessage" action="edit-copy-message"/>
|
||||
<menuitem name="ViewContextMenuCopyLine" action="edit-copy-line"/>
|
||||
<menuitem name="ViewContextMenuFilterLevel" action="filter-out-higher-levels"/>
|
||||
|
|
Loading…
Reference in a new issue