diff -up 0ad-0.0.14-alpha/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp.orig 0ad-0.0.14-alpha/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp --- 0ad-0.0.14-alpha/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp.orig 2013-09-05 11:13:07.035046355 -0300 +++ 0ad-0.0.14-alpha/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp 2013-09-05 11:13:09.036046432 -0300 @@ -692,30 +692,20 @@ bool ScenarioEditor::OpenFile(const wxSt void ScenarioEditor::OnOpen(wxCommandEvent& WXUNUSED(event)) { - wxFileDialog dlg (NULL, wxFileSelectorPromptStr, - Datafile::GetDataDirectory() + _T("/mods/public/maps/scenarios"), m_OpenFilename, - _T("PMP files (*.pmp)|*.pmp|All files (*.*)|*.*"), - wxFD_OPEN); - // Set default filter - dlg.SetFilterIndex(0); - - wxString cwd = wxFileName::GetCwd(); - - if (dlg.ShowModal() == wxID_OK) - { - // TODO: Handle maps in subdirectories of maps/scenarios - wxFileName filename(dlg.GetFilename()); - if (!OpenFile(filename.GetName(), filename.GetFullName())) - { - wxLogError(_("Map '%ls' does not exist"), filename.GetName().c_str()); - } - - // paranoia - MSDN says OFN_NOCHANGEDIR (used when we don't give wxCHANGE_DIR) - // "is ineffective for GetOpenFileName", but it seems to work anyway - wxCHECK_RET(cwd == wxFileName::GetCwd(), _T("cwd changed")); + wxFileName filename(m_OpenFilename); + wxFileName dirname(_T("/usr/share/0ad/mods/public/maps/scenarios")); + wxString string = wxGetTextFromUser(dirname.GetFullPath() + _T("/"), + _T("Choose filename"), + filename.GetName()); + if (!string.IsEmpty()) { + filename.Assign(dirname.GetFullPath() + _("/") + string); + filename.SetExt(_T("pmp")); + + if (!OpenFile(filename.GetName(), filename.GetFullName())) { + wxLogError(_("Map '%ls' does not exist"), + filename.GetName().c_str()); } - - // TODO: Make this a non-undoable command + } } void ScenarioEditor::OnImportHeightmap(wxCommandEvent& WXUNUSED(event)) @@ -779,40 +769,57 @@ void ScenarioEditor::OnSave(wxCommandEve void ScenarioEditor::OnSaveAs(wxCommandEvent& WXUNUSED(event)) { - wxFileDialog dlg (NULL, wxFileSelectorPromptStr, - Datafile::GetDataDirectory() + _T("/mods/public/maps/scenarios"), m_OpenFilename, - _T("PMP files (*.pmp)|*.pmp|All files (*.*)|*.*"), - wxFD_SAVE | wxFD_OVERWRITE_PROMPT); - // Set default filter - dlg.SetFilterIndex(0); - - if (dlg.ShowModal() == wxID_OK) - { - // On wxMSW the extension is automatically set to pmp if that filter is selected - // but not on wxGTK or wxOSX. Set it explicitly since it's the only possible format. - wxFileName filename(dlg.GetFilename()); - filename.SetExt(_T("pmp")); - if (!filename.IsOk()) - { // Shouldn't happen - wxLogError(_("Invalid filename '%ls'"), filename.GetFullName().c_str()); - return; - } + wxFileName filename(m_OpenFilename); + wxFileName dirname(_T("/usr/share/0ad/mods/public/maps/scenarios")); + wxString string = wxGetTextFromUser(dirname.GetFullPath() + _T("/"), + _T("Choose filename"), + filename.GetName()); + if (!string.IsEmpty()) { + filename.Assign(dirname.GetFullPath() + _("/") + string); + filename.SetExt(_T("pmp")); + + if (!dirname.DirExists(dirname.GetFullPath())) { + wxLogError(_("Directory '%ls' does not exist"), + dirname.GetFullPath().c_str()); + return; + } + if (!dirname.IsDirWritable(dirname.GetFullPath())) { + wxLogError(_("Directory '%ls' is not writable"), + dirname.GetFullPath().c_str()); + return; + } + if (!filename.IsOk()) { + wxLogError(_("Invalid filename '%ls'"), + filename.GetFullName().c_str()); + return; + } + if (filename.FileExists(filename.GetFullPath())) { + if (wxMessageBox(_("File ") + filename.GetFullPath() + + _(" exists, overwrite?"), + _("Confirm"), wxOK | wxCANCEL) != wxOK) + return; + if (!filename.IsFileWritable(filename.GetFullPath())) { + wxLogError(_("File '%ls' is not writable"), + filename.GetFullPath().c_str()); + return; + } + } - wxBusyInfo busy(_("Saving ") + filename.GetFullName()); - wxBusyCursor busyc; + wxBusyInfo busy(_("Saving ") + filename.GetFullName()); + wxBusyCursor busyc; - m_ToolManager.SetCurrentTool(_T("")); + m_ToolManager.SetCurrentTool(_T("")); - // TODO: Handle maps in subdirectories of maps/scenarios - std::wstring map(filename.GetFullName().wc_str()); - POST_MESSAGE(SaveMap, (map)); + // TODO: Handle maps in subdirectories of maps/scenarios + std::wstring map(filename.GetFullName().wc_str()); + POST_MESSAGE(SaveMap, (map)); - SetOpenFilename(filename.GetFullName()); + SetOpenFilename(filename.GetFullName()); - // Wait for it to finish saving - qPing qry; - qry.Post(); - } + // Wait for it to finish saving + qPing qry; + qry.Post(); + } } void ScenarioEditor::SetOpenFilename(const wxString& filename)