| 1 |
#include "file_ficker_property.h" |
| 2 |
#include "file_picker_ctrl.h" |
| 3 |
#include "wxc_project_metadata.h" |
| 4 |
#include <wx/filename.h> |
| 5 |
|
| 6 |
FilePickerProperty::FilePickerProperty(const wxString& label, const wxString& path, const wxString& tooltip) |
| 7 |
: PropertyBase(tooltip) |
| 8 |
{ |
| 9 |
wxString tip; |
| 10 |
tip << GetTooltip(); |
| 11 |
|
| 12 |
SetTooltip(tip); |
| 13 |
SetLabel(label); |
| 14 |
SetValue(path); |
| 15 |
} |
| 16 |
|
| 17 |
FilePickerProperty::FilePickerProperty() |
| 18 |
: PropertyBase(wxT("")) |
| 19 |
{ |
| 20 |
} |
| 21 |
|
| 22 |
FilePickerProperty::~FilePickerProperty() {} |
| 23 |
|
| 24 |
wxString FilePickerProperty::GetValue() const { return m_path; } |
| 25 |
|
| 26 |
JSONElement FilePickerProperty::Serialize() const |
| 27 |
{ |
| 28 |
JSONElement json = JSONElement::createObject(); |
| 29 |
json.addProperty(wxT("type"), wxT("filePicker")); |
| 30 |
DoBaseSerialize(json); |
| 31 |
json.addProperty(wxT("m_path"), m_path); |
| 32 |
return json; |
| 33 |
} |
| 34 |
|
| 35 |
void FilePickerProperty::SetValue(const wxString& value) { m_path = value; } |
| 36 |
|
| 37 |
void FilePickerProperty::UnSerialize(const JSONElement& json) |
| 38 |
{ |
| 39 |
DoBaseUnSerialize(json); |
| 40 |
m_path = json.namedObject(wxT("m_path")).toString(); |
| 41 |
} |
| 42 |
|
| 43 |
void FilePickerProperty::FixPaths(const wxString& cwd) |
| 44 |
{ |
| 45 |
wxString wd = cwd; |
| 46 |
if(wd.IsEmpty()) { wd = wxcProjectMetadata::Get().GetProjectPath(); } |
| 47 |
|
| 48 |
wxFileName fn(m_path); |
| 49 |
if(fn.IsAbsolute() && wd.IsEmpty() == false) { |
| 50 |
fn.MakeRelativeTo(wd); |
| 51 |
m_path = fn.GetFullPath(); |
| 52 |
} |
| 53 |
} |