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.21 - (hide annotations) (download) (as text)
Thu Sep 29 04:15:30 2005 UTC (18 years, 5 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_4-0002
Changes since 1.20: +19 -27 lines
File MIME type: text/x-c++src
use XRC file for mnFrame

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

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