3 #include <wx/control.h>
4 #include <wx/combobox.h>
5 #include <wx/cmdline.h>
6 #include "platform/wxwidgets/loadsave.hpp"
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
)
57 wxString _title
= towxstring(title
);
58 wxString _startdir
= towxstring(basepath
);
60 for(auto i
: p
.types
) {
62 filespec
= filespec
+ "|";
63 if(i
.extensions
!= "")
64 filespec
= filespec
+ i
.name
+ " (" + i
.extensions
+ ")|" + i
.extensions
;
66 filespec
= filespec
+ i
.name
+ "|*";
68 wxFileDialog
* d
= new wxFileDialog(parent
, _title
, _startdir
, wxT(""), towxstring(filespec
), saving
?
69 wxFD_SAVE
: wxFD_OPEN
);
71 d
->SetFilename(towxstring(defaultname
));
72 d
->SetFilterIndex(p
.default_type
);
73 if(p
.default_filename
!= "")
74 d
->SetFilename(towxstring(p
.default_filename
));
75 if(d
->ShowModal() == wxID_CANCEL
)
76 throw canceled_exception();
77 std::string filename
= tostdstring(d
->GetPath());
78 int findex
= d
->GetFilterIndex();
81 throw canceled_exception();
82 if(saving
&& p
.types
[findex
].primaryext
!= "") {
83 //Append extension if needed.
84 std::string ext
= p
.types
[findex
].primaryext
;
85 size_t dpos
= filename
.find_last_of(".");
86 std::string extension
;
87 if(dpos
< filename
.length()) {
88 extension
= filename
.substr(dpos
+ 1);
89 std::transform(extension
.begin(), extension
.end(), extension
.begin(), ::tolower
);
92 filename
= filename
+ "." + ext
;
94 filedialog_output_params r
;
96 r
.typechoice
= findex
;
100 lua_script_type filetype_lua_script
;
101 single_type
filetype_macro("lmc", "Macro files");
102 single_type
filetype_watch("lwch", "Memory watch");
103 single_type
filetype_commentary("lsvs", "Commentary track");
104 single_type
filetype_sox("sox", "SoX file");
105 single_type
filetype_sub("sub", "Microsub subtitles");
106 single_type
filetype_png("png", "Portable Network Graphics");
107 single_type
filetype_hexbookmarks("lhb", "Hex editor bookmarks");
108 single_type
filetype_memorysearch("lms", "Memory search save");
109 single_type
filetype_textfile("txt", "Text file");
110 single_type
filetype_trace("trace", "Trace file");
111 single_type
filetype_font("font", "Font file");
112 single_type
filetype_disassembly("asm", "Disassembly");
113 single_type
filetype_r16m("r16m", "R16m movie dump");