1 #include "platform/wxwidgets/loadsave.hpp"
4 #include <wx/control.h>
5 #include <wx/combobox.h>
6 #include <wx/cmdline.h>
8 single_type::single_type(const std::string
& _ext
, const std::string
& _desc
)
14 desc
= _ext
+ " files";
19 filedialog_input_params
single_type::input(bool save
) const
21 filedialog_input_params p
;
23 p
.types
.push_back(filedialog_type_entry(desc
, "*."+ext
, ext
));
24 p
.types
.push_back(filedialog_type_entry("All files", "", ""));
29 std::string
single_type::output(const filedialog_output_params
& p
, bool save
) const
34 filedialog_input_params
lua_script_type::input(bool save
) const
36 filedialog_input_params p
;
37 p
.types
.push_back(filedialog_type_entry("Lua scripts", "*.lua", "lua"));
38 p
.types
.push_back(filedialog_type_entry("Packed lua scripts", "*.zlua", "zlua"));
39 p
.types
.push_back(filedialog_type_entry("All files", "", ""));
44 std::string
lua_script_type::output(const filedialog_output_params
& p
, bool save
) const
47 return p
.path
+ "/main.lua";
53 filedialog_output_params
show_filedialog(wxWindow
* parent
, const std::string
& title
, const std::string
& basepath
,
54 const filedialog_input_params
& p
, const std::string
& defaultname
, bool saving
)
56 wxString _title
= towxstring(title
);
57 wxString _startdir
= towxstring(basepath
);
59 for(auto i
: p
.types
) {
61 filespec
= filespec
+ "|";
62 if(i
.extensions
!= "")
63 filespec
= filespec
+ i
.name
+ " (" + i
.extensions
+ ")|" + i
.extensions
;
65 filespec
= filespec
+ i
.name
+ "|*";
67 wxFileDialog
* d
= new wxFileDialog(parent
, _title
, _startdir
, wxT(""), towxstring(filespec
), saving
?
68 wxFD_SAVE
: wxFD_OPEN
);
70 d
->SetFilename(towxstring(defaultname
));
71 d
->SetFilterIndex(p
.default_type
);
72 if(p
.default_filename
!= "")
73 d
->SetFilename(towxstring(p
.default_filename
));
74 if(d
->ShowModal() == wxID_CANCEL
)
75 throw canceled_exception();
76 std::string filename
= tostdstring(d
->GetPath());
77 int findex
= d
->GetFilterIndex();
80 throw canceled_exception();
81 if(saving
&& p
.types
[findex
].primaryext
!= "") {
82 //Append extension if needed.
83 std::string ext
= p
.types
[findex
].primaryext
;
84 size_t dpos
= filename
.find_first_of(".");
85 if(dpos
> filename
.length() || filename
.substr(dpos
+ 1) != ext
)
86 filename
= filename
+ "." + ext
;
88 filedialog_output_params r
;
90 r
.typechoice
= findex
;
94 lua_script_type filetype_lua_script
;
95 single_type
filetype_macro("lmc", "Macro files");
96 single_type
filetype_watch("lwch", "Memory watch");
97 single_type
filetype_commentary("lsvs", "Commentary track");
98 single_type
filetype_sox("sox", "SoX file");
99 single_type
filetype_sub("sub", "Microsub subtitles");
100 single_type
filetype_png("png", "Portable Network Graphics");
101 single_type
filetype_hexbookmarks("lhb", "Hex editor bookmarks");
102 single_type
filetype_memorysearch("lms", "Memory search save");
103 single_type
filetype_textfile("txt", "Text file");