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.17 - (hide annotations) (download) (as text)
Thu Sep 15 03:02:37 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
Changes since 1.16: +55 -8 lines
File MIME type: text/x-c++src
implemet "Expand/Collpase/Clear All"

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

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