135 lines
4.8 KiB
Diff
135 lines
4.8 KiB
Diff
|
diff -up 0ad-0.0.11-alpha/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp.orig 0ad-0.0.11-alpha/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp
|
||
|
--- 0ad-0.0.11-alpha/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp.orig 2012-11-03 13:31:29.921199195 -0200
|
||
|
+++ 0ad-0.0.11-alpha/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp 2012-11-03 15:57:00.017533500 -0200
|
||
|
@@ -691,30 +691,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))
|
||
|
@@ -778,40 +768,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)
|