Author Topic: Usability enhancement: To save project as template  (Read 3352 times)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Usability enhancement: To save project as template
« 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

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.
« Last Edit: August 13, 2014, 01:51:54 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org