Example #1
0
    def undo(self):
        """Undo removing of a tab."""
        # Remove unused tab which may be created after the last tab is closed
        last_close = config.get('tabs', 'last-close')
        use_current_tab = False
        if last_close in ['blank', 'startpage', 'default-page']:
            only_one_tab_open = self.count() == 1
            no_history = self.widget(0).history().count() == 1
            urls = {
                'blank': QUrl('about:blank'),
                'startpage': QUrl(config.get('general', 'startpage')[0]),
                'default-page': config.get('general', 'default-page'),
            }
            first_tab_url = self.widget(0).page().mainFrame().requestedUrl()
            last_close_urlstr = urls[last_close].toString().rstrip('/')
            first_tab_urlstr = first_tab_url.toString().rstrip('/')
            last_close_url_used = first_tab_urlstr == last_close_urlstr
            use_current_tab = (only_one_tab_open and no_history and
                               last_close_url_used)

        url, history_data = self._undo_stack.pop()

        if use_current_tab:
            self.openurl(url, newtab=False)
            newtab = self.widget(0)
        else:
            newtab = self.tabopen(url, background=False)

        qtutils.deserialize(history_data, newtab.history())
Example #2
0
    def undo(self):
        """Undo removing of a tab."""
        # Remove unused tab which may be created after the last tab is closed
        last_close = config.get('tabs', 'last-close')
        use_current_tab = False
        if last_close in ['blank', 'startpage', 'default-page']:
            only_one_tab_open = self.count() == 1
            no_history = self.widget(0).history().count() == 1
            urls = {
                'blank': QUrl('about:blank'),
                'startpage': QUrl(config.get('general', 'startpage')[0]),
                'default-page': config.get('general', 'default-page'),
            }
            first_tab_url = self.widget(0).page().mainFrame().requestedUrl()
            last_close_urlstr = urls[last_close].toString().rstrip('/')
            first_tab_urlstr = first_tab_url.toString().rstrip('/')
            last_close_url_used = first_tab_urlstr == last_close_urlstr
            use_current_tab = (only_one_tab_open and no_history
                               and last_close_url_used)

        url, history_data = self._undo_stack.pop()

        if use_current_tab:
            self.openurl(url, newtab=False)
            newtab = self.widget(0)
        else:
            newtab = self.tabopen(url, background=False)

        qtutils.deserialize(history_data, newtab.history())
Example #3
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        cur_tabbed_browser = self._tabbed_browser()
        curtab = self._current_widget()
        cur_title = cur_tabbed_browser.page_title(self._current_index())
        # The new tab could be in a new tabbed_browser (e.g. because of
        # tabs-are-windows being set)
        new_tabbed_browser = self._tabbed_browser(window)
        newtab = new_tabbed_browser.tabopen(background=bg, explicit=True)
        new_tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                        window=newtab.win_id)
        idx = new_tabbed_browser.indexOf(newtab)
        new_tabbed_browser.set_page_title(idx, cur_title)
        new_tabbed_browser.setTabIcon(idx, curtab.icon())
        newtab.keep_icon = True
        newtab.setZoomFactor(curtab.zoomFactor())
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Example #4
0
    def undo(self):
        """Undo removing of a tab."""
        # Remove unused tab which may be created after the last tab is closed
        last_close = config.get("tabs", "last-close")
        use_current_tab = False
        if last_close in ["blank", "startpage", "default-page"]:
            only_one_tab_open = self.count() == 1
            no_history = self.widget(0).history().count() == 1
            urls = {
                "blank": QUrl("about:blank"),
                "startpage": QUrl(config.get("general", "startpage")[0]),
                "default-page": config.get("general", "default-page"),
            }
            first_tab_url = self.widget(0).page().mainFrame().requestedUrl()
            last_close_urlstr = urls[last_close].toString().rstrip("/")
            first_tab_urlstr = first_tab_url.toString().rstrip("/")
            last_close_url_used = first_tab_urlstr == last_close_urlstr
            use_current_tab = only_one_tab_open and no_history and last_close_url_used

        url, history_data = self._undo_stack.pop()

        if use_current_tab:
            self.openurl(url, newtab=False)
            newtab = self.widget(0)
        else:
            newtab = self.tabopen(url, background=False)

        qtutils.deserialize(history_data, newtab.history())
Example #5
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        cur_tabbed_browser = self._tabbed_browser()
        curtab = self._current_widget()
        cur_title = cur_tabbed_browser.page_title(self._current_index())
        # The new tab could be in a new tabbed_browser (e.g. because of
        # tabs-are-windows being set)
        new_tabbed_browser = self._tabbed_browser(window)
        newtab = new_tabbed_browser.tabopen(background=bg, explicit=True)
        new_tabbed_browser = objreg.get('tabbed-browser',
                                        scope='window',
                                        window=newtab.win_id)
        idx = new_tabbed_browser.indexOf(newtab)
        new_tabbed_browser.set_page_title(idx, cur_title)
        new_tabbed_browser.setTabIcon(idx, curtab.icon())
        newtab.keep_icon = True
        newtab.setZoomFactor(curtab.zoomFactor())
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Example #6
0
def test_serialize(obj):
    """Test a serialize/deserialize round trip.

    Args:
        obj: The object to test with.
    """
    new_obj = type(obj)()
    qtutils.deserialize(qtutils.serialize(obj), new_obj)
    assert new_obj == obj
Example #7
0
def test_serialize(obj):
    """Test a serialize/deserialize round trip.

    Args:
        obj: The object to test with.
    """
    new_obj = type(obj)()
    qtutils.deserialize(qtutils.serialize(obj), new_obj)
    assert new_obj == obj
Example #8
0
    def tab_clone(self, bg=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.

        Return:
            The new QWebView.
        """
        curtab = self._current_widget()
        tabbed_browser = objreg.get('tabbed-browser')
        newtab = tabbed_browser.tabopen(background=bg, explicit=True)
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Example #9
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        curtab = self._current_widget()
        tabbed_browser = self._tabbed_browser(window)
        newtab = tabbed_browser.tabopen(background=bg, explicit=True)
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Example #10
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        curtab = self._current_widget()
        tabbed_browser = self._tabbed_browser(window)
        newtab = tabbed_browser.tabopen(background=bg, explicit=True)
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Example #11
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        curtab = self._current_widget()
        tabbed_browser = self._tabbed_browser(window)
        newtab = tabbed_browser.tabopen(background=bg, explicit=True)
        idx = tabbed_browser.indexOf(newtab)
        tabbed_browser.setTabText(idx, curtab.title().replace('&', '&&'))
        tabbed_browser.setTabIcon(idx, curtab.icon())
        newtab.keep_icon = True
        newtab.setZoomFactor(curtab.zoomFactor())
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Example #12
0
 def deserialize(self, data):
     return qtutils.deserialize(data, self._history)
Example #13
0
 def undo(self):
     """Undo removing of a tab."""
     url, history_data = self._undo_stack.pop()
     newtab = self.tabopen(url)
     qtutils.deserialize(history_data, newtab.history())
Example #14
0
 def undo(self):
     """Undo removing of a tab."""
     url, history_data = self._undo_stack.pop()
     newtab = self.tabopen(url)
     qtutils.deserialize(history_data, newtab.history())