From f3c0bcfab0cff80daad95da8236334a18164e87d Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Thu, 16 May 2013 14:42:52 +0000
Subject: [PATCH] Open generic wxPreferencesEditor at last shown page.

This is very convenient under systems using a modal dialog for the preferences
editor implementation (such as MSW), as it allows to do several changes in the
same page without having to select it manually every time.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74005 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 src/generic/preferencesg.cpp | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/generic/preferencesg.cpp b/src/generic/preferencesg.cpp
index 98170cf071..72624a93ec 100644
--- a/src/generic/preferencesg.cpp
+++ b/src/generic/preferencesg.cpp
@@ -65,6 +65,16 @@ public:
         m_notebook->AddPage(win, page->GetName());
     }
 
+    int GetSelectedPage() const
+    {
+        return m_notebook->GetSelection();
+    }
+
+    void SelectPage(int page)
+    {
+        m_notebook->ChangeSelection(page);
+    }
+
 private:
     wxNotebook *m_notebook;
 };
@@ -156,17 +166,32 @@ private:
 class wxModalPreferencesEditorImpl : public wxGenericPreferencesEditorImplBase
 {
 public:
+    wxModalPreferencesEditorImpl()
+    {
+        m_currentPage = -1;
+    }
+
     virtual void Show(wxWindow* parent)
     {
         wxScopedPtr<wxGenericPrefsDialog> dlg(CreateDialog(parent));
         dlg->Fit();
-        dlg->ShowModal();
+
+        // Restore the previously selected page, if any.
+        if ( m_currentPage != -1 )
+            dlg->SelectPage(m_currentPage);
+
+        // Don't remember the last selected page if the dialog was cancelled.
+        if ( dlg->ShowModal() != wxID_CANCEL )
+            m_currentPage = dlg->GetSelectedPage();
     }
 
     virtual void Dismiss()
     {
         // nothing to do
     }
+
+private:
+    int m_currentPage;
 };
 
 #endif // !wxHAS_PREF_EDITOR_MODELESS
-- 
2.47.2