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.10 - (show annotations) (download) (as text)
Sat Aug 13 06:12:05 2005 UTC (18 years, 7 months ago) by maloninc
Branch: MAIN
CVS Tags: rel-1_1, dev-1_1-0009
Changes since 1.9: +3 -1 lines
File MIME type: text/x-c++src
fix rename bug.

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

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