Fix number of compile errors and warnings with GCC 14
[lsnes.git] / src / platform / wxwidgets / loadsave.cpp
blob29adc5dc9b0314eda45bc1c39cf4b99985a92be5
1 #include <wx/wx.h>
2 #include <wx/event.h>
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)
10 ext = _ext;
11 if(_desc != "")
12 desc = _desc;
13 else if(_ext != "")
14 desc = _ext + " files";
15 else
16 desc = "All files";
19 filedialog_input_params single_type::input(bool save) const
21 filedialog_input_params p;
22 if(ext != "")
23 p.types.push_back(filedialog_type_entry(desc, "*."+ext, ext));
24 p.types.push_back(filedialog_type_entry("All files", "", ""));
25 p.default_type = 0;
26 return p;
29 std::string single_type::output(const filedialog_output_params& p, bool save) const
31 return p.path;
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", "", ""));
40 p.default_type = 0;
41 return p;
44 std::string lua_script_type::output(const filedialog_output_params& p, bool save) const
46 if(p.typechoice == 1)
47 return p.path + "/main.lua";
48 else
49 return p.path;
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 CHECK_UI_THREAD;
57 wxString _title = towxstring(title);
58 wxString _startdir = towxstring(basepath);
59 std::string filespec;
60 for(auto i : p.types) {
61 if(filespec != "")
62 filespec = filespec + "|";
63 if(i.extensions != "")
64 filespec = filespec + i.name + " (" + i.extensions + ")|" + i.extensions;
65 else
66 filespec = filespec + i.name + "|*";
68 wxFileDialog* d = new wxFileDialog(parent, _title, _startdir, wxT(""), towxstring(filespec), saving ?
69 wxFD_SAVE : wxFD_OPEN);
70 if(defaultname != "")
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();
79 d->Destroy();
80 if(filename == "")
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);
91 if(extension != ext)
92 filename = filename + "." + ext;
94 filedialog_output_params r;
95 r.path = filename;
96 r.typechoice = findex;
97 return r;
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");