]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/nodesdb.cpp
Added regex to WXINC line (patch from Markus G)
[wxWidgets.git] / contrib / utils / wxrcedit / nodesdb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
3 // Created: 2000/05/05
4 // RCS-ID: $Id$
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #ifdef __GNUG__
10 #pragma implementation "nodesdb.h"
11 #endif
12
13 // For compilers that support precompilation, includes _T("wx/wx.h").
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #include "wx/wx.h"
21 #include "wx/textfile.h"
22 #include "wx/tokenzr.h"
23 #include "wx/dir.h"
24 #include "nodesdb.h"
25 #include "wx/arrimpl.cpp"
26
27 WX_DEFINE_OBJARRAY(NodeInfoArray);
28 WX_DEFINE_OBJARRAY(PropertyInfoArray);
29
30
31
32
33 void NodeInfo::Read(const wxString& filename, wxPathList& list)
34 {
35 wxString tp;
36 wxString nd, cht;
37 bool ab = FALSE;
38 long icn = -1;
39
40 NodeClass.Empty();
41
42 wxString path = list.FindValidPath(filename);
43 if (path.IsEmpty()) return;
44
45 wxTextFile tf;
46 tf.Open(path);
47
48 if (!tf.IsOpened()) return;
49
50 for (size_t i = 0; i < tf.GetLineCount(); i++)
51 {
52 if (tf[i].IsEmpty() || tf[i][0u] == _T('#')) continue;
53 wxStringTokenizer tkn(tf[i], _T(' '));
54 wxString s = tkn.GetNextToken();
55 if (s == _T("node"))
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"))
62 {
63 if (tkn.GetNextToken() == _T("from"))
64 {
65 s = tkn.GetNextToken();
66 DerivedFrom.Add(s);
67 Read(s + _T(".df"), list);
68 }
69 }
70 else if (s == _T("abstract"))
71 ab = true;
72 else if (s == _T("type"))
73 {
74 tp = tkn.GetNextToken();
75 }
76 else if (s == _T("var"))
77 {
78 PropertyInfo pi;
79 pi.Name = tkn.GetNextToken();
80 tkn.GetNextToken();
81 pi.Type = tkn.GetNextToken();
82 if (tkn.HasMoreTokens()) pi.MoreInfo = tkn.GetNextToken();
83
84 bool fnd = FALSE;
85 for (size_t j = 0; j < Props.GetCount(); j++)
86 {
87 if (Props[j].Name == pi.Name)
88 {
89 if (Props[j].Type == pi.Type && pi.Type == _T("flags"))
90 Props[j].MoreInfo << _T(',') << pi.MoreInfo;
91 else
92 Props[j] = pi;
93 fnd = TRUE;
94 }
95 }
96
97 if (!fnd) Props.Add(pi);
98 }
99 }
100
101 if (!nd.IsEmpty()) NodeClass = nd;
102 if (!cht.IsEmpty()) ChildType = cht;
103 if (!!tp) Type = tp;
104 if (icn != -1) Icon = icn;
105 Abstract = ab;
106 }
107
108
109
110
111
112
113
114
115
116 NodesDb* NodesDb::ms_Instance = NULL;
117
118 NodesDb *NodesDb::Get()
119 {
120 if (ms_Instance == NULL)
121 {
122 (void)new NodesDb;
123 }
124 return ms_Instance;
125 }
126
127
128 NodesDb::NodesDb()
129 {
130 ms_Instance = this;
131
132 m_Paths.Add(_T("."));
133 m_Paths.Add(_T("./df"));
134 #ifdef __UNIX__
135 m_Paths.Add(wxGetHomeDir() + _T("/.wxrcedit"));
136 #ifdef wxINSTALL_PREFIX
137 m_Paths.Add(wxINSTALL_PREFIX _T("/share/wx/wxrcedit"));
138 #endif
139 #endif
140
141 Load();
142 }
143
144
145
146 void NodesDb::Load()
147 {
148 for (size_t i = 0; i < m_Paths.GetCount(); i++)
149 LoadDir(m_Paths[i]);
150 }
151
152
153
154 void NodesDb::LoadDir(const wxString& path)
155 {
156 if (!wxDirExists(path)) return;
157
158 wxDir dir(path);
159 wxString filename;
160 bool cont;
161
162 cont = dir.GetFirst(&filename, "*.df");
163 while (cont)
164 {
165 LoadFile(filename);
166 cont = dir.GetNext(&filename);
167 }
168 }
169
170
171
172 void NodesDb::LoadFile(const wxString& file)
173 {
174 NodeInfo *ni = new NodeInfo;
175 ni->Type = wxEmptyString;
176 ni->Icon = 0;
177 wxPathList paths;
178 size_t i;
179
180 for (i = 0; i < m_Paths.GetCount(); i++)
181 paths.Add(m_Paths[i]);
182
183 ni->Read(file, paths);
184
185 // maybe we already parsed it?
186 for (i = 0; i < m_Infos.GetCount(); i++)
187 if (m_Infos[i].NodeClass == ni->NodeClass) return;
188
189 m_Infos.Add(ni);
190 }