Example #1
0
 def show_context_menu(self, pos):
     menu = QMenu(self)
     menu.addAction(actions['edit-toc'])
     menu.addAction(_('&Expand all'), self.view.expandAll)
     menu.addAction(_('&Collapse all'), self.view.collapseAll)
     menu.addAction(self.refresh_action)
     menu.exec_(self.view.mapToGlobal(pos))
 def show_context_menu(self, point):
     idx = self.currentIndex()
     if idx and idx.isValid() and not idx.data(Qt.UserRole).toPyObject():
         m = QMenu()
         m.addAction(QIcon(I('view.png')), _('View this cover at full size'), self.show_cover)
         m.addAction(QIcon(I('edit-copy.png')), _('Copy this cover to clipboard'), self.copy_cover)
         m.exec_(QCursor.pos())
Example #3
0
 def show_context_menu(self, point):
     idx = self.currentIndex()
     if idx and idx.isValid() and not idx.data(Qt.UserRole).toPyObject():
         m = QMenu()
         m.addAction(QIcon(I('view.png')),
                     _('View this cover at full size'), self.show_cover)
         m.exec_(QCursor.pos())
Example #4
0
 def show_context_menu(self, pos):
     menu = QMenu(self)
     menu.addAction(actions['edit-toc'])
     menu.addAction(_('&Expand all'), self.view.expandAll)
     menu.addAction(_('&Collapse all'), self.view.collapseAll)
     menu.addAction(self.refresh_action)
     menu.exec_(self.view.mapToGlobal(pos))
Example #5
0
 def context_menu(self, pos):
     m = QMenu()
     if self.items.count() > 0:
         m.addAction(QIcon(I('edit-copy.png')),
                     _('Copy list of errors to clipboard'),
                     self.copy_to_clipboard)
     if list(m.actions()):
         m.exec_(self.mapToGlobal(pos))
Example #6
0
 def contextMenuEvent(self, ev):
     menu = QMenu(self)
     ca = self.pageAction(QWebPage.Copy)
     if ca.isEnabled():
         menu.addAction(ca)
     menu.addAction(actions['reload-preview'])
     menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
     menu.exec_(ev.globalPos())
Example #7
0
 def contextMenuEvent(self, ev):
     menu = QMenu(self)
     ca = self.pageAction(QWebPage.Copy)
     if ca.isEnabled():
         menu.addAction(ca)
     menu.addAction(actions['reload-preview'])
     menu.addAction(QIcon(I('debug.png')), _('Inspect element'),
                    self.inspect)
     menu.exec_(ev.globalPos())
Example #8
0
 def contextMenuEvent(self, ev):
     cm = QMenu(self)
     paste = cm.addAction(_("Paste Cover"))
     copy = cm.addAction(_("Copy Cover"))
     if not QApplication.instance().clipboard().mimeData().hasImage():
         paste.setEnabled(False)
     copy.triggered.connect(self.copy_to_clipboard)
     paste.triggered.connect(self.paste_from_clipboard)
     cm.exec_(ev.globalPos())
Example #9
0
 def contextMenuEvent(self, ev):
     cm = QMenu(self)
     paste = cm.addAction(_('Paste Cover'))
     copy = cm.addAction(_('Copy Cover'))
     if not QApplication.instance().clipboard().mimeData().hasImage():
         paste.setEnabled(False)
     copy.triggered.connect(self.copy_to_clipboard)
     paste.triggered.connect(self.paste_from_clipboard)
     cm.exec_(ev.globalPos())
Example #10
0
 def contextMenuEvent(self, ev):
     m = QMenu(self)
     m.addAction(_('Sort alphabetically'), self.sort_alphabetically)
     hidden = self.current_db.prefs['virt_libs_hidden']
     if hidden:
         s = m._s = m.addMenu(_('Restore hidden tabs'))
         for x in hidden:
             s.addAction(x, partial(self.restore, x))
     m.addAction(_('Hide virtual library tabs'), self.disable_bar)
     m.exec_(ev.globalPos())
Example #11
0
 def contextMenuEvent(self, ev):
     m = QMenu(self)
     m.addAction(_('Sort alphabetically'), self.sort_alphabetically)
     hidden = self.current_db.prefs['virt_libs_hidden']
     if hidden:
         s = m._s = m.addMenu(_('Restore hidden tabs'))
         for x in hidden:
             s.addAction(x, partial(self.restore, x))
     m.addAction(_('Hide virtual library tabs'), self.disable_bar)
     m.exec_(ev.globalPos())
