2 * @file PropColorSchemes.cpp
4 * @brief Implementation of PropColorSchemes propertysheet
8 #include "PropColorSchemes.h"
9 #include "OptionsDef.h"
10 #include "OptionsInit.h"
11 #include "OptionsMgr.h"
12 #include "RegOptionsMgr.h"
13 #include "OptionsPanel.h"
15 #include "DirTravel.h"
17 #include "Environment.h"
24 * @brief Default constructor.
26 PropColorSchemes::PropColorSchemes(COptionsMgr *optionsMgr)
27 : OptionsPanel(optionsMgr, PropColorSchemes::IDD)
31 void PropColorSchemes::DoDataExchange(CDataExchange* pDX)
33 CDialog::DoDataExchange(pDX);
34 //{{AFX_DATA_MAP(PropColorSchemes)
39 BEGIN_MESSAGE_MAP(PropColorSchemes, OptionsPanel)
40 //{{AFX_MSG_MAP(PropColorSchemes)
41 ON_CBN_SELCHANGE(IDC_COLOR_SCHEMES, OnCbnSelchangeColorSchemes)
46 * @brief Reads options values from storage to UI.
48 void PropColorSchemes::ReadOptions()
50 m_sColorScheme = GetOptionsMgr()->GetString(OPT_COLOR_SCHEME);
54 * @brief Writes options values from UI to storage.
56 void PropColorSchemes::WriteOptions()
58 GetOptionsMgr()->SaveOption(OPT_COLOR_SCHEME, m_sColorScheme);
61 static String GetColorSchemesFolder()
63 return paths::ConcatPath(env::GetProgPath(), _T("ColorSchemes"));
66 static std::vector<String> GetColorSchemeNames()
68 DirItemArray dirs, files;
69 std::vector<String> names;
71 LoadAndSortFiles(GetColorSchemesFolder(), &dirs, &files, false);
73 for (DirItem& item : files)
77 paths::SplitFilename(item.filename, nullptr, &filename, &ext);
78 if (strutils::compare_nocase(ext, _T("ini")) == 0)
79 names.push_back(filename);
86 * @brief Called before propertysheet is drawn.
88 BOOL PropColorSchemes::OnInitDialog()
90 CComboBox * combo = (CComboBox*) GetDlgItem(IDC_COLOR_SCHEMES);
92 for (auto& name : GetColorSchemeNames())
94 combo->AddString(name.c_str());
95 if (strutils::compare_nocase(name, m_sColorScheme) == 0)
96 combo->SetCurSel(combo->GetCount() - 1);
98 if (combo->GetCurSel() == -1 && combo->GetCount() > 0)
101 OptionsPanel::OnInitDialog();
102 return TRUE; // return TRUE unless you set the focus to a control
105 void PropColorSchemes::OnCbnSelchangeColorSchemes()
108 GetDlgItemText(IDC_COLOR_SCHEMES, sColorScheme);
109 m_sColorScheme = sColorScheme;
111 String path = paths::ConcatPath(GetColorSchemesFolder(), sColorScheme + _T(".ini"));
112 if (GetOptionsMgr()->ImportOptions(path) != COption::OPT_OK)
114 LangMessageBox(IDS_OPT_IMPORT_ERR, MB_ICONWARNING);
117 GetParent()->GetParent()->PostMessage(WM_APP + IDC_COLOR_SCHEMES);