Develop and Download Open Source Software

Browse CVS Repository

Contents of /malonnote/mnController.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (show annotations) (download) (as text)
Tue Sep 13 04:22:15 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0003
Changes since 1.14: +1 -0 lines
File MIME type: text/x-c++src
implement searching all memo

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 #include <wx/tokenzr.h>
8 #include <wx/utils.h>
9
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 EVT_MENU(ID_MenuFileHighlight, mnController::handleHighlightButton)
19 EVT_MENU(ID_MenuFileEdit, mnController::handleEditButton)
20 EVT_MENU(ID_MenuFileExit, mnController::handleExit)
21 EVT_MENU(ID_MenuFileConfig, mnController::handleConfig)
22 EVT_MENU(wxID_ABOUT, mnController::handleAbout)
23 EVT_CLOSE(mnController::handleClose)
24 EVT_COMMAND(ID_HtmlTextCtrl, mnEVT_LINK_CLICK, mnController::handleLinkClick)
25 END_EVENT_TABLE()
26
27 mnController::mnController(mnFrame* inframe)
28 {
29 wxString* dirName = new wxString();
30 wxString gotDirName;
31 wxDirDialog* dlg;
32
33 frame = inframe;
34
35 /* create wiki model */
36 wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
37 if(config->Read(wxT(CONF_WIKI_DIR), dirName) == FALSE) {
38 delete dirName;
39 dlg = new wxDirDialog(frame);
40 if(dlg->ShowModal() == wxID_OK) {
41 gotDirName = dlg->GetPath();
42 wiki = new mnModel(gotDirName.mb_str());
43 config->Write(wxT(CONF_WIKI_DIR), gotDirName.c_str());
44 }
45 else {
46 frame->Close();
47 }
48 }
49 else {
50 wiki = new mnModel(dirName->mb_str());
51 }
52
53 delete config;
54 }
55
56 void mnController::handleConfig(wxCommandEvent& event)
57 {
58 wxDirDialog* dlg;
59 wxString gotDirName;
60 wxString* dirName = new wxString();
61
62 wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
63
64 if(config->Read(wxT(CONF_WIKI_DIR), dirName)) {
65 if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){
66 delete config;
67 return;
68 }
69 }
70
71 dlg = new wxDirDialog(frame);
72 if(dlg->ShowModal() == wxID_OK) {
73 gotDirName = dlg->GetPath();
74 delete wiki;
75 wiki = new mnModel(gotDirName.mb_str());
76 config->Write(wxT(CONF_WIKI_DIR), gotDirName.c_str());
77 }
78 delete config;
79
80 frame->showSearchResult(wiki);
81 }
82
83 void mnController::handleSearch(wxCommandEvent& event)
84 {
85 wxString* str = new wxString(event.GetString());
86 WikiList* wikiList;
87 WikiList::Node* node;
88
89 wikiList = wiki->search(str->mb_str());
90
91 node = wikiList->GetFirst();
92 if(!node) {
93 wxLogMessage(wxT("Not Found! [%s]"), (const char*)str->c_str());
94 return;
95 }
96
97 wiki->addSearchStr(str);
98 frame->showSearchResult(wiki);
99 }
100
101
102 void mnController::handleNewButton(wxCommandEvent& event)
103 {
104 int ans;
105 WikiData* wikiData = wiki->newWikiData();
106 wxString plainTextStr;
107 wxString newSubjectStr;
108 mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
109 const wxString* wikiText = wikiData->getText();
110 const wxString* subject = wikiData->getSubject();
111
112 dlg->setSubject(*subject);
113 dlg->setPlainText(*wikiText);
114 ans = dlg->ShowModal();
115
116 if(ans != wxID_OK) return ;
117
118 plainTextStr = dlg->getPlainText();
119 newSubjectStr = dlg->getSubject();
120 wikiData->modText(&plainTextStr);
121 wikiData->save();
122
123 wikiData->modSubject(&newSubjectStr);
124
125 frame->showSearchResult(wiki);
126 delete dlg;
127 }
128
129 void mnController::handleRemoveButton(wxCommandEvent& event)
130 {
131 wxTreeItemData* item = frame->getSelectedItem();
132
133 if(item){
134 if(wxMessageBox(wxT("Do you realy remove this memo?\n") + frame->getSelectedLabel(), wxT("Realy?"), wxYES_NO|wxICON_QUESTION) == wxYES){
135 ((WikiData*)(item))->removeDataFile();
136 }
137 }
138 else {
139 wiki->removeSearchStr(frame->getSelectedLabel());
140 }
141 frame->showSearchResult(wiki);
142 }
143
144 void mnController::handleHighlightButton(wxCommandEvent& event)
145 {
146 frame->highlightSelectedItem();
147 }
148
149
150 void mnController::handleTreeItemSelect(wxTreeEvent& event)
151 {
152 frame->showSelectedItemText(event);
153 }
154
155
156 void mnController::handleTreeItemSelecting(wxTreeEvent& event)
157 {
158 }
159
160 void mnController::handleBeginLabelEdit(wxTreeEvent& event)
161 {
162 if(!frame->isEditableTreeLabel(event.GetItem())) event.Veto();
163 }
164
165 void mnController::handleEndLabelEdit(wxTreeEvent& event)
166 {
167 wxString newSubject = event.GetLabel();
168 wxTreeItemData* item = frame->getSelectedItem();
169
170 if(item == NULL) {
171 return ;
172 }
173
174 if(newSubject.Len() == 0) {
175 event.Veto();
176 frame->showSearchResult(wiki);
177 return;
178 }
179
180 ((WikiData*)(item))->modSubject(&newSubject);
181
182 event.Veto();
183 frame->showSearchResult(wiki);
184 }
185
186 void mnController::handleClose(wxCloseEvent& event)
187 {
188 frame->Destroy();
189 }
190
191 void mnController::handleExit(wxCommandEvent& event)
192 {
193 frame->Close();
194 }
195
196
197 void mnController::handleAbout(wxCommandEvent& event)
198 {
199 wxMessageBox(wxT(MN_APP_VERSION), wxT("Abount MalonNote"), wxOK|wxICON_INFORMATION);
200 }
201
202
203 void mnController::handleEditButton(wxCommandEvent& event)
204 {
205 wxString plainTextStr;
206 wxString newSubjectStr;
207 wxTreeItemData* itemData = frame->getSelectedItem();
208 wxString subject = frame->getSelectedLabel();
209 mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
210 int ans;
211
212 if(itemData == NULL) return;
213 const wxString* wikiText = ((WikiData*)(itemData))->getText();
214
215 dlg->setSubject(subject);
216 dlg->setPlainText(*wikiText);
217 ans = dlg->ShowModal();
218
219 if(ans != wxID_OK) return ;
220 if(itemData == NULL) return ;
221
222 plainTextStr = dlg->getPlainText();
223 newSubjectStr = dlg->getSubject();
224 ((WikiData*)(itemData))->modText(&plainTextStr);
225 ((WikiData*)(itemData))->save();
226
227 ((WikiData*)(itemData))->modSubject(&newSubjectStr);
228
229 frame->showSearchResult(wiki);
230 delete dlg;
231 }
232
233 void mnController::handleLinkClick(wxCommandEvent &event)
234 {
235 const wxString* wikiDataDir;
236 wxString href = event.GetString();
237 wxString tag;
238 wxString val;
239 wxString doc;
240 wxStringTokenizer tkz(href, wxT(":"));
241
242 tag = tkz.GetNextToken();
243 val = tkz.GetNextToken();
244 if(tag.CmpNoCase(wxT("mnlink")) == 0) {
245 event.SetString(val);
246 handleSearch(event);
247 }
248 else if(tag.CmpNoCase(wxT("mndoc")) == 0) {
249 wikiDataDir = wiki->getWikiDataDir();
250 doc = *wikiDataDir + wxT("/docs/") + val;
251 openDoc(doc);
252 }
253 else {
254 openUrl(href);
255 }
256 }
257
258 void mnController::openUrl(wxString& url)
259 {
260 wxString cmd;
261
262 #ifdef __WXMSW__
263 cmd.sprintf(wxT("explorer %s"), url.c_str());
264 #endif
265
266 #ifdef __WXMAC__
267 cmd.sprintf(wxT("open %s"), url.c_str());
268 #endif
269
270 #ifdef __WXCOCOA__
271 cmd.sprintf(wxT("open %s"), url.c_str());
272 #endif
273
274 #ifdef __WXGTK__
275 cmd.sprintf(wxT("gnome-open %s"), url.c_str());
276 #endif
277
278 //wxExecute(argv);
279 wxExecute(cmd);
280 }
281
282 void mnController::openDoc(wxString& doc)
283 {
284 wxString cmd;
285
286 #ifdef __WXMSW__
287 cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());
288 #endif
289
290 #ifdef __WXMAC__
291 cmd.sprintf(wxT("open %s"), doc.c_str());
292 #endif
293
294 #ifdef __WXCOCOA__
295 cmd.sprintf(wxT("open %s"), doc.c_str());
296 #endif
297
298 #ifdef __WXGTK__
299 cmd.sprintf(wxT("gnome-open %s"), doc.c_str());
300 #endif
301
302 wxExecute(cmd);
303 }

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