From fab4a3229a476d4caf8e2a7b54825588f1b07cfd Mon Sep 17 00:00:00 2001 From: codereader Date: Wed, 28 Jun 2017 20:15:01 +0200 Subject: [PATCH] Attempt to fix #4526: Panel sizes not persisted between startups (Linux) --- include/imainframelayout.h | 5 +++++ radiant/ui/mainframe/EmbeddedLayout.cpp | 5 +++++ radiant/ui/mainframe/EmbeddedLayout.h | 9 +++++---- radiant/ui/mainframe/FloatingLayout.cpp | 7 ++++++- radiant/ui/mainframe/FloatingLayout.h | 9 +++++---- radiant/ui/mainframe/MainFrame.cpp | 16 ++++++++++++++++ radiant/ui/mainframe/RegularLayout.cpp | 5 +++++ radiant/ui/mainframe/RegularLayout.h | 9 +++++---- radiant/ui/mainframe/SplitPaneLayout.cpp | 5 +++++ radiant/ui/mainframe/SplitPaneLayout.h | 9 +++++---- 10 files changed, 62 insertions(+), 17 deletions(-) diff --git a/include/imainframelayout.h b/include/imainframelayout.h index bc37bc45e4..026c8b505b 100644 --- a/include/imainframelayout.h +++ b/include/imainframelayout.h @@ -38,6 +38,11 @@ class IMainFrameLayout * its state. */ virtual void toggleFullscreenCameraView() = 0; + + /** + * Loads and applies the stored state from the registry. + */ + virtual void restoreStateFromRegistry() = 0; }; typedef std::shared_ptr IMainFrameLayoutPtr; diff --git a/radiant/ui/mainframe/EmbeddedLayout.cpp b/radiant/ui/mainframe/EmbeddedLayout.cpp index 43685907ec..121827d955 100644 --- a/radiant/ui/mainframe/EmbeddedLayout.cpp +++ b/radiant/ui/mainframe/EmbeddedLayout.cpp @@ -176,6 +176,11 @@ void EmbeddedLayout::restoreStateFromPath(const std::string& path) } } +void EmbeddedLayout::restoreStateFromRegistry() +{ + restoreStateFromPath(RKEY_EMBEDDED_ROOT); +} + void EmbeddedLayout::saveStateToPath(const std::string& path) { GlobalRegistry().createKeyWithName(path, "pane", "horizontal"); diff --git a/radiant/ui/mainframe/EmbeddedLayout.h b/radiant/ui/mainframe/EmbeddedLayout.h index b2848abd96..be0805e54b 100644 --- a/radiant/ui/mainframe/EmbeddedLayout.h +++ b/radiant/ui/mainframe/EmbeddedLayout.h @@ -28,10 +28,11 @@ class EmbeddedLayout : public: // IMainFrameLayout implementation - virtual std::string getName(); - virtual void activate(); - virtual void deactivate(); - virtual void toggleFullscreenCameraView(); + std::string getName() override; + void activate() override; + void deactivate() override; + void toggleFullscreenCameraView() override; + void restoreStateFromRegistry() override; // The creation function, needed by the mainframe layout manager static EmbeddedLayoutPtr CreateInstance(); diff --git a/radiant/ui/mainframe/FloatingLayout.cpp b/radiant/ui/mainframe/FloatingLayout.cpp index 118dc1ff6b..ba4a6a95af 100644 --- a/radiant/ui/mainframe/FloatingLayout.cpp +++ b/radiant/ui/mainframe/FloatingLayout.cpp @@ -131,10 +131,15 @@ void FloatingLayout::toggleFullscreenCameraView() _floatingCamWnd->ShowFullScreen(!_floatingCamWnd->IsFullScreen()); } +void FloatingLayout::restoreStateFromRegistry() +{ + // nothing yet +} + // The creation function, needed by the mainframe layout manager FloatingLayoutPtr FloatingLayout::CreateInstance() { - return FloatingLayoutPtr(new FloatingLayout); + return std::make_shared(); } } // namespace ui diff --git a/radiant/ui/mainframe/FloatingLayout.h b/radiant/ui/mainframe/FloatingLayout.h index a06b31159e..66c2ae1fa2 100644 --- a/radiant/ui/mainframe/FloatingLayout.h +++ b/radiant/ui/mainframe/FloatingLayout.h @@ -22,10 +22,11 @@ class FloatingLayout : public: // IMainFrameLayout implementation - virtual std::string getName(); - virtual void activate(); - virtual void deactivate(); - virtual void toggleFullscreenCameraView(); + std::string getName() override; + void activate() override; + void deactivate() override; + void toggleFullscreenCameraView() override; + void restoreStateFromRegistry() override; // The creation function, needed by the mainframe layout manager static FloatingLayoutPtr CreateInstance(); diff --git a/radiant/ui/mainframe/MainFrame.cpp b/radiant/ui/mainframe/MainFrame.cpp index 0741fa9108..f8c8a613dd 100644 --- a/radiant/ui/mainframe/MainFrame.cpp +++ b/radiant/ui/mainframe/MainFrame.cpp @@ -228,6 +228,22 @@ void MainFrame::construct() } } +#ifdef __linux__ + // #4526: In Linux, do another restore after the top level window has been shown + // After startup, GTK emits onSizeAllocate events which trigger a Layout() sequence + // messing up the pane positions, so do the restore() one more time after the main + // window came up. + _topLevelWindow->Bind(wxEVT_SHOW, [&](wxShowEvent& ev) + { + if (_currentLayout && ev.IsShown()) + { + _currentLayout->restoreStateFromRegistry(); + } + + ev.Skip(); + }); +#endif + // register the commands GlobalMainFrameLayoutManager().registerCommands(); diff --git a/radiant/ui/mainframe/RegularLayout.cpp b/radiant/ui/mainframe/RegularLayout.cpp index e93d6a7926..a3d9b09206 100644 --- a/radiant/ui/mainframe/RegularLayout.cpp +++ b/radiant/ui/mainframe/RegularLayout.cpp @@ -175,6 +175,11 @@ void RegularLayout::restoreStateFromPath(const std::string& path) } } +void RegularLayout::restoreStateFromRegistry() +{ + restoreStateFromPath(RKEY_REGULAR_ROOT); +} + void RegularLayout::saveStateToPath(const std::string& path) { GlobalRegistry().createKeyWithName(path, "pane", "horizontal"); diff --git a/radiant/ui/mainframe/RegularLayout.h b/radiant/ui/mainframe/RegularLayout.h index 0316a438f6..b639938dd8 100644 --- a/radiant/ui/mainframe/RegularLayout.h +++ b/radiant/ui/mainframe/RegularLayout.h @@ -38,10 +38,11 @@ class RegularLayout : public: // IMainFrameLayout implementation - virtual std::string getName(); - virtual void activate(); - virtual void deactivate(); - virtual void toggleFullscreenCameraView(); + std::string getName() override; + void activate() override; + void deactivate() override; + void toggleFullscreenCameraView() override; + void restoreStateFromRegistry() override; // The creation function, needed by the mainframe layout manager static RegularLayoutPtr CreateRegularLeftInstance(); diff --git a/radiant/ui/mainframe/SplitPaneLayout.cpp b/radiant/ui/mainframe/SplitPaneLayout.cpp index 776df70f5e..fd8d051261 100644 --- a/radiant/ui/mainframe/SplitPaneLayout.cpp +++ b/radiant/ui/mainframe/SplitPaneLayout.cpp @@ -360,6 +360,11 @@ void SplitPaneLayout::toggleFullscreenCameraView() } } +void SplitPaneLayout::restoreStateFromRegistry() +{ + restoreStateFromPath(RKEY_SPLITPANE_ROOT); +} + SplitPaneLayout::Position SplitPaneLayout::getCameraPositionFromRegistry() { int value = registry::getValue(RKEY_SPLITPANE_CAMPOS); diff --git a/radiant/ui/mainframe/SplitPaneLayout.h b/radiant/ui/mainframe/SplitPaneLayout.h index 84892c1f7e..b57c0ab88b 100644 --- a/radiant/ui/mainframe/SplitPaneLayout.h +++ b/radiant/ui/mainframe/SplitPaneLayout.h @@ -83,10 +83,11 @@ class SplitPaneLayout : public: // IMainFrameLayout implementation - virtual std::string getName(); - virtual void activate(); - virtual void deactivate(); - virtual void toggleFullscreenCameraView(); + std::string getName() override; + void activate() override; + void deactivate() override; + void toggleFullscreenCameraView() override; + void restoreStateFromRegistry() override; // The creation function, needed by the mainframe layout manager static SplitPaneLayoutPtr CreateInstance();