Patch #1752 2006-12-22 11:19

dermeister

Fix fur Bug #9668
Download
1752-Fix_fur_Bug_96.patch (1.8 KB)
Category
Application::Bugfix
Status
Closed
Close date
2006-12-24 11:18
Assigned to
 
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp        (revision 3412)
+++ src/sdk/cbeditor.cpp        (working copy)
@@ -1248,16 +1248,33 @@
     int StoredIndex = 0;
     wxString Filters = FileFilters::GetFilterString();
     wxString Path = fname.GetPath();
-    if(mgr)
+    wxString Extension = fname.GetExt();
+       wxString Filter;
+
+    if (!Extension.IsEmpty())
     {
-        wxString Filter = mgr->Read(_T("/file_dialogs/save_file_as/filter"), _T("C/C++ files"));
-        if(!Filter.IsEmpty())
-        {
-            FileFilters::GetFilterIndexFromName(Filters, Filter, StoredIndex);
-        }
-        if (Path.IsEmpty())
-            Path = mgr->Read(_T("/file_dialogs/save_file_as/directory"), Path);
+       // Select filter belonging to this file type:
+       Extension.Prepend(_T("."));
+       Filter = FileFilters::GetFilterString(Extension);
     }
+    else if(mgr)
+    {
+       // File type is unknown. Select the last used filter:
+        Filter = mgr->Read(_T("/file_dialogs/save_file_as/filter"), _T("C/C++ files"));
+    }
+       if(!Filter.IsEmpty())
+       {
+               // We found a filter, look up its index:
+               int sep = Filter.find(_T("|"));
+               if (sep != wxNOT_FOUND)
+                       Filter.Truncate(sep);
+               if (!Filter.IsEmpty())
+                       FileFilters::GetFilterIndexFromName(Filters, Filter, StoredIndex);
+       }
+
+    if ((mgr) && (Path.IsEmpty()))
+               Path = mgr->Read(_T("/file_dialogs/save_file_as/directory"), Path);
+
     wxFileDialog* dlg = new wxFileDialog(Manager::Get()->GetAppWindow(),
                                          _("Save file"),
                                          Path,
dermeister 2006-12-22 11:20

This patch fixes bug #9668 ("File -> Save As" defaults to c/c++ filetype).

If the file that has to be saved already has an extension this extension will be used to look up the correct filter for this file. Otherwise the old method will be used.

killerbot 2006-12-24 11:17

applied : rev 3421

Thanks.

killerbot 2006-12-24 11:18

fixed. rev 3421