Save the size of the style editor in addition to the position

Originally committed to SVN as r6743.
This commit is contained in:
Thomas Goyne 2012-05-02 22:42:37 +00:00
parent 5a067f56e4
commit 63d60b9b1e
4 changed files with 20 additions and 8 deletions

View File

@ -388,7 +388,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
StyleName->SetInsertionPoint(0);
StyleName->SetInsertionPoint(-1);
persist.reset(new PersistLocation(this, "Tool/Style Editor"));
persist.reset(new PersistLocation(this, "Tool/Style Editor", true));
Bind(wxEVT_CHILD_FOCUS, &DialogStyleEditor::OnChildFocus, this);

View File

@ -482,6 +482,8 @@
},
"Style Editor" : {
"Last" : {
"Height" : -1,
"Width" : -1,
"X" : -1,
"Y" : -1
},

View File

@ -31,9 +31,11 @@
#include <wx/display.h>
#endif
PersistLocation::PersistLocation(wxDialog *dialog, std::string options_prefix)
PersistLocation::PersistLocation(wxDialog *dialog, std::string options_prefix, bool size_too)
: x_opt(OPT_SET(options_prefix + "/Last/X"))
, y_opt(OPT_SET(options_prefix + "/Last/Y"))
, w_opt(size_too ? OPT_SET(options_prefix + "/Last/Width") : 0)
, h_opt(size_too ? OPT_SET(options_prefix + "/Last/Height") : 0)
, maximize_opt(OPT_SET(options_prefix + "/Maximized"))
, dialog(dialog)
{
@ -45,6 +47,9 @@ PersistLocation::PersistLocation(wxDialog *dialog, std::string options_prefix)
// First move to the saved place so that it ends up on the right monitor
dialog->Move(x, y);
if (size_too && w_opt->GetInt() > 0 && h_opt->GetInt() > 0)
dialog->SetSize(w_opt->GetInt(), h_opt->GetInt());
int display_index = wxDisplay::GetFromWindow(dialog);
// If it's moved offscreen center on the parent and try again
@ -75,11 +80,9 @@ PersistLocation::PersistLocation(wxDialog *dialog, std::string options_prefix)
dialog->Bind(wxEVT_MOVE, &PersistLocation::OnMove, this);
if (dialog->GetWindowStyle() & wxMAXIMIZE_BOX) {
dialog->Bind(wxEVT_SIZE, &PersistLocation::OnSize, this);
if (maximize_opt->GetBool())
dialog->Maximize();
}
dialog->Bind(wxEVT_SIZE, &PersistLocation::OnSize, this);
if ((dialog->GetWindowStyle() & wxMAXIMIZE_BOX) && maximize_opt->GetBool())
dialog->Maximize();
}
void PersistLocation::OnMove(wxMoveEvent &e) {
@ -91,5 +94,9 @@ void PersistLocation::OnMove(wxMoveEvent &e) {
void PersistLocation::OnSize(wxSizeEvent &e) {
maximize_opt->SetBool(dialog->IsMaximized());
if (w_opt) {
w_opt->SetInt(dialog->GetSize().GetWidth());
h_opt->SetInt(dialog->GetSize().GetHeight());
}
e.Skip();
}

View File

@ -39,6 +39,8 @@ class wxSizeEvent;
class PersistLocation {
agi::OptionValue *x_opt;
agi::OptionValue *y_opt;
agi::OptionValue *w_opt;
agi::OptionValue *h_opt;
agi::OptionValue *maximize_opt;
wxDialog *dialog;
@ -49,5 +51,6 @@ public:
/// Persist the location of a dialog
/// @param dialog The dialog to save and restore the position of
/// @param options_prefix Prefix for the options names to store the location
PersistLocation(wxDialog *dialog, std::string options_prefix);
/// @param size_too Save and restore the size in addition to position
PersistLocation(wxDialog *dialog, std::string options_prefix, bool size_too = false);
};