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.7 - (hide annotations) (download) (as text)
Mon Aug 1 10:46:20 2005 UTC (18 years, 7 months ago) by maloninc
Branch: MAIN
CVS Tags: dev-1_0-0009
Changes since 1.6: +4 -19 lines
File MIME type: text/x-c++src
implement clickable window, named mnHtmlWindow.
but, it can't load linked page, only show href value.

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    
8     BEGIN_EVENT_TABLE(mnController, wxEvtHandler)
9     EVT_TEXT_ENTER(ID_SearchTextCtrl, mnController::handleSearch)
10     EVT_TREE_SEL_CHANGED(ID_SearchTree, mnController::handleTreeItemSelect)
11     EVT_TREE_SEL_CHANGING(ID_SearchTree, mnController::handleTreeItemSelecting)
12     EVT_TREE_BEGIN_LABEL_EDIT(ID_SearchTree, mnController::handleBeginLabelEdit)
13     EVT_TREE_END_LABEL_EDIT(ID_SearchTree, mnController::handleEndLabelEdit)
14     EVT_MENU(ID_MenuFileNew, mnController::handleNewButton)
15     EVT_MENU(ID_MenuFileRemove, mnController::handleRemoveButton)
16 maloninc 1.4 EVT_MENU(ID_MenuFileEdit, mnController::handleEditButton)
17 maloninc 1.1 EVT_MENU(ID_MenuFileExit, mnController::handleExit)
18     EVT_MENU(ID_MenuFileConfig, mnController::handleConfig)
19     EVT_MENU(wxID_ABOUT, mnController::handleAbout)
20     EVT_CLOSE(mnController::handleClose)
21 maloninc 1.7 EVT_COMMAND(ID_HtmlTextCtrl, mnEVT_LINK_CLICK, mnController::handleLinkClick)
22 maloninc 1.1 END_EVENT_TABLE()
23    
24     mnController::mnController(mnFrame* inframe)
25     {
26     wxString* dirName = new wxString();
27     wxString gotDirName;
28     wxDirDialog* dlg;
29    
30     frame = inframe;
31     isEditing = FALSE;
32    
33     /* create wiki model */
34     wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
35     if(config->Read(wxT(CONF_WIKI_DIR), dirName) == FALSE) {
36     delete dirName;
37     dlg = new wxDirDialog(frame);
38     if(dlg->ShowModal() == wxID_OK) {
39     gotDirName = dlg->GetPath();
40     wiki = new mnModel(gotDirName.mb_str());
41     config->Write(wxT(CONF_WIKI_DIR), gotDirName.c_str());
42     }
43     else {
44     frame->Close();
45     }
46     }
47     else {
48     wiki = new mnModel(dirName->mb_str());
49     }
50    
51     delete config;
52     }
53    
54     void mnController::handleConfig(wxCommandEvent& event)
55     {
56     wxDirDialog* dlg;
57     wxString gotDirName;
58     wxString* dirName = new wxString();
59    
60     wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
61    
62     if(config->Read(wxT(CONF_WIKI_DIR), dirName)) {
63     if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){
64     delete config;
65     isEditing = FALSE;
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     isEditing = FALSE;
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     isEditing = FALSE;
100     }
101    
102     void mnController::handleNewButton(wxCommandEvent& event)
103     {
104 maloninc 1.6 int ans;
105     WikiData* wikiData = wiki->newWikiData();
106     wxString plainTextStr;
107     wxString newSubjectStr;
108     mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
109     const wxString* wikiText = wikiData->getText();
110     const wxString* subject = wikiData->getSubject();
111    
112     dlg->setSubject(*subject);
113     dlg->setPlainText(*wikiText);
114     ans = dlg->ShowModal();
115    
116     if(ans != wxID_OK) return ;
117    
118     plainTextStr = dlg->getPlainText();
119     newSubjectStr = dlg->getSubject();
120     wikiData->modText(&plainTextStr);
121     wikiData->save();
122    
123     wikiData->modSubject(&newSubjectStr);
124 maloninc 1.1
125 maloninc 1.6 frame->showSearchResult(wiki);
126     delete dlg;
127 maloninc 1.1 }
128    
129     void mnController::handleRemoveButton(wxCommandEvent& event)
130     {
131     wxTreeItemData* item = frame->getSelectedItem();
132    
133     if(item){
134     ((WikiData*)(item))->removeDataFile();
135     }
136     else {
137     wiki->removeSearchStr(frame->getSelectedLabel());
138     }
139     frame->showSearchResult(wiki);
140     isEditing = FALSE;
141     }
142    
143     void mnController::handleTreeItemSelect(wxTreeEvent& event)
144     {
145     frame->showSelectedItemText(event);
146     isEditing = FALSE;
147     }
148    
149    
150     void mnController::handleTreeItemSelecting(wxTreeEvent& event)
151     {
152     if(frame->isNewItem(event.GetOldItem())) {
153     frame->showSearchResult(wiki);
154     event.Veto();
155     }
156     }
157    
158     void mnController::handleBeginLabelEdit(wxTreeEvent& event)
159     {
160     if(!frame->isEditableTreeLabel(event.GetItem())) event.Veto();
161     }
162    
163     void mnController::handleEndLabelEdit(wxTreeEvent& event)
164     {
165     wxString newSubject = event.GetLabel();
166     wxTreeItemData* item = frame->getSelectedItem();
167    
168     if(item == NULL) return ;
169 maloninc 1.2
170 maloninc 1.1 if(newSubject.Len() == 0) {
171 maloninc 1.2 event.Veto();
172 maloninc 1.1 frame->showSearchResult(wiki);
173     return;
174     }
175    
176     ((WikiData*)(item))->modSubject(&newSubject);
177 maloninc 1.2 if(frame->isNewItem(event.GetItem())){
178     return;
179     }
180    
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.7 wxLogMessage(event.GetString());
235     }
236 maloninc 1.1

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