def _createContextMenu(self, pos):
        '''
        @param: pos QPoint
        '''
        menu = QMenu()
        actNewTab = menu.addAction(IconProvider.newTabIcon(),
                                   _('Open in new tab'))
        actNewWindow = menu.addAction(IconProvider.newWindowIcon(),
                                      _('Open in new window'))
        actNewPrivateWindow = menu.addAction(
            IconProvider.privateBrowsingIcon(),
            _('Open in new private window'))

        menu.addSeparator()
        actDelete = menu.addAction(QIcon.fromTheme('edit-delete'), _('Delete'))

        actNewTab.triggered.connect(lambda x: self._openUrlInNewTab())
        actNewWindow.triggered.connect(lambda x: self._openUrlInNewWindow())
        actNewPrivateWindow.triggered.connect(
            lambda x: self._openUrlInNewPrivateWindow())
        actDelete.triggered.connect(self.ui.historyTree.removeSelectedItems)

        if self.ui.historyTree.selectedUrl().isEmpty():
            actNewTab.setDisabled(True)
            actNewWindow.setDisabled(True)
            actNewPrivateWindow.setDisabled(True)

        menu.exec_(pos)
    def _createContextMenu(self, pos):
        menu = QMenu()
        actNewTab = menu.addAction(IconProvider.newTabIcon(),
                                   _("Open in new tab"))
        actNewWindow = menu.addAction(IconProvider.newWindowIcon(),
                                      _("Open in new window"))
        actNewPrivateWindow = menu.addAction(
            IconProvider.privateBrowsingIcon(),
            _("Open in new private window"))

        menu.addSeparator()
        actCopyUrl = menu.addAction(_("Copy url"), self._copyUrl)
        actCopyTitle = menu.addAction(_("Copy title"), self._copyTitle)

        menu.addSeparator()
        actDelete = menu.addAction(QIcon.fromTheme("edit-delete"), _("Delete"))

        actNewTab.triggered.connect(self._openUrlInNewTab)
        actNewWindow.triggered.connect(self._openUrlInNewWindow)
        actNewPrivateWindow.triggered.connect(self._openUrlInNewPrivateWindow)
        actDelete.triggered.connect(self._ui.historyTree.removeSelectedItems)

        if self._ui.historyTree.selectedUrl().isEmpty():
            actNewTab.setDisabled(True)
            actNewWindow.setDisabled(True)
            actNewPrivateWindow.setDisabled(True)
            actCopyTitle.setDisabled(True)
            actCopyUrl.setDisabled(True)

        menu.exec_(pos)
    def _contextMenuRequested(self, pos):
        '''
        @param: pos QPoint
        '''
        # BookmarksToolbarButton
        button = self._buttonAt(pos)
        if button:
            self._clickedBookmark = button.bookmark()
        else:
            self._clickedBookmark = None

        menu = QMenu()
        actNewTab = menu.addAction(IconProvider.newTabIcon(),
                                   _('Open in new tab'))
        actNewWindow = menu.addAction(IconProvider.newWindowIcon(),
                                      _('Open in new window'))
        actNewPrivateWindow = menu.addAction(
            IconProvider.privateBrowsingIcon(),
            _('Open in new private window'))
        menu.addSeparator()
        actEdit = menu.addAction(_('Edit'))
        actDelete = menu.addAction(QIcon.fromTheme('edit-delete'), _('Delete'))
        menu.addSeparator()
        self._actShowOnlyIcons = menu.addAction(_('Show Only Icons'))
        self._actShowOnlyIcons.setCheckable(True)
        self._actShowOnlyIcons.setChecked(
            self._bookmarks.showOnlyIconsInToolbar())
        self._actShowOnlyIcons.toggled.connect(self._showOnlyIconsChanged)
        self._actShowOnlyText = menu.addAction(_('Show Only Text'))
        self._actShowOnlyText.setCheckable(True)
        self._actShowOnlyText.setChecked(
            self._bookmarks.showOnlyTextInToolbar())
        self._actShowOnlyText.toggled.connect(self._showOnlyTextChanged)

        actNewTab.triggered.connect(self._openBookmarkInNewTab)
        actNewWindow.triggered.connect(self._openBookmarkInNewWindow)
        actNewPrivateWindow.triggered.connect(
            self._openBookmarkInNewPrivateWindow)
        actEdit.triggered.connect(self._editBookmark)
        actDelete.triggered.connect(self._deleteBookmark)

        canBeModify = self._clickedBookmark and self._bookmarks.canBeModified(
            self._clickedBookmark)
        actEdit.setEnabled(canBeModify)
        actDelete.setEnabled(canBeModify)
        canOpen = self._clickedBookmark and self._clickedBookmark.isUrl()
        actNewTab.setEnabled(canOpen)
        actNewWindow.setEnabled(canOpen)
        actNewPrivateWindow.setEnabled(canOpen)

        menu.exec_(self.mapToGlobal(pos))

        if button:
            # Clear mouse over state after closing menu
            button.update()

        self._clickedBookmark = None
        self._actShowOnlyIcons = None
        self._actShowOnlyText = None
