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.16 - (hide annotations) (download) (as text)
Tue Sep 13 11:17:03 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0004
Changes since 1.15: +7 -0 lines
File MIME type: text/x-c++src
implement group by TYPE

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

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