mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Save toolbar actions in profile
This commit is contained in:
parent
a65259b1c8
commit
aeb0fdc473
@ -111,6 +111,13 @@ def save_viewer_profile(profile_name, profile, *user_names: str):
|
|||||||
profile = json.loads(profile)
|
profile = json.loads(profile)
|
||||||
if isinstance(profile, dict):
|
if isinstance(profile, dict):
|
||||||
profile['__timestamp__'] = isoformat(utcnow())
|
profile['__timestamp__'] = isoformat(utcnow())
|
||||||
|
from calibre.gui2.viewer.toolbars import current_actions, DEFAULT_ACTIONS
|
||||||
|
ca = current_actions()
|
||||||
|
s = {}
|
||||||
|
if ca != DEFAULT_ACTIONS:
|
||||||
|
s['toolbar-actions'] = ca
|
||||||
|
if s:
|
||||||
|
profile['__standalone_extra_settings__'] = s
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(viewer_config_dir, 'profiles.json'), 'rb') as f:
|
with open(os.path.join(viewer_config_dir, 'profiles.json'), 'rb') as f:
|
||||||
raw = json.loads(f.read())
|
raw = json.loads(f.read())
|
||||||
|
@ -152,6 +152,7 @@ class ActionsToolBar(ToolBar):
|
|||||||
web_view.read_aloud_state_changed.connect(self.update_read_aloud_action)
|
web_view.read_aloud_state_changed.connect(self.update_read_aloud_action)
|
||||||
web_view.customize_toolbar.connect(self.customize, type=Qt.ConnectionType.QueuedConnection)
|
web_view.customize_toolbar.connect(self.customize, type=Qt.ConnectionType.QueuedConnection)
|
||||||
web_view.view_created.connect(self.on_view_created)
|
web_view.view_created.connect(self.on_view_created)
|
||||||
|
web_view.change_toolbar_actions.connect(self.change_toolbar_actions)
|
||||||
|
|
||||||
self.web_actions = {}
|
self.web_actions = {}
|
||||||
self.back_action = a = shortcut_action('back')
|
self.back_action = a = shortcut_action('back')
|
||||||
@ -223,6 +224,13 @@ class ActionsToolBar(ToolBar):
|
|||||||
|
|
||||||
self.add_actions()
|
self.add_actions()
|
||||||
|
|
||||||
|
def change_toolbar_actions(self, toolbar_actions):
|
||||||
|
if toolbar_actions is None:
|
||||||
|
vprefs.__delitem__('actions-toolbar-actions')
|
||||||
|
else:
|
||||||
|
vprefs.set('actions-toolbar-actions', toolbar_actions)
|
||||||
|
self.add_actions()
|
||||||
|
|
||||||
def update_web_action(self):
|
def update_web_action(self):
|
||||||
a = self.sender()
|
a = self.sender()
|
||||||
for x, ac in self.web_actions.items():
|
for x, ac in self.web_actions.items():
|
||||||
|
@ -492,6 +492,7 @@ class WebView(RestartingWebEngineView):
|
|||||||
standalone_misc_settings_changed = pyqtSignal(object)
|
standalone_misc_settings_changed = pyqtSignal(object)
|
||||||
view_created = pyqtSignal(object)
|
view_created = pyqtSignal(object)
|
||||||
content_file_changed = pyqtSignal(str)
|
content_file_changed = pyqtSignal(str)
|
||||||
|
change_toolbar_actions = pyqtSignal(object)
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
self._host_widget = None
|
self._host_widget = None
|
||||||
@ -581,6 +582,11 @@ class WebView(RestartingWebEngineView):
|
|||||||
self.execute_when_ready('profile_response', 'apply-profile', settings)
|
self.execute_when_ready('profile_response', 'apply-profile', settings)
|
||||||
elif which == 'request-save':
|
elif which == 'request-save':
|
||||||
self.execute_when_ready('profile_response', 'request-save', profile_name)
|
self.execute_when_ready('profile_response', 'request-save', profile_name)
|
||||||
|
elif which == 'apply-profile-to-viewer-ui':
|
||||||
|
toolbar_actions = None
|
||||||
|
s = settings.get('__standalone_extra_settings__', {})
|
||||||
|
toolbar_actions = s.get('toolbar-actions', None)
|
||||||
|
self.change_toolbar_actions.emit(toolbar_actions)
|
||||||
|
|
||||||
def link_hovered(self, url):
|
def link_hovered(self, url):
|
||||||
if url == 'javascript:void(0)':
|
if url == 'javascript:void(0)':
|
||||||
|
@ -38,11 +38,12 @@ def use_profile(container_id, profile_name, profile_data):
|
|||||||
return
|
return
|
||||||
sd = get_session_data()
|
sd = get_session_data()
|
||||||
apply_reader_profile(sd, profile_data)
|
apply_reader_profile(sd, profile_data)
|
||||||
|
if ui_operations.apply_profile:
|
||||||
|
ui_operations.apply_profile(profile_data)
|
||||||
container.dispatchEvent(new Event('settings_changed'))
|
container.dispatchEvent(new Event('settings_changed'))
|
||||||
container.dispatchEvent(new Event('close_panel'))
|
container.dispatchEvent(new Event('close_panel'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def delete_profile(container_id, profile_name):
|
def delete_profile(container_id, profile_name):
|
||||||
question_dialog(_('Are you sure?'), _('Are you sure you want to delete the saved profile named: {}?').format(profile_name),
|
question_dialog(_('Are you sure?'), _('Are you sure you want to delete the saved profile named: {}?').format(profile_name),
|
||||||
def (ok):
|
def (ok):
|
||||||
|
@ -89,6 +89,7 @@ def profile_response(which, x):
|
|||||||
apply_reader_profile(sd, x)
|
apply_reader_profile(sd, x)
|
||||||
if view:
|
if view:
|
||||||
view.preferences_changed()
|
view.preferences_changed()
|
||||||
|
ui_operations.apply_profile(x)
|
||||||
elif which is 'request-save':
|
elif which is 'request-save':
|
||||||
sd = get_session_data()
|
sd = get_session_data()
|
||||||
settings = settings_for_reader_profile(sd)
|
settings = settings_for_reader_profile(sd)
|
||||||
@ -371,6 +372,8 @@ if window is window.top:
|
|||||||
install(TRANSLATIONS_DATA)
|
install(TRANSLATIONS_DATA)
|
||||||
ui_operations.get_all_profiles = get_all_profiles
|
ui_operations.get_all_profiles = get_all_profiles
|
||||||
ui_operations.save_profile = save_profile
|
ui_operations.save_profile = save_profile
|
||||||
|
ui_operations.apply_profile = def(profile):
|
||||||
|
to_python.profile_op('apply-profile-to-viewer-ui', "", profile)
|
||||||
ui_operations.get_file = get_file
|
ui_operations.get_file = get_file
|
||||||
ui_operations.get_url_for_book_file_name = get_url_for_book_file_name
|
ui_operations.get_url_for_book_file_name = get_url_for_book_file_name
|
||||||
ui_operations.get_mathjax_files = get_mathjax_files
|
ui_operations.get_mathjax_files = get_mathjax_files
|
||||||
|
Loading…
x
Reference in New Issue
Block a user