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.23 - (hide annotations) (download) (as text)
Fri Sep 30 01:38:17 2005 UTC (18 years, 5 months ago) by maloninc
Branch: MAIN
Changes since 1.22: +18 -0 lines
File MIME type: text/x-c++src
implement open docs directory menu

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 maloninc 1.23 EVT_MENU(XRCID("OpenDocsDir"), mnController::handleOpenDocsDir)
25 maloninc 1.21 EVT_MENU(XRCID("Expand"), mnController::handleTreeExpand)
26     EVT_MENU(XRCID("Collapse"), mnController::handleTreeCollapse)
27     EVT_MENU(XRCID("Clear"), mnController::handleTreeClear)
28 maloninc 1.22 EVT_MENU(wxID_ABOUT, mnController::handleAbout)
29 maloninc 1.1 EVT_CLOSE(mnController::handleClose)
30 maloninc 1.21 EVT_COMMAND(XRCID("wikiHtmlTextCtrl"), mnEVT_LINK_CLICK, mnController::handleLinkClick)
31 maloninc 1.1 END_EVENT_TABLE()
32    
33     mnController::mnController(mnFrame* inframe)
34     {
35     wxString* dirName = new wxString();
36     wxString gotDirName;
37     wxDirDialog* dlg;
38    
39     frame = inframe;
40    
41     /* create wiki model */
42     wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
43     if(config->Read(wxT(CONF_WIKI_DIR), dirName) == FALSE) {
44     delete dirName;
45     dlg = new wxDirDialog(frame);
46     if(dlg->ShowModal() == wxID_OK) {
47     gotDirName = dlg->GetPath();
48     wiki = new mnModel(gotDirName.mb_str());
49     config->Write(wxT(CONF_WIKI_DIR), gotDirName.c_str());
50     }
51     else {
52     frame->Close();
53     }
54     }
55     else {
56     wiki = new mnModel(dirName->mb_str());
57     }
58    
59     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 maloninc 1.1 void mnController::handleAbout(wxCommandEvent& event)
250     {
251 maloninc 1.2 wxMessageBox(wxT(MN_APP_VERSION), wxT("Abount MalonNote"), wxOK|wxICON_INFORMATION);
252 maloninc 1.1 }
253    
254    
255 maloninc 1.4 void mnController::handleEditButton(wxCommandEvent& event)
256     {
257 maloninc 1.5 wxString plainTextStr;
258     wxString newSubjectStr;
259 maloninc 1.6 wxTreeItemData* itemData = frame->getSelectedItem();
260     wxString subject = frame->getSelectedLabel();
261 maloninc 1.5 mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
262 maloninc 1.6 int ans;
263    
264 maloninc 1.18 if(!frame->isEditableTreeLabel(frame->getSelection())) return; /* selection is not memo data */
265    
266 maloninc 1.6 const wxString* wikiText = ((WikiData*)(itemData))->getText();
267    
268     dlg->setSubject(subject);
269     dlg->setPlainText(*wikiText);
270     ans = dlg->ShowModal();
271 maloninc 1.5
272     if(ans != wxID_OK) return ;
273 maloninc 1.6 if(itemData == NULL) return ;
274 maloninc 1.5
275     plainTextStr = dlg->getPlainText();
276     newSubjectStr = dlg->getSubject();
277 maloninc 1.6 ((WikiData*)(itemData))->modText(&plainTextStr);
278     ((WikiData*)(itemData))->save();
279 maloninc 1.5
280 maloninc 1.6 ((WikiData*)(itemData))->modSubject(&newSubjectStr);
281 maloninc 1.4
282 maloninc 1.19 notifyUpdate((WikiData*)itemData);
283    
284     delete dlg;
285     }
286    
287     void mnController::notifyUpdate(WikiData* data)
288     {
289 maloninc 1.18 const wxArrayString* searchStrList= wiki->getSearchStrList();
290     char* tokenList[32];
291 maloninc 1.19
292 maloninc 1.18 memset(tokenList, 0, sizeof(char*)*32);
293     for(int i = 0; i < searchStrList->Count(); i++) {
294     wxString& searchStr = searchStrList->Item(i);
295     if( wiki->makeSearchToken(searchStr.mb_str(), tokenList) ) { /* create token */
296 maloninc 1.19 if(wiki->matchWithToken((wxString*)(data->getFileName()), tokenList)) { /* match */
297     wiki->addSearchResultList(&searchStr, data);
298 maloninc 1.18 frame->updateSearchResult(wiki, &searchStr);
299     }
300 maloninc 1.19 else { /* not match */
301     if( wiki->delSearchResultList(&searchStr, data) ) {
302     frame->updateSearchResult(wiki, &searchStr); /* only when suceed to delete */
303     }
304 maloninc 1.18 }
305 maloninc 1.19 for(int j = 0; tokenList[j] != NULL; j++) free(tokenList[j]);
306     memset(tokenList, 0, sizeof(char*)*32);
307 maloninc 1.18 }
308     }
309 maloninc 1.20 data->setOldSubjectFromCurrent(); // restore old subject
310 maloninc 1.4 }
311 maloninc 1.1
312 maloninc 1.7 void mnController::handleLinkClick(wxCommandEvent &event)
313 maloninc 1.1 {
314 maloninc 1.9 const wxString* wikiDataDir;
315 maloninc 1.8 wxString href = event.GetString();
316     wxString tag;
317 maloninc 1.9 wxString val;
318     wxString doc;
319 maloninc 1.8 wxStringTokenizer tkz(href, wxT(":"));
320    
321     tag = tkz.GetNextToken();
322 maloninc 1.9 val = tkz.GetNextToken();
323     if(tag.CmpNoCase(wxT("mnlink")) == 0) {
324     event.SetString(val);
325 maloninc 1.8 handleSearch(event);
326     }
327 maloninc 1.9 else if(tag.CmpNoCase(wxT("mndoc")) == 0) {
328     wikiDataDir = wiki->getWikiDataDir();
329     doc = *wikiDataDir + wxT("/docs/") + val;
330     openDoc(doc);
331     }
332 maloninc 1.8 else {
333     openUrl(href);
334     }
335 maloninc 1.7 }
336 maloninc 1.1
337 maloninc 1.23 void mnController::handleOpenDocsDir(wxCommandEvent &event)
338     {
339     const wxString* wikiDataDir;
340     wxString cmd;
341     wxString docDir;
342    
343     wikiDataDir = wiki->getWikiDataDir();
344     docDir = *wikiDataDir + wxT("/docs/");
345    
346     /* create docs directory, anyway */
347     cmd.sprintf(wxT("mkdir "), docDir.c_str());
348     wxExecute(cmd);
349    
350     /* open docs directory */
351     openDoc(docDir);
352     }
353    
354 maloninc 1.8 void mnController::openUrl(wxString& url)
355     {
356     wxString cmd;
357    
358     #ifdef __WXMSW__
359 maloninc 1.21 cmd.sprintf(wxT("cmd /c \"start %s\""), url.c_str());
360 maloninc 1.8 #endif
361    
362     #ifdef __WXMAC__
363     cmd.sprintf(wxT("open %s"), url.c_str());
364     #endif
365    
366     #ifdef __WXCOCOA__
367     cmd.sprintf(wxT("open %s"), url.c_str());
368     #endif
369    
370     #ifdef __WXGTK__
371 maloninc 1.12 cmd.sprintf(wxT("gnome-open %s"), url.c_str());
372 maloninc 1.8 #endif
373    
374     //wxExecute(argv);
375     wxExecute(cmd);
376     }
377 maloninc 1.9
378     void mnController::openDoc(wxString& doc)
379     {
380     wxString cmd;
381    
382     #ifdef __WXMSW__
383     cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());
384     #endif
385    
386     #ifdef __WXMAC__
387     cmd.sprintf(wxT("open %s"), doc.c_str());
388     #endif
389    
390     #ifdef __WXCOCOA__
391     cmd.sprintf(wxT("open %s"), doc.c_str());
392     #endif
393    
394     #ifdef __WXGTK__
395 maloninc 1.12 cmd.sprintf(wxT("gnome-open %s"), doc.c_str());
396 maloninc 1.9 #endif
397    
398     wxExecute(cmd);
399     }

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