Example #12
0
 def show_context_menu(self, pos):
     m = QMenu(self)
     a = m.addAction
     for x in ('undo', 'redo'):
         a(actions['editor-%s' % x])
     m.addSeparator()
     for x in ('cut', 'copy', 'paste'):
         a(actions['editor-' + x])
     m.addSeparator()
     m.addAction(_('&Select all'), self.editor.select_all)
     m.addAction(actions['mark-selected-text'])
     m.exec_(self.editor.mapToGlobal(pos))
Example #13
0
 def contextMenuEvent(self, event):
     index = self.indexAt(event.pos())
     
     if not index.isValid():
         return
     
     plugin = self.model().get_plugin(index)
     
     menu = QMenu()
     ca = menu.addAction(_('Configure...'), partial(self.configure_plugin, plugin))
     if not plugin.is_customizable():
         ca.setEnabled(False)
     menu.exec_(event.globalPos())
Example #14
0
 def context_menu(self, pos):
     index = self.indexAt(pos)
     if index.isValid():
         char_code, ok = self.model().data(index, Qt.UserRole).toInt()
         if ok:
             m = QMenu(self)
             m.addAction(QIcon(I('edit-copy.png')), _('Copy %s to clipboard') % chr(char_code), partial(self.copy_to_clipboard, char_code))
             m.addAction(QIcon(I('rating.png')),
                         (_('Remove %s from favorites') if self.showing_favorites else _('Add %s to favorites')) % chr(char_code),
                         partial(self.remove_from_favorites, char_code))
             if self.showing_favorites:
                 m.addAction(_('Restore favorites to defaults'), self.restore_defaults)
             m.exec_(self.mapToGlobal(pos))
Example #15
0
 def context_menu(self, pos):
     index = self.indexAt(pos)
     if index.isValid():
         char_code, ok = self.model().data(index, Qt.UserRole).toInt()
         if ok:
             m = QMenu(self)
             m.addAction(QIcon(I('edit-copy.png')), _('Copy %s to clipboard') % chr(char_code), partial(self.copy_to_clipboard, char_code))
             m.addAction(QIcon(I('rating.png')),
                         (_('Remove %s from favorites') if self.showing_favorites else _('Add %s to favorites')) % chr(char_code),
                         partial(self.remove_from_favorites, char_code))
             if self.showing_favorites:
                 m.addAction(_('Restore favorites to defaults'), self.restore_defaults)
             m.exec_(self.mapToGlobal(pos))
Example #16
0
    def show_context_menu(self, pos):
        m = QMenu(self)
        a = m.addAction
        c = self.editor.cursorForPosition(pos)
        r = self.editor.syntax_range_for_cursor(c)
        if r is not None and r.format.property(SPELL_PROPERTY).toBool():
            word = self.editor.text_for_range(c.block(), r)
            locale = self.editor.spellcheck_locale_for_cursor(c)
            orig_pos = c.position()
            c.setPosition(orig_pos - utf16_length(word))
            found = False
            self.editor.setTextCursor(c)
            if self.editor.find_spell_word([word], locale.langcode, center_on_cursor=False):
                found = True
                fc = self.editor.textCursor()
                if fc.position() < c.position():
                    self.editor.find_spell_word([word], locale.langcode, center_on_cursor=False)
            if found:
                suggestions = dictionaries.suggestions(word, locale)[:7]
                if suggestions:
                    for suggestion in suggestions:
                        ac = m.addAction(suggestion, partial(self.editor.simple_replace, suggestion))
                        f = ac.font()
                        f.setBold(True), ac.setFont(f)
                    m.addSeparator()
                m.addAction(actions['spell-next'])
                m.addAction(_('Ignore this word'), partial(self._nuke_word, None, word, locale))
                dics = dictionaries.active_user_dictionaries
                if len(dics) > 0:
                    if len(dics) == 1:
                        m.addAction(_('Add this word to the dictionary: {0}').format(dics[0].name), partial(
                            self._nuke_word, dics[0].name, word, locale))
                    else:
                        ac = m.addAction(_('Add this word to the dictionary'))
                        dmenu = QMenu(m)
                        ac.setMenu(dmenu)
                        for dic in dics:
                            dmenu.addAction(dic.name, partial(self._nuke_word, dic.name, word, locale))
                m.addSeparator()

        for x in ('undo', 'redo'):
            a(actions['editor-%s' % x])
        m.addSeparator()
        for x in ('cut', 'copy', 'paste'):
            a(actions['editor-' + x])
        m.addSeparator()
        m.addAction(_('&Select all'), self.editor.select_all)
        m.addAction(actions['mark-selected-text'])
        if self.syntax == 'html':
            m.addAction(actions['multisplit'])
        m.exec_(self.editor.mapToGlobal(pos))
    def contextMenuEvent(self, event):
        index = self.indexAt(event.pos())

        if not index.isValid():
            return

        plugin = self.model().get_plugin(index)

        menu = QMenu()
        ca = menu.addAction(_('Configure...'),
                            partial(self.configure_plugin, plugin))
        if not plugin.is_customizable():
            ca.setEnabled(False)
        menu.exec_(event.globalPos())
