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.13 - (hide annotations) (download) (as text)
Mon Oct 23 08:00:09 2006 UTC (17 years, 5 months ago) by maloninc
Branch: MAIN
Changes since 1.12: +10 -1 lines
File MIME type: text/x-c++src
readAll with wxTimer

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

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