mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit metadata dialog: When using the change case operations if some text is selected, only operate on the selected text. Fixes #1963822 [change case doesn't care about selection](https://bugs.launchpad.net/calibre/+bug/1963822)
This commit is contained in:
parent
51f5dcb678
commit
47a24ae092
@ -798,10 +798,16 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
|
|
||||||
def text(self):
|
def text(self):
|
||||||
return self.textCursor().selectedText()
|
return self.textCursor().selectedText()
|
||||||
|
selectedText = text
|
||||||
|
|
||||||
def setText(self, text):
|
def setText(self, text):
|
||||||
with self.editing_cursor() as c:
|
with self.editing_cursor() as c:
|
||||||
c.insertText(text)
|
c.insertText(text)
|
||||||
|
insert = setText
|
||||||
|
|
||||||
|
def hasSelectedText(self):
|
||||||
|
c = self.textCursor()
|
||||||
|
return c.hasSelection()
|
||||||
|
|
||||||
def contextMenuEvent(self, ev):
|
def contextMenuEvent(self, ev):
|
||||||
menu = self.createStandardContextMenu()
|
menu = self.createStandardContextMenu()
|
||||||
|
@ -492,25 +492,32 @@ class LineEditECM: # {{{
|
|||||||
self.create_change_case_menu(menu)
|
self.create_change_case_menu(menu)
|
||||||
menu.exec(event.globalPos())
|
menu.exec(event.globalPos())
|
||||||
|
|
||||||
|
def modify_case_operation(self, func):
|
||||||
|
has_selection = self.hasSelectedText()
|
||||||
|
text = self.selectedText() if has_selection else self.text()
|
||||||
|
ntext = func(text)
|
||||||
|
if ntext != text:
|
||||||
|
self.insert(ntext) if has_selection else self.setText(ntext)
|
||||||
|
|
||||||
def upper_case(self):
|
def upper_case(self):
|
||||||
from calibre.utils.icu import upper
|
from calibre.utils.icu import upper
|
||||||
self.setText(upper(str(self.text())))
|
self.modify_case_operation(upper)
|
||||||
|
|
||||||
def lower_case(self):
|
def lower_case(self):
|
||||||
from calibre.utils.icu import lower
|
from calibre.utils.icu import lower
|
||||||
self.setText(lower(str(self.text())))
|
self.modify_case_operation(lower)
|
||||||
|
|
||||||
def swap_case(self):
|
def swap_case(self):
|
||||||
from calibre.utils.icu import swapcase
|
from calibre.utils.icu import swapcase
|
||||||
self.setText(swapcase(str(self.text())))
|
self.modify_case_operation(swapcase)
|
||||||
|
|
||||||
def title_case(self):
|
def title_case(self):
|
||||||
from calibre.utils.titlecase import titlecase
|
from calibre.utils.titlecase import titlecase
|
||||||
self.setText(titlecase(str(self.text())))
|
self.modify_case_operation(titlecase)
|
||||||
|
|
||||||
def capitalize(self):
|
def capitalize(self):
|
||||||
from calibre.utils.icu import capitalize
|
from calibre.utils.icu import capitalize
|
||||||
self.setText(capitalize(str(self.text())))
|
self.modify_case_operation(capitalize)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user