Save and restore sash positions in the main DoM.
authorCarl Hetherington <cth@carlh.net>
Wed, 12 Oct 2022 21:21:09 +0000 (23:21 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 14 Oct 2022 09:41:18 +0000 (11:41 +0200)
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic.cc
src/wx/content_panel.cc

index eeb009594a0d1db48b905d78cb9331cdaa3aafd7..81daff5b6bed8e2eee19ee743ec56391ab0f7489 100644 (file)
@@ -207,6 +207,9 @@ Config::set_defaults ()
        set_notification_email_to_default ();
        set_cover_sheet_to_default ();
 
+       _main_divider_sash_position = {};
+       _main_content_divider_sash_position = {};
+
        _export.set_defaults();
 }
 
@@ -604,6 +607,8 @@ try
        }
        _auto_crop_threshold = f.optional_number_child<double>("AutoCropThreshold").get_value_or(0.1);
        _last_release_notes_version = f.optional_string_child("LastReleaseNotesVersion");
+       _main_divider_sash_position = f.optional_number_child<int>("MainDividerSashPosition");
+       _main_content_divider_sash_position = f.optional_number_child<int>("MainContentDividerSashPosition");
 
        _export.read(f.optional_node_child("Export"));
 }
@@ -1071,6 +1076,12 @@ Config::write_config () const
        if (_last_release_notes_version) {
                root->add_child("LastReleaseNotesVersion")->add_child_text(*_last_release_notes_version);
        }
+       if (_main_divider_sash_position) {
+               root->add_child("MainDividerSashPosition")->add_child_text(raw_convert<string>(*_main_divider_sash_position));
+       }
+       if (_main_content_divider_sash_position) {
+               root->add_child("MainContentDividerSashPosition")->add_child_text(raw_convert<string>(*_main_content_divider_sash_position));
+       }
 
        _export.write(root->add_child("Export"));
 
index 8fbdeaf9584ffe9f9aa85c9084b2fd867aa80bb9..1a11b4a411635e1b550cdb5e78d32e36121843db 100644 (file)
@@ -590,6 +590,14 @@ public:
                return _last_release_notes_version;
        }
 
+       boost::optional<int> main_divider_sash_position() const {
+               return _main_divider_sash_position;
+       }
+
+       boost::optional<int> main_content_divider_sash_position() const {
+               return _main_content_divider_sash_position;
+       }
+
        /* SET (mostly) */
 
        void set_master_encoding_threads (int n) {
@@ -1138,6 +1146,14 @@ public:
                return _export;
        }
 
+       void set_main_divider_sash_position(int position) {
+               maybe_set(_main_divider_sash_position, position);
+       }
+
+       void set_main_content_divider_sash_position(int position) {
+               maybe_set(_main_content_divider_sash_position, position);
+       }
+
        void changed (Property p = OTHER);
        boost::signals2::signal<void (Property)> Changed;
        /** Emitted if read() failed on an existing Config file.  There is nothing
@@ -1370,6 +1386,8 @@ private:
        RoughDuration _default_kdm_duration;
        double _auto_crop_threshold;
        boost::optional<std::string> _last_release_notes_version;
+       boost::optional<int> _main_divider_sash_position;
+       boost::optional<int> _main_content_divider_sash_position;
 
        ExportConfig _export;
 
index a10cb9b35505f9b322f2033f79bafaa2c17ce34f..eec81d3c80e36ec394f86cd5bb87f8e3890578f9 100644 (file)
@@ -287,7 +287,11 @@ public:
        bool OnSashPositionChange(int new_position) override
        {
                /* Try to stop the left bit of the splitter getting too small */
-               return new_position > _left_panel_minimum_size;
+               auto const ok = new_position > _left_panel_minimum_size;
+               if (ok) {
+                       Config::instance()->set_main_divider_sash_position(new_position);
+               }
+               return ok;
        }
 
 private:
@@ -297,7 +301,7 @@ private:
                        /* The window is now fairly big but the left panel is small; this happens when the DCP-o-matic window
                         * is shrunk and then made larger again.  Try to set a sensible left panel size in this case.
                         */
-                       SetSashPosition(_left_panel_minimum_size);
+                       SetSashPosition(Config::instance()->main_divider_sash_position().get_value_or(_left_panel_minimum_size));
                }
 
                ev.Skip();
@@ -410,7 +414,7 @@ public:
 
                _right_panel->SetSizer(right_sizer);
 
-               _splitter->SplitVertically(left_panel, _right_panel, left_panel->GetSize().GetWidth() + 8);
+               _splitter->SplitVertically(left_panel, _right_panel, Config::instance()->main_divider_sash_position().get_value_or(left_panel->GetSize().GetWidth() + 8));
 
                set_menu_sensitivity ();
 
index df6308bea548929f1ba50a9dd0ffe366c00693f3..cadf3682a9b4e0677acc1087ddfaf5cc4e10dda9 100644 (file)
@@ -90,22 +90,26 @@ public:
        bool OnSashPositionChange(int new_position) override
        {
                /* Try to stop the top bit of the splitter getting so small that buttons disappear */
-               return new_position > 220;
+               auto const ok = new_position > 220;
+               if (ok) {
+                       Config::instance()->set_main_content_divider_sash_position(new_position);
+               }
+               return ok;
        }
 
        void first_shown(wxWindow* top, wxWindow* bottom)
        {
                int const sn = wxDisplay::GetFromWindow(this);
+               /* Fallback for when GetFromWindow fails for reasons that aren't clear */
+               int pos = -600;
                if (sn >= 0) {
                        wxRect const screen = wxDisplay(sn).GetClientArea();
                        /* This is a hack to try and make the content notebook a sensible size; large on big displays but small
                           enough on small displays to leave space for the content area.
                           */
-                       SplitHorizontally(top, bottom, screen.height > 800 ? -600 : -_top_panel_minimum_size);
-               } else {
-                       /* Fallback for when GetFromWindow fails for reasons that aren't clear */
-                       SplitHorizontally(top, bottom, -600);
+                       pos = screen.height > 800 ? -600 : -_top_panel_minimum_size;
                }
+               SplitHorizontally(top, bottom, Config::instance()->main_content_divider_sash_position().get_value_or(pos));
                _first_shown = true;
        }
 
@@ -117,7 +121,7 @@ private:
                        /* The window is now fairly big but the top panel is small; this happens when the DCP-o-matic window
                         * is shrunk and then made larger again.  Try to set a sensible top panel size in this case (#1839).
                         */
-                       SetSashPosition(_top_panel_minimum_size);
+                       SetSashPosition(Config::instance()->main_content_divider_sash_position().get_value_or(_top_panel_minimum_size));
                }
 
                ev.Skip ();