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