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.14 - (hide annotations) (download) (as text)
Tue Sep 13 00:51:06 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0002
Changes since 1.13: +1 -1 lines
File MIME type: text/x-c++src
fixed remove comfirmation.

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     EVT_MENU(wxID_ABOUT, mnController::handleAbout)
23     EVT_CLOSE(mnController::handleClose)
24 maloninc 1.7 EVT_COMMAND(ID_HtmlTextCtrl, mnEVT_LINK_CLICK, mnController::handleLinkClick)
25 maloninc 1.1 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     void mnController::handleNewButton(wxCommandEvent& event)
102     {
103 maloninc 1.6 int ans;
104     WikiData* wikiData = wiki->newWikiData();
105     wxString plainTextStr;
106     wxString newSubjectStr;
107     mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
108     const wxString* wikiText = wikiData->getText();
109     const wxString* subject = wikiData->getSubject();
110    
111     dlg->setSubject(*subject);
112     dlg->setPlainText(*wikiText);
113     ans = dlg->ShowModal();
114    
115     if(ans != wxID_OK) return ;
116    
117     plainTextStr = dlg->getPlainText();
118     newSubjectStr = dlg->getSubject();
119     wikiData->modText(&plainTextStr);
120     wikiData->save();
121    
122     wikiData->modSubject(&newSubjectStr);
123 maloninc 1.1
124 maloninc 1.6 frame->showSearchResult(wiki);
125     delete dlg;
126 maloninc 1.1 }
127    
128     void mnController::handleRemoveButton(wxCommandEvent& event)
129     {
130     wxTreeItemData* item = frame->getSelectedItem();
131    
132     if(item){
133 maloninc 1.14 if(wxMessageBox(wxT("Do you realy remove this memo?\n") + frame->getSelectedLabel(), wxT("Realy?"), wxYES_NO|wxICON_QUESTION) == wxYES){
134 maloninc 1.13 ((WikiData*)(item))->removeDataFile();
135     }
136 maloninc 1.1 }
137     else {
138     wiki->removeSearchStr(frame->getSelectedLabel());
139     }
140     frame->showSearchResult(wiki);
141     }
142    
143 maloninc 1.11 void mnController::handleHighlightButton(wxCommandEvent& event)
144     {
145     frame->highlightSelectedItem();
146     }
147    
148    
149 maloninc 1.1 void mnController::handleTreeItemSelect(wxTreeEvent& event)
150     {
151     frame->showSelectedItemText(event);
152     }
153    
154    
155     void mnController::handleTreeItemSelecting(wxTreeEvent& event)
156     {
157     }
158    
159     void mnController::handleBeginLabelEdit(wxTreeEvent& event)
160     {
161     if(!frame->isEditableTreeLabel(event.GetItem())) event.Veto();
162     }
163    
164     void mnController::handleEndLabelEdit(wxTreeEvent& event)
165     {
166     wxString newSubject = event.GetLabel();
167     wxTreeItemData* item = frame->getSelectedItem();
168    
169 maloninc 1.10 if(item == NULL) {
170     return ;
171     }
172 maloninc 1.2
173 maloninc 1.1 if(newSubject.Len() == 0) {
174 maloninc 1.2 event.Veto();
175 maloninc 1.1 frame->showSearchResult(wiki);
176     return;
177     }
178    
179     ((WikiData*)(item))->modSubject(&newSubject);
180 maloninc 1.2
181     event.Veto();
182 maloninc 1.1 frame->showSearchResult(wiki);
183     }
184    
185     void mnController::handleClose(wxCloseEvent& event)
186     {
187     frame->Destroy();
188     }
189    
190     void mnController::handleExit(wxCommandEvent& event)
191     {
192     frame->Close();
193     }
194    
195    
196     void mnController::handleAbout(wxCommandEvent& event)
197     {
198 maloninc 1.2 wxMessageBox(wxT(MN_APP_VERSION), wxT("Abount MalonNote"), wxOK|wxICON_INFORMATION);
199 maloninc 1.1 }
200    
201    
202 maloninc 1.4 void mnController::handleEditButton(wxCommandEvent& event)
203     {
204 maloninc 1.5 wxString plainTextStr;
205     wxString newSubjectStr;
206 maloninc 1.6 wxTreeItemData* itemData = frame->getSelectedItem();
207     wxString subject = frame->getSelectedLabel();
208 maloninc 1.5 mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
209 maloninc 1.6 int ans;
210    
211     if(itemData == NULL) return;
212     const wxString* wikiText = ((WikiData*)(itemData))->getText();
213    
214     dlg->setSubject(subject);
215     dlg->setPlainText(*wikiText);
216     ans = dlg->ShowModal();
217 maloninc 1.5
218     if(ans != wxID_OK) return ;
219 maloninc 1.6 if(itemData == NULL) return ;
220 maloninc 1.5
221     plainTextStr = dlg->getPlainText();
222     newSubjectStr = dlg->getSubject();
223 maloninc 1.6 ((WikiData*)(itemData))->modText(&plainTextStr);
224     ((WikiData*)(itemData))->save();
225 maloninc 1.5
226 maloninc 1.6 ((WikiData*)(itemData))->modSubject(&newSubjectStr);
227 maloninc 1.4
228 maloninc 1.5 frame->showSearchResult(wiki);
229     delete dlg;
230 maloninc 1.4 }
231 maloninc 1.1
232 maloninc 1.7 void mnController::handleLinkClick(wxCommandEvent &event)
233 maloninc 1.1 {
234 maloninc 1.9 const wxString* wikiDataDir;
235 maloninc 1.8 wxString href = event.GetString();
236     wxString tag;
237 maloninc 1.9 wxString val;
238     wxString doc;
239 maloninc 1.8 wxStringTokenizer tkz(href, wxT(":"));
240    
241     tag = tkz.GetNextToken();
242 maloninc 1.9 val = tkz.GetNextToken();
243     if(tag.CmpNoCase(wxT("mnlink")) == 0) {
244     event.SetString(val);
245 maloninc 1.8 handleSearch(event);
246     }
247 maloninc 1.9 else if(tag.CmpNoCase(wxT("mndoc")) == 0) {
248     wikiDataDir = wiki->getWikiDataDir();
249     doc = *wikiDataDir + wxT("/docs/") + val;
250     openDoc(doc);
251     }
252 maloninc 1.8 else {
253     openUrl(href);
254     }
255 maloninc 1.7 }
256 maloninc 1.1
257 maloninc 1.8 void mnController::openUrl(wxString& url)
258     {
259     wxString cmd;
260    
261     #ifdef __WXMSW__
262     cmd.sprintf(wxT("explorer %s"), url.c_str());
263     #endif
264    
265     #ifdef __WXMAC__
266     cmd.sprintf(wxT("open %s"), url.c_str());
267     #endif
268    
269     #ifdef __WXCOCOA__
270     cmd.sprintf(wxT("open %s"), url.c_str());
271     #endif
272    
273     #ifdef __WXGTK__
274 maloninc 1.12 cmd.sprintf(wxT("gnome-open %s"), url.c_str());
275 maloninc 1.8 #endif
276    
277     //wxExecute(argv);
278     wxExecute(cmd);
279     }
280 maloninc 1.9
281     void mnController::openDoc(wxString& doc)
282     {
283     wxString cmd;
284    
285     #ifdef __WXMSW__
286     cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());
287     #endif
288    
289     #ifdef __WXMAC__
290     cmd.sprintf(wxT("open %s"), doc.c_str());
291     #endif
292    
293     #ifdef __WXCOCOA__
294     cmd.sprintf(wxT("open %s"), doc.c_str());
295     #endif
296    
297     #ifdef __WXGTK__
298 maloninc 1.12 cmd.sprintf(wxT("gnome-open %s"), doc.c_str());
299 maloninc 1.9 #endif
300    
301     wxExecute(cmd);
302     }

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