New file dialogs code

This commit is contained in:
Ilari Liusvaara 2013-07-25 15:19:26 +03:00
parent d23d312e78
commit a2fc2a19ec
9 changed files with 282 additions and 135 deletions

View file

@ -0,0 +1,75 @@
#ifndef _platform__wxwidgets__loadsave__hpp__included__
#define _platform__wxwidgets__loadsave__hpp__included__
#include <string>
#include "platform/wxwidgets/platform.hpp"
struct filedialog_type_entry
{
filedialog_type_entry(std::string _name, std::string _extensions, std::string _primaryext)
{
name = _name;
extensions = _extensions;
primaryext = _primaryext;
}
std::string name;
std::string extensions;
std::string primaryext;
};
struct filedialog_input_params
{
std::vector<filedialog_type_entry> types;
int default_type;
};
struct filedialog_output_params
{
std::string path;
int typechoice;
};
class single_type
{
public:
typedef std::string returntype;
single_type(const std::string& _ext, const std::string& _desc = "");
filedialog_input_params input(bool save) const;
std::string output(const filedialog_output_params& p, bool save) const;
private:
std::string ext;
std::string desc;
};
extern single_type filetype_lua_script;
extern single_type filetype_macro;
extern single_type filetype_watch;
extern single_type filetype_commentary;
extern single_type filetype_sox;
extern single_type filetype_sub;
extern single_type filetype_png;
filedialog_output_params show_filedialog(wxWindow* parent, const std::string& title, const std::string& basepath,
const filedialog_input_params& p, const std::string& defaultname, bool saving);
template<typename T>
typename T::returntype choose_file_load(wxWindow* parent, const std::string& title, const std::string& basepath,
const T& types, const std::string& defaultname = "")
{
filedialog_input_params p = types.input(false);
filedialog_output_params q = show_filedialog(parent, title, basepath, p, defaultname, false);
return types.output(q, false);
}
template<typename T>
typename T::returntype choose_file_save(wxWindow* parent, const std::string& title, const std::string& basepath,
const T& types, const std::string& defaultname = "")
{
filedialog_input_params p = types.input(true);
filedialog_output_params q = show_filedialog(parent, title, basepath, p, defaultname, true);
return types.output(q, true);
}
#endif

View file

@ -88,8 +88,6 @@ public:
};
//Prompt for stuff. These all can throw canceled_exception.
std::string pick_file(wxWindow* parent, const std::string& title, const std::string& startdir, bool forsave,
std::string ext = "", std::string dfltname = "");
std::string pick_file_member(wxWindow* parent, const std::string& title, const std::string& startdir);
std::string pick_among(wxWindow* parent, const std::string& title, const std::string& prompt,
const std::vector<std::string>& choices, unsigned defaultchoice = 0);

View file

@ -6,6 +6,7 @@
#include "library/zip.hpp"
#include "platform/wxwidgets/platform.hpp"
#include "platform/wxwidgets/loadsave.hpp"
#include <wx/wx.h>
#include <wx/event.h>
@ -258,7 +259,7 @@ void wxeditor_authors::on_dir_select(wxCommandEvent& e)
void wxeditor_authors::on_add(wxCommandEvent& e)
{
try {
std::string luascript = pick_file(this, "Pick lua script", ".", false, "lua");
std::string luascript = choose_file_load(this, "Pick lua script", ".", filetype_lua_script);
try {
auto& p = open_file_relative(luascript, "");
delete &p;

View file

@ -9,6 +9,7 @@
#include "library/json.hpp"
#include "platform/wxwidgets/platform.hpp"
#include "platform/wxwidgets/loadsave.hpp"
#include <wx/wx.h>
#include <wx/event.h>
@ -378,7 +379,7 @@ void wxeditor_macro::on_load(wxCommandEvent& e)
std::string mname = pick_text(this, "Name new macro", "Enter name for the new macro:", "");
if(mname == "")
return;
std::string file = pick_file(this, "Select macro", project_otherpath(), false, "lmc");
std::string file = choose_file_load(this, "Load macro from", project_otherpath(), filetype_macro);
std::vector<char> contents = read_file_relative(file, "");
controller_macro m(JSON::node(std::string(contents.begin(), contents.end())));
controls.set_macro(mname, m);
@ -404,7 +405,7 @@ void wxeditor_macro::on_save(wxCommandEvent& e)
std::string mdata = _macro->serialize().serialize();
//Okay, have the macro data, now prompt for file and save.
try {
std::string tfile = pick_file(this, "Save macro (.lmc)", project_otherpath(), true, "lmc");
std::string tfile = choose_file_save(this, "Save macro to", project_otherpath(), filetype_macro);
std::ofstream f(tfile);
f << mdata;
if(!f)
@ -445,3 +446,4 @@ void wxeditor_macro_display(wxWindow* parent)
}
editor->Destroy();
}

View file

@ -3,6 +3,7 @@
#include <stdexcept>
#include "platform/wxwidgets/platform.hpp"
#include "platform/wxwidgets/loadsave.hpp"
#include <wx/wx.h>
#include <wx/event.h>
@ -29,11 +30,9 @@ public:
void on_select(wxCommandEvent& e);
void on_play(wxCommandEvent& e);
void on_delete(wxCommandEvent& e);
void on_export_p(wxCommandEvent& e);
void on_export_q(wxCommandEvent& e);
void on_export(wxCommandEvent& e);
void on_export_s(wxCommandEvent& e);
void on_import_p(wxCommandEvent& e);
void on_import_q(wxCommandEvent& e);
void on_import(wxCommandEvent& e);
void on_change_ts(wxCommandEvent& e);
void on_change_gain(wxCommandEvent& e);
void on_load(wxCommandEvent& e);
@ -50,10 +49,8 @@ private:
wxButton* playbutton;
wxButton* deletebutton;
wxButton* exportpbutton;
wxButton* exportqbutton;
wxButton* exportsbutton;
wxButton* importpbutton;
wxButton* importqbutton;
wxButton* changetsbutton;
wxButton* changegainbutton;
wxButton* loadbutton;
@ -69,7 +66,7 @@ wxeditor_voicesub::wxeditor_voicesub(wxWindow* parent)
{
closing = false;
Centre();
wxFlexGridSizer* top_s = new wxFlexGridSizer(7, 1, 0, 0);
wxFlexGridSizer* top_s = new wxFlexGridSizer(6, 1, 0, 0);
SetSizer(top_s);
top_s->Add(subtitles = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(300, 400), 0, NULL,
@ -83,17 +80,10 @@ wxeditor_voicesub::wxeditor_voicesub(wxWindow* parent)
pbutton_s->SetSizeHints(this);
pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->Add(new wxStaticText(this, wxID_ANY, wxT("Export")), 0, wxGROW);
pbutton_s->Add(exportqbutton = new wxButton(this, wxID_ANY, wxT("Ogg")), 0, wxGROW);
pbutton_s->Add(exportpbutton = new wxButton(this, wxID_ANY, wxT("Sox")), 0, wxGROW);
pbutton_s->Add(exportsbutton = new wxButton(this, wxID_ANY, wxT("Superstream")), 0, wxGROW);
top_s->Add(pbutton_s, 1, wxGROW);
pbutton_s->SetSizeHints(this);
pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->Add(new wxStaticText(this, wxID_ANY, wxT("Import")), 0, wxGROW);
pbutton_s->Add(importqbutton = new wxButton(this, wxID_ANY, wxT("Ogg")), 0, wxGROW);
pbutton_s->Add(importpbutton = new wxButton(this, wxID_ANY, wxT("Sox")), 0, wxGROW);
pbutton_s->Add(new wxStaticText(this, wxID_ANY, wxT("I/O")), 0, wxGROW);
pbutton_s->Add(importpbutton = new wxButton(this, wxID_ANY, wxT("Import")), 0, wxGROW);
pbutton_s->Add(exportpbutton = new wxButton(this, wxID_ANY, wxT("Export")), 0, wxGROW);
pbutton_s->Add(exportsbutton = new wxButton(this, wxID_ANY, wxT("Export all")), 0, wxGROW);
top_s->Add(pbutton_s, 1, wxGROW);
pbutton_s->SetSizeHints(this);
@ -123,15 +113,11 @@ wxeditor_voicesub::wxeditor_voicesub(wxWindow* parent)
deletebutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_voicesub::on_delete), NULL, this);
exportpbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_voicesub::on_export_p), NULL, this);
exportqbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_voicesub::on_export_q), NULL, this);
wxCommandEventHandler(wxeditor_voicesub::on_export), NULL, this);
exportsbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_voicesub::on_export_s), NULL, this);
importpbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_voicesub::on_import_p), NULL, this);
importqbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_voicesub::on_import_q), NULL, this);
wxCommandEventHandler(wxeditor_voicesub::on_import), NULL, this);
changetsbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_voicesub::on_change_ts), NULL, this);
changegainbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
@ -168,7 +154,6 @@ void wxeditor_voicesub::on_select(wxCommandEvent& e)
playbutton->Enable(valid);
deletebutton->Enable(valid);
exportpbutton->Enable(valid);
exportqbutton->Enable(valid);
changetsbutton->Enable(valid);
changegainbutton->Enable(valid);
}
@ -197,31 +182,39 @@ void wxeditor_voicesub::on_delete(wxCommandEvent& e)
}
}
void wxeditor_voicesub::on_export_p(wxCommandEvent& e)
namespace
{
uint64_t id = get_id();
if(id == NOTHING)
return;
try {
std::string filename;
filename = pick_file(this, "Select sox file to export", project_otherpath(), true, "sox");
voicesub_export_stream(id, filename, EXTFMT_SOX);
} catch(canceled_exception& e) {
} catch(std::exception& e) {
show_message_ok(this, "Error exporting", e.what(), wxICON_EXCLAMATION);
}
class _opus_or_sox
{
public:
typedef std::pair<std::string, enum external_stream_format> returntype;
_opus_or_sox() {}
filedialog_input_params input(bool save) const
{
filedialog_input_params p;
p.types.push_back(filedialog_type_entry("Opus streams", "*.opus", "opus"));
p.types.push_back(filedialog_type_entry("SoX files", "*.sox", "sox"));
p.default_type = 0;
return p;
}
std::pair<std::string, enum external_stream_format> output(const filedialog_output_params& p,
bool save) const
{
return std::make_pair(p.path, (p.typechoice == 1) ? EXTFMT_SOX : EXTFMT_OGGOPUS);
}
} filetype_opus_sox;
}
void wxeditor_voicesub::on_export_q(wxCommandEvent& e)
void wxeditor_voicesub::on_export(wxCommandEvent& e)
{
uint64_t id = get_id();
if(id == NOTHING)
return;
try {
std::string filename;
filename = pick_file(this, "Select Ogg (Opus) file to export", project_otherpath(), true,
"opus");
voicesub_export_stream(id, filename, EXTFMT_OGGOPUS);
auto filename = choose_file_save(this, "Select file to epxort", project_otherpath(),
filetype_opus_sox);
voicesub_export_stream(id, filename.first, filename.second);
} catch(canceled_exception& e) {
} catch(std::exception& e) {
show_message_ok(this, "Error exporting", e.what(), wxICON_EXCLAMATION);
@ -232,8 +225,8 @@ void wxeditor_voicesub::on_export_s(wxCommandEvent& e)
{
try {
std::string filename;
filename = pick_file(this, "Select sox file to export (superstream)", project_otherpath(), true,
"sox");
filename = choose_file_save(this, "Select file to export superstream", project_otherpath(),
filetype_sox);
voicesub_export_superstream(filename);
} catch(canceled_exception& e) {
} catch(std::exception& e) {
@ -241,30 +234,15 @@ void wxeditor_voicesub::on_export_s(wxCommandEvent& e)
}
}
void wxeditor_voicesub::on_import_p(wxCommandEvent& e)
void wxeditor_voicesub::on_import(wxCommandEvent& e)
{
try {
std::string filename;
uint64_t ts;
ts = voicesub_parse_timebase(pick_text(this, "Enter timebase", "Enter position for newly "
"imported stream"));
filename = pick_file(this, "Select sox file to import", project_otherpath(), false, "sox");
voicesub_import_stream(ts, filename, EXTFMT_SOX);
} catch(canceled_exception& e) {
} catch(std::exception& e) {
show_message_ok(this, "Error importing", e.what(), wxICON_EXCLAMATION);
}
}
void wxeditor_voicesub::on_import_q(wxCommandEvent& e)
{
try {
std::string filename;
uint64_t ts;
ts = voicesub_parse_timebase(pick_text(this, "Enter timebase", "Enter position for newly "
"imported stream"));
filename = pick_file(this, "Select Ogg (Opus) file to import", project_otherpath(), false, "opus");
voicesub_import_stream(ts, filename, EXTFMT_OGGOPUS);
auto filename = choose_file_save(this, "Select file to import", project_otherpath(),
filetype_opus_sox);
voicesub_import_stream(ts, filename.first, filename.second);
} catch(canceled_exception& e) {
} catch(std::exception& e) {
show_message_ok(this, "Error importing", e.what(), wxICON_EXCLAMATION);
@ -311,7 +289,7 @@ void wxeditor_voicesub::on_load(wxCommandEvent& e)
std::string filename;
try {
//Use "." here because there can't be active project.
filename = pick_file(this, "Select collection to load", ".", false, "lsvs");
filename = choose_file_load(this, "Select collection to load", ".", filetype_commentary);
} catch(...) {
return;
}
@ -350,7 +328,6 @@ void wxeditor_voicesub::refresh()
loadbutton->Enable(!pflag);
exportsbutton->Enable(cflag);
importpbutton->Enable(cflag);
importqbutton->Enable(cflag);
int sel = subtitles->GetSelection();
subtitles->Clear();
smap.clear();

View file

@ -0,0 +1,81 @@
#include "platform/wxwidgets/loadsave.hpp"
#include <wx/wx.h>
#include <wx/event.h>
#include <wx/control.h>
#include <wx/combobox.h>
#include <wx/cmdline.h>
single_type::single_type(const std::string& _ext, const std::string& _desc)
{
ext = _ext;
if(_desc != "")
desc = _desc;
else if(_ext != "")
desc = _ext + " files";
else
desc = "All files";
}
filedialog_input_params single_type::input(bool save) const
{
filedialog_input_params p;
if(ext != "")
p.types.push_back(filedialog_type_entry(desc, "*."+ext, ext));
p.types.push_back(filedialog_type_entry("All files", "", ""));
p.default_type = 0;
return p;
}
std::string single_type::output(const filedialog_output_params& p, bool save) const
{
return p.path;
}
filedialog_output_params show_filedialog(wxWindow* parent, const std::string& title, const std::string& basepath,
const filedialog_input_params& p, const std::string& defaultname, bool saving)
{
wxString _title = towxstring(title);
wxString _startdir = towxstring(basepath);
std::string filespec;
for(auto i : p.types) {
if(filespec != "")
filespec = filespec + "|";
if(i.extensions != "")
filespec = filespec + i.name + " (" + i.extensions + ")|" + i.extensions;
else
filespec = filespec + i.name + "|*";
}
wxFileDialog* d = new wxFileDialog(parent, _title, _startdir, wxT(""), towxstring(filespec), saving ?
wxFD_SAVE : wxFD_OPEN);
if(defaultname != "")
d->SetFilename(towxstring(defaultname));
d->SetFilterIndex(p.default_type);
if(d->ShowModal() == wxID_CANCEL)
throw canceled_exception();
std::string filename = tostdstring(d->GetPath());
int findex = d->GetFilterIndex();
d->Destroy();
if(filename == "")
throw canceled_exception();
if(saving && p.types[findex].primaryext != "") {
//Append extension if needed.
std::string ext = p.types[findex].primaryext;
size_t dpos = filename.find_first_of(".");
if(dpos > filename.length() || filename.substr(dpos + 1) != ext)
filename = filename + "." + ext;
}
filedialog_output_params r;
r.path = filename;
r.typechoice = findex;
return r;
}
single_type filetype_lua_script("lua", "Lua scripts");
single_type filetype_macro("lmc", "Macro files");
single_type filetype_watch("lwch", "Memory watch");
single_type filetype_commentary("lsvs", "Commentary track");
single_type filetype_sox("sox", "SoX file");
single_type filetype_sub("sub", "Microsub subtitles");
single_type filetype_png("png", "Portable Network Graphics");

View file

@ -1,4 +1,3 @@
//Gaah... wx/wx.h (contains something that breaks if included after snes/snes.hpp from bsnes v085.
#include <wx/wx.h>
#include "lsnes.hpp"
@ -610,43 +609,25 @@ void _runuifun_async(void (*fn)(void*), void* arg)
canceled_exception::canceled_exception() : std::runtime_error("Dialog canceled") {}
std::string pick_file(wxWindow* parent, const std::string& title, const std::string& startdir, bool forsave,
std::string ext, std::string dfltname)
std::string pick_file(wxWindow* parent, const std::string& title, const std::string& startdir)
{
wxString _title = towxstring(title);
wxString _startdir = towxstring(startdir);
std::string filespec;
if(ext == "lsmv" && !forsave)
filespec = "lsmv files|*.lsmv|lsmv backup files|*.lsmv.backup|All files|*";
else if(ext == "lss" && !forsave)
filespec = "lss files|*.lss|lss backup files|*.lss.backup|All files|*";
else if(ext != "")
filespec = ext + " files|*." + ext + "|All files|*";
else
filespec = "All files|*";
wxFileDialog* d = new wxFileDialog(parent, _title, _startdir, wxT(""), towxstring(filespec), forsave ?
wxFD_SAVE : wxFD_OPEN);
if(dfltname != "")
d->SetFilename(towxstring(dfltname));
filespec = "All files|*";
wxFileDialog* d = new wxFileDialog(parent, _title, _startdir, wxT(""), towxstring(filespec), wxFD_OPEN);
if(d->ShowModal() == wxID_CANCEL)
throw canceled_exception();
std::string filename = tostdstring(d->GetPath());
int findex = d->GetFilterIndex();
d->Destroy();
if(filename == "")
throw canceled_exception();
if(forsave && ext != "" && findex == 0) {
//Append extension if needed.
size_t dpos = filename.find_first_of(".");
if(dpos > filename.length() || filename.substr(dpos + 1) != ext)
filename = filename + "." + ext;
}
return filename;
}
std::string pick_file_member(wxWindow* parent, const std::string& title, const std::string& startdir)
{
std::string filename = pick_file(parent, title, startdir, false);
std::string filename = pick_file(parent, title, startdir);
//Did we pick a .zip file?
if(!regex_match(".*\\.[zZ][iI][pP]", filename))
return filename; //Not a ZIP.

View file

@ -3,6 +3,7 @@
#include <wx/dnd.h>
#include "platform/wxwidgets/menu_dump.hpp"
#include "platform/wxwidgets/platform.hpp"
#include "platform/wxwidgets/loadsave.hpp"
#include "platform/wxwidgets/window_mainwindow.hpp"
#include "platform/wxwidgets/window_messages.hpp"
#include "platform/wxwidgets/window_status.hpp"
@ -58,9 +59,6 @@ enum
wxID_SAVE_MOVIE,
wxID_SAVE_SUBTITLES,
wxID_LOAD_STATE,
wxID_LOAD_STATE_RO,
wxID_LOAD_STATE_RW,
wxID_LOAD_STATE_P,
wxID_LOAD_MOVIE,
wxID_RUN_SCRIPT,
wxID_RUN_LUA,
@ -834,9 +832,6 @@ wxwin_mainwindow::wxwin_mainwindow()
menu_end_sub();
menu_start_sub(wxT("Load"));
menu_entry(wxID_LOAD_STATE, wxT("State..."));
menu_entry(wxID_LOAD_STATE_RO, wxT("State (readonly)..."));
menu_entry(wxID_LOAD_STATE_RW, wxT("State (read-write)..."));
menu_entry(wxID_LOAD_STATE_P, wxT("State (preserve input)..."));
menu_entry(wxID_LOAD_MOVIE, wxT("Movie..."));
if(loaded_library::call_library() != "") {
menu_separator();
@ -1071,9 +1066,59 @@ void wxwin_mainwindow::refresh_title() throw()
menubar->SetMenuLabel(1, towxstring(our_rom->rtype->get_systemmenu_name()));
}
namespace
{
struct movie_or_savestate
{
public:
typedef std::pair<std::string,std::string> returntype;
movie_or_savestate(bool is_state)
{
state = is_state;
}
filedialog_input_params input(bool save) const
{
filedialog_input_params p;
std::string ext = state ? project_savestate_ext() : "lsmv";
if(save)
p.types.push_back(filedialog_type_entry(state ? "Savestates" : "Movies", "*." + ext,
ext));
else
p.types.push_back(filedialog_type_entry(state ? "Savestates" : "Movies", "*." + ext +
";*." + ext + ".backup", ext));
if(!save && state) {
p.types.push_back(filedialog_type_entry("Savestates [read only]", "*." + ext +
";*." + ext + ".backup", ext));
p.types.push_back(filedialog_type_entry("Savestates [read-write]", "*." + ext +
";*." + ext + ".backup", ext));
p.types.push_back(filedialog_type_entry("Savestates [preserve]", "*." + ext +
";*." + ext + ".backup", ext));
}
p.default_type = 0;
return p;
}
std::pair<std::string, std::string> output(const filedialog_output_params& p, bool save) const
{
std::string cmdmod;
switch(p.typechoice) {
case 0: cmdmod = ""; break;
case 1: cmdmod = "-readonly"; break;
case 2: cmdmod = "-state"; break;
case 3: cmdmod = "-preserve"; break;
}
return std::make_pair(cmdmod, p.path);
}
private:
bool state;
};
struct movie_or_savestate filetype_movie(false);
struct movie_or_savestate filetype_savestate(true);
}
void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
{
std::string filename;
std::pair<std::string, std::string> filename2;
bool s;
switch(e.GetId()) {
case wxID_FRAMEADVANCE:
@ -1103,60 +1148,43 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
platform::queue("cancel-saves");
return;
case wxID_LOAD_MOVIE:
filename = pick_file(this, "Load Movie", project_moviepath(), false, "lsmv");
filename = choose_file_load(this, "Load Movie", project_moviepath(), filetype_movie).second;
recent_movies->add(filename);
platform::queue("load-movie " + filename);
return;
case wxID_LOAD_STATE:
filename = pick_file(this, "Load State", project_moviepath(), false, project_savestate_ext());
recent_movies->add(filename);
platform::queue("load " + filename);
return;
case wxID_LOAD_STATE_RO:
filename = pick_file(this, "Load State (Read-Only)", project_moviepath(), false,
project_savestate_ext());
recent_movies->add(filename);
platform::queue("load-readonly " + filename);
return;
case wxID_LOAD_STATE_RW:
filename = pick_file(this, "Load State (Read-Write)", project_moviepath(), false,
project_savestate_ext());
recent_movies->add(filename);
platform::queue("load-state " + filename);
return;
case wxID_LOAD_STATE_P:
filename = pick_file(this, "Load State (Preserve)", project_moviepath(), false,
project_savestate_ext());
recent_movies->add(filename);
platform::queue("load-preserve " + filename);
filename2 = choose_file_load(this, "Load State", project_moviepath(), filetype_savestate);
recent_movies->add(filename2.second);
platform::queue("load" + filename2.first + " " + filename2.second);
return;
case wxID_REWIND_MOVIE:
platform::queue("rewind-movie");
return;
case wxID_SAVE_MOVIE:
filename = pick_file(this, "Save Movie", project_moviepath(), true, "lsmv",
project_prefixname("lsmv"));
filename = choose_file_save(this, "Save Movie", project_moviepath(), filetype_movie,
project_prefixname("lsmv")).second;
recent_movies->add(filename);
platform::queue("save-movie " + filename);
return;
case wxID_SAVE_SUBTITLES:
platform::queue("save-subtitle " + pick_file(this, "Save Subtitle (.sub)", project_moviepath(), true,
"sub", project_prefixname("sub")));
platform::queue("save-subtitle " + choose_file_save(this, "Save subtitles", project_moviepath(),
filetype_sub, project_prefixname("sub")));
return;
case wxID_SAVE_STATE:
filename = pick_file(this, "Save State", project_moviepath(), true, project_savestate_ext());
filename = choose_file_save(this, "Save State", project_moviepath(), filetype_savestate).second;
recent_movies->add(filename);
platform::queue("save-state " + filename);
return;
case wxID_SAVE_SCREENSHOT:
platform::queue("take-screenshot " + pick_file(this, "Save Screenshot", project_moviepath(), true,
"png", get_default_screenshot_name()));
platform::queue("take-screenshot " + choose_file_save(this, "Save Screenshot", project_moviepath(),
filetype_png, get_default_screenshot_name()));
return;
case wxID_RUN_SCRIPT:
platform::queue("run-script " + pick_file_member(this, "Select Script", project_otherpath()));
return;
case wxID_RUN_LUA:
platform::queue("run-lua " + pick_file(this, "Select Lua Script", project_otherpath(), false, "lua"));
platform::queue("run-lua " + choose_file_load(this, "Select Lua Script", project_otherpath(),
filetype_lua_script));
return;
case wxID_RESET_LUA:
platform::queue("reset-lua");
@ -1198,7 +1226,8 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
modal_pause_holder hld;
std::set<std::string> old_watches;
runemufn([&old_watches]() { old_watches = get_watches(); });
std::string filename = pick_file(this, "Save watches to file", project_otherpath(), true, "lwch");
std::string filename = choose_file_save(this, "Save watches to file", project_otherpath(),
filetype_watch);
std::ofstream out(filename.c_str());
for(auto i : old_watches) {
std::string val;
@ -1213,7 +1242,8 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
std::set<std::string> old_watches;
runemufn([&old_watches]() { old_watches = get_watches(); });
std::map<std::string, std::string> new_watches;
std::string filename = pick_file(this, "Choose memory watch file", project_otherpath(), "lwch");
std::string filename = choose_file_load(this, "Choose memory watch file", project_otherpath(),
filetype_watch);
try {
std::istream& in = open_file_relative(filename, "");
while(in) {
@ -1344,8 +1374,8 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
break;
case wxID_LOAD_LIBRARY: {
std::string name = std::string("load ") + loaded_library::call_library();
with_loaded_library(new loaded_library(pick_file(this, name, project_otherpath(), false,
loaded_library::call_library_ext())));
with_loaded_library(new loaded_library(choose_file_load(this, name, project_otherpath(),
single_type(loaded_library::call_library_ext(), loaded_library::call_library()))));
handle_post_loadlibrary();
break;
}

View file

@ -22,6 +22,8 @@
#include <boost/filesystem.hpp>
#include "platform/wxwidgets/platform.hpp"
#include "platform/wxwidgets/loadsave.hpp"
#define ASK_SRAMS_BASE (wxID_HIGHEST + 129)
#define ASK_SRAMS_LAST (wxID_HIGHEST + 255)
@ -292,7 +294,7 @@ no_watch:
void wxwin_newproject::on_memorywatch_select(wxCommandEvent& e)
{
try {
std::string lwch = pick_file(this, "Select memory watch file", ".", false, "lwch");
std::string lwch = choose_file_load(this, "Select memory watch file", ".", filetype_watch);
try {
auto& p = open_file_relative(lwch, "");
delete &p;
@ -320,7 +322,7 @@ no_watch:
void wxwin_newproject::on_add(wxCommandEvent& e)
{
try {
std::string luascript = pick_file(this, "Pick lua script", ".", false, "lua");
std::string luascript = choose_file_load(this, "Pick lua script", ".", filetype_lua_script);
try {
auto& p = open_file_relative(luascript, "");
delete &p;