Develop and Download Open Source Software

Browse CVS Repository

Contents of /malonnote/mnNotePanel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Oct 4 12:45:02 2005 UTC (18 years, 5 months ago) by maloninc
Branch: MAIN
File MIME type: text/x-c++src
implement TAB function. But not complete.

1 // -*- C++ -*- generated by wxGlade 0.3.5.1 on Wed Jun 29 12:57:38 2005
2 #include <wx/regex.h>
3 #include <wx/tokenzr.h>
4 #include <wx/xrc/xmlres.h>
5 #include "mnID.h"
6 #include "mnDef.h"
7 #include "mnNotePanel.h"
8 #include "mnDialog.h"
9 #include "mnNotePanelController.h"
10
11 mnNotePanel::mnNotePanel(wxWindow* parent, wxString* dirName)
12 {
13 wxXmlResource::Get()->LoadPanel(this, parent, wxT("notePanel"));
14
15 /* init members */
16 searchTree = XRCCTRL(*this, "searchTree", wxTreeCtrl);
17 wikiHtmlTextCtrl = XRCCTRL(*this, "wikiHtmlTextCtrl", mnHtmlWindow);
18
19 /* create search tree */
20 searchItemRoot = searchTree->AddRoot(wxT(LABEL_ITEM_TREE), -1, -1, NULL);
21
22 /* create controller, and push as event handler */
23 panelController = new mnNotePanelController(this, dirName);
24 PushEventHandler(panelController);
25 }
26
27 mnNotePanelController* mnNotePanel::getController()
28 {
29 return panelController;
30 }
31
32 #if 0
33 void mnNotePanel::updateSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
34 {
35 wxTreeItemIdValue cookie1, cookie2;
36 wxTreeItemId searchStrId;
37 wxTreeItemId wikiDataId;
38 const WikiList* wikiList;
39 WikiList::Node* node;
40 WikiData* data;
41 const wxString* subject;
42
43 memset(&cookie1, 1, sizeof(cookie1));
44 memset(&cookie2, 2, sizeof(cookie2));
45 searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
46 while(searchStrId.IsOk()) {
47 if(searchTree->GetItemText(searchStrId) == *searchStr) {
48 wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
49 while(wikiDataId.IsOk()) {
50 searchTree->SetItemData(wikiDataId, NULL);
51 wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
52 }
53 searchTree->DeleteChildren(searchStrId);
54 break;
55 }
56 searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
57 }
58
59 wikiList = wiki->getSearchResultList(searchStr);
60 if(wikiList == NULL) {
61 MN_FATAL_ERROR(wxT("wikiList is null"));
62 return;
63 }
64
65 node = wikiList->GetFirst();
66 while(node) {
67 data = node->GetData();
68 subject = data->getSubject();
69 searchTree->AppendItem(searchStrId, *subject, -1, -1, (wxTreeItemData*)data);
70 node = node->GetNext();
71 }
72 if(isExpand){
73 searchTree->Expand(searchStrId);
74 }
75 else {
76 searchTree->Collapse(searchStrId);
77 }
78 }
79 #endif
80
81
82 void mnNotePanel::addSearchResult(mnModel* wiki, wxString* searchStr, bool isExpand)
83 {
84 wxTreeItemId searchItem;
85 const WikiList* wikiList;
86 WikiList::Node* node;
87 WikiData* data;
88 const wxString* subject;
89
90 wikiList = wiki->getSearchResultList(searchStr);
91 if(wikiList == NULL) {
92 MN_FATAL_ERROR(wxT("wikiList is null"));
93 return;
94 }
95
96 //searchItem = searchTree->AppendItem(searchItemRoot, *searchStr, -1, -1, NULL);
97 searchItem = searchTree->InsertItem(searchItemRoot, 0, *searchStr, -1, -1, NULL);
98 node = wikiList->GetFirst();
99 while(node) {
100 data = node->GetData();
101 subject = data->getSubject();
102 searchTree->AppendItem(searchItem, *subject, -1, -1, (wxTreeItemData*)data);
103 node = node->GetNext();
104 }
105
106 searchTree->Expand(searchItemRoot);
107 if(isExpand){
108 searchTree->Expand(searchItem);
109 }
110 else {
111 searchTree->Collapse(searchItem);
112 }
113 }
114
115 #if 0
116 void mnNotePanel::makeHtml(WikiData* wikiData, bool isHighlight)
117 {
118 const wxString* fileName = wikiData->getFileName();
119 const wxString* wikiText = wikiData->getText();
120 wxString htmlText(*wikiText);
121
122 /* escape < */
123 wxRegEx exp01(wxT("<"), wxRE_NEWLINE|wxRE_DEFAULT);
124 exp01.Replace(&htmlText, wxT("\\&lt "));
125
126 /* escape > */
127 wxRegEx exp02(wxT(">"), wxRE_NEWLINE|wxRE_DEFAULT);
128 exp02.Replace(&htmlText, wxT("\\&gt "));
129
130 /* [[ ]] */
131 wxRegEx exp1(wxT("\\[\\[([^\\}]+)\\]\\]"));
132 exp1.Replace(&htmlText, wxT("<a href=mnlink:\\1>\\1</a>"));
133
134 /* http:// */
135 wxRegEx exp2(wxT("(http://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
136 exp2.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
137
138 /* file:// */
139 wxRegEx exp3(wxT("(file://[^ ]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
140 exp3.Replace(&htmlText, wxT("<a href=\\1>\\1</a>"));
141
142 /* *XXXX */
143 wxRegEx exp4(wxT("^\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
144 exp4.Replace(&htmlText, wxT("<h3>\\1</h3>"));
145
146 /* **XXXX */
147 wxRegEx exp5(wxT("^\\*\\*([^\\*]+)"), wxRE_NEWLINE|wxRE_DEFAULT);
148 exp5.Replace(&htmlText, wxT("<h4>\\1</h4>"));
149
150 /* :''XXXX'': */
151 wxRegEx exp6(wxT("^:''(.+)'':(.+)"), wxRE_NEWLINE|wxRE_DEFAULT);
152 exp6.Replace(&htmlText, wxT("<u><b>\\1:\\2</b></u>"));
153
154 /* ---- */
155 wxRegEx exp7(wxT("^----.*"), wxRE_NEWLINE|wxRE_DEFAULT);
156 exp7.Replace(&htmlText, wxT("<hr>"));
157
158 /* {{ }} */
159 wxRegEx exp8(wxT("\\{\\{([^\\}]+)\\}\\}"));
160 exp8.Replace(&htmlText, wxT("<a href=mndoc:\\1>\\1</a>"));
161
162 /* table */
163 wxRegEx exp10(wxT(",([^,\n]+)"), wxRE_DEFAULT);
164 exp10.Replace(&htmlText, wxT("<td>\\1</td>"));
165 wxRegEx exp11(wxT("^<td>"), wxRE_NEWLINE|wxRE_DEFAULT);
166 exp11.Replace(&htmlText, wxT("<tr><td>"));
167 wxRegEx exp12(wxT("</td>$"), wxRE_NEWLINE|wxRE_DEFAULT);
168 exp12.Replace(&htmlText, wxT("</td></tr>"));
169 wxRegEx exp15(wxT("</tr>\n"));
170 exp15.Replace(&htmlText, wxT("</tr>"));
171
172 wxRegEx exp13(wxT("^<tr>"), wxRE_NEWLINE|wxRE_DEFAULT);
173 exp13.Replace(&htmlText, wxT("<table border><tr>"));
174 wxRegEx exp14(wxT("</tr>$"), wxRE_NEWLINE|wxRE_DEFAULT);
175 exp14.Replace(&htmlText, wxT("</tr></table>"));
176
177
178 /* Highlight search text */
179 highlight = isHighlight;
180 if(isHighlight) {
181 wxTreeItemId parentId = searchTree->GetItemParent(searchTree->GetSelection());
182 wxString searchWords = searchTree->GetItemText(parentId);
183 wxStringTokenizer tkz(searchWords, wxT(" "));
184 while ( tkz.HasMoreTokens() )
185 {
186 wxString token = tkz.GetNextToken();
187 wxRegEx exp9(wxT("(?!<[^>]+)(") + token + wxT(")(?![^<]+>)"), wxRE_ADVANCED|wxRE_ICASE|wxRE_NEWLINE);
188 exp9.Replace(&htmlText, wxT("<b><font color=\"red\">\\1</font></b>"));
189 }
190 }
191
192
193 /* make HTML document */
194 wxString wikiHtml;
195 wikiHtml.Append(wxT("<meta http-equiv=\"Content-Type\"content=\"text/html; charset="));
196 wikiHtml.Append(wxT(CODE_SET_SYSTEM));
197 wikiHtml.Append(wxT("\">"));
198 wikiHtml.Append(wxT("<pre>"));
199 wikiHtml.Append(htmlText);
200 wikiHtml.Append(wxT("</pre>"));
201
202 wikiHtmlTextCtrl->SetPage(wikiHtml);
203 }
204
205 void mnNotePanel::showSelectedItemText(wxTreeEvent& event)
206 {
207 wxTreeItemId id;
208 wxTreeItemData* item;
209
210 id = searchTree->GetSelection();
211 item = searchTree->GetItemData(id);
212
213 if(!id.IsOk() || !isEditableTreeLabel(id) || item == NULL) { /* selection is not memo data */
214 wikiHtmlTextCtrl->SetPage(wxT(""));
215 return;
216 }
217 makeHtml((WikiData*)item, false);
218 }
219
220 wxTreeItemId mnNotePanel::getSelection()
221 {
222 return searchTree->GetSelection();
223 }
224
225 void mnNotePanel::highlightSelectedItem()
226 {
227 wxTreeItemData* item = getSelectedItem();
228
229 if(!isEditableTreeLabel(searchTree->GetSelection())) { /* selection is not memo data */
230 wikiHtmlTextCtrl->SetPage(wxT(""));
231 return;
232 }
233
234 if(highlight){
235 makeHtml((WikiData*)item, false);
236 }
237 else {
238 makeHtml((WikiData*)item, true);
239 }
240 }
241
242 void mnNotePanel::expandAllTree()
243 {
244 wxTreeItemIdValue cookie;
245 wxTreeItemId itemId;
246
247 memset(&cookie, 1, sizeof(cookie));
248 itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
249 while(itemId.IsOk()) {
250 searchTree->Expand(itemId);
251 itemId = searchTree->GetNextChild(searchItemRoot, cookie);
252 }
253 }
254
255 void mnNotePanel::collapseAllTree()
256 {
257 wxTreeItemIdValue cookie;
258 wxTreeItemId itemId;
259
260 memset(&cookie, 1, sizeof(cookie));
261 itemId = searchTree->GetFirstChild(searchItemRoot, cookie);
262 while(itemId.IsOk()) {
263 searchTree->Collapse(itemId);
264 itemId = searchTree->GetNextChild(searchItemRoot, cookie);
265 }
266 }
267
268 void mnNotePanel::clearAllTree()
269 {
270 wxTreeItemIdValue cookie1, cookie2;
271 wxTreeItemId searchStrId;
272 wxTreeItemId wikiDataId;
273
274 memset(&cookie1, 1, sizeof(cookie1));
275 memset(&cookie2, 2, sizeof(cookie2));
276 searchStrId = searchTree->GetFirstChild(searchItemRoot, cookie1);
277 while(searchStrId.IsOk()) {
278 wikiDataId = searchTree->GetFirstChild(searchStrId, cookie2);
279 while(wikiDataId.IsOk()) {
280 searchTree->SetItemData(wikiDataId, NULL);
281 wikiDataId = searchTree->GetNextChild(searchStrId, cookie2);
282 }
283 searchStrId = searchTree->GetNextChild(searchItemRoot, cookie1);
284 }
285
286 searchTree->DeleteChildren(searchItemRoot);
287 }
288
289 void mnNotePanel::removeSelectedItem()
290 {
291 searchTree->Delete(searchTree->GetSelection());
292 }
293
294 wxTreeItemData* mnNotePanel::getSelectedItem()
295 {
296 return searchTree->GetItemData(searchTree->GetSelection());
297 }
298
299 wxString mnNotePanel::getSelectedLabel()
300 {
301 return searchTree->GetItemText(searchTree->GetSelection());
302 }
303
304 bool mnNotePanel::isEditableTreeLabel(wxTreeItemId id)
305 {
306 if(id.IsOk()){
307 return !(searchTree->GetItemParent(id) == searchItemRoot || id == searchItemRoot);
308 }
309 else {
310 return false;
311 }
312 }
313
314 #endif

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26