Example #18
0
 def show_context_menu(self, pos):
     m = QMenu(self)
     a = m.addAction
     for x in ('undo', 'redo'):
         a(actions['editor-%s' % x])
     m.addSeparator()
     for x in ('cut', 'copy', 'paste'):
         a(actions['editor-' + x])
     m.addSeparator()
     m.addAction(_('&Select all'), self.editor.select_all)
     m.addAction(actions['mark-selected-text'])
     if self.syntax == 'html':
         m.addAction(actions['multisplit'])
     m.exec_(self.editor.mapToGlobal(pos))
Example #19
0
 def contextMenuEvent(self, ev):
     menu = QMenu(self)
     p = self.page()
     mf = p.mainFrame()
     r = mf.hitTestContent(ev.pos())
     url = unicode(r.linkUrl().toString(QUrl.None)).strip()
     ca = self.pageAction(QWebPage.Copy)
     if ca.isEnabled():
         menu.addAction(ca)
     menu.addAction(actions['reload-preview'])
     menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
     if url.partition(':')[0].lower() in {'http', 'https'}:
         menu.addAction(_('Open link'), partial(open_url, r.linkUrl()))
     menu.exec_(ev.globalPos())
Example #20
0
 def contextMenuEvent(self, ev):
     menu = QMenu(self)
     p = self.page()
     mf = p.mainFrame()
     r = mf.hitTestContent(ev.pos())
     url = unicode(r.linkUrl().toString(QUrl.None)).strip()
     ca = self.pageAction(QWebPage.Copy)
     if ca.isEnabled():
         menu.addAction(ca)
     menu.addAction(actions['reload-preview'])
     menu.addAction(QIcon(I('debug.png')), _('Inspect element'),
                    self.inspect)
     if url.partition(':')[0].lower() in {'http', 'https'}:
         menu.addAction(_('Open link'), partial(open_url, r.linkUrl()))
     menu.exec_(ev.globalPos())
Example #21
0
 def contextMenuEvent(self, event):
     index = self.indexAt(event.pos())
     
     if not index.isValid():
         return
     
     result = self.model().get_result(index)
     
     menu = QMenu()
     da = menu.addAction(_('Download...'), partial(self.download_requested.emit, result))
     if not result.downloads:
         da.setEnabled(False)
     menu.addSeparator()
     menu.addAction(_('Goto in store...'), partial(self.open_requested.emit, result))
     menu.exec_(event.globalPos())
Example #22
0
    def contextMenuEvent(self, event):
        index = self.indexAt(event.pos())

        if not index.isValid():
            return

        result = self.model().get_result(index)

        menu = QMenu()
        da = menu.addAction(_('Download...'),
                            partial(self.download_requested.emit, result))
        if not result.downloads:
            da.setEnabled(False)
        menu.addSeparator()
        menu.addAction(_('Goto in store...'),
                       partial(self.open_requested.emit, result))
        menu.exec_(event.globalPos())
