Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: stahta01 on August 13, 2014, 12:04:25 pm

Title: Usability enhancement: To save project as template
Post by: stahta01 on August 13, 2014, 12:04:25 pm
Quote
Usability enhancement: Use wx GetForbiddenChars function to remove illegal filename characters from default template name.

I am working on getting the Windows Code::Blocks projects to save as a template without error or warnings.

The ":" in the CB project title is not allowed in filenames under windows.

This patch fixes that.

I have also done the patch in this Git Repo forked from "obfuscated/codeblocks_sf" Repo
https://github.com/stahta01/codeblocks_sf_tims/tree/build/templates (https://github.com/stahta01/codeblocks_sf_tims/tree/build/templates)

Code partly copied from the CB codesnippetstreectrl.cpp file.

Code
Index: src/sdk/templatemanager.cpp
===================================================================
--- src/sdk/templatemanager.cpp (revision 9855)
+++ src/sdk/templatemanager.cpp (working copy)
@@ -263,8 +263,16 @@
         return;
     }
 
+    // get default template title
+    wxString title = prj->GetTitle();
+    
+    // filter title, removing all illegal filename characters
+    wxFileName titleFileName(title) ;
+    wxString forbidden = titleFileName.GetForbiddenChars();
+    for (size_t i=0; i < forbidden.Length(); ++i)
+        title.Replace(wxString(forbidden[i]), wxT(""),true);
+    
     // check if it exists and ask a different title
-    wxString title = prj->GetTitle();
     while (true)
     {
         // ask for template title (unique)

Tim S.