Develop and Download Open Source Software

Browse CVS Repository

Annotation of /malonnote/mnNotePanelController.cpp

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


Revision 1.15 - (hide annotations) (download) (as text)
Tue Oct 24 06:46:32 2006 UTC (17 years, 5 months ago) by maloninc
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +3 -3 lines
File MIME type: text/x-c++src
add fast search option menu, modify readme

1 maloninc 1.1 #include "mnID.h"
2     #include "mnDef.h"
3 maloninc 1.5 #include "mnNotePanel.h"
4 maloninc 1.1 #include "mnNotePanelController.h"
5 maloninc 1.5 #include <wx/uri.h>
6 maloninc 1.1 #include <wx/config.h>
7 maloninc 1.5 #include <wx/regex.h>
8 maloninc 1.1 #include <wx/utils.h>
9     #include <wx/xrc/xmlres.h>
10 maloninc 1.5 #include <wx/tokenzr.h>
11 maloninc 1.1
12     BEGIN_EVENT_TABLE(mnNotePanelController, wxEvtHandler)
13     EVT_TEXT_ENTER(XRCID("searchTextCtrl"), mnNotePanelController::handleSearch)
14     EVT_TREE_SEL_CHANGED(XRCID("searchTree"), mnNotePanelController::handleTreeItemSelect)
15     EVT_TREE_SEL_CHANGING(XRCID("searchTree"), mnNotePanelController::handleTreeItemSelecting)
16     EVT_TREE_BEGIN_LABEL_EDIT(XRCID("searchTree"), mnNotePanelController::handleBeginLabelEdit)
17     EVT_TREE_END_LABEL_EDIT(XRCID("searchTree"), mnNotePanelController::handleEndLabelEdit)
18 maloninc 1.5 #ifdef __WXMAC__
19     EVT_WEBKIT_STATE_CHANGED(mnNotePanelController::handleLinkClick)
20     #else
21 maloninc 1.1 EVT_COMMAND(XRCID("wikiHtmlTextCtrl"), mnEVT_LINK_CLICK, mnNotePanelController::handleLinkClick)
22 maloninc 1.5 #endif
23 maloninc 1.1 END_EVENT_TABLE()
24    
25     mnNotePanelController::mnNotePanelController(mnNotePanel* inPanel, wxString* inWikiDir)
26     {
27 maloninc 1.2 wiki = new mnModel(inWikiDir->mb_str());
28 maloninc 1.15 readAll(true);
29 maloninc 1.13
30 maloninc 1.1 panel = inPanel;
31     }
32    
33 maloninc 1.4 mnNotePanelController::~mnNotePanelController()
34     {
35     }
36    
37 maloninc 1.15 void mnNotePanelController::readAll(bool flag)
38 maloninc 1.13 {
39 maloninc 1.15 wiki->readAll(flag);
40 maloninc 1.13 }
41    
42 maloninc 1.3 const wxString* mnNotePanelController::getWikiDataDir()
43     {
44     return wiki->getWikiDataDir();
45     }
46    
47 maloninc 1.1 void mnNotePanelController::handleSearch(wxCommandEvent& event)
48     {
49     wxString* str = new wxString(event.GetString());
50     WikiList* wikiList;
51     WikiList::Node* node;
52    
53     wikiList = wiki->search(str->mb_str());
54    
55     node = wikiList->GetFirst();
56     if(!node) {
57     wxLogMessage(wxT("Not Found! [%s]"), (const char*)str->c_str());
58     return;
59     }
60    
61     if(wiki->addSearchStr(str)) {
62     wiki->addSearchList(str, wikiList);
63     panel->addSearchResult(wiki, str);
64     }
65     else { /* str is already in search list */
66     delete wikiList;
67     }
68     }
69    
70     void mnNotePanelController::handleGroup(wxCommandEvent& event)
71     {
72     WikiList* wikiList;
73     const wxArrayString* searchStrList;
74     int i;
75     wxCursor normal;
76     wxCursor watch(wxCURSOR_WATCH);
77    
78 maloninc 1.2 panel->SetCursor(watch);
79 maloninc 1.1 wiki->group();
80 maloninc 1.2 panel->clearAllTree();
81 maloninc 1.1 searchStrList = wiki->getSearchStrList();
82     for(i = 0; i < searchStrList->Count(); i++) {
83     wxString& searchStr = searchStrList->Item(i);
84 maloninc 1.2 panel->addSearchResult(wiki, &searchStr);
85 maloninc 1.1 }
86 maloninc 1.2 panel->SetCursor(normal);
87 maloninc 1.1 }
88    
89 maloninc 1.2 void mnNotePanelController::handleNew(wxCommandEvent& event)
90 maloninc 1.1 {
91     int ans;
92     WikiData* wikiData = wiki->newWikiData();
93     wxString plainTextStr;
94     wxString newSubjectStr;
95 maloninc 1.2 mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(panel);
96 maloninc 1.1 const wxString* wikiText = wikiData->getText();
97     const wxString* subject = wikiData->getSubject();
98    
99     dlg->setSubject(*subject);
100     dlg->setPlainText(*wikiText);
101     ans = dlg->ShowModal();
102    
103     if(ans != wxID_OK) return ;
104    
105     plainTextStr = dlg->getPlainText();
106     newSubjectStr = dlg->getSubject();
107     wikiData->modText(&plainTextStr);
108     wikiData->save();
109    
110     wikiData->modSubject(&newSubjectStr);
111    
112     notifyUpdate(wikiData);
113    
114     delete dlg;
115     }
116    
117 maloninc 1.2 void mnNotePanelController::handleRemove(wxCommandEvent& event)
118 maloninc 1.1 {
119 maloninc 1.2 wxTreeItemData* item = panel->getSelectedItem();
120 maloninc 1.1
121 maloninc 1.2 if(panel->isEditableTreeLabel(panel->getSelection())) {
122     if(wxMessageBox(wxT("Do you realy remove this memo?\n") + panel->getSelectedLabel(), wxT("Realy?"), wxYES_NO|wxICON_QUESTION) == wxYES){
123 maloninc 1.1 ((WikiData*)(item))->removeDataFile();
124     notifyUpdate((WikiData*)(item));
125     }
126     else {
127     return;
128     }
129     }
130     else {
131 maloninc 1.2 wiki->removeSearchStr(panel->getSelectedLabel());
132     panel->removeSelectedItem();
133 maloninc 1.1 }
134    
135     }
136    
137 maloninc 1.2 void mnNotePanelController::handleHighlight(wxCommandEvent& event)
138 maloninc 1.1 {
139 maloninc 1.2 panel->highlightSelectedItem();
140 maloninc 1.1 }
141    
142    
143     void mnNotePanelController::handleTreeItemSelect(wxTreeEvent& event)
144     {
145 maloninc 1.2 panel->showSelectedItemText(event);
146 maloninc 1.1 }
147    
148    
149     void mnNotePanelController::handleTreeItemSelecting(wxTreeEvent& event)
150     {
151     }
152    
153     void mnNotePanelController::handleBeginLabelEdit(wxTreeEvent& event)
154     {
155 maloninc 1.2 if(!panel->isEditableTreeLabel(event.GetItem())) event.Veto();
156 maloninc 1.1 }
157    
158     void mnNotePanelController::handleEndLabelEdit(wxTreeEvent& event)
159     {
160     wxString newSubject = event.GetLabel();
161 maloninc 1.2 wxTreeItemData* item = panel->getSelectedItem();
162 maloninc 1.1
163     if(item == NULL) {
164     return ;
165     }
166    
167     if(newSubject.Len() == 0) {
168     event.Veto();
169     return;
170     }
171    
172     ((WikiData*)(item))->modSubject(&newSubject);
173    
174     event.Veto();
175    
176     notifyUpdate((WikiData*)item);
177     }
178    
179     void mnNotePanelController::handleTreeExpand(wxCommandEvent& event)
180     {
181 maloninc 1.2 panel->expandAllTree();
182 maloninc 1.1 }
183    
184     void mnNotePanelController::handleTreeCollapse(wxCommandEvent& event)
185     {
186 maloninc 1.2 panel->collapseAllTree();
187 maloninc 1.1 }
188    
189     void mnNotePanelController::handleTreeClear(wxCommandEvent& event)
190     {
191     wiki->clearSearchStrList();
192     wiki->clearSearchResultList();
193 maloninc 1.2 panel->clearAllTree();
194 maloninc 1.1 }
195    
196 maloninc 1.2 void mnNotePanelController::handleEdit(wxCommandEvent& event)
197 maloninc 1.1 {
198     wxString plainTextStr;
199     wxString newSubjectStr;
200 maloninc 1.2 wxTreeItemData* itemData = panel->getSelectedItem();
201     wxString subject = panel->getSelectedLabel();
202     mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(panel);
203 maloninc 1.1 int ans;
204    
205 maloninc 1.2 if(!panel->isEditableTreeLabel(panel->getSelection())) return; /* selection is not memo data */
206 maloninc 1.1
207     const wxString* wikiText = ((WikiData*)(itemData))->getText();
208    
209     dlg->setSubject(subject);
210     dlg->setPlainText(*wikiText);
211     ans = dlg->ShowModal();
212    
213     if(ans != wxID_OK) return ;
214     if(itemData == NULL) return ;
215    
216     plainTextStr = dlg->getPlainText();
217     newSubjectStr = dlg->getSubject();
218     ((WikiData*)(itemData))->modText(&plainTextStr);
219     ((WikiData*)(itemData))->save();
220    
221     ((WikiData*)(itemData))->modSubject(&newSubjectStr);
222    
223     notifyUpdate((WikiData*)itemData);
224    
225     delete dlg;
226     }
227    
228 maloninc 1.5 wxString mnNotePanelController::delPercent(const wxString& str)
229     {
230 maloninc 1.6 #ifdef __WXMAC__
231 maloninc 1.5 wxURI uri;
232     return uri.Unescape(str);
233 maloninc 1.6 #else
234     return str;
235     #endif
236 maloninc 1.5 }
237    
238    
239 maloninc 1.1 void mnNotePanelController::notifyUpdate(WikiData* data)
240     {
241     const wxArrayString* searchStrList= wiki->getSearchStrList();
242     char* tokenList[32];
243    
244     memset(tokenList, 0, sizeof(char*)*32);
245     for(int i = 0; i < searchStrList->Count(); i++) {
246     wxString& searchStr = searchStrList->Item(i);
247     if( wiki->makeSearchToken(searchStr.mb_str(), tokenList) ) { /* create token */
248     if(wiki->matchWithToken((wxString*)(data->getFileName()), tokenList)) { /* match */
249     wiki->addSearchResultList(&searchStr, data);
250 maloninc 1.2 panel->updateSearchResult(wiki, &searchStr);
251 maloninc 1.1 }
252     else { /* not match */
253     if( wiki->delSearchResultList(&searchStr, data) ) {
254 maloninc 1.2 panel->updateSearchResult(wiki, &searchStr); /* only when suceed to delete */
255 maloninc 1.1 }
256     }
257     for(int j = 0; tokenList[j] != NULL; j++) free(tokenList[j]);
258     memset(tokenList, 0, sizeof(char*)*32);
259     }
260     }
261     data->setOldSubjectFromCurrent(); // restore old subject
262     }
263    
264 maloninc 1.5 #ifdef __WXMAC__
265     void mnNotePanelController::handleLinkClick(wxWebKitStateChangedEvent &event)
266     #else
267 maloninc 1.1 void mnNotePanelController::handleLinkClick(wxCommandEvent &event)
268 maloninc 1.5 #endif
269 maloninc 1.1 {
270 maloninc 1.5 wxString href;
271 maloninc 1.1 const wxString* wikiDataDir;
272 maloninc 1.5 #ifdef __WXMAC__
273     href = event.GetURL();
274     if (href.Find(wxT("file:///tmp/")) == -1 &&
275     href.Length() != 0 &&
276     event.GetState() == wxWEBKIT_STATE_NEGOTIATING){
277     ((wxWebKitCtrl*)(event.GetEventObject()))->Stop(); // Stop native webkit loading
278     }
279     else {
280     event.Skip();
281     }
282     #else
283     href = event.GetString();
284     #endif
285    
286     if(href.Find(wxT("file:///tmp/")) != -1) {
287     // do nothing
288     }
289     else if(href.Find(wxT(MNLINK)) != -1) {
290     wxRegEx exp(wxT(MNLINK));
291     exp.Replace(&href, wxT(""));
292     event.SetString((delPercent(href)).c_str());
293 maloninc 1.1 handleSearch(event);
294     }
295 maloninc 1.5 else if(href.Find(wxT(MNDOC)) != -1) {
296     wxRegEx exp(wxT(MNDOC));
297     exp.Replace(&href, wxT(""));
298 maloninc 1.1 wikiDataDir = wiki->getWikiDataDir();
299 maloninc 1.7 wxString doc = *wikiDataDir + wxT(DOCS_DIR) + delPercent(href);
300 maloninc 1.1 openDoc(doc);
301     }
302     else {
303     openUrl(href);
304     }
305     }
306    
307     void mnNotePanelController::handleOpenDocsDir(wxCommandEvent &event)
308     {
309     const wxString* wikiDataDir;
310     wxString cmd;
311     wxString docDir;
312    
313     wikiDataDir = wiki->getWikiDataDir();
314 maloninc 1.7 docDir = *wikiDataDir + wxT(DOCS_DIR);
315 maloninc 1.1
316     /* create docs directory, anyway */
317 maloninc 1.8 cmd.sprintf(wxT(MKDIR), docDir.c_str());
318 maloninc 1.1 wxExecute(cmd);
319    
320     /* open docs directory */
321 maloninc 1.9 openDir(docDir);
322 maloninc 1.1 }
323    
324     void mnNotePanelController::openUrl(wxString& url)
325     {
326     wxString cmd;
327    
328     #ifdef __WXMSW__
329     cmd.sprintf(wxT("cmd /c \"start %s\""), url.c_str());
330     #endif
331    
332     #ifdef __WXMAC__
333 maloninc 1.9 cmd.sprintf(wxT("open \'%s\'"), url.c_str());
334 maloninc 1.1 #endif
335    
336     #ifdef __WXCOCOA__
337 maloninc 1.9 cmd.sprintf(wxT("open \'%s\'"), url.c_str());
338 maloninc 1.1 #endif
339    
340     #ifdef __WXGTK__
341 maloninc 1.9 cmd.sprintf(wxT("gnome-open \'%s\'"), url.c_str());
342 maloninc 1.1 #endif
343    
344     //wxExecute(argv);
345     wxExecute(cmd);
346     }
347    
348     void mnNotePanelController::openDoc(wxString& doc)
349     {
350     wxString cmd;
351    
352     #ifdef __WXMSW__
353 maloninc 1.11 #include <windows.h>
354     ShellExecute(NULL, wxT("OPEN"), doc.c_str(), NULL, NULL, SW_SHOWNORMAL);
355     return;
356 maloninc 1.1 #endif
357    
358     #ifdef __WXMAC__
359 maloninc 1.9 cmd.sprintf(wxT("open \'%s\'"), doc.c_str());
360 maloninc 1.1 #endif
361    
362     #ifdef __WXCOCOA__
363 maloninc 1.9 cmd.sprintf(wxT("open \'%s\'"), doc.c_str());
364 maloninc 1.1 #endif
365    
366     #ifdef __WXGTK__
367 maloninc 1.9 cmd.sprintf(wxT("gnome-open \'%s\'"), doc.c_str());
368     #endif
369    
370 maloninc 1.11 wxExecute(cmd);
371 maloninc 1.9 }
372    
373     void mnNotePanelController::openDir(wxString& dir)
374     {
375     wxString cmd;
376    
377     #ifdef __WXMSW__
378     cmd.sprintf(wxT("explorer \"%s\""), dir.c_str());
379     #endif
380    
381     #ifdef __WXMAC__
382     cmd.sprintf(wxT("open \'%s\'"), dir.c_str());
383     #endif
384    
385     #ifdef __WXCOCOA__
386     cmd.sprintf(wxT("open \'%s\'"), dir.c_str());
387     #endif
388    
389     #ifdef __WXGTK__
390     cmd.sprintf(wxT("gnome-open \'%s\'"), dir.c_str());
391 maloninc 1.1 #endif
392    
393     wxExecute(cmd);
394     }
395    
396 maloninc 1.9

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