RelayFile/UserInterface/UserInterface.cxx

81 lines
2.5 KiB
C++
Raw Normal View History

2025-05-05 23:22:43 +08:00
#include "UserInterface.h"
2025-05-09 22:31:51 +08:00
#include <Util.h>
#include <filesystem>
#include <wx/fileconf.h>
namespace fs = std::filesystem;
2025-05-05 23:22:43 +08:00
2025-05-08 21:13:36 +08:00
UserInterface::UserInterface(const wxString& title) : wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600))
{
2025-05-08 21:44:16 +08:00
mgr_.SetManagedWindow(this);
2025-05-09 22:31:51 +08:00
InitMenu();
2025-05-08 21:44:16 +08:00
InitUI();
InitData();
2025-05-09 22:31:51 +08:00
TryRestoreLayout();
2025-05-08 21:13:36 +08:00
}
2025-05-05 23:22:43 +08:00
UserInterface::~UserInterface()
{
2025-05-08 21:44:16 +08:00
mgr_.UnInit();
2025-05-08 21:13:36 +08:00
}
void UserInterface::InitUI()
{
2025-05-08 21:44:16 +08:00
// Add Panel
controlMgr_ = std::make_shared<ControlManager>(this);
2025-05-08 22:11:39 +08:00
mgr_.AddPane(controlMgr_->header_,
2025-05-08 23:24:17 +08:00
wxAuiPaneInfo().Name("header").Caption(_("header")).CloseButton(false).Floatable(false).MinSize(-1, 40));
mgr_.AddPane(controlMgr_->local_, wxAuiPaneInfo().Name("local").Caption(_("local")).CloseButton(false).BestSize(300, 400));
2025-05-09 22:31:51 +08:00
mgr_.AddPane(controlMgr_->remote_, wxAuiPaneInfo().Name("remote").Caption(_("remote")).CloseButton(false).BestSize(300, 400));
mgr_.AddPane(controlMgr_->task_,
wxAuiPaneInfo().Name("task").Caption(_("task")).CloseButton(false).BestSize(300, 400).CenterPane());
2025-05-08 21:44:16 +08:00
// update
mgr_.Update();
2025-05-08 21:13:36 +08:00
}
2025-05-09 22:31:51 +08:00
void UserInterface::InitMenu()
{
menuBar_ = new wxMenuBar();
wxMenu* auimenu = new wxMenu();
auimenu->Append(ID_SaveLayout, "&SaveLayou\tCtrl-S", _("Save Layout"));
menuBar_->Append(auimenu, "&Aui");
SetMenuBar(menuBar_);
Bind(wxEVT_MENU, &UserInterface::OnSaveLayout, this, ID_SaveLayout);
}
2025-05-08 21:13:36 +08:00
void UserInterface::InitData()
{
2025-05-09 22:31:51 +08:00
auto configDir = wxUtil::GetConfigDir();
wxUtil::CreateConfigDir(configDir, wxT("RelayFile"), configDir_);
configPath_ = configDir + wxT("/RelayFile.ini");
}
void UserInterface::TryRestoreLayout()
{
fs::path path(configPath_.ToStdString());
if (!fs::exists(path)) {
return;
}
auto* config = new wxFileConfig(wxEmptyString, wxEmptyString, configPath_);
wxString perspective = config->Read("perspective");
if (!perspective.IsEmpty()) {
mgr_.LoadPerspective(perspective);
}
delete config;
}
void UserInterface::OnSaveLayout(wxCommandEvent& event)
{
auto perspective = mgr_.SavePerspective();
auto* config = new wxFileConfig(wxEmptyString, wxEmptyString, configPath_);
if (config->Write("perspective", perspective)) {
config->Flush();
wxMessageBox(_("Save Layout Success"), _("Save Layout"), wxOK | wxICON_INFORMATION);
} else {
wxMessageBox(_("Save Layout Failed"), _("Save Layout"), wxOK | wxICON_ERROR);
}
delete config;
2025-05-08 21:13:36 +08:00
}