Beispiel #4
0
    def _createContextMenu(self, pos):
        '''
        @param: pos QPoint
        '''
        menu = QMenu()
        actNewTab = menu.addAction(IconProvider.newTabIcon(), _('Open in new tab'))
        actNewWindow = menu.addAction(IconProvider.newWindowIcon(), _('Open in new window'))
        actNewPrivateWindow = menu.addAction(IconProvider.privateBrowsingIcon(), _('Open in new private window'))

        menu.addSeparator()
        actNewBookmark = menu.addAction(_('New Bookmark'), self._addBookmark)
        actNewFolder = menu.addAction(_('New Folder'), self._addFolder)
        actNewSeparator = menu.addAction(_('New Separator'), self._addSeparator)
        menu.addSeparator()
        actDelete = menu.addAction(QIcon.fromTheme('edit-delete'), _('Delete'))

        actNewTab.triggered.connect(self._openBookmarkInNewTab)
        actNewWindow.triggered.connect(self._openBookmarkInNewWindow)
        actNewPrivateWindow.triggered.connect(self._openBookmarkInNewPrivateWindow)
        actDelete.triggered.connect(self._deleteBookmarks)

        canBeDelete = False
        # QList<BookmarkItem>
        items = self._ui.tree.selectedBookmarks()
        for item in items:
            if self._bookmarks.canBeModified(item):
                canBeDelete = True
                break

        if not canBeDelete:
            actDelete.setDisabled(True)

        if not self._selectedBookmark or not self._selectedBookmark.isUlr():
            actNewTab.setDisabled(True)
            actNewWindow.setDisabled(True)
            actNewPrivateWindow.setDisabled(True)

        if not self._selectedBookmark:
            actNewBookmark.setDisabled(True)
            actNewFolder.setDisabled(True)
            actNewSeparator.setDisabled(True)

        menu.exec_(pos)
Beispiel #5
0
    def _createLinkContextMenu(self, menu, hitTest):
        '''
        @param: menu QMenu
        @param: hitTest WebHitTestResult
        '''
        menu.addSeparator()
        act = Action(IconProvider.newTabIcon(), _('Open link in new &tab'), menu)
        act.setData(hitTest.linkUrl())
        act.triggered.connect(lambda: self.userDefinedOpenUrlInNewTab())
        act.ctrlTriggered.connect(lambda: self.userDefineOpenUrlInBgTab())
        menu.addAction(act)
        act = menu.addAction(IconProvider.newWindowIcon(), _('Open link in new &window'),
                self._openUrlInNewWindow)
        act.setData(hitTest.linkUrl())
        act = menu.addAction(IconProvider.privateBrowsingIcon(), _('Open link in &private window'),
                gVar.app.startPrivateBrowsing)
        act.setData(hitTest.linkUrl())
        menu.addSeparator()

        bData = [hitTest.linkUrl(), hitTest.linkTitle()]  # QVariantList
        act = menu.addAction(QIcon.fromTheme('bookmark-new'), _('B&ookmark link'),
            self._bookmarkLink)
        act.setData(bData)

        menu.addAction(QIcon.fromTheme('document-save'), _('&Save link as...'),
                self._downloadLinkToDisk)
        act = menu.addAction(QIcon.fromTheme('mail-message-new'), _('Send link...'),
                self._sendTextByMail)
        act.setData(hitTest.linkUrl().toEncoded())
        act = menu.addAction(QIcon.fromTheme('edit-copy'), _('&Copy link address'),
                self._copyLinkToClipboard)
        act.setData(hitTest.linkUrl())
        menu.addSeparator()

        if self.selectedText():
            menu.addAction(self.pageAction(QWebEnginePage.Copy))
