Develop and Download Open Source Software

Browse CVS Repository

Annotation of /malonnote/mnController.cpp

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


Revision 1.20 - (hide annotations) (download) (as text)
Tue Sep 20 06:29:53 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: rel_1_3, dev_1_3-0008, dev_1_3-0007, dev_1_4-0001
Changes since 1.19: +5 -1 lines
File MIME type: text/x-c++src
implement group by TYPE, and MAX_TOKEN=32

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

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