mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Allow changing the case of selected text by right clicking and choosing the appropriate change case action. Fixes #1353263 [[Enhancement] - add Change Case functionality to Edit Book](https://bugs.launchpad.net/calibre/+bug/1353263)
This commit is contained in:
parent
ebfdca8c18
commit
d39c25b413
@ -28,7 +28,8 @@ from calibre.gui2.tweak_book.editor.smart import NullSmarts
|
||||
from calibre.gui2.tweak_book.editor.smart.html import HTMLSmarts
|
||||
from calibre.gui2.tweak_book.editor.smart.css import CSSSmarts
|
||||
from calibre.spell.break_iterator import index_of
|
||||
from calibre.utils.icu import safe_chr, string_length
|
||||
from calibre.utils.icu import safe_chr, string_length, capitalize, upper, lower, swapcase
|
||||
from calibre.utils.titlecase import titlecase
|
||||
|
||||
PARAGRAPH_SEPARATOR = '\u2029'
|
||||
entity_pat = re.compile(r'&(#{0,1}[a-zA-Z0-9]{1,8});')
|
||||
@ -826,3 +827,10 @@ class TextEdit(PlainTextEdit):
|
||||
c = self.textCursor()
|
||||
c.setPosition(block.position() + col)
|
||||
self.setTextCursor(c)
|
||||
|
||||
def change_case(self, action, cursor=None):
|
||||
cursor = cursor or self.textCursor()
|
||||
text = self.selected_text_from_cursor(cursor)
|
||||
text = {'lower':lower, 'upper':upper, 'capitalize':capitalize, 'title':titlecase, 'swap':swapcase}[action](text)
|
||||
cursor.insertText(text)
|
||||
self.setTextCursor(cursor)
|
||||
|
@ -488,6 +488,14 @@ class Editor(QMainWindow):
|
||||
m.addSeparator()
|
||||
m.addAction(_('&Select all'), self.editor.select_all)
|
||||
m.addAction(actions['mark-selected-text'])
|
||||
if self.syntax != 'css' and actions['editor-cut'].isEnabled():
|
||||
cm = QMenu(_('Change &case'), m)
|
||||
for ac, text in (
|
||||
('upper', _('&Upper case')), ('lower', _('&Lower case')), ('swap', _('&Swap case')),
|
||||
('title', _('&Title case')), ('capitalize', _('&Capitalize'))
|
||||
):
|
||||
cm.addAction(text, partial(self.editor.change_case, ac))
|
||||
m.addMenu(cm)
|
||||
if self.syntax == 'html':
|
||||
m.addAction(actions['multisplit'])
|
||||
m.exec_(self.editor.mapToGlobal(pos))
|
||||
|
Loading…
x
Reference in New Issue
Block a user