Skip to content

Commit

Permalink
fix a bug GetConfig() will add slash to directories
Browse files Browse the repository at this point in the history
  • Loading branch information
matyalatte committed Sep 25, 2022
1 parent 0b4b9c4 commit d659669
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/custom_wx_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CustomPickerBase : public wxFileDirPickerCtrlBase {
const wxString& name);
void UpdateTextCtrlFromPicker();
void UpdatePickerFromTextCtrl();
virtual wxString GetFullPath() {return "";}
};

// Customized wxFilePicker
Expand All @@ -100,6 +101,7 @@ class CustomFilePicker : public CustomPickerBase {
virtual ~CustomFilePicker() {}

wxString GetTextCtrlValue() const wxOVERRIDE;
wxString GetFullPath() wxOVERRIDE;

bool IsCwdToUpdate() const wxOVERRIDE {
return HasFlag(wxFLP_CHANGE_DIR);
Expand Down Expand Up @@ -154,6 +156,7 @@ class CustomDirPicker : public CustomPickerBase {
virtual ~CustomDirPicker() {}

wxString GetTextCtrlValue() const wxOVERRIDE;
wxString GetFullPath() wxOVERRIDE;

bool IsCwdToUpdate() const wxOVERRIDE {
return HasFlag(wxDIRP_CHANGE_DIR);
Expand Down
3 changes: 1 addition & 2 deletions src/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ CheckArray::CheckArray(wxPanel* panel, nlohmann::json j, int y) :
checks->push_back(
new wxCheckBox(panel, wxID_ANY,
wxString::FromUTF8(j["items"][i]),
wxPoint(20, y + 20 + i * 20), wxSize(350, 15))
);
wxPoint(20, y + 20 + i * 20), wxSize(350, 15)));
}
if (j.contains("values")) {
SetValues(j["values"]);
Expand Down
11 changes: 9 additions & 2 deletions src/custom_wx_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void CustomPickerBase::UpdateTextCtrlFromPicker() {
}

void CustomPickerBase::UpdatePickerFromTextCtrl() {
wxString newpath(GetTextCtrlValue());
wxString newpath(GetFullPath());
if (m_pickerIface->GetPath() != newpath) {
m_pickerIface->SetPath(newpath);

Expand Down Expand Up @@ -219,10 +219,13 @@ CustomFilePicker::CustomFilePicker(
if (HasTextCtrl())
GetTextCtrl()->AutoCompleteFileNames();
m_text->SetDropTarget(new DropFilePath<CustomFilePicker>(this, m_custom_text_ctrl));

}

wxString CustomFilePicker::GetTextCtrlValue() const {
return m_custom_text_ctrl->GetActualValue();
}

wxString CustomFilePicker::GetFullPath() {
return wxFileName(m_custom_text_ctrl->GetActualValue()).GetFullPath();
}

Expand Down Expand Up @@ -250,5 +253,9 @@ CustomDirPicker::CustomDirPicker(
}

wxString CustomDirPicker::GetTextCtrlValue() const {
return m_custom_text_ctrl->GetActualValue();
}

wxString CustomDirPicker::GetFullPath() {
return wxFileName::DirName(m_custom_text_ctrl->GetActualValue()).GetFullPath();
}
2 changes: 0 additions & 2 deletions tests/main_frame/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,5 @@ TEST(MainFrameTest, LoadSaveConfig) {
MainFrame* main_frame = new MainFrame(nlohmann::json(test_json), nlohmann::json(test_config));
main_frame->SaveConfig();
nlohmann::json saved_config = json_utils::LoadJson("gui_config.json");
test_config.erase("Some folder path");
saved_config.erase("Some folder path");
EXPECT_EQ(test_config, saved_config);
}

0 comments on commit d659669

Please sign in to comment.