Commit 704e642b authored by Loic Guegan's avatar Loic Guegan
Browse files

Add apply config

parent 829af363
Pipeline #216576319 failed with stage
in 7 minutes and 58 seconds
......@@ -67,14 +67,14 @@ EngineSettings::EngineSettings(wxWindow *parent) :
VBox->Add(engineListLabel);
EngineList = new wxListCtrl(this, wxID_ANY, wxDefaultPosition,
wxSize(-1, 150), wxLC_REPORT | wxLC_EDIT_LABELS);
EngineList->AppendColumn("Name",wxLIST_FORMAT_LEFT,100);
EngineList->AppendColumn("Location",wxLIST_FORMAT_LEFT,300);
EngineList->AppendColumn("Name", wxLIST_FORMAT_LEFT, 100);
EngineList->AppendColumn("Location", wxLIST_FORMAT_LEFT, 300);
VBox->Add(EngineList, 0, wxEXPAND | wxTOP, 10);
this->Bind(wxEVT_LIST_ITEM_DESELECTED, &EngineSettings::EngineListHandler,
this);
this->Bind(wxEVT_LIST_ITEM_SELECTED, &EngineSettings::EngineListHandler,
this);
this->Bind(wxEVT_LIST_END_LABEL_EDIT,&EngineSettings::EngineListHandler,
this->Bind(wxEVT_LIST_END_LABEL_EDIT, &EngineSettings::EngineListHandler,
this);
// Adding button below the engine list
wxBoxSizer *HBox = new wxBoxSizer(wxHORIZONTAL);
......@@ -93,6 +93,7 @@ EngineSettings::EngineSettings(wxWindow *parent) :
VBox->Add(optionLabel, 0, wxEXPAND | wxTOP, 10);
EngineConf = new wxPropertyGrid(this, wxID_ANY, wxDefaultPosition,
wxSize(-1, 150));
this->Bind(wxEVT_PG_CHANGED, &EngineSettings::PropertyGridHandler, this);
VBox->Add(EngineConf, 0, wxEXPAND | wxTOP, 10);
// Finishing configuration
......@@ -105,6 +106,32 @@ void EngineSettings::Apply() {
CNF.SetPtree("engines", Config); // Apply the configuration
}
void EngineSettings::PropertyGridHandler(wxPropertyGridEvent &event) {
if (event.GetEventType() == wxEVT_PG_CHANGED) {
int engineId = EngineList->GetNextItem(-1, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
engineId=EngineList->GetItemData(engineId);
string name=event.GetPropertyName().ToStdString();
wxVariant data=event.GetPropertyValue();
wxVariant attr=event.GetProperty()->GetAttribute("type");
wxVariant propId=event.GetProperty()->GetAttribute("id");
string path="list."+to_string(engineId)+".options."+propId.GetString().ToStdString();
if(data.GetType()=="bool"){
if(data.GetBool())
Config.put(path+".value","true");
else
Config.put(path+".value","false");
}
else{
if(!attr.IsNull() && attr.GetString() == "combo"){
string value=Config.get<string>(path+".var."+to_string(data.GetInteger()));
Config.put(path+".value",value);
}
}
}
}
void EngineSettings::SetupEngineConf(string engine) {
EngineConf->Clear();
string optsPath = "list." + engine + ".options";
......@@ -120,10 +147,12 @@ void EngineSettings::SetupEngineConf(string engine) {
std::stoi(value));
prop->SetAttribute("Min", Config.get<string>(curOptPath + ".min"));
prop->SetAttribute("Max", Config.get<string>(curOptPath + ".max"));
prop->SetAttribute("id", wxVariant(optId));
EngineConf->Append(prop);
} else if (type == "check") {
wxBoolProperty *prop = new wxBoolProperty(name, name,
value == "true");
prop->SetAttribute("id", wxVariant(optId));
EngineConf->Append(prop);
} else if (type == "combo") {
wxArrayString choices;
......@@ -134,9 +163,12 @@ void EngineSettings::SetupEngineConf(string engine) {
curOptPath + ".var." + choice.first));
}
wxEnumProperty *prop = new wxEnumProperty(name, name, choices);
prop->SetAttribute("type", wxVariant("combo"));
prop->SetAttribute("id", wxVariant(optId));
EngineConf->Append(prop);
} else {
wxStringProperty *prop = new wxStringProperty(name, name, value);
prop->SetAttribute("id", wxVariant(optId));
EngineConf->Append(prop);
}
}
......@@ -144,7 +176,7 @@ void EngineSettings::SetupEngineConf(string engine) {
void EngineSettings::ButtonHandler(wxCommandEvent &event) {
if (event.GetId() == 125) {
int id = EngineList->GetNextItem(-1, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
wxLIST_STATE_SELECTED);
if (id != -1) {
Config.get_child("list").erase(to_string(id));
EngineList->DeleteItem(id);
......@@ -160,7 +192,7 @@ void EngineSettings::RefreshEngineList() {
int id = 0;
while (id >= 0) {
id = EngineList->GetNextItem(-1, wxLIST_NEXT_ALL,
wxLIST_STATE_DONTCARE);
wxLIST_STATE_DONTCARE);
if (id >= 0)
EngineList->DeleteItem(id);
}
......@@ -178,13 +210,12 @@ void EngineSettings::RefreshEngineList() {
void EngineSettings::EngineListHandler(wxListEvent &event) {
if (event.GetEventType() == wxEVT_LIST_ITEM_DESELECTED)
Delete->Disable();
else if (event.GetEventType()==wxEVT_LIST_END_LABEL_EDIT){
string engine=std::to_string(event.GetItem().GetData());
string newName=event.GetItem().GetText().ToStdString();
Config.put("list."+engine+".name",newName);
else if (event.GetEventType() == wxEVT_LIST_END_LABEL_EDIT) {
string engine = std::to_string(event.GetItem().GetData());
string newName = event.GetItem().GetText().ToStdString();
Config.put("list." + engine + ".name", newName);
RefreshEngineList();
}
else {
} else {
Delete->Enable();
SetupEngineConf(std::to_string(event.GetItem().GetData()));
}
......
......@@ -77,6 +77,7 @@ public:
void RefreshEngineList();
/// @brief Refresh @a EngineConf etc..
void EngineListHandler(wxListEvent &event);
void PropertyGridHandler(wxPropertyGridEvent& event);
/// @see ochess::Observer::Notify()
void Notify(SUBJECT sbj) override;
/// @brief Button handler for the EngineSettings panel
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment