Skip to content

Made save / restore size and position of the main window using wxConfig #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions source/interface_derived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <fstream>
#include <wx/dirdlg.h>
#include <wx/aboutdlg.h>
#include <wx/config.h>
#if defined _WIN32
#include "dirent.h"
#else
Expand All @@ -29,6 +30,11 @@ using namespace std::filesystem;

#define LEARN_TAB 2
#define WEBVIEW 2000
#define CONFIG_NAME "com.nativeunityhub.config"
#define SETTING_WIDTH "W_WIDTH"
#define SETTING_HEIGHT "W_HEIGHT"
#define SETTING_POSITION_X "POSITION_X"
#define SETTING_POSITION_Y "POSITION_Y"
//the web view unloads after 5 minutes of page hidden
const int TIMER_LENGTH = 5 * 1000 * 60;

Expand Down Expand Up @@ -74,6 +80,14 @@ wxEND_EVENT_TABLE()

//call superclass constructor
MainFrameDerived::MainFrameDerived() : MainFrame(NULL){
// set saved position and size
wxConfig *config = new wxConfig(CONFIG_NAME);
int width, height, x, y;
if (config->Read(SETTING_WIDTH, &width) && config->Read(SETTING_HEIGHT, &height) &&
config->Read(SETTING_POSITION_X, &x) && config->Read(SETTING_POSITION_Y, &y)) {
this->SetSize(x, y, width, height);
}
delete config;
//set up project list columns
{
string cols[] = {"Project Name","Unity Version","Last Modified","Path"};
Expand Down Expand Up @@ -109,6 +123,21 @@ MainFrameDerived::MainFrameDerived() : MainFrame(NULL){
projSearchCtrl->SetFocus();
}

void MainFrameDerived::OnQuit(wxCommandEvent&){
// save window size and position
wxConfig *config = new wxConfig(CONFIG_NAME);
int width, height, x, y;
this->GetSize(&width, &height);
this->GetPosition(&x, &y);
config->Write(SETTING_WIDTH, width);
config->Write(SETTING_HEIGHT, height);
config->Write(SETTING_POSITION_X, x);
config->Write(SETTING_POSITION_Y, y);
delete config;

Close();
}

void MainFrameDerived::OnSelectProject(wxListEvent&){
for (auto ptr : projectActionItems){
ptr->Enable();
Expand Down
4 changes: 1 addition & 3 deletions source/interface_derived.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class MainFrameDerived : public MainFrame{
void OnSelectEditor(wxCommandEvent&);
void OnSelectEditorPath(wxCommandEvent&);

void OnQuit(wxCommandEvent&) {
Close();
}
void OnQuit(wxCommandEvent&);

wxWindow* const projectActionItems[3]{
revealProjBtn,
Expand Down