From: rambetter Date: Sun, 19 Dec 2010 01:08:29 +0000 (+0000) Subject: Another Windows file dialog change in Rambetter-temp-fixes branch. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=541a4fda890c9b47f6e8990034271a7c74586740;p=xonotic%2Fnetradiant.git 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: https://zerowing.idsoftware.com/svn/radiant/GtkRadiant/branches/Rambetter-temp-fixes@353 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- diff --git a/radiant/gtkmisc.cpp b/radiant/gtkmisc.cpp index 6ce83c75..f398604b 100644 --- a/radiant/gtkmisc.cpp +++ b/radiant/gtkmisc.cpp @@ -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