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.12 - (hide annotations) (download) (as text)
Sat Aug 27 01:19:57 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0001
Changes since 1.11: +2 -5 lines
File MIME type: text/x-c++src
implement gnome-open

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

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