Beispiel #6
0
    def _init(self):
        # Standard actions - needed on Mac to be placed correctly in
        # "application" menu
        action = QAction(QIcon.fromTheme('help-about'), '&About App', self)
        action.setMenuRole(QAction.AboutRole)
        action.triggered.connect(self._showAboutDialog)
        self._actions['Standard/About'] = action

        action = QAction(IconProvider.settingsIcon(), 'Pr&eferences', self)
        action.setMenuRole(QAction.PreferencesRole)
        action.setShortcut(QKeySequence(QKeySequence.Preferences))
        action.triggered.connect(self._showPreferences)
        self._actions['Standard/Preferences'] = action

        action = QAction(QIcon.fromTheme('application-exit'), 'Quit', self)
        action.setMenuRole(QAction.QuitRole)
        # Shortcut set from browserWindow
        action.triggered.connect(self._quitApplication)
        self._actions['Standard/Quit'] = action

        # File menu
        self._menuFile = QMenu('&File', self)
        self._menuFile.aboutToShow.connect(self._aboutToShowFileMenu)

        self._ADD_ACTION('File/NewTab', self._menuFile, IconProvider.newTabIcon(),
            'New Tab', self._newTab, 'Ctrl+T')
        self._ADD_ACTION('File/NewWindow', self._menuFile, IconProvider.newWindowIcon(),
            '&New Window', self._newWindow, 'Ctrl+N')
        self._ADD_ACTION('File/NewPrivateWindow', self._menuFile, IconProvider.privateBrowsingIcon(),
            'New &Private Window', self._newPrivateWindow, 'Ctrl+Shift+P')
        self._ADD_ACTION('File/OpenLocation', self._menuFile, QIcon.fromTheme('document-open-remote'),
            'Open Location', self._openLocation, 'Ctrl+L')
        self._ADD_ACTION('File/OpenFile', self._menuFile, QIcon.fromTheme('document-open'),
            'Open &File...', self._openFile, 'Ctrl+O')
        self._ADD_ACTION('File/CloseWindow', self._menuFile, QIcon.fromTheme('window-close'),
            'Close Window', self._closeWindow, 'Ctrl+Shift+W')
        self._menuFile.addSeparator()

        sessionManager = gVar.app.sessionManager()
        if sessionManager:
            sessionsSubmenu = QMenu('Sessions', self)
            sessionsSubmenu.aboutToShow.connect(sessionManager._aboutToShowSessionsMenu)
            self._menuFile.addMenu(sessionsSubmenu)
            action = QAction('Session Manager', self)
            action.triggered.connect(sessionManager.openSessionManagerDialog)
            self._actions['File/SessionManager'] = action
            self._menuFile.addAction(action)
            self._menuFile.addSeparator()

        self._ADD_ACTION('File/SavePageAs', self._menuFile, QIcon.fromTheme('document-save'),
            '&Save Page As...', self._savePageAs, 'Ctrl+S')
        self._ADD_ACTION('File/SendLink', self._menuFile, QIcon.fromTheme('mail-message-new'),
            'Send Link...', self._sendLink, '')
        self._ADD_ACTION('File/Print', self._menuFile, QIcon.fromTheme('document-print'),
            '&Print...', self._printPage, 'Ctrl+P')
        self._menuFile.addSeparator()
        self._menuFile.addAction(self._actions['Standard/Quit'])

        # Edit Menu
        self._menuEdit = QMenu('&Edit', self)
        self._menuEdit.aboutToShow.connect(self._aboutToShowEditMenu)

        action = self._ADD_ACTION('Edit/Undo', self._menuEdit, QIcon.fromTheme('edit-undo'),
            '&Undo', self._editUndo, 'Ctrl+Z')
        action.setShortcutContext(Qt.WidgetShortcut)
        action = self._ADD_ACTION('Edit/Redo', self._menuEdit, QIcon.fromTheme('edit-redo'),
            '&Redo', self._editRedo, 'Ctrl+Shift+Z')
        action.setShortcutContext(Qt.WidgetShortcut)
        self._menuEdit.addSeparator()
        action = self._ADD_ACTION('Edit/Cut', self._menuEdit, QIcon.fromTheme('edit-cut'),
            '&Cut', self._editCut, 'Ctrl+X')
        action.setShortcutContext(Qt.WidgetShortcut)
        action = self._ADD_ACTION('Edit/Copy', self._menuEdit, QIcon.fromTheme('edit-copy'),
            'C&opy', self._editCopy, 'Ctrl+C')
        action.setShortcutContext(Qt.WidgetShortcut)
        action = self._ADD_ACTION('Edit/Paste', self._menuEdit, QIcon.fromTheme('edit-paste'),
            '&Paste', self._editPaste, 'Ctrl+V')
        action.setShortcutContext(Qt.WidgetShortcut)
        self._menuEdit.addSeparator()
        action = self._ADD_ACTION('Edit/SelectAll', self._menuEdit, QIcon.fromTheme('edit-select-all'),
            'Select &All', self._editSelectAll, 'Ctrl+A')
        action.setShortcutContext(Qt.WidgetShortcut)
        action = self._ADD_ACTION('Edit/Find', self._menuEdit, QIcon.fromTheme('edit-find'),
            '&Find', self._editFind, 'Ctrl+F')
        action.setShortcutContext(Qt.WidgetShortcut)

        self._menuFile.addSeparator()

        # View menu
        self._menuView = QMenu('&View', self)
        self._menuView.aboutToShow.connect(self._aboutToShowViewMenu)

        toolbarsMenu = QMenu('Toolbars', self._menuView)
        toolbarsMenu.aboutToShow.connect(self._aboutToShowtoolbarsMenu)
        sidebarMenu = QMenu('Sidebar', self._menuView)
        sidebarMenu.aboutToShow.connect(self._aboutToShowSidebarsMenu)
        encodingMenu = QMenu('Character &Encoding', self._menuView)
        encodingMenu.aboutToShow.connect(self._aboutToShowEncodingMenu)

        # Create menus to make shortcuts available event before first showing
        # the menu
        self._window.createToolbarsMenu(toolbarsMenu)
        self._window.createSidebarsMenu(sidebarMenu)

        self._menuView.addMenu(toolbarsMenu)
        self._menuView.addMenu(sidebarMenu)
        self._ADD_CHECKABLE_ACTION('View/ShowStatusBar', self._menuView, QIcon(),
            'Sta&tus Bar', self._showStatusBar, '')
        self._menuView.addSeparator()
        self._ADD_ACTION('View/Stop', self._menuView, QIcon.fromTheme('process-stop'),
            '&Stop', self._stop, 'Esc')
        self._ADD_ACTION('View/Reload', self._menuView, QIcon.fromTheme('view-refresh'),
            '&Reload', self._reload, 'F5')
        self._menuView.addSeparator()
        self._ADD_ACTION('View/ZoomIn', self._menuView, QIcon.fromTheme('zoom-in'),
            'Zoom &In', self._zoomIn, 'Ctrl++')
        self._ADD_ACTION('View/ZoomOut', self._menuView, QIcon.fromTheme('zoom-out'),
            'Zoom &Out', self._zoomOut, 'Ctrl+-')
        self._ADD_ACTION('View/ZoomReset', self._menuView, QIcon.fromTheme('zoom-original'),
            'Reset', self._zoomReset, 'Ctrl+0')
        self._menuView.addSeparator()
        self._menuView.addMenu(encodingMenu)
        self._menuView.addSeparator()
        action = self._ADD_ACTION('View/PageSource', self._menuView, QIcon.fromTheme('text-html'),
            '&Page Source', self._showPageSource, 'Ctrl+U')
        action.setShortcutContext(Qt.WidgetShortcut)
        self._ADD_CHECKABLE_ACTION('View/FullScreen', self._menuView, QIcon.fromTheme('view-fullscreen'),
            '&FullScreen', self._showFullScreen, 'F11')

        # Tool menu
        self._menuTools = QMenu('&Tools', self)
        self._menuTools.aboutToShow.connect(self._aboutToShowToolsMenu)

        self._ADD_ACTION('Tools/WebSearch', self._menuTools, QIcon.fromTheme('edit-find'),
            '&Web Search', self._webSearch, 'Ctrl+K')
        action = self._ADD_ACTION('Tools/SiteInfo', self._menuTools, QIcon.fromTheme('dialog-information'),
            'Site &Info', self._showSiteInfo, 'Ctrl+I')
        action.setShortcutContext(Qt.WidgetShortcut)
        self._menuTools.addSeparator()
        self._ADD_ACTION('Tools/DownloadManager', self._menuTools, QIcon.fromTheme('download'),
            '&Download Manager', self._showDownloadManager, 'Ctrl+Y')
        self._ADD_ACTION('Tools/CookiesManager', self._menuTools, QIcon(),
            '&Cookies Manager', self._showCookieManager, '')
        self._ADD_ACTION('Tools/WebInspector', self._menuTools, QIcon(),
            'Web In&spector', self._toggleWebInspector, 'Ctrl+Shift+I')
        self._ADD_ACTION('Tools/ClearRecentHistory', self._menuTools, QIcon.fromTheme('edit-clear'),
            'Clear Recent &History', self._showClearRecentHistoryDialog, 'Ctrl+Shift+Del')

        if not WebInspector.isEnabled():
            self._actions['Tools/WebInspector'].setVisible(False)

        self._submenuExtensions = QMenu('&Extensions', self)
        self._submenuExtensions.menuAction().setVisible(False)
        self._menuTools.addMenu(self._submenuExtensions)
        self._menuTools.addSeparator()

        # Help menu
        self._menuHelp = QMenu('&Help', self)

        # ifndef Q_OS_MACOS
        self._ADD_ACTION('Help/AboutQt', self._menuHelp, QIcon(),
            'About &Qt', self._aboutQt, '')
        self._menuHelp.addAction(self._actions['Standard/About'])
        self._menuHelp.addSeparator()
        # endif

        self._ADD_ACTION('Help/InfoAboutApp', self._menuHelp, QIcon.fromTheme('help-contents'),
            'Information about application', self._showInfoAboutApp, '')
        self._ADD_ACTION('Help/ConfigInfo', self._menuHelp, QIcon(),
            'Configuration Information', self._showConfigInfo, '')
        self._ADD_ACTION('Help/ReportIssue', self._menuHelp, QIcon(),
            'Report &Issue', self._reportIssue, '')

        self._actions['Help/InfoAboutApp'].setShortcut(QKeySequence(QKeySequence.HelpContents))

        # History menu
        self._menuHistory = HistoryMenu()
        self._menuHistory.setMainWindow(self._window)

        # Bookmarks menu
        self._menuBookmarks = BookmarksMenu()
        self._menuBookmarks.setMainWindow(self._window)

        # Other actions
        action = QAction(QIcon.fromTheme('user-trash'),
            'Restore &Closed Tab', self)
        action.setShortcut(QKeySequence('Ctrl+Shift+T'))
        action.triggered.connect(self._restoreClosedTab)
        self._actions['Other/RestoreClosedTab'] = action

        # # ifdef Q_OS_MACOS
        # self._actions['View/FullScreen'].setShortcut(QKeySequence('Ctrl+Meta+F'))
        # # Add standard actions to File Menu (as it won't be ever cleared) and
        # # Mac menubar should move them to "Application" menu
        # self._menuFile.addAction(self._actions['Standard/About'])
        # self._menuFile.addAction(self._actions['Standard/Preferences'])

        # # Prevent ConfigInfo action to be detected as "Preferences..." action in
        # # Mac
        # self._actions['Help/ConfigInfo'].setMenuRole(QAction.NoRole)

        # # Create Dock Menu
        # dockMenu = QMenu(0)
        # dockMenu.addAction(self._actions['File/NewTab'])
        # dockMenu.addAction(self._actions['File/NewWindow'])
        # dockMenu.addAction(self._actions['File/NewPrivateWindow'])
        # qt_mac_set_dock_menu(dockMenu)
        # # endif

        if const.OS_UNIX and not const.OS_MACOS:
            self._menuEdit.addAction(self._actions['Standard/Preferences'])
        elif not const.OS_MACOS:
            self._menuTools.addAction(self._actions['Standard/Preferences'])

        self._addActionsToWindow()