Example #23
0
    def eventFilter(self, obj, event):
        base = super(Central, self)
        if obj is not self.editor_tabs.tabBar() or event.type() != QEvent.MouseButtonPress or event.button() not in (Qt.RightButton, Qt.MidButton):
            return base.eventFilter(obj, event)
        index = self.editor_tabs.tabBar().tabAt(event.pos())
        if index < 0:
            return base.eventFilter(obj, event)
        if event.button() == Qt.MidButton:
            self._close_requested(index)
        ed = self.editor_tabs.widget(index)
        if ed is not None:
            menu = QMenu(self)
            menu.addAction(actions['close-current-tab'].icon(), _('Close tab'), partial(self.close_requested.emit, ed))
            menu.addSeparator()
            menu.addAction(actions['close-all-but-current-tab'].icon(), _('Close other tabs'), partial(self.close_all_but, ed))
            menu.exec_(self.editor_tabs.tabBar().mapToGlobal(event.pos()))

        return True
Example #24
0
    def eventFilter(self, obj, event):
        base = super(Central, self)
        if obj is not self.editor_tabs.tabBar() or event.type() != QEvent.MouseButtonPress or event.button() not in (Qt.RightButton, Qt.MidButton):
            return base.eventFilter(obj, event)
        index = self.editor_tabs.tabBar().tabAt(event.pos())
        if index < 0:
            return base.eventFilter(obj, event)
        if event.button() == Qt.MidButton:
            self._close_requested(index)
        ed = self.editor_tabs.widget(index)
        if ed is not None:
            menu = QMenu(self)
            menu.addAction(actions['close-current-tab'].icon(), _('Close tab'), partial(self.close_requested.emit, ed))
            menu.addSeparator()
            menu.addAction(actions['close-all-but-current-tab'].icon(), _('Close other tabs'), partial(self.close_all_but, ed))
            menu.exec_(self.editor_tabs.tabBar().mapToGlobal(event.pos()))

        return True
Example #25
0
    def show_context_menu(self, pos):
        m = QMenu(self)
        a = m.addAction
        i = unicode(self.textCursor().selectedText())
        if i:
            a(QIcon(I('edit-copy.png')), _('Copy to clipboard'), self.copy).setShortcut(QKeySequence.Copy)

        if len(self.changes) > 0:
            a(QIcon(I('arrow-up.png')), _('Previous change'), partial(self.next_change.emit, -1))
            a(QIcon(I('arrow-down.png')), _('Next change'), partial(self.next_change.emit, 1))

        if self.show_open_in_editor:
            b = self.cursorForPosition(pos).block()
            if b.isValid():
                a(QIcon(I('tweak.png')), _('Open file in the editor'), partial(self.generate_sync_request, b.blockNumber()))

        if len(m.actions()) > 0:
            m.exec_(self.mapToGlobal(pos))
 def contextMenuEvent(self, event):
     menu = QMenu(self)
     pos = event.pos()
     index = self.indexAt(pos)
     if index.isValid():
         item = self.indexAt(pos).internalPointer()
         node = self.item_to_node_dict[item]
         nodeset = [ node ] # ? ? ? ?
         optflag = False  # ? ? ? ?
         cmenu_spec = self.treemodel.make_cmenuspec_for_set(nodeset, optflag)
         for x in cmenu_spec:
             if x is not None:
                 str, thunk = x[:2]
                 act = QAction(str, self)
                 act.setEnabled("disabled" not in x[2:])
                 self.connect(act, SIGNAL("triggered()"), thunk)
                 menu.addAction(act)
             else:
                 menu.addSeparator()
         menu.exec_(event.globalPos())
 def contextMenuEvent(self, event):
     menu = QMenu(self)
     pos = event.pos()
     index = self.indexAt(pos)
     if index.isValid():
         item = self.indexAt(pos).internalPointer()
         node = self.item_to_node_dict[item]
         nodeset = [node]  # ? ? ? ?
         optflag = False  # ? ? ? ?
         cmenu_spec = self.ne1model.make_cmenuspec_for_set(nodeset, optflag)
         for x in cmenu_spec:
             if x is not None:
                 str, thunk = x[:2]
                 act = QAction(str, self)
                 act.setEnabled("disabled" not in x[2:])
                 self.connect(act, SIGNAL("triggered()"), thunk)
                 menu.addAction(act)
             else:
                 menu.addSeparator()
         menu.exec_(event.globalPos())
