19#include <wx/fontenum.h>
21#include <wx/stdpaths.h>
23#include "../utils/PropertiesData.h"
26GeneralPropertiesForm::GeneralPropertiesForm(wxWindow* parent,
PropertiesData* properties)
27 : GeneralPropertiesFormBase(parent)
29 m_properties = properties;
30 auto data = m_properties->GetGeneralPropertiesData();
33 m_choiceLanguage->Clear();
34 m_choiceLanguage->Insert(_(
"English"), 0);
35 m_choiceLanguage->Insert(_(
"Portuguese"), 1);
36 m_choiceTheme->Clear();
37 m_choiceTheme->Insert(_(
"Light"), 0);
38 m_choiceTheme->Insert(_(
"Dark"), 1);
42 m_choicePlotLib->Clear();
43 m_choicePlotLib->Insert(_(
"Chart Director"), 0);
44 m_choicePlotLib->Insert(_(
"wxMathPlot"), 1);
46 switch (data.language) {
47 case wxLANGUAGE_ENGLISH: {
48 m_choiceLanguage->SetSelection(0);
50 case wxLANGUAGE_PORTUGUESE_BRAZILIAN: {
51 m_choiceLanguage->SetSelection(1);
54 m_choiceLanguage->SetSelection(wxNOT_FOUND);
57 switch (data.plotLib) {
58 case PlotLib::wxCHART_DIR: {
59 m_choicePlotLib->SetSelection(0);
61 case PlotLib::wxMATH_PLOT: {
62 m_choicePlotLib->SetSelection(1);
67 m_choiceTheme->SetSelection(0);
70 m_choiceTheme->SetSelection(1);
75 m_filePickerATPFolder->SetPath(data.atpPath.GetFullPath());
78 wxFont currentFont(data.labelFontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
false, data.labelFont);
79 m_fontPickerText->SetSelectedFont(currentFont);
82GeneralPropertiesForm::~GeneralPropertiesForm() {}
83void GeneralPropertiesForm::OnButtonOKClick(wxCommandEvent& event)
85 if (ValidateData()) EndModal(wxID_OK);
88bool GeneralPropertiesForm::ValidateData()
90 auto data = m_properties->GetGeneralPropertiesData();
91 auto checkData = m_properties->GetGeneralPropertiesData();
92 bool needRestart =
false;
93 data.atpPath = wxFileName(m_filePickerATPFolder->GetPath());
94 wxFont slectedFont = m_fontPickerText->GetSelectedFont();
95 data.labelFont = slectedFont.GetFaceName();
96 data.labelFontSize = slectedFont.GetPointSize();
99 wxFileName fn(wxStandardPaths::Get().GetDocumentsDir() + wxFileName::GetPathSeparator() +
"PSP-UFU" + wxFileName::GetPathSeparator() +
"config.ini");
100 wxTextFile file(fn.GetFullPath());
101 if (!file.Create()) {
104 wxMessageDialog msgDialog(
this,
105 _(
"It was not possible to access the init file.\nThe settings won't be applied."),
106 _(
"Error"), wxOK | wxCENTRE | wxICON_ERROR);
107 msgDialog.ShowModal();
112 wxString line =
"lang=";
113 switch (m_choiceLanguage->GetSelection()) {
116 data.language = wxLANGUAGE_ENGLISH;
120 data.language = wxLANGUAGE_PORTUGUESE_BRAZILIAN;
124 if (data.language != checkData.language) needRestart =
true;
127 switch (m_choicePlotLib->GetSelection()) {
130 data.plotLib = PlotLib::wxCHART_DIR;
134 data.plotLib = PlotLib::wxMATH_PLOT;
141 switch (m_choiceTheme->GetSelection()) {
144 data.theme = THEME_LIGHT;
145 wxTheApp->SetAppearance(wxApp::Appearance::Light);
149 data.theme = THEME_DARK;
150 wxTheApp->SetAppearance(wxApp::Appearance::Dark);
154 if (data.theme != checkData.theme) needRestart =
true;
157 line += data.labelFont;
160 line =
"labelfontsize=";
161 line += wxString::Format(
"%d", data.labelFontSize);
166 line += data.atpPath.GetFullPath();
173 wxMessageDialog msgDialog(
this, _(
"The application must be restarted to settings changes be applied."),
174 _(
"Info"), wxOK | wxCENTRE | wxICON_INFORMATION);
175 msgDialog.ShowModal();
177 m_properties->SetGeneralPropertiesData(data);
181void GeneralPropertiesForm::OnThemeSelected(wxCommandEvent& event)
183 switch (event.GetSelection())
186 wxTheApp->SetAppearance(wxApp::Appearance::Light);
189 wxTheApp->SetAppearance(wxApp::Appearance::Dark);
General and simulation data manager.