Patch #2425 2008-04-01 02:45

drewboo

SDK recognises source and header extensions in project mgr
Download
2425-SDK_recognises.patch (6.9 KB)
Category
Application::Refinement
Status
Accepted
Close date
2008-05-07 08:50
Assigned to
mortenmacfly
Index: src/sdk/globals.cpp
===================================================================
--- src/sdk/globals.cpp    (revision 4978)
+++ src/sdk/globals.cpp    (working copy)
@@ -31,6 +31,7 @@
 #include <algorithm>
 #include "filefilters.h"
 #include "tinyxml/tinywxuni.h"
+#include "filegroupsandmasks.h"


 namespace compatibility { typedef TernaryCondTypedef<wxMinimumVersion<2,5>::eval, wxTreeItemIdValue, long int>::eval tree_cookie_t; };
@@ -284,6 +285,27 @@
     else if (ext.IsSameAs(FileFilters::SCRIPT_EXT))
         return ftScript;

+    // DrewBoo: Before giving up, see if the ProjectManager
+    // considers this extension a source or header
+    else
+    {
+        ProjectManager *pm = Manager::Get()->GetProjectManager();
+        if ( pm )
+        {
+            const FilesGroupsAndMasks* fg = pm->GetFilesGroupsAndMasks();
+            if ( fg )
+            {
+               for ( unsigned int i = 0; i != fg->GetGroupsCount(); ++i )
+               {
+                    if ( fg->GetGroupName(i) == _T("Sources") && fg->MatchesMask( ext, i ) )
+                        return ftSource;
+                    if ( fg->GetGroupName(i) == _T("Headers") && fg->MatchesMask( ext, i ) )
+                        return ftHeader;
+               }
+            }
+        }
+    }
+
     return ftOther;
 }

Index: src/sdk/filegroupsandmasks.cpp
===================================================================
--- src/sdk/filegroupsandmasks.cpp    (revision 4978)
+++ src/sdk/filegroupsandmasks.cpp    (working copy)
@@ -179,11 +179,11 @@
     return GetStringFromArray(fg->fileMasks);
 }

-bool FilesGroupsAndMasks::MatchesMask(const wxString& ext, unsigned int group)
+bool FilesGroupsAndMasks::MatchesMask(const wxString& ext, unsigned int group) const
 {
     if (ext.IsEmpty() || group >= m_Groups.GetCount())
         return false;
-    FileGroups* fg = m_Groups[group];
+    const FileGroups* fg = m_Groups[group];
     for (unsigned int i = 0; i < fg->fileMasks.GetCount(); ++i)
     {
         if (ext.Matches(fg->fileMasks[i]))
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp    (revision 4978)
+++ src/sdk/editormanager.cpp    (working copy)
@@ -40,6 +40,7 @@
 #include <wx/bmpbuttn.h>
 #include <wx/progdlg.h>
 #include <wx/fontutil.h>
+#include <wx/tokenzr.h>

 #include "editorcolourset.h"
 #include "editorconfigurationdlg.h"
@@ -50,6 +51,7 @@
 #include "filefilters.h"
 #include "searchresultslog.h"
 #include "projectfileoptionsdlg.h"
+#include "filegroupsandmasks.h"

 #include "wx/wxFlatNotebook/wxFlatNotebook.h"

@@ -1024,6 +1026,36 @@
             fname.SetExt(FileFilters::CXX_EXT);
             if (fname.FileExists())
                 break;
+
+// DrewBoo: See if the project manager knows of other extensions
+//   (This could also outright replace the hard-coded extensions above)
+            ProjectManager *pm = Manager::Get()->GetProjectManager();
+            if ( !pm )
+                break;
+
+            const FilesGroupsAndMasks* fg = pm->GetFilesGroupsAndMasks();
+            if ( !fg )
+                break;
+
+            for ( unsigned int i = 0; i != fg->GetGroupsCount(); ++i )
+            {
+                if ( fg->GetGroupName(i) == _("Sources") )
+                {
+                    wxStringTokenizer tkz( fg->GetFileMasks(i), _T(";") );
+                    while ( tkz.HasMoreTokens() )
+                    {
+                        wxString token = tkz.GetNextToken();
+                        wxString ext;
+                        if ( token.StartsWith( _("*."), &ext ) )
+                        {
+                            fname.SetExt(ext);
+                            if (fname.FileExists())
+                                break;
+                        }
+                    }
+                    break;
+                }
+            }
         }
         else if (ft == ftSource)
         {
@@ -1039,6 +1071,36 @@
             fname.SetExt(FileFilters::HXX_EXT);
             if (fname.FileExists())
                 break;
+
+// DrewBoo: See if the project manager knows of other extensions
+//   (This could also outright replace the hard-coded extensions above)
+            ProjectManager *pm = Manager::Get()->GetProjectManager();
+            if ( !pm )
+                break;
+
+            const FilesGroupsAndMasks* fg = pm->GetFilesGroupsAndMasks();
+            if ( !fg )
+                break;
+
+            for ( unsigned int i = 0; i != fg->GetGroupsCount(); ++i )
+            {
+                if ( fg->GetGroupName(i) == _("Headers") )
+                {
+                    wxStringTokenizer tkz( fg->GetFileMasks(i), _T(";") );
+                    while ( tkz.HasMoreTokens() )
+                    {
+                        wxString token = tkz.GetNextToken();
+                        wxString ext;
+                        if ( token.StartsWith( _("*."), &ext ) )
+
download for full patch...
arkay 2008-04-05 15:55

I patched it a little (against the svn tree)...

- xrc: wxListBox -> wxLB_HSCROLL|wxLB_NEEDED_SB|wxLB_SORT

- cpp: only show classes / structs which actually have something to implement (at least 1 ctor/dtor/method)

mortenmacfly 2008-05-05 12:09

I will apply the cpp part soon (modified so it does not break ABI compatibility).

But I have no glue what you mean with the "xrc" part. The patch does *not* patch any xrc files at all. Am I missing something here?

I leave this open for a while to clarify. Otherwise please submit a new patch with the parts missing. Thanks! :-)

drewboo 2008-05-05 15:18

I don't remember mentioning any xrc changes. This is supposed to be a code-only patch. No interface has changed. Could you clarify what you mean, Morten?

mortenmacfly 2008-05-05 15:28

Have a look at the comments of the patch - I meant the first comment. Here is the link:

http://developer.berlios.de/patch/?func=detailpatch&patch_id=2425&group_id=5358

BTW: I see this comment is of a user called "arkay"... so probably you are not the one to ask...?! But who is "arkay" then?!

drewboo 2008-05-05 20:21

I'm thinking arkay commented on the wrong patch. Neither of his two comments make sense to me in the context of this patch.