Beispiel #7
0
    def _init(self):
        tabWidget = self._window.tabWidget()
        if self._clickedTab != -1:
            webTab = tabWidget.webTab(self._clickedTab)
            if not webTab:
                return

            if webTab.webView().isLoading():
                self.addAction(QIcon.fromTheme('process-stop'), _('&Stop Tab'),
                               self._stopTab)
            else:
                self.addAction(QIcon.fromTheme('view-refresh'),
                               _('&Reload Tab'), self._reloadTab)

            self.addAction(QIcon.fromTheme('tab-duplicate'),
                           _('&Duplicate Tab'), self._duplicateTab)

            if self._options & self.ShowDetachTabAction and (
                    gVar.app.windowCount() > 1 or tabWidget.count() > 1):
                self.addAction(QIcon.fromTheme('tab-detach'), _('D&etach Tab'),
                               self._detachTab)

            self.addAction(
                webTab.isPinned() and _('Un&pin Tab') or _('&Pin Tab'),
                self._pinTab)
            self.addAction(
                webTab.isMuted() and _('Un&mute Tab') or _('&Mute Tab'),
                self._muteTab)

            if not webTab.isRestored():
                self.addAction(_('Load Tab'), self._loadTab)
            else:
                self.addAction(_('Unload Tab'), self._unloadTab)

            self.addSeparator()
            self.addAction(_('Re&load All Tabs'), tabWidget.reloadAllTabs)
            self.addAction(_('Bookmark &All Tabs'),
                           self._window.bookmarkAllTabs)
            self.addSeparator()

            if self._options & self.ShowCloseOtherTabsActions:
                self.addAction(_('Close Ot&her Tabs'),
                               self._closeAllButCurrent)
                self.addAction(
                    self._options & self.HorizontalTabs
                    and _('Close Tabs To The Right')
                    or _('Close Tabs To The Bottom'), self._closeToRight)
                self.addAction(
                    self._options & self.HorizontalTabs
                    and _('Close Tabs To The Left')
                    or _('Close Tabs To The Top'), self._closeToLeft)
                self.addSeparator()

            self.addAction(self._window.action('Other/RestoreClosedTab'))
            self.addAction(QIcon.fromTheme('window-close'), _('Cl&ose Tab'),
                           self._closeTab)
        else:
            self.addAction(IconProvider.newTabIcon(), _('&New tab'),
                           self._window.addTab)
            self.addSeparator()
            self.addAction(_('Reloa&d All Tabs'), tabWidget.reloadAllTabs)
            self.addAction(_('Bookmark &All Tabs'),
                           self._window.bookmarkAllTabs)
            self.addSeparator()
            self.addAction(self._window.action('Other/RestoreClosedTab'))

        self._window.action('Other/RestoreClosedTab').setEnabled(
            tabWidget.canRestoreTab())

        self.aboutToHide.connect(lambda: self._window.action(
            'Other/RestoreClosedTab').setEnabled(True))