mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Comments Editor: Add options to change the case of the selected text to the right click menu. Fixes #1780469 [[Enhancement] Additiiona feature for metadata comments box](https://bugs.launchpad.net/calibre/+bug/1780469)
This commit is contained in:
parent
ed437c3e0d
commit
7b480b371a
@ -23,6 +23,7 @@ except ImportError:
|
|||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
from calibre import xml_replace_entities, prepare_string_for_xml
|
from calibre import xml_replace_entities, prepare_string_for_xml
|
||||||
from calibre.gui2 import open_url, error_dialog, choose_files, gprefs, NO_URL_FORMATTING, secure_web_page
|
from calibre.gui2 import open_url, error_dialog, choose_files, gprefs, NO_URL_FORMATTING, secure_web_page
|
||||||
|
from calibre.gui2.widgets import LineEditECM
|
||||||
from calibre.utils.soupparser import fromstring
|
from calibre.utils.soupparser import fromstring
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
@ -71,7 +72,7 @@ class BlockStyleAction(QAction): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
class EditorWidget(QWebView): # {{{
|
class EditorWidget(QWebView, LineEditECM): # {{{
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QWebView.__init__(self, parent)
|
QWebView.__init__(self, parent)
|
||||||
@ -418,12 +419,21 @@ class EditorWidget(QWebView): # {{{
|
|||||||
return False
|
return False
|
||||||
return QWebView.event(self, ev)
|
return QWebView.event(self, ev)
|
||||||
|
|
||||||
|
def text(self):
|
||||||
|
return self.page().selectedText()
|
||||||
|
|
||||||
|
def setText(self, text):
|
||||||
|
self.exec_command('insertText', text)
|
||||||
|
|
||||||
def contextMenuEvent(self, ev):
|
def contextMenuEvent(self, ev):
|
||||||
menu = self.page().createStandardContextMenu()
|
menu = self.page().createStandardContextMenu()
|
||||||
paste = self.pageAction(QWebPage.Paste)
|
paste = self.pageAction(QWebPage.Paste)
|
||||||
for action in menu.actions():
|
for action in menu.actions():
|
||||||
if action == paste:
|
if action == paste:
|
||||||
menu.insertAction(action, self.pageAction(QWebPage.PasteAndMatchStyle))
|
menu.insertAction(action, self.pageAction(QWebPage.PasteAndMatchStyle))
|
||||||
|
st = self.text()
|
||||||
|
if st and st.strip():
|
||||||
|
self.create_change_case_menu(menu)
|
||||||
parent = self._parent()
|
parent = self._parent()
|
||||||
if hasattr(parent, 'toolbars_visible'):
|
if hasattr(parent, 'toolbars_visible'):
|
||||||
vis = parent.toolbars_visible
|
vis = parent.toolbars_visible
|
||||||
|
@ -92,7 +92,7 @@ class FilenamePattern(QWidget, Ui_Form): # {{{
|
|||||||
self.re.lineEdit().setText(val)
|
self.re.lineEdit().setText(val)
|
||||||
|
|
||||||
val_hist += gprefs.get('filename_pattern_history', [
|
val_hist += gprefs.get('filename_pattern_history', [
|
||||||
'(?P<title>.+)', '(?P<author>[^_-]+) -?\s*(?P<series>[^_0-9-]*)(?P<series_index>[0-9]*)\s*-\s*(?P<title>[^_].+) ?'])
|
'(?P<title>.+)', r'(?P<author>[^_-]+) -?\s*(?P<series>[^_0-9-]*)(?P<series_index>[0-9]*)\s*-\s*(?P<title>[^_].+) ?'])
|
||||||
if val in val_hist:
|
if val in val_hist:
|
||||||
del val_hist[val_hist.index(val)]
|
del val_hist[val_hist.index(val)]
|
||||||
val_hist.insert(0, val)
|
val_hist.insert(0, val)
|
||||||
@ -460,11 +460,8 @@ class LineEditECM(object): # {{{
|
|||||||
Extend the context menu of a QLineEdit to include more actions.
|
Extend the context menu of a QLineEdit to include more actions.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def contextMenuEvent(self, event):
|
def create_change_case_menu(self, menu):
|
||||||
menu = self.createStandardContextMenu()
|
case_menu = QMenu(_('Change case'), menu)
|
||||||
menu.addSeparator()
|
|
||||||
|
|
||||||
case_menu = QMenu(_('Change case'))
|
|
||||||
action_upper_case = case_menu.addAction(_('Upper case'))
|
action_upper_case = case_menu.addAction(_('Upper case'))
|
||||||
action_lower_case = case_menu.addAction(_('Lower case'))
|
action_lower_case = case_menu.addAction(_('Lower case'))
|
||||||
action_swap_case = case_menu.addAction(_('Swap case'))
|
action_swap_case = case_menu.addAction(_('Swap case'))
|
||||||
@ -476,8 +473,13 @@ class LineEditECM(object): # {{{
|
|||||||
action_swap_case.triggered.connect(self.swap_case)
|
action_swap_case.triggered.connect(self.swap_case)
|
||||||
action_title_case.triggered.connect(self.title_case)
|
action_title_case.triggered.connect(self.title_case)
|
||||||
action_capitalize.triggered.connect(self.capitalize)
|
action_capitalize.triggered.connect(self.capitalize)
|
||||||
|
|
||||||
menu.addMenu(case_menu)
|
menu.addMenu(case_menu)
|
||||||
|
return case_menu
|
||||||
|
|
||||||
|
def contextMenuEvent(self, event):
|
||||||
|
menu = self.createStandardContextMenu()
|
||||||
|
menu.addSeparator()
|
||||||
|
self.create_change_case_menu(menu)
|
||||||
menu.exec_(event.globalPos())
|
menu.exec_(event.globalPos())
|
||||||
|
|
||||||
def upper_case(self):
|
def upper_case(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user