Example #28
0
 def displayContextMenu(self, pos):
     """
     type pos: int
     """
     menu = QMenu()
     removeAction = menu.addAction("Remove")
     action = menu.exec_(self.mapToGlobal(pos))
     if action == removeAction:
         while self.filterTable.rowCount() > self.row + 1:
             self.filterTable.removeRow(self.filterTable.rowCount() - 1)
         self.filterTable.removeCellWidget(self.row, self.filtTableConnectCol)
Example #29
0
    def contextMenuEvent(self, ev):
        m = QMenu(self)
        w = self.model().word_for_row(self.currentIndex().row())
        if w is not None:
            a = m.addAction(_('Change %s to') % w[0])
            cm = QMenu()
            a.setMenu(cm)
            cm.addAction(_('Specify replacement manually'), partial(self.change_to.emit, w, None))
            cm.addSeparator()
            for s in dictionaries.suggestions(*w):
                cm.addAction(s, partial(self.change_to.emit, w, s))

        m.addAction(_('Ignore/Unignore all selected words'), self.ignore_all)
        a = m.addAction(_('Add/Remove all selected words'))
        am = QMenu()
        a.setMenu(am)
        for dic in sorted(dictionaries.active_user_dictionaries, key=lambda x:sort_key(x.name)):
            am.addAction(dic.name, partial(self.add_all.emit, dic.name))

        m.exec_(ev.globalPos())
   def showSegContextMenu(self):
      menu = QMenu(self.segDefTableView)
      if len(self.segDefTableView.selectedIndexes())==0:
         return

      row = self.segDefTableView.selectedIndexes()[0].row()
      deleteSegMenuItem = menu.addAction("Delete Segment")
      action = menu.exec_(QCursor.pos())
      
      if action == deleteSegMenuItem:
         self.deleteSegRow(row)
   def showOrdContextMenu(self):
      menu = QMenu(self.segOrdListBox)
      if len(self.segOrdListBox.selectedItems())==0:
         return

      item = self.segOrdListBox.currentItem()
      deleteOrdMenuItem = menu.addAction("Delete Ordering")
      action = menu.exec_(QCursor.pos())
      
      if action == deleteOrdMenuItem:
         self.deleteOrdItem(item)
 def displayContextMenu(self, pos):
     """
     type pos: int
     """
     menu = QMenu()
     removeAction = menu.addAction("Remove")
     action = menu.exec_(self.mapToGlobal(pos))
     if action == removeAction:
         while (self.filterTable.rowCount() > self.row + 1):
             self.filterTable.removeRow(self.filterTable.rowCount() - 1)
         self.filterTable.removeCellWidget(self.row,
                                           self.filtTableConnectCol)
Example #33
0
    def show_context_menu(self, pos):
        m = QMenu(self)
        a = m.addAction
        i = unicode(self.textCursor().selectedText()).rstrip('\0')
        if i:
            a(QIcon(I('edit-copy.png')), _('Copy to clipboard'),
              self.copy).setShortcut(QKeySequence.Copy)

        if len(self.changes) > 0:
            a(QIcon(I('arrow-up.png')), _('Previous change'),
              partial(self.next_change.emit, -1))
            a(QIcon(I('arrow-down.png')), _('Next change'),
              partial(self.next_change.emit, 1))

        if self.show_open_in_editor:
            b = self.cursorForPosition(pos).block()
            if b.isValid():
                a(QIcon(I('tweak.png')), _('Open file in the editor'),
                  partial(self.generate_sync_request, b.blockNumber()))

        if len(m.actions()) > 0:
            m.exec_(self.mapToGlobal(pos))
