mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Allow MessagePopup to store data with the undo URL
This commit is contained in:
parent
7a5176e1b4
commit
7fe6b7dfe5
@ -825,7 +825,7 @@ class Boss(QObject):
|
||||
# }}}
|
||||
|
||||
# Global history {{{
|
||||
def do_global_undo(self):
|
||||
def do_global_undo(self, *a):
|
||||
container = self.global_undo.undo()
|
||||
if container is not None:
|
||||
set_current_container(container)
|
||||
|
@ -262,7 +262,7 @@ def install_new_plugins():
|
||||
|
||||
class MessagePopup(QLabel):
|
||||
|
||||
undo_requested = pyqtSignal()
|
||||
undo_requested = pyqtSignal(object)
|
||||
|
||||
def __init__(self, parent):
|
||||
QLabel.__init__(self, parent)
|
||||
@ -294,12 +294,16 @@ class MessagePopup(QLabel):
|
||||
def link_activated(self, link):
|
||||
self.hide()
|
||||
if link.startswith('undo://'):
|
||||
self.undo_requested.emit()
|
||||
import base64, json
|
||||
data = base64.urlsafe_b64decode(link.rpartition('/')[-1])
|
||||
self.undo_requested.emit(json.loads(data))
|
||||
|
||||
def __call__(self, text='Testing message popup', show_undo=True, timeout=5000, has_markup=False):
|
||||
text = '<p>' + (text if has_markup else prepare_string_for_xml(text))
|
||||
if show_undo:
|
||||
text += '\xa0\xa0<a style="text-decoration: none" href="undo://me.com">{}</a>'.format(_('Undo'))
|
||||
import base64, json
|
||||
data = base64.urlsafe_b64encode(json.dumps(show_undo).encode('utf-8')).decode('ascii')
|
||||
text += '\xa0\xa0<a style="text-decoration: none" href="undo://me.com/{}">{}</a>'.format(data, _('Undo'))
|
||||
text += f'\xa0\xa0<a style="text-decoration: none; color: {self.color}" href="close://me.com">✖</a>'
|
||||
self.setText(text)
|
||||
self.resize(self.sizeHint())
|
||||
@ -317,7 +321,7 @@ class Main(MainWindow):
|
||||
|
||||
APP_NAME = _('Edit book')
|
||||
STATE_VERSION = 0
|
||||
undo_requested = pyqtSignal()
|
||||
undo_requested = pyqtSignal(object)
|
||||
|
||||
def __init__(self, opts, notify=None):
|
||||
MainWindow.__init__(self, opts, disable_automatic_gc=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user