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.12 - (hide annotations) (download) (as text)
Fri Oct 20 11:58:52 2006 UTC (17 years, 6 months ago) by maloninc
Branch: MAIN
Changes since 1.11: +2 -0 lines
File MIME type: text/x-c++src
readAll when started, and proressbar

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

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