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.8 - (hide annotations) (download) (as text)
Tue Aug 2 07:21:38 2005 UTC (18 years, 7 months ago) by maloninc
Branch: MAIN
CVS Tags: dev-1_0-0010, dev-1_0-0011
Changes since 1.7: +45 -1 lines
File MIME type: text/x-c++src
implement mnlink, and URL link.
And HTML tiny rendaring
but, not implemet {{}} tag

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.4 EVT_MENU(ID_MenuFileEdit, mnController::handleEditButton)
19 maloninc 1.1 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 maloninc 1.7 EVT_COMMAND(ID_HtmlTextCtrl, mnEVT_LINK_CLICK, mnController::handleLinkClick)
24 maloninc 1.1 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     isEditing = FALSE;
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     isEditing = FALSE;
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     isEditing = FALSE;
83     }
84    
85     void mnController::handleSearch(wxCommandEvent& event)
86     {
87     wxString* str = new wxString(event.GetString());
88     WikiList* wikiList;
89     WikiList::Node* node;
90    
91     wikiList = wiki->search(str->mb_str());
92    
93     node = wikiList->GetFirst();
94     if(!node) {
95     wxLogMessage(wxT("Not Found! [%s]"), (const char*)str->c_str());
96     return;
97     }
98    
99     wiki->addSearchStr(str);
100     frame->showSearchResult(wiki);
101     isEditing = FALSE;
102     }
103    
104     void mnController::handleNewButton(wxCommandEvent& event)
105     {
106 maloninc 1.6 int ans;
107     WikiData* wikiData = wiki->newWikiData();
108     wxString plainTextStr;
109     wxString newSubjectStr;
110     mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
111     const wxString* wikiText = wikiData->getText();
112     const wxString* subject = wikiData->getSubject();
113    
114     dlg->setSubject(*subject);
115     dlg->setPlainText(*wikiText);
116     ans = dlg->ShowModal();
117    
118     if(ans != wxID_OK) return ;
119    
120     plainTextStr = dlg->getPlainText();
121     newSubjectStr = dlg->getSubject();
122     wikiData->modText(&plainTextStr);
123     wikiData->save();
124    
125     wikiData->modSubject(&newSubjectStr);
126 maloninc 1.1
127 maloninc 1.6 frame->showSearchResult(wiki);
128     delete dlg;
129 maloninc 1.1 }
130    
131     void mnController::handleRemoveButton(wxCommandEvent& event)
132     {
133     wxTreeItemData* item = frame->getSelectedItem();
134    
135     if(item){
136     ((WikiData*)(item))->removeDataFile();
137     }
138     else {
139     wiki->removeSearchStr(frame->getSelectedLabel());
140     }
141     frame->showSearchResult(wiki);
142     isEditing = FALSE;
143     }
144    
145     void mnController::handleTreeItemSelect(wxTreeEvent& event)
146     {
147     frame->showSelectedItemText(event);
148     isEditing = FALSE;
149     }
150    
151    
152     void mnController::handleTreeItemSelecting(wxTreeEvent& event)
153     {
154     if(frame->isNewItem(event.GetOldItem())) {
155     frame->showSearchResult(wiki);
156     event.Veto();
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) return ;
171 maloninc 1.2
172 maloninc 1.1 if(newSubject.Len() == 0) {
173 maloninc 1.2 event.Veto();
174 maloninc 1.1 frame->showSearchResult(wiki);
175     return;
176     }
177    
178     ((WikiData*)(item))->modSubject(&newSubject);
179 maloninc 1.2 if(frame->isNewItem(event.GetItem())){
180     return;
181     }
182    
183     event.Veto();
184 maloninc 1.1 frame->showSearchResult(wiki);
185     }
186    
187     void mnController::handleClose(wxCloseEvent& event)
188     {
189     frame->Destroy();
190     }
191    
192     void mnController::handleExit(wxCommandEvent& event)
193     {
194     frame->Close();
195     }
196    
197    
198     void mnController::handleAbout(wxCommandEvent& event)
199     {
200 maloninc 1.2 wxMessageBox(wxT(MN_APP_VERSION), wxT("Abount MalonNote"), wxOK|wxICON_INFORMATION);
201 maloninc 1.1 }
202    
203    
204 maloninc 1.4 void mnController::handleEditButton(wxCommandEvent& event)
205     {
206 maloninc 1.5 wxString plainTextStr;
207     wxString newSubjectStr;
208 maloninc 1.6 wxTreeItemData* itemData = frame->getSelectedItem();
209     wxString subject = frame->getSelectedLabel();
210 maloninc 1.5 mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
211 maloninc 1.6 int ans;
212    
213     if(itemData == NULL) return;
214     const wxString* wikiText = ((WikiData*)(itemData))->getText();
215    
216     dlg->setSubject(subject);
217     dlg->setPlainText(*wikiText);
218     ans = dlg->ShowModal();
219 maloninc 1.5
220     if(ans != wxID_OK) return ;
221 maloninc 1.6 if(itemData == NULL) return ;
222 maloninc 1.5
223     plainTextStr = dlg->getPlainText();
224     newSubjectStr = dlg->getSubject();
225 maloninc 1.6 ((WikiData*)(itemData))->modText(&plainTextStr);
226     ((WikiData*)(itemData))->save();
227 maloninc 1.5
228 maloninc 1.6 ((WikiData*)(itemData))->modSubject(&newSubjectStr);
229 maloninc 1.4
230 maloninc 1.5 frame->showSearchResult(wiki);
231     delete dlg;
232 maloninc 1.4 }
233 maloninc 1.1
234 maloninc 1.7 void mnController::handleLinkClick(wxCommandEvent &event)
235 maloninc 1.1 {
236 maloninc 1.8 wxString href = event.GetString();
237     wxString tag;
238     wxString url;
239     wxStringTokenizer tkz(href, wxT(":"));
240    
241     tag = tkz.GetNextToken();
242     url = tkz.GetNextToken();
243    
244     if(tag.Cmp(wxT("mnlink")) == 0) {
245     event.SetString(url);
246     handleSearch(event);
247     }
248     else {
249     openUrl(href);
250     }
251 maloninc 1.7 }
252 maloninc 1.1
253 maloninc 1.8 void mnController::openUrl(wxString& url)
254     {
255     wxChar* argv[5];
256     wxString cmd;
257    
258     #ifdef __WXMSW__
259     argv[0] = wxT("explorer");
260     argv[1] = (wxChar*)url.c_str();
261     argv[2] = NULL;
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     wxLogMessage(wxT("Ooops!, I don't know how to launch %s"), url.c_str());
275     return;
276     #endif
277    
278     //wxExecute(argv);
279     wxExecute(cmd);
280     }

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