Another Windows file dialog change in Rambetter-temp-fixes branch.

Handling file extensions better	during save operations.	 This is more
Windows-compliant.  For	example, when saving map:
- If ".xmap" filter is selected	and user types "foo.map", map will be
saved as "foo.map" (previous behavior was "foo.xmap").
- If an	unrecognized file extension is typed, GtkRadiant will now honor	that
but issue a warning popup window: "Unknown file extension for this save         
operation.  Attempt to save anyways?". 	All known extensions for the type
are checked.  Previous behavior	was that the extension is always changed
based on selected filter.

I will continue	making lots of incremental fixes to Rambetter-temp-fixes.

THIS PATCH SHOULD BE MERGED INTO TRUNK.


git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/branches/Rambetter-temp-fixes@353 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
rambetter 2010-12-19 01:08:29 +00:00
parent b1b208f12e
commit 6412c5ca77

View file

@ -1123,7 +1123,12 @@ public:
return filetype_t();
}
filetype_t GetTypeForIndex(int index) // Zero-based index.
int GetNumTypes()
{
return m_nTypes;
}
filetype_t GetTypeForIndex(int index) const // Zero-based index.
{
if (index >= 0 && index < m_nTypes)
return filetype_t(m_pTypes[index].m_name.c_str(), m_pTypes[index].m_pattern.c_str());
@ -1493,17 +1498,33 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
*w = '/';
#if defined(WIN32)
if (g_PrefsDlg.m_bNativeGUI) // filetype mask not supported in gtk dialog yet
if (g_PrefsDlg.m_bNativeGUI)
{
// when saving, force an extension depending on filetype
/* \todo SPoG - file_dialog should return filetype information separately.. not force file extension.. */
if(!open && pattern != NULL)
{
// last ext separator
w = strrchr(szFile, '.');
// no extension
w = (w!=NULL) ? w : szFile+strlen(szFile);
strcpy(w, type.pattern+1);
if (w == NULL) { // No extension.
w = szFile + strlen(szFile);
strcpy(w, type.pattern + 1); // Add extension of selected filter type.
}
else { // An extension was explicitly in the filename.
int knownExtension = 0;
for (int i = typelist.GetNumTypes() - 1; i >= 0; i--) {
type = typelist.GetTypeForIndex(i);
if (stricmp(w, type.pattern + 1) == 0) {
knownExtension = 1;
break;
}
}
if (!knownExtension) {
if (gtk_MessageBox(parent, "Unknown file extension for this save operation.\nAttempt to save anyways?",
"GtkRadiant", MB_YESNO) == IDNO) {
return NULL;
}
}
}
}
}
#endif