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.19 - (hide annotations) (download) (as text)
Fri Sep 16 04:12:58 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0006
Changes since 1.18: +42 -27 lines
File MIME type: text/x-c++src
implement group by TYPE, but it may be bugy? (9/16)

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    
118 maloninc 1.16 wiki->group();
119 maloninc 1.19
120     frame->clearAllTree();
121     searchStrList = wiki->getSearchStrList();
122     for(i = 0; i < searchStrList->Count(); i++) {
123     wxString& searchStr = searchStrList->Item(i);
124     frame->addSearchResult(wiki, &searchStr);
125     }
126 maloninc 1.16 }
127    
128 maloninc 1.15
129 maloninc 1.1 void mnController::handleNewButton(wxCommandEvent& event)
130     {
131 maloninc 1.6 int ans;
132     WikiData* wikiData = wiki->newWikiData();
133     wxString plainTextStr;
134     wxString newSubjectStr;
135     mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
136     const wxString* wikiText = wikiData->getText();
137     const wxString* subject = wikiData->getSubject();
138    
139     dlg->setSubject(*subject);
140     dlg->setPlainText(*wikiText);
141     ans = dlg->ShowModal();
142    
143     if(ans != wxID_OK) return ;
144    
145     plainTextStr = dlg->getPlainText();
146     newSubjectStr = dlg->getSubject();
147     wikiData->modText(&plainTextStr);
148     wikiData->save();
149    
150     wikiData->modSubject(&newSubjectStr);
151 maloninc 1.1
152 maloninc 1.19 notifyUpdate(wikiData);
153    
154 maloninc 1.6 delete dlg;
155 maloninc 1.1 }
156    
157     void mnController::handleRemoveButton(wxCommandEvent& event)
158     {
159     wxTreeItemData* item = frame->getSelectedItem();
160    
161 maloninc 1.18 if(frame->isEditableTreeLabel(frame->getSelection())) {
162 maloninc 1.14 if(wxMessageBox(wxT("Do you realy remove this memo?\n") + frame->getSelectedLabel(), wxT("Realy?"), wxYES_NO|wxICON_QUESTION) == wxYES){
163 maloninc 1.13 ((WikiData*)(item))->removeDataFile();
164 maloninc 1.19 notifyUpdate((WikiData*)(item));
165 maloninc 1.13 }
166 maloninc 1.17 else {
167     return;
168     }
169 maloninc 1.1 }
170     else {
171     wiki->removeSearchStr(frame->getSelectedLabel());
172 maloninc 1.19 frame->removeSelectedItem();
173 maloninc 1.1 }
174 maloninc 1.17
175 maloninc 1.1 }
176    
177 maloninc 1.11 void mnController::handleHighlightButton(wxCommandEvent& event)
178     {
179     frame->highlightSelectedItem();
180     }
181    
182    
183 maloninc 1.1 void mnController::handleTreeItemSelect(wxTreeEvent& event)
184     {
185     frame->showSelectedItemText(event);
186     }
187    
188    
189     void mnController::handleTreeItemSelecting(wxTreeEvent& event)
190     {
191     }
192    
193     void mnController::handleBeginLabelEdit(wxTreeEvent& event)
194     {
195     if(!frame->isEditableTreeLabel(event.GetItem())) event.Veto();
196     }
197    
198     void mnController::handleEndLabelEdit(wxTreeEvent& event)
199     {
200     wxString newSubject = event.GetLabel();
201     wxTreeItemData* item = frame->getSelectedItem();
202    
203 maloninc 1.10 if(item == NULL) {
204     return ;
205     }
206 maloninc 1.2
207 maloninc 1.1 if(newSubject.Len() == 0) {
208 maloninc 1.2 event.Veto();
209 maloninc 1.1 return;
210     }
211    
212     ((WikiData*)(item))->modSubject(&newSubject);
213 maloninc 1.2
214     event.Veto();
215 maloninc 1.17
216 maloninc 1.19 notifyUpdate((WikiData*)item);
217 maloninc 1.1 }
218    
219     void mnController::handleClose(wxCloseEvent& event)
220     {
221     frame->Destroy();
222     }
223    
224     void mnController::handleExit(wxCommandEvent& event)
225     {
226     frame->Close();
227     }
228    
229 maloninc 1.17 void mnController::handleTreeExpand(wxCommandEvent& event)
230     {
231     frame->expandAllTree();
232     }
233    
234     void mnController::handleTreeCollapse(wxCommandEvent& event)
235     {
236     frame->collapseAllTree();
237     }
238    
239     void mnController::handleTreeClear(wxCommandEvent& event)
240     {
241 maloninc 1.19 wiki->clearSearchStrList();
242     wiki->clearSearchResultList();
243 maloninc 1.17 frame->clearAllTree();
244     }
245    
246     void mnController::handleTreeDisableUpdate(wxCommandEvent& event)
247     {
248     autoUpdateMode = (autoUpdateMode) ? false : true;
249     if(autoUpdateMode)
250     frame->showSearchResult(wiki);
251     }
252 maloninc 1.1
253     void mnController::handleAbout(wxCommandEvent& event)
254     {
255 maloninc 1.2 wxMessageBox(wxT(MN_APP_VERSION), wxT("Abount MalonNote"), wxOK|wxICON_INFORMATION);
256 maloninc 1.1 }
257    
258    
259 maloninc 1.4 void mnController::handleEditButton(wxCommandEvent& event)
260     {
261 maloninc 1.5 wxString plainTextStr;
262     wxString newSubjectStr;
263 maloninc 1.6 wxTreeItemData* itemData = frame->getSelectedItem();
264     wxString subject = frame->getSelectedLabel();
265 maloninc 1.5 mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
266 maloninc 1.6 int ans;
267    
268 maloninc 1.18 if(!frame->isEditableTreeLabel(frame->getSelection())) return; /* selection is not memo data */
269    
270 maloninc 1.6 const wxString* wikiText = ((WikiData*)(itemData))->getText();
271    
272     dlg->setSubject(subject);
273     dlg->setPlainText(*wikiText);
274     ans = dlg->ShowModal();
275 maloninc 1.5
276     if(ans != wxID_OK) return ;
277 maloninc 1.6 if(itemData == NULL) return ;
278 maloninc 1.5
279     plainTextStr = dlg->getPlainText();
280     newSubjectStr = dlg->getSubject();
281 maloninc 1.6 ((WikiData*)(itemData))->modText(&plainTextStr);
282     ((WikiData*)(itemData))->save();
283 maloninc 1.5
284 maloninc 1.6 ((WikiData*)(itemData))->modSubject(&newSubjectStr);
285 maloninc 1.4
286 maloninc 1.19 notifyUpdate((WikiData*)itemData);
287    
288     delete dlg;
289     }
290    
291     void mnController::notifyUpdate(WikiData* data)
292     {
293 maloninc 1.18 const wxArrayString* searchStrList= wiki->getSearchStrList();
294     char* tokenList[32];
295 maloninc 1.19
296 maloninc 1.18 memset(tokenList, 0, sizeof(char*)*32);
297     for(int i = 0; i < searchStrList->Count(); i++) {
298     wxString& searchStr = searchStrList->Item(i);
299     if( wiki->makeSearchToken(searchStr.mb_str(), tokenList) ) { /* create token */
300 maloninc 1.19 if(wiki->matchWithToken((wxString*)(data->getFileName()), tokenList)) { /* match */
301     wiki->addSearchResultList(&searchStr, data);
302 maloninc 1.18 frame->updateSearchResult(wiki, &searchStr);
303     }
304 maloninc 1.19 else { /* not match */
305     if( wiki->delSearchResultList(&searchStr, data) ) {
306     frame->updateSearchResult(wiki, &searchStr); /* only when suceed to delete */
307     }
308 maloninc 1.18 }
309 maloninc 1.19 for(int j = 0; tokenList[j] != NULL; j++) free(tokenList[j]);
310     memset(tokenList, 0, sizeof(char*)*32);
311 maloninc 1.18 }
312     }
313 maloninc 1.4 }
314 maloninc 1.1
315 maloninc 1.7 void mnController::handleLinkClick(wxCommandEvent &event)
316 maloninc 1.1 {
317 maloninc 1.9 const wxString* wikiDataDir;
318 maloninc 1.8 wxString href = event.GetString();
319     wxString tag;
320 maloninc 1.9 wxString val;
321     wxString doc;
322 maloninc 1.8 wxStringTokenizer tkz(href, wxT(":"));
323    
324     tag = tkz.GetNextToken();
325 maloninc 1.9 val = tkz.GetNextToken();
326     if(tag.CmpNoCase(wxT("mnlink")) == 0) {
327     event.SetString(val);
328 maloninc 1.8 handleSearch(event);
329     }
330 maloninc 1.9 else if(tag.CmpNoCase(wxT("mndoc")) == 0) {
331     wikiDataDir = wiki->getWikiDataDir();
332     doc = *wikiDataDir + wxT("/docs/") + val;
333     openDoc(doc);
334     }
335 maloninc 1.8 else {
336     openUrl(href);
337     }
338 maloninc 1.7 }
339 maloninc 1.1
340 maloninc 1.8 void mnController::openUrl(wxString& url)
341     {
342     wxString cmd;
343    
344     #ifdef __WXMSW__
345     cmd.sprintf(wxT("explorer %s"), url.c_str());
346     #endif
347    
348     #ifdef __WXMAC__
349     cmd.sprintf(wxT("open %s"), url.c_str());
350     #endif
351    
352     #ifdef __WXCOCOA__
353     cmd.sprintf(wxT("open %s"), url.c_str());
354     #endif
355    
356     #ifdef __WXGTK__
357 maloninc 1.12 cmd.sprintf(wxT("gnome-open %s"), url.c_str());
358 maloninc 1.8 #endif
359    
360     //wxExecute(argv);
361     wxExecute(cmd);
362     }
363 maloninc 1.9
364     void mnController::openDoc(wxString& doc)
365     {
366     wxString cmd;
367    
368     #ifdef __WXMSW__
369     cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());
370     #endif
371    
372     #ifdef __WXMAC__
373     cmd.sprintf(wxT("open %s"), doc.c_str());
374     #endif
375    
376     #ifdef __WXCOCOA__
377     cmd.sprintf(wxT("open %s"), doc.c_str());
378     #endif
379    
380     #ifdef __WXGTK__
381 maloninc 1.12 cmd.sprintf(wxT("gnome-open %s"), doc.c_str());
382 maloninc 1.9 #endif
383    
384     wxExecute(cmd);
385     }

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