Refactor tab and window title update methods
This commit is contained in:
parent
054e9ab439
commit
bf32c544a2
@ -161,31 +161,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
# (e.g. last tab removed)
|
||||
log.webview.debug("Not updating window title because index is -1")
|
||||
return
|
||||
tabtitle = self.page_title(idx)
|
||||
widget = self.widget(idx)
|
||||
|
||||
fields = {}
|
||||
if widget.load_status == webview.LoadStatus.loading:
|
||||
fields['perc'] = '[{}%] '.format(widget.progress)
|
||||
else:
|
||||
fields['perc'] = ''
|
||||
fields['perc_raw'] = widget.progress
|
||||
fields['title'] = tabtitle
|
||||
fields['title_sep'] = ' - ' if tabtitle else ''
|
||||
fields = self.get_tab_fields(idx)
|
||||
fields['id'] = self._win_id
|
||||
y = widget.scroll_pos[1]
|
||||
if y <= 0:
|
||||
scroll_pos = 'top'
|
||||
elif y >= 100:
|
||||
scroll_pos = 'bot'
|
||||
else:
|
||||
scroll_pos = '{:2}%'.format(y)
|
||||
|
||||
fields['scroll_pos'] = scroll_pos
|
||||
try:
|
||||
fields['host'] = self.current_url().host()
|
||||
except qtutils.QtValueError:
|
||||
fields['host'] = ''
|
||||
|
||||
fmt = config.get('ui', 'window-title-format')
|
||||
self.window().setWindowTitle(fmt.format(**fields))
|
||||
|
@ -99,19 +99,34 @@ class TabWidget(QTabWidget):
|
||||
|
||||
def update_tab_title(self, idx):
|
||||
"""Update the tab text for the given tab."""
|
||||
fields = self.get_tab_fields(idx)
|
||||
fields['title'] = fields['title'].replace('&', '&&')
|
||||
fields['index'] = idx + 1
|
||||
|
||||
fmt = config.get('tabs', 'title-format')
|
||||
self.tabBar().setTabText(idx, fmt.format(**fields))
|
||||
|
||||
def get_tab_fields(self, idx):
|
||||
"""Get the tab field data."""
|
||||
widget = self.widget(idx)
|
||||
page_title = self.page_title(idx).replace('&', '&&')
|
||||
page_title = self.page_title(idx)
|
||||
|
||||
fields = {}
|
||||
fields['id'] = widget.tab_id
|
||||
fields['title'] = page_title
|
||||
fields['title_sep'] = ' - ' if page_title else ''
|
||||
fields['perc_raw'] = widget.progress
|
||||
|
||||
if widget.load_status == webview.LoadStatus.loading:
|
||||
fields['perc'] = '[{}%] '.format(widget.progress)
|
||||
else:
|
||||
fields['perc'] = ''
|
||||
fields['perc_raw'] = widget.progress
|
||||
fields['title'] = page_title
|
||||
fields['index'] = idx + 1
|
||||
fields['id'] = widget.tab_id
|
||||
fields['title_sep'] = ' - ' if page_title else ''
|
||||
|
||||
try:
|
||||
fields['host'] = self.tab_url(idx).host()
|
||||
except qtutils.QtValueError:
|
||||
fields['host'] = ''
|
||||
|
||||
y = widget.scroll_pos[1]
|
||||
if y <= 0:
|
||||
scroll_pos = 'top'
|
||||
@ -121,13 +136,7 @@ class TabWidget(QTabWidget):
|
||||
scroll_pos = '{:2}%'.format(y)
|
||||
|
||||
fields['scroll_pos'] = scroll_pos
|
||||
try:
|
||||
fields['host'] = self.tab_url(idx).host()
|
||||
except qtutils.QtValueError:
|
||||
fields['host'] = ''
|
||||
|
||||
fmt = config.get('tabs', 'title-format')
|
||||
self.tabBar().setTabText(idx, fmt.format(**fields))
|
||||
return fields
|
||||
|
||||
@config.change_filter('tabs', 'title-format')
|
||||
def update_tab_titles(self):
|
||||
|
Loading…
Reference in New Issue
Block a user