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.2 - (show annotations) (download) (as text)
Wed Oct 5 04:55:48 2005 UTC (18 years, 5 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_5-0002, dev_1_5-0001
Changes since 1.1: +1 -4 lines
File MIME type: text/x-c++src
implement TAB function, except AddDir, RemoveDir

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

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