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: https://zerowing.idsoftware.com/svn/radiant/GtkRadiant/branches/Rambetter-temp-fixes@353
8a3a26a2-13c4-0310-b231-
cf6edde360e5
- 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());
{
if (index >= 0 && index < m_nTypes)
return filetype_t(m_pTypes[index].m_name.c_str(), m_pTypes[index].m_pattern.c_str());
*w = '/';
#if defined(WIN32)
*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, '.');
/* \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;
+ }
+ }
+ }