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.18 - (hide annotations) (download) (as text)
Thu Sep 15 09:20:48 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0005
Changes since 1.17: +21 -8 lines
File MIME type: text/x-c++src
implement effective update, but it's incomplete. (9/15)

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.17 if(autoUpdateMode)
87     frame->showSearchResult(wiki);
88 maloninc 1.1 }
89    
90     void mnController::handleSearch(wxCommandEvent& event)
91     {
92     wxString* str = new wxString(event.GetString());
93     WikiList* wikiList;
94     WikiList::Node* node;
95    
96     wikiList = wiki->search(str->mb_str());
97    
98     node = wikiList->GetFirst();
99     if(!node) {
100     wxLogMessage(wxT("Not Found! [%s]"), (const char*)str->c_str());
101     return;
102     }
103    
104     wiki->addSearchStr(str);
105 maloninc 1.18 wiki->addSearchList(str, wikiList);
106 maloninc 1.17
107 maloninc 1.18 frame->addSearchResult(wiki, str);
108 maloninc 1.1 }
109    
110 maloninc 1.16 void mnController::handleGroup(wxCommandEvent& event)
111     {
112     wiki->group();
113 maloninc 1.17
114     if(autoUpdateMode)
115     frame->showSearchResult(wiki, false);
116     else
117     wxLogMessage(wxT("Pleas enable AutoUpdate"));
118 maloninc 1.16 }
119    
120 maloninc 1.15
121 maloninc 1.1 void mnController::handleNewButton(wxCommandEvent& event)
122     {
123 maloninc 1.6 int ans;
124     WikiData* wikiData = wiki->newWikiData();
125     wxString plainTextStr;
126     wxString newSubjectStr;
127     mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
128     const wxString* wikiText = wikiData->getText();
129     const wxString* subject = wikiData->getSubject();
130    
131     dlg->setSubject(*subject);
132     dlg->setPlainText(*wikiText);
133     ans = dlg->ShowModal();
134    
135     if(ans != wxID_OK) return ;
136    
137     plainTextStr = dlg->getPlainText();
138     newSubjectStr = dlg->getSubject();
139     wikiData->modText(&plainTextStr);
140     wikiData->save();
141    
142     wikiData->modSubject(&newSubjectStr);
143 maloninc 1.1
144 maloninc 1.17 if(autoUpdateMode)
145     frame->showSearchResult(wiki);
146 maloninc 1.6 delete dlg;
147 maloninc 1.1 }
148    
149     void mnController::handleRemoveButton(wxCommandEvent& event)
150     {
151     wxTreeItemData* item = frame->getSelectedItem();
152    
153 maloninc 1.18 if(frame->isEditableTreeLabel(frame->getSelection())) {
154 maloninc 1.14 if(wxMessageBox(wxT("Do you realy remove this memo?\n") + frame->getSelectedLabel(), wxT("Realy?"), wxYES_NO|wxICON_QUESTION) == wxYES){
155 maloninc 1.13 ((WikiData*)(item))->removeDataFile();
156     }
157 maloninc 1.17 else {
158     return;
159     }
160 maloninc 1.1 }
161     else {
162     wiki->removeSearchStr(frame->getSelectedLabel());
163     }
164 maloninc 1.17
165     if(autoUpdateMode)
166     frame->showSearchResult(wiki);
167     else
168     frame->removeSelectedItem();
169 maloninc 1.1 }
170    
171 maloninc 1.11 void mnController::handleHighlightButton(wxCommandEvent& event)
172     {
173     frame->highlightSelectedItem();
174     }
175    
176    
177 maloninc 1.1 void mnController::handleTreeItemSelect(wxTreeEvent& event)
178     {
179     frame->showSelectedItemText(event);
180     }
181    
182    
183     void mnController::handleTreeItemSelecting(wxTreeEvent& event)
184     {
185     }
186    
187     void mnController::handleBeginLabelEdit(wxTreeEvent& event)
188     {
189     if(!frame->isEditableTreeLabel(event.GetItem())) event.Veto();
190     }
191    
192     void mnController::handleEndLabelEdit(wxTreeEvent& event)
193     {
194     wxString newSubject = event.GetLabel();
195     wxTreeItemData* item = frame->getSelectedItem();
196    
197 maloninc 1.10 if(item == NULL) {
198     return ;
199     }
200 maloninc 1.2
201 maloninc 1.1 if(newSubject.Len() == 0) {
202 maloninc 1.2 event.Veto();
203 maloninc 1.17 if(autoUpdateMode)
204     frame->showSearchResult(wiki);
205 maloninc 1.1 return;
206     }
207    
208     ((WikiData*)(item))->modSubject(&newSubject);
209 maloninc 1.2
210     event.Veto();
211 maloninc 1.17
212     if(autoUpdateMode)
213     frame->showSearchResult(wiki);
214 maloninc 1.1 }
215    
216     void mnController::handleClose(wxCloseEvent& event)
217     {
218     frame->Destroy();
219     }
220    
221     void mnController::handleExit(wxCommandEvent& event)
222     {
223     frame->Close();
224     }
225    
226 maloninc 1.17 void mnController::handleTreeExpand(wxCommandEvent& event)
227     {
228     frame->expandAllTree();
229     }
230    
231     void mnController::handleTreeCollapse(wxCommandEvent& event)
232     {
233     frame->collapseAllTree();
234     }
235    
236     void mnController::handleTreeClear(wxCommandEvent& event)
237     {
238     frame->clearAllTree();
239     }
240    
241     void mnController::handleTreeDisableUpdate(wxCommandEvent& event)
242     {
243     autoUpdateMode = (autoUpdateMode) ? false : true;
244     if(autoUpdateMode)
245     frame->showSearchResult(wiki);
246     }
247 maloninc 1.1
248     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.18 const wxArrayString* searchStrList= wiki->getSearchStrList();
282     char* tokenList[32];
283     memset(tokenList, 0, sizeof(char*)*32);
284     for(int i = 0; i < searchStrList->Count(); i++) {
285     wxString& searchStr = searchStrList->Item(i);
286     if( wiki->makeSearchToken(searchStr.mb_str(), tokenList) ) { /* create token */
287     if(wiki->matchWithToken((wxString*)((WikiData*)(itemData))->getFileName(), tokenList)) { /* match */
288     wiki->addSearchResultList(&searchStr, (WikiData*)(itemData));
289     frame->updateSearchResult(wiki, &searchStr);
290     }
291     else {
292     //wiki->delSearchResultList(searchStr, (WikiData*)(itemData));
293     //frame->updateSearchResult(wiki, &searchStr);
294     }
295     }
296     }
297 maloninc 1.5 delete dlg;
298 maloninc 1.4 }
299 maloninc 1.1
300 maloninc 1.7 void mnController::handleLinkClick(wxCommandEvent &event)
301 maloninc 1.1 {
302 maloninc 1.9 const wxString* wikiDataDir;
303 maloninc 1.8 wxString href = event.GetString();
304     wxString tag;
305 maloninc 1.9 wxString val;
306     wxString doc;
307 maloninc 1.8 wxStringTokenizer tkz(href, wxT(":"));
308    
309     tag = tkz.GetNextToken();
310 maloninc 1.9 val = tkz.GetNextToken();
311     if(tag.CmpNoCase(wxT("mnlink")) == 0) {
312     event.SetString(val);
313 maloninc 1.8 handleSearch(event);
314     }
315 maloninc 1.9 else if(tag.CmpNoCase(wxT("mndoc")) == 0) {
316     wikiDataDir = wiki->getWikiDataDir();
317     doc = *wikiDataDir + wxT("/docs/") + val;
318     openDoc(doc);
319     }
320 maloninc 1.8 else {
321     openUrl(href);
322     }
323 maloninc 1.7 }
324 maloninc 1.1
325 maloninc 1.8 void mnController::openUrl(wxString& url)
326     {
327     wxString cmd;
328    
329     #ifdef __WXMSW__
330     cmd.sprintf(wxT("explorer %s"), url.c_str());
331     #endif
332    
333     #ifdef __WXMAC__
334     cmd.sprintf(wxT("open %s"), url.c_str());
335     #endif
336    
337     #ifdef __WXCOCOA__
338     cmd.sprintf(wxT("open %s"), url.c_str());
339     #endif
340    
341     #ifdef __WXGTK__
342 maloninc 1.12 cmd.sprintf(wxT("gnome-open %s"), url.c_str());
343 maloninc 1.8 #endif
344    
345     //wxExecute(argv);
346     wxExecute(cmd);
347     }
348 maloninc 1.9
349     void mnController::openDoc(wxString& doc)
350     {
351     wxString cmd;
352    
353     #ifdef __WXMSW__
354     cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());
355     #endif
356    
357     #ifdef __WXMAC__
358     cmd.sprintf(wxT("open %s"), doc.c_str());
359     #endif
360    
361     #ifdef __WXCOCOA__
362     cmd.sprintf(wxT("open %s"), doc.c_str());
363     #endif
364    
365     #ifdef __WXGTK__
366 maloninc 1.12 cmd.sprintf(wxT("gnome-open %s"), doc.c_str());
367 maloninc 1.9 #endif
368    
369     wxExecute(cmd);
370     }

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