mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Enhancement #2079784: Save the main window geometry when saving a layout.
This commit is contained in:
parent
3d19fb01be
commit
cea3db20c2
@ -8,6 +8,7 @@ from qt.core import QComboBox, QDialog, QDialogButtonBox, QFormLayout, QIcon, QL
|
||||
|
||||
from calibre.gui2 import error_dialog, gprefs, question_dialog
|
||||
from calibre.gui2.actions import InterfaceAction, show_menu_under_widget
|
||||
from calibre.gui2.geometry import _restore_geometry, save_geometry, delete_geometry
|
||||
from calibre.utils.icu import sort_key
|
||||
|
||||
|
||||
@ -166,8 +167,12 @@ class LayoutActions(InterfaceAction):
|
||||
|
||||
Throws KeyError if the name doesn't exist.
|
||||
'''
|
||||
layouts = gprefs['saved_layouts']
|
||||
# This can be called by plugins so let the exception fly
|
||||
|
||||
# Restore the application window geometry if we have it.
|
||||
_restore_geometry(self.gui, gprefs, f'saved_layout_{name}')
|
||||
# Now the panel sizes inside the central widget
|
||||
layouts = gprefs['saved_layouts']
|
||||
settings = layouts[name]
|
||||
# Order is important here. change_layout() must be called before
|
||||
# unserializing the settings or panes like book details won't display
|
||||
@ -201,6 +206,9 @@ class LayoutActions(InterfaceAction):
|
||||
:param:`name` The name for the settings.
|
||||
:param:`settings`: The gui layout settings to save.
|
||||
'''
|
||||
# Save the main window geometry.
|
||||
save_geometry(self.gui, gprefs, f'saved_layout_{name}')
|
||||
# Now the panel sizes inside the central widget
|
||||
layouts = gprefs['saved_layouts']
|
||||
layouts.update({name: settings})
|
||||
gprefs['saved_layouts'] = layouts
|
||||
@ -218,6 +226,9 @@ class LayoutActions(InterfaceAction):
|
||||
_('Do you really want to delete the saved layout {0}?').format(name),
|
||||
skip_dialog_name='delete_saved_gui_layout'):
|
||||
return
|
||||
|
||||
# The information is stored as 2 preferences. Delete them both.
|
||||
delete_geometry(gprefs, f'saved_layout_{name}')
|
||||
layouts = gprefs['saved_layouts']
|
||||
layouts.pop(name, None)
|
||||
self.populate_menu()
|
||||
|
@ -12,6 +12,10 @@ from calibre.constants import is_debugging as _is_debugging
|
||||
from calibre.utils.config_base import tweaks
|
||||
|
||||
|
||||
def geometry_pref_name(name):
|
||||
return f'geometry-of-{name}'
|
||||
|
||||
|
||||
def is_debugging():
|
||||
return _is_debugging() and tweaks.get('show_geometry_debug_output')
|
||||
|
||||
@ -77,6 +81,10 @@ def geometry_for_restore_as_dict(self: QWidget):
|
||||
return ans
|
||||
|
||||
|
||||
def delete_geometry(prefs: dict, name: str):
|
||||
prefs.pop(geometry_pref_name(name), None)
|
||||
|
||||
|
||||
def save_geometry(self: QWidget, prefs: dict, name: str):
|
||||
x = geometry_for_restore_as_dict(self)
|
||||
if x:
|
||||
@ -84,7 +92,7 @@ def save_geometry(self: QWidget, prefs: dict, name: str):
|
||||
debug('Saving geometry for:', name)
|
||||
debug(x)
|
||||
x['qt'] = bytearray(self.saveGeometry())
|
||||
prefs.set(f'geometry-of-{name}', x)
|
||||
prefs.set(geometry_pref_name(name), x)
|
||||
|
||||
|
||||
def find_matching_screen(screen_as_dict):
|
||||
@ -153,7 +161,7 @@ def _restore_to_new_screen(self: QWidget, s: QScreen, saved_data: dict) -> bool:
|
||||
|
||||
|
||||
def _restore_geometry(self: QWidget, prefs: dict, name: str, get_legacy_saved_geometry: callable = None) -> bool:
|
||||
x = prefs.get(f'geometry-of-{name}')
|
||||
x = prefs.get(geometry_pref_name(name))
|
||||
if not x:
|
||||
old = get_legacy_saved_geometry() if get_legacy_saved_geometry else prefs.get(name)
|
||||
if old is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user