Skip to content

Commit

Permalink
Add config option to enable tree-tabs
Browse files Browse the repository at this point in the history
The underlying structures always stay enabled as the overhead is very small;
this option only toggles show of the tree
  • Loading branch information
pinusc committed Feb 17, 2019
1 parent c9b5d71 commit 411d39a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
5 changes: 5 additions & 0 deletions qutebrowser/config/configdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,11 @@ tabs.wrap:
type: Bool
desc: Wrap when changing tabs.

tabs.tree_tabs:
default: false
type: Bool
desc: Enable tree-tabs

## url

url.auto_search:
Expand Down
35 changes: 23 additions & 12 deletions qutebrowser/mainwindow/tabwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ def __init__(self, win_id, parent=None):
self.setElideMode(Qt.ElideRight)
self.setUsesScrollButtons(True)
bar.setDrawBase(False)
self._init_config()
config.instance.changed.connect(self._init_config)

# root of the tab tree, common for all tabs in the window
self.tree_root = Node(None)

self._init_config()
config.instance.changed.connect(self._init_config)


@config.change_filter('tabs')
def _init_config(self):
"""Initialize attributes based on the config."""
Expand All @@ -99,6 +101,12 @@ def _init_config(self):
tabbar.setSelectionBehaviorOnRemove(selection_behavior)
tabbar.refresh()

# For tree-tabs
self.update_tab_titles() # Must also be called when deactivating
if config.cache['tabs.tree_tabs']:
# Positions matter only if enabling
self.update_tree_tab_positions('configChange')

def set_tab_indicator_color(self, idx, color):
"""Set the tab indicator color.
Expand Down Expand Up @@ -157,18 +165,21 @@ def update_tab_title(self, idx, field=None):
fields = self.get_tab_fields(idx)
fields['title'] = fields['title'].replace('&', '&&')

# TODO move to custom TreeTab class as a function with memoziation
# we remove the first two chars because every tab is child of tree root
# and that gets rendered as well
tree_prefixes = [pre[2:] for pre, _ in render_tree(self.tree_root)]
if config.val.tabs.tree_tabs:
# TODO move to custom TreeTab class as a function with memoziation
# we remove the first two chars because every tab is child of tree root
# and that gets rendered as well
tree_prefixes = [pre[2:] for pre, _ in render_tree(self.tree_root)]

# probably a hack, I believe there is a better way to check if the window and the first tab is initialized before tree root
if len(tree_prefixes) > self.count():
tree_prefix = tree_prefixes[idx+1]
else:
tree_prefix = ""
# probably a hack, I believe there is a better way to check if the window and the first tab is initialized before tree root
if len(tree_prefixes) > self.count():
tree_prefix = tree_prefixes[idx+1]
else:
tree_prefix = ""

fields['index'] = tree_prefix + str(idx + 1)
fields['index'] = tree_prefix + str(idx + 1)
else:
fields['index'] = idx

title = '' if fmt is None else fmt.format(**fields)
tabbar = self.tabBar()
Expand Down

0 comments on commit 411d39a

Please sign in to comment.