Example #34
0
    def show_context_menu(self, point):
        item = self.currentItem()

        def key(k):
            sc = unicode(
                QKeySequence(k | Qt.CTRL).toString(QKeySequence.NativeText))
            return ' [%s]' % sc

        if item is not None:
            m = QMenu()
            ci = unicode(item.data(0, Qt.DisplayRole).toString())
            p = item.parent() or self.invisibleRootItem()
            idx = p.indexOfChild(item)
            if idx > 0:
                m.addAction(QIcon(I('arrow-up.png')),
                            (_('Move "%s" up') % ci) + key(Qt.Key_Up),
                            self.move_up)
            if idx + 1 < p.childCount():
                m.addAction(QIcon(I('arrow-down.png')),
                            (_('Move "%s" down') % ci) + key(Qt.Key_Down),
                            self.move_down)
            m.addAction(QIcon(I('trash.png')), _('Remove all selected items'),
                        self.del_items)
            if item.parent() is not None:
                m.addAction(QIcon(I('back.png')),
                            (_('Unindent "%s"') % ci) + key(Qt.Key_Left),
                            self.move_left)
            if idx > 0:
                m.addAction(QIcon(I('forward.png')),
                            (_('Indent "%s"') % ci) + key(Qt.Key_Right),
                            self.move_right)
            m.addAction(QIcon(I('edit_input.png')),
                        _('Change the location this entry points to'),
                        self.edit_item)
            m.addAction(_('Change all selected items to title case'),
                        self.title_case)
            m.addAction(QIcon(I('modified.png')),
                        _('Bulk rename all selected items'), self.bulk_rename)
            m.exec_(QCursor.pos())
Example #35
0
 def openMenu(self, position):
     """
     Method that handles actions from context menu.
     Parameters:
     position - Position of the action on screen (right click).
     """
     menu = QMenu()
     copyChannels = menu.addAction("Copy channels to all time series")
     clearChannels = menu.addAction("Clear")
     action = menu.exec_(self.ui.listWidgetChannels.mapToGlobal(position))
     if action == copyChannels:
         self.channelCopy.emit(self.index)
     elif action == clearChannels:
         self.ui.listWidgetChannels.clear()
Example #36
0
    def show_context_menu(self, point):
        item = self.currentItem()
        def key(k):
            sc = unicode(QKeySequence(k | Qt.CTRL).toString(QKeySequence.NativeText))
            return ' [%s]'%sc

        if item is not None:
            m = QMenu()
            ci = unicode(item.data(0, Qt.DisplayRole).toString())
            p = item.parent() or self.invisibleRootItem()
            idx = p.indexOfChild(item)
            if idx > 0:
                m.addAction(QIcon(I('arrow-up.png')), (_('Move "%s" up')%ci)+key(Qt.Key_Up), self.move_up)
            if idx + 1 < p.childCount():
                m.addAction(QIcon(I('arrow-down.png')), (_('Move "%s" down')%ci)+key(Qt.Key_Down), self.move_down)
            m.addAction(QIcon(I('trash.png')), _('Remove all selected items'), self.del_items)
            if item.parent() is not None:
                m.addAction(QIcon(I('back.png')), (_('Unindent "%s"')%ci)+key(Qt.Key_Left), self.move_left)
            if idx > 0:
                m.addAction(QIcon(I('forward.png')), (_('Indent "%s"')%ci)+key(Qt.Key_Right), self.move_right)
            m.addAction(QIcon(I('edit_input.png')), _('Change the location this entry points to'), self.edit_item)
            m.addAction(_('Change all selected items to title case'), self.title_case)
            m.exec_(QCursor.pos())
Example #37
0
 def contextMenuEvent(self, ev):
     menu = QMenu(self)
     menu.addAction(actions['reload-preview'])
     menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
     menu.exec_(ev.globalPos())
Example #38
0
    def show_context_menu(self, pos):
        m = QMenu(self)
        a = m.addAction
        c = self.editor.cursorForPosition(pos)
        origc = QTextCursor(c)
        r = origr = self.editor.syntax_range_for_cursor(c)
        if (r is None or not r.format.property(SPELL_PROPERTY).toBool()) and c.positionInBlock() > 0:
            c.setPosition(c.position() - 1)
            r = self.editor.syntax_range_for_cursor(c)

        if r is not None and r.format.property(SPELL_PROPERTY).toBool():
            word = self.editor.text_for_range(c.block(), r)
            locale = self.editor.spellcheck_locale_for_cursor(c)
            orig_pos = c.position()
            c.setPosition(orig_pos - utf16_length(word))
            found = False
            self.editor.setTextCursor(c)
            if self.editor.find_spell_word([word], locale.langcode, center_on_cursor=False):
                found = True
                fc = self.editor.textCursor()
                if fc.position() < c.position():
                    self.editor.find_spell_word([word], locale.langcode, center_on_cursor=False)
            if found:
                suggestions = dictionaries.suggestions(word, locale)[:7]
                if suggestions:
                    for suggestion in suggestions:
                        ac = m.addAction(suggestion, partial(self.editor.simple_replace, suggestion))
                        f = ac.font()
                        f.setBold(True), ac.setFont(f)
                    m.addSeparator()
                m.addAction(actions['spell-next'])
                m.addAction(_('Ignore this word'), partial(self._nuke_word, None, word, locale))
                dics = dictionaries.active_user_dictionaries
                if len(dics) > 0:
                    if len(dics) == 1:
                        m.addAction(_('Add this word to the dictionary: {0}').format(dics[0].name), partial(
                            self._nuke_word, dics[0].name, word, locale))
                    else:
                        ac = m.addAction(_('Add this word to the dictionary'))
                        dmenu = QMenu(m)
                        ac.setMenu(dmenu)
                        for dic in dics:
                            dmenu.addAction(dic.name, partial(self._nuke_word, dic.name, word, locale))
                m.addSeparator()

        if origr is not None and origr.format.property(LINK_PROPERTY).toBool():
            href = self.editor.text_for_range(origc.block(), origr)
            m.addAction(_('Open %s') % href, partial(self.link_clicked.emit, href))

        if origr is not None and (origr.format.property(TAG_NAME_PROPERTY).toBool() or origr.format.property(CSS_PROPERTY).toBool()):
            word = self.editor.text_for_range(origc.block(), origr)
            item_type = 'tag_name' if origr.format.property(TAG_NAME_PROPERTY).toBool() else 'css_property'
            url = help_url(word, item_type, self.editor.highlighter.doc_name, extra_data=current_container().opf_version)
            if url is not None:
                m.addAction(_('Show help for: %s') % word, partial(open_url, url))

        for x in ('undo', 'redo'):
            a(actions['editor-%s' % x])
        m.addSeparator()
        for x in ('cut', 'copy', 'paste'):
            a(actions['editor-' + x])
        m.addSeparator()
        m.addAction(_('&Select all'), self.editor.select_all)
        m.addAction(actions['mark-selected-text'])
        if self.syntax == 'html':
            m.addAction(actions['multisplit'])
        m.exec_(self.editor.mapToGlobal(pos))
Example #39
0
    def show_context_menu(self, pos):
        m = QMenu(self)
        a = m.addAction
        c = self.editor.cursorForPosition(pos)
        fmt = self.editor.syntax_format_for_cursor(c)
        spell = fmt.property(
            SPELL_PROPERTY).toPyObject() if fmt is not None else None
        if spell is not None:
            word, locale = spell
            orig_pos = c.position()
            c.setPosition(orig_pos - utf16_length(word))
            found = False
            self.editor.setTextCursor(c)
            if self.editor.find_spell_word([word],
                                           locale.langcode,
                                           center_on_cursor=False):
                found = True
                fc = self.editor.textCursor()
                if fc.position() < c.position():
                    self.editor.find_spell_word([word],
                                                locale.langcode,
                                                center_on_cursor=False)
            if found:
                suggestions = dictionaries.suggestions(word, locale)[:7]
                if suggestions:
                    for suggestion in suggestions:
                        ac = m.addAction(
                            suggestion,
                            partial(self.editor.simple_replace, suggestion))
                        f = ac.font()
                        f.setBold(True), ac.setFont(f)
                    m.addSeparator()
                m.addAction(actions['spell-next'])
                m.addAction(_('Ignore this word'),
                            partial(self._nuke_word, None, word, locale))
                dics = dictionaries.active_user_dictionaries
                if len(dics) > 0:
                    if len(dics) == 1:
                        m.addAction(
                            _('Add this word to the dictionary: {0}').format(
                                dics[0].name),
                            partial(self._nuke_word, dics[0].name, word,
                                    locale))
                    else:
                        ac = m.addAction(_('Add this word to the dictionary'))
                        dmenu = QMenu(m)
                        ac.setMenu(dmenu)
                        for dic in dics:
                            dmenu.addAction(
                                dic.name,
                                partial(self._nuke_word, dic.name, word,
                                        locale))
                m.addSeparator()

        for x in ('undo', 'redo'):
            a(actions['editor-%s' % x])
        m.addSeparator()
        for x in ('cut', 'copy', 'paste'):
            a(actions['editor-' + x])
        m.addSeparator()
        m.addAction(_('&Select all'), self.editor.select_all)
        m.addAction(actions['mark-selected-text'])
        if self.syntax == 'html':
            m.addAction(actions['multisplit'])
        m.exec_(self.editor.mapToGlobal(pos))
Example #40
0
 def context_menu(self, pos):
     m = QMenu()
     if self.items.count() > 0:
         m.addAction(QIcon(I('edit-copy.png')), _('Copy list of errors to clipboard'), self.copy_to_clipboard)
     if list(m.actions()):
         m.exec_(self.mapToGlobal(pos))
Example #41
0
    def show_context_menu(self, pos):
        m = QMenu(self)
        a = m.addAction
        c = self.editor.cursorForPosition(pos)
        origc = QTextCursor(c)
        r = origr = self.editor.syntax_range_for_cursor(c)
        if (r is None or not r.format.property(SPELL_PROPERTY).toBool()
            ) and c.positionInBlock() > 0:
            c.setPosition(c.position() - 1)
            r = self.editor.syntax_range_for_cursor(c)

        if r is not None and r.format.property(SPELL_PROPERTY).toBool():
            word = self.editor.text_for_range(c.block(), r)
            locale = self.editor.spellcheck_locale_for_cursor(c)
            orig_pos = c.position()
            c.setPosition(orig_pos - utf16_length(word))
            found = False
            self.editor.setTextCursor(c)
            if self.editor.find_spell_word([word],
                                           locale.langcode,
                                           center_on_cursor=False):
                found = True
                fc = self.editor.textCursor()
                if fc.position() < c.position():
                    self.editor.find_spell_word([word],
                                                locale.langcode,
                                                center_on_cursor=False)
            if found:
                suggestions = dictionaries.suggestions(word, locale)[:7]
                if suggestions:
                    for suggestion in suggestions:
                        ac = m.addAction(
                            suggestion,
                            partial(self.editor.simple_replace, suggestion))
                        f = ac.font()
                        f.setBold(True), ac.setFont(f)
                    m.addSeparator()
                m.addAction(actions['spell-next'])
                m.addAction(_('Ignore this word'),
                            partial(self._nuke_word, None, word, locale))
                dics = dictionaries.active_user_dictionaries
                if len(dics) > 0:
                    if len(dics) == 1:
                        m.addAction(
                            _('Add this word to the dictionary: {0}').format(
                                dics[0].name),
                            partial(self._nuke_word, dics[0].name, word,
                                    locale))
                    else:
                        ac = m.addAction(_('Add this word to the dictionary'))
                        dmenu = QMenu(m)
                        ac.setMenu(dmenu)
                        for dic in dics:
                            dmenu.addAction(
                                dic.name,
                                partial(self._nuke_word, dic.name, word,
                                        locale))
                m.addSeparator()

        if origr is not None and origr.format.property(LINK_PROPERTY).toBool():
            href = self.editor.text_for_range(origc.block(), origr)
            m.addAction(
                _('Open %s') % href, partial(self.link_clicked.emit, href))

        if origr is not None and (
                origr.format.property(TAG_NAME_PROPERTY).toBool()
                or origr.format.property(CSS_PROPERTY).toBool()):
            word = self.editor.text_for_range(origc.block(), origr)
            item_type = 'tag_name' if origr.format.property(
                TAG_NAME_PROPERTY).toBool() else 'css_property'
            url = help_url(word,
                           item_type,
                           self.editor.highlighter.doc_name,
                           extra_data=current_container().opf_version)
            if url is not None:
                m.addAction(
                    _('Show help for: %s') % word, partial(open_url, url))

        for x in ('undo', 'redo'):
            a(actions['editor-%s' % x])
        m.addSeparator()
        for x in ('cut', 'copy', 'paste'):
            a(actions['editor-' + x])
        m.addSeparator()
        m.addAction(_('&Select all'), self.editor.select_all)
        m.addAction(actions['mark-selected-text'])
        if self.syntax == 'html':
            m.addAction(actions['multisplit'])
        m.exec_(self.editor.mapToGlobal(pos))
Example #42
0
 def contextMenuEvent(self, ev):
     menu = QMenu(self)
     menu.addAction(actions['reload-preview'])
     menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
     menu.exec_(ev.globalPos())