1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-01-22 14:41:39 +00:00

Save dock panel position on quit

* Restore the details dialog dock position if it was previously docked (i.e. not floating).
* Since the details_dialog instance was not deleted after closing by default, the previous instances were still saving their own geometry. We now delete them explicitely if we have to recreate a new instance to avoid the signal triggering the callback to save the geometry.
* Since restoreGeometry() and saveGeometry() are only called in our QDockWidget, it should be safe to modify the methods for the Preferences class (in qtlib).
This commit is contained in:
glubsy
2020-07-30 20:25:20 +02:00
parent 23642815f6
commit 11254381a8
3 changed files with 22 additions and 9 deletions

View File

@@ -285,16 +285,18 @@ class DupeGuru(QObject):
"""Creates resultWindow and details_dialog depending on the selected ``app_mode``.
"""
if self.details_dialog is not None:
# The object is not deleted entirely, avoid saving its geometry in the future
# self.willSavePrefs.disconnect(self.details_dialog.appWillSavePrefs)
# or simply delete it on close which is probably cleaner:
self.details_dialog.setAttribute(Qt.WA_DeleteOnClose)
self.details_dialog.close()
self.details_dialog.setParent(None)
# self.details_dialog.setParent(None) # seems unnecessary
if self.resultWindow is not None:
self.resultWindow.close()
self.resultWindow.setParent(None)
self.resultWindow = ResultWindow(self.directories_dialog, self)
self.directories_dialog._updateActionsState()
self.details_dialog = self._get_details_dialog_class()(self.resultWindow, self)
self.resultWindow.addDockWidget(
Qt.BottomDockWidgetArea, self.details_dialog)
def show_results_window(self):
self.showResultsWindow()

View File

@@ -24,18 +24,22 @@ class DetailsDialog(QDockWidget):
# To avoid saving uninitialized geometry on appWillSavePrefs, we track whether our dialog
# has been shown. If it has, we know that our geometry should be saved.
self._shown_once = False
self.app.prefs.restoreGeometry("DetailsWindowRect", self)
self._wasDocked, area = self.app.prefs.restoreGeometry("DetailsWindowRect", self)
self.tableModel = DetailsModel(self.model, app)
# tableView is defined in subclasses
self.tableView.setModel(self.tableModel)
self.model.view = self
self.app.willSavePrefs.connect(self.appWillSavePrefs)
# self.setAttribute(Qt.WA_DeleteOnClose)
parent.addDockWidget(
area if self._wasDocked else Qt.BottomDockWidgetArea, self)
def _setupUi(self): # Virtual
pass
def show(self):
if not self._shown_once and self._wasDocked:
self.setFloating(False)
self._shown_once = True
super().show()
self.update_options()
@@ -63,7 +67,7 @@ class DetailsDialog(QDockWidget):
# --- Events
def appWillSavePrefs(self):
if self._shown_once and self.isFloating():
if self._shown_once:
self.app.prefs.saveGeometry("DetailsWindowRect", self)
# --- model --> view