]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/nodesdb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "nodesdb.h"
13 // For compilers that support precompilation, includes _T("wx/wx.h").
14 #include "wx/wxprec.h"
21 #include "wx/textfile.h"
22 #include "wx/tokenzr.h"
25 #include "wx/arrimpl.cpp"
27 WX_DEFINE_OBJARRAY(NodeInfoArray
);
28 WX_DEFINE_OBJARRAY(PropertyInfoArray
);
33 void NodeInfo::Read(const wxString
& filename
, wxPathList
& list
)
42 wxString path
= list
.FindValidPath(filename
);
43 if (path
.empty()) return;
48 if (!tf
.IsOpened()) return;
50 for (size_t i
= 0; i
< tf
.GetLineCount(); i
++)
52 if (tf
[i
].empty() || tf
[i
][0u] == _T('#')) continue;
53 wxStringTokenizer
tkn(tf
[i
], _T(' '));
54 wxString s
= tkn
.GetNextToken();
56 nd
= tkn
.GetNextToken();
57 else if (s
== _T("childtype"))
58 cht
= tkn
.GetNextToken();
59 else if (s
== _T("icon"))
60 tkn
.GetNextToken().ToLong(&icn
);
61 else if (s
== _T("derived"))
63 if (tkn
.GetNextToken() == _T("from"))
65 s
= tkn
.GetNextToken();
67 Read(s
+ _T(".df"), list
);
70 else if (s
== _T("abstract"))
72 else if (s
== _T("type"))
74 tp
= tkn
.GetNextToken();
76 else if (s
== _T("var"))
79 pi
.Name
= tkn
.GetNextToken();
81 pi
.Type
= tkn
.GetNextToken();
82 if (tkn
.HasMoreTokens()) pi
.MoreInfo
= tkn
.GetNextToken();
85 for (size_t j
= 0; j
< Props
.GetCount(); j
++)
87 if (Props
[j
].Name
== pi
.Name
)
89 if (Props
[j
].Type
== pi
.Type
&& pi
.Type
== _T("flags"))
90 Props
[j
].MoreInfo
<< _T(',') << pi
.MoreInfo
;
97 if (!fnd
) Props
.Add(pi
);
101 if (!nd
.empty()) NodeClass
= nd
;
102 if (!cht
.empty()) ChildType
= cht
;
103 if (!tp
.empty()) Type
= tp
;
104 if (icn
!= -1) Icon
= icn
;
116 NodesDb
* NodesDb::ms_Instance
= NULL
;
118 NodesDb
*NodesDb::Get()
120 if (ms_Instance
== NULL
)
132 m_Paths
.Add(_T("."));
133 m_Paths
.Add(_T("./df"));
135 m_Paths
.Add(wxGetHomeDir() + _T("/.wxrcedit"));
136 #ifdef wxINSTALL_PREFIX
137 m_Paths
.Add(wxINSTALL_PREFIX
_T("/share/wx/wxrcedit"));
148 for (size_t i
= 0; i
< m_Paths
.GetCount(); i
++)
154 void NodesDb::LoadDir(const wxString
& path
)
156 if (!wxDirExists(path
)) return;
162 cont
= dir
.GetFirst(&filename
, _T("*.df"));
166 cont
= dir
.GetNext(&filename
);
172 void NodesDb::LoadFile(const wxString
& file
)
174 NodeInfo
*ni
= new NodeInfo
;
175 ni
->Type
= wxEmptyString
;
180 for (i
= 0; i
< m_Paths
.GetCount(); i
++)
181 paths
.Add(m_Paths
[i
]);
183 ni
->Read(file
, paths
);
185 // maybe we already parsed it?
186 for (i
= 0; i
< m_Infos
.GetCount(); i
++)
187 if (m_Infos
[i
].NodeClass
== ni
->NodeClass
) return;