Skip to content

Commit

Permalink
#5537: DeclarationSelector is now able to persist the sash position o…
Browse files Browse the repository at this point in the history
…f the splitter window.

Provided it's registered by the owning dialog to the WindowState handler.
  • Loading branch information
codereader committed Sep 18, 2022
1 parent 8505b54 commit b8b06d8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
7 changes: 3 additions & 4 deletions libs/wxutil/EntityClassChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace
constexpr const char* const TITLE_ADD_ENTITY = N_("Create Entity");
constexpr const char* const TITLE_CONVERT_TO_ENTITY = N_("Convert to Entity");
constexpr const char* const TITLE_SELECT_ENTITY = N_("Select Entity Class");
constexpr const char* const RKEY_SPLIT_POS = "user/ui/entityClassChooser/splitPos";
constexpr const char* const RKEY_WINDOW_STATE = "user/ui/entityClassChooser/window";
constexpr const char* const RKEY_LAST_SELECTED_ECLASS = "user/ui/entityClassChooser/lastSelectedEclass";

constexpr const char* const FOLDER_ICON = "folder16.png";
Expand Down Expand Up @@ -275,6 +273,9 @@ EntityClassChooser::EntityClassChooser(Purpose purpose) :
mainSizer->Add(buttonSizer, 0, wxALIGN_RIGHT, 12);

loadEntityClasses();

// Save the state of the selector widget on dialog close
RegisterPersistableObject(_selector);
}

EntityClassChooser::~EntityClassChooser()
Expand Down Expand Up @@ -340,8 +341,6 @@ int EntityClassChooser::ShowModal()

int returnCode = DialogBase::ShowModal();

_panedPosition.saveToPath(RKEY_SPLIT_POS);

return returnCode;
}

Expand Down
4 changes: 0 additions & 4 deletions libs/wxutil/EntityClassChooser.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once

#include "dialog/DialogBase.h"
#include "PanedPosition.h"
#include "WindowPosition.h"

#include <sigc++/connection.h>
#include <wx/dataview.h>
Expand Down Expand Up @@ -32,8 +30,6 @@ class EntityClassChooser final :
private:
EntityClassSelector* _selector;

PanedPosition _panedPosition;

sigc::connection _defsReloaded;

wxButton* _affirmativeButton;
Expand Down
8 changes: 3 additions & 5 deletions libs/wxutil/PanedPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace
{
const int DEFAULT_POSITION = 200;
constexpr int DEFAULT_POSITION = 200;
}

namespace wxutil
Expand All @@ -27,16 +27,14 @@ void PanedPosition::connect(wxSplitterWindow* paned)

_paned = paned;

_paned->Bind(wxEVT_SPLITTER_SASH_POS_CHANGED,
&PanedPosition::onPositionChange, this);
_paned->Bind(wxEVT_SPLITTER_SASH_POS_CHANGED, &PanedPosition::onPositionChange, this);
}

void PanedPosition::disconnect()
{
if (_paned)
{
_paned->Unbind(wxEVT_SPLITTER_SASH_POS_CHANGED,
&PanedPosition::onPositionChange, this);
_paned->Unbind(wxEVT_SPLITTER_SASH_POS_CHANGED, &PanedPosition::onPositionChange, this);

_paned.Release();
}
Expand Down
12 changes: 7 additions & 5 deletions libs/wxutil/PanedPosition.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "ui/iwindowstate.h"
#include <wx/event.h>
#include <wx/weakref.h>

Expand All @@ -15,14 +16,15 @@ namespace wxutil
*
* Use the connect() method to connect a wxSplitterWindow to this object.
*
* Use the loadFromNode() and saveToNode() methods to save the internal
* size info into the given xml::Node
* Register this instance to a wxutil::WindowState helper to let the
* divider position be saved to the registry on dialog close.
*
* This is used in various places (mainframe, entity inspector) to store
* the size/position of the paned views on shutdown.
*/
class PanedPosition :
public wxEvtHandler
public wxEvtHandler,
public ui::IPersistableObject
{
private:
// The position of this object
Expand All @@ -42,8 +44,8 @@ class PanedPosition :

void setPosition(int position);

void saveToPath(const std::string& path);
void loadFromPath(const std::string& path);
void saveToPath(const std::string& path) override;
void loadFromPath(const std::string& path) override;

private:
// The callback that gets invoked on position change
Expand Down
19 changes: 19 additions & 0 deletions libs/wxutil/decl/DeclarationSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ void DeclarationSelector::AddPreviewToRightPane(ui::IDeclarationPreview* preview
splitter->SetMinimumPaneSize(200); // no unsplitting
splitter->SplitVertically(_leftPanel, _rightPanel, 350);

_panedPosition = std::make_unique<PanedPosition>();
_panedPosition->connect(splitter);

auto widget = preview->GetPreviewWidget();

widget->Reparent(_rightPanel);
Expand Down Expand Up @@ -104,6 +107,22 @@ void DeclarationSelector::FocusTreeView()
_treeView->SetFocus();
}

void DeclarationSelector::loadFromPath(const std::string& registryKey)
{
if (_panedPosition)
{
_panedPosition->loadFromPath(registryKey);
}
}

void DeclarationSelector::saveToPath(const std::string& registryKey)
{
if (_panedPosition)
{
_panedPosition->saveToPath(registryKey);
}
}

DeclarationTreeView* DeclarationSelector::GetTreeView() const
{
return _treeView;
Expand Down
10 changes: 9 additions & 1 deletion libs/wxutil/decl/DeclarationSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#include <vector>
#include "idecltypes.h"
#include "ui/iwindowstate.h"
#include <wx/panel.h>
#include <wx/sizer.h>

#include "ui/ideclpreview.h"
#include "../dataview/DeclarationTreeView.h"
#include "wxutil/PanedPosition.h"

namespace wxutil
{
Expand All @@ -19,7 +21,8 @@ class DeclFileInfo;
* Preview widgets can optionally be appended to the right or the bottom of the tree view.
*/
class DeclarationSelector :
public wxPanel
public wxPanel,
public ui::IPersistableObject
{
private:
decl::Type _declType;
Expand All @@ -37,6 +40,8 @@ class DeclarationSelector :

DeclFileInfo* _declFileInfo;

std::unique_ptr<PanedPosition> _panedPosition;

public:
// Construct a selector widget with the default set of tree view columns
DeclarationSelector(wxWindow* parent, decl::Type declType);
Expand All @@ -63,6 +68,9 @@ class DeclarationSelector :
// Set the focus on the treeview widget
void FocusTreeView();

void loadFromPath(const std::string& registryKey) override;
void saveToPath(const std::string& registryKey) override;

protected:
DeclarationTreeView* GetTreeView() const;

Expand Down

0 comments on commit b8b06d8

Please sign in to comment.