[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master e4f1a40: Store the last selected page of MvcC
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master e4f1a40: Store the last selected page of MvcController persistently |
Date: |
Wed, 25 Apr 2018 11:38:03 -0400 (EDT) |
branch: master
commit e4f1a40cf81bcb9ca65777cb193e198582229cf3
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Store the last selected page of MvcController persistently
Instead of just remembering the last selected page during each program
execution (and doing it manually), register the MvcController book
control with wxPersistenceManager to automatically remember and restore
the last selected page automatically even between program executions.
[Amended by GWC to be acceptable to 'hooks/pre-commit'.]
---
mvc_controller.cpp | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/mvc_controller.cpp b/mvc_controller.cpp
index 04a7b68..6914184 100644
--- a/mvc_controller.cpp
+++ b/mvc_controller.cpp
@@ -44,6 +44,7 @@
#include <wx/checkbox.h>
#include <wx/ctrlsub.h>
#include <wx/datectrl.h>
+#include <wx/persist/bookctrl.h>
#include <wx/radiobox.h>
#include <wx/spinctrl.h>
#include <wx/textctrl.h>
@@ -56,11 +57,6 @@
namespace
{
-/// Open new bookcontrol to page selected in most recent instance.
-///
-/// A page selection is maintained for each bookcontrol resource.
-
-std::map<std::string,std::size_t> last_selected_page;
/// Custom event to trigger a call to SetFocus(). This action requires
/// a custom event because wxFocusEvent does not change focus--it only
@@ -115,7 +111,16 @@ MvcController::MvcController
// https://lists.nongnu.org/archive/html/lmi/2018-03/msg00041.html
SetIcons(TopWindow().GetIcons());
-
BookControl().ChangeSelection(last_selected_page[view_.ResourceFileName()]);
+ // Use resource file name as the unique identifier of the particular
+ // controller, as different controllers use different book controls with
+ // different number of pages, and so shouldn't reuse the last saved page of
+ // each other.
+ //
+ // For cosmetic purposes, remove the ".xrc" suffix of the resource file
+ // name as it doesn't really make much sense in the config file/registry
+ // context.
+ wxString const name{view_.ResourceFileName()};
+ wxPersistentRegisterAndRestore(&BookControl(), name.BeforeLast('.'));
// This assignment must follow the call to LoadDialog().
// Initialization to 'parent' in the ctor-initializer-list
@@ -732,10 +737,6 @@ void MvcController::UponPageChanged(wxBookCtrlBaseEvent&
event)
{
event.Skip();
- int const z = event.GetSelection();
- LMI_ASSERT(wxNOT_FOUND != z);
- last_selected_page[view_.ResourceFileName()] = z;
-
ConditionallyEnable();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [lmi] master e4f1a40: Store the last selected page of MvcController persistently,
Greg Chicares <=