From f8dffb4e5c56b663eb4678ee82aa56043899377d Mon Sep 17 00:00:00 2001 From: thuck Date: Mon, 7 Nov 2016 08:02:25 +0100 Subject: [PATCH] Some modifications from initial feedback Moved pin information from BrowserTab to TabData. Changed attribute from pin to pinned. Changed "ifs" to implicit check boolen value. Removed blancked line on before else statement. --- qutebrowser/browser/browsertab.py | 3 ++- qutebrowser/browser/commands.py | 15 ++++++++++----- qutebrowser/mainwindow/tabwidget.py | 4 ++-- qutebrowser/misc/sessions.py | 4 ++-- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 67d2bee44..843447825 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -86,6 +86,7 @@ class TabData: viewing_source: Set if we're currently showing a source view. open_target: How the next clicked link should be opened. override_target: Override for open_target for fake clicks (like hints). + pinned: Flag to pin the tab """ def __init__(self): @@ -94,6 +95,7 @@ class TabData: self.inspector = None self.open_target = usertypes.ClickTarget.normal self.override_target = None + self.pinned = False def combined_target(self): if self.override_target is not None: @@ -560,7 +562,6 @@ class AbstractTab(QWidget): self._mouse_event_filter = mouse.MouseEventFilter( self, widget_class=self.WIDGET_CLASS, parent=self) self.backend = None - self.pin = False # FIXME:qtwebengine Should this be public api via self.hints? # Also, should we get it out of objreg? diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 4fb076d80..d6ab0771a 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -229,7 +229,7 @@ class CommandDispatcher: if tab is None: return - if tab.pin is True: + if tab.data.pinned: result = message.ask("Are you sure you want to close a pinned tab?", mode=usertypes.PromptMode.yesno, default=False) @@ -251,13 +251,19 @@ class CommandDispatcher: @cmdutils.argument('index') @cmdutils.argument('count', count=True) def tab_pin(self, index=None, count=None): + """Pin/Unpin the current tab. + + Args: + index: Location where the tab should be pinned/unpinned. + count: The tab index to pin or unpin + """ tab = self._cntwidget(count) if tab is None: return - tab.pin = not tab.pin + tab.data.pinned = not tab.data.pinned - if tab.pin is True: + if tab.data.pinned: index = 1 if index is None else int(index) else: index = self._count() if index is None else int(index) @@ -307,9 +313,8 @@ class CommandDispatcher: else: # Explicit count with a tab that doesn't exist. return - elif curtab.pin is True: + elif curtab.data.pinned: message.info("Tab is pinned!") - else: curtab.openurl(cur_url) diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 4f1d45842..a6d56014b 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -125,7 +125,7 @@ class TabWidget(QTabWidget): fields['title'] = page_title fields['title_sep'] = ' - ' if page_title else '' fields['perc_raw'] = tab.progress() - fields['pin'] = tab.pin + fields['pin'] = tab.data.pinned if tab.load_status() == usertypes.LoadStatus.loading: fields['perc'] = '[{}%] '.format(tab.progress()) @@ -448,7 +448,7 @@ class TabBar(QTabBar): #TODO: relative size and/or configured one try: tab = objreg.get('tab', scope='tab', window=self._win_id, tab=index) - if tab.pin is True: + if tab.data.pinned: size = QSize(40, height) qtutils.ensure_valid(size) return size diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index d7c844c77..ce1582413 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -206,7 +206,7 @@ class SessionManager(QObject): pos = user_data['scroll-pos'] data['scroll-pos'] = {'x': pos.x(), 'y': pos.y()} - data['pin'] = tab.pin + data['pin'] = tab.data.pinned return data @@ -336,7 +336,7 @@ class SessionManager(QObject): user_data['scroll-pos'] = QPoint(pos['x'], pos['y']) if 'pin' in histentry: - new_tab.pin = histentry['pin'] + new_tab.data.pinned = histentry['pin'] active = histentry.get('active', False) url = QUrl.fromEncoded(histentry['url'].encode('ascii'))