User forums > Help

minor issues about cbp file

<< < (3/3)

Alpha:

--- Quote from: Alpha on December 02, 2011, 03:26:54 am ---Another option would be to have Code::Blocks store any xml comments (<!-- text -->) during the opening of a workspace/project file; then on save, write all stored comments to the top of the respective files.  (File format would be left backwards-compatible.)

--- End quote ---
Proof of concept (for *.cbp's):

--- Code: ---Index: src/sdk/projectloader.cpp
===================================================================
--- src/sdk/projectloader.cpp (revision 7696)
+++ src/sdk/projectloader.cpp (working copy)
@@ -256,6 +256,21 @@
 //        wxString minor = version->Attribute("minor");
     }
 
+    pMsg->DebugLog(_T("Scanning project for comments..."));
+    TiXmlNode* child = 0;
+    while(child = doc.IterateChildren(child))
+    {
+        if(child->Type() == TiXmlNode::TINYXML_COMMENT)
+        {
+            m_pProject->fileComments << wxString::FromAscii(child->Value()) << wxT("\n");
+        }
+    }
+    if(m_pProject->fileComments.Right(1) == wxT("\n"))
+    {
+        m_pProject->fileComments.Truncate(m_pProject->fileComments.Length() - 1);
+    }
+
     pMsg->DebugLog(wxString(_T("Done loading project in ")) << wxString::Format(_T("%d"), (int) sw.Time()) << _T("ms"));
     return true;
 }
@@ -1077,6 +1092,10 @@
     TiXmlDocument doc;
     doc.SetCondenseWhiteSpace(false);
     doc.InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes"));
+    if(!m_pProject->fileComments.IsEmpty())
+    {
+        doc.InsertEndChild(TiXmlComment(m_pProject->fileComments.ToAscii()));
+    }
     TiXmlElement* rootnode = static_cast<TiXmlElement*>(doc.InsertEndChild(TiXmlElement(ROOT_TAG)));
     if (!rootnode)
         return false;
Index: src/include/cbproject.h
===================================================================
--- src/include/cbproject.h (revision 7696)
+++ src/include/cbproject.h (working copy)
@@ -683,6 +683,8 @@
           */
         virtual FilesList& GetFilesList(){ return m_Files; }
 
+        wxString fileComments;
+
     private:
         void Open();
         void ExpandVirtualBuildTargetGroup(const wxString& alias, wxArrayString& result) const;

--- End code ---
This is probably not the best method, but it does work.

thomas:
Oh my... that again.

The mere fact that one can open an undocumented, machine-generated and machine-read, proprietary file in a text editor does not mean it's ok to do it, nor that it should be supported. There's been no week ever since I thought using XML was a brilliant idea during which I've not regretted that.

Project files, like the config file, are not meant to be edited by hand. Adding explicit support for making edits persistent is opening a can of worms. Heck, I've even considered ROT13 encoding config and projects at some point just because some smart alec came up with "but it's XML, it is meant to be edited" every couple of months. Even if you were Tim Bray, I'd show you the middle finger for that, because no matter what, sooner or later someone will fuck up his project file with a manual edit, and again people will spend their time trying to figure why Code::Blocks scrambles files.

If the admins at Savannah are unable to deduct a project files's license from the project's license or from what's in the LICENSE file, I'm truly sorry for them.

Now if there is truly need to store license information in the project file, add a tab "project info" to the project properties dialog, and put text edit fields such as "author", "license", "checkout URL", whatever, into that tab. Put the properly quoted info into the project file using the intended API in a well-defined way. Add a separate section, if you deem this appropriate.

That said, I'll revert any commit I see which makes manual edits persistent.

MortenMacFly:

--- Quote from: thomas on January 17, 2012, 02:47:05 pm ---That said, I'll revert any commit I see which makes manual edits persistent.

--- End quote ---
I agree with Thomas here.

Actually the change is quite simple: Modify the project page that shows the project notes and extend it as you like, then provide a patch. However, I still believe that the notes page *is* already the right place to put license info, if needed and it *is* persisted.

Alpha:
Thank you for pointing that out.  I will often just pursue whatever goal I happen to have an idea about at the time; I think I need to work harder at restraining myself long enough to consider what I am actually doing :-[.


--- Quote from: Alpha on December 02, 2011, 03:26:54 am ---I have another minor issue: when using a dynamic library, there are options to create a custom name for the import library and the definition file.  Any changes made here work during the active session, however, they are not saved in the cbp.

--- End quote ---
However, am I correct in my assumption that it is OK for me to work on adding this to the file format?

Navigation

[0] Message Index

[*] Previous page

Go to full version