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.6 - (hide annotations) (download) (as text)
Sun Jul 31 22:22:14 2005 UTC (18 years, 7 months ago) by maloninc
Branch: MAIN
CVS Tags: dev-1_0-0008
Changes since 1.5: +36 -11 lines
File MIME type: text/x-c++src
to create new item, but can't display with hyper link. It displays only
plain text.

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     END_EVENT_TABLE()
22    
23     mnController::mnController(mnFrame* inframe)
24     {
25     wxString* dirName = new wxString();
26     wxString gotDirName;
27     wxDirDialog* dlg;
28    
29     frame = inframe;
30     isEditing = FALSE;
31    
32     /* create wiki model */
33     wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
34     if(config->Read(wxT(CONF_WIKI_DIR), dirName) == FALSE) {
35     delete dirName;
36     dlg = new wxDirDialog(frame);
37     if(dlg->ShowModal() == wxID_OK) {
38     gotDirName = dlg->GetPath();
39     wiki = new mnModel(gotDirName.mb_str());
40     config->Write(wxT(CONF_WIKI_DIR), gotDirName.c_str());
41     }
42     else {
43     frame->Close();
44     }
45     }
46     else {
47     wiki = new mnModel(dirName->mb_str());
48     }
49    
50     delete config;
51     }
52    
53     void mnController::handleConfig(wxCommandEvent& event)
54     {
55     wxDirDialog* dlg;
56     wxString gotDirName;
57     wxString* dirName = new wxString();
58    
59     saveData();
60    
61     wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
62    
63     if(config->Read(wxT(CONF_WIKI_DIR), dirName)) {
64     if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){
65     delete config;
66     isEditing = FALSE;
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     isEditing = FALSE;
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     saveData();
91    
92     wikiList = wiki->search(str->mb_str());
93    
94     node = wikiList->GetFirst();
95     if(!node) {
96     wxLogMessage(wxT("Not Found! [%s]"), (const char*)str->c_str());
97     return;
98     }
99    
100     wiki->addSearchStr(str);
101     frame->showSearchResult(wiki);
102     isEditing = FALSE;
103     }
104    
105     void mnController::handleNewButton(wxCommandEvent& event)
106     {
107 maloninc 1.6 int ans;
108     WikiData* wikiData = wiki->newWikiData();
109     wxString plainTextStr;
110     wxString newSubjectStr;
111     mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note"));
112     const wxString* wikiText = wikiData->getText();
113     const wxString* subject = wikiData->getSubject();
114    
115     dlg->setSubject(*subject);
116     dlg->setPlainText(*wikiText);
117     ans = dlg->ShowModal();
118    
119     if(ans != wxID_OK) return ;
120    
121     plainTextStr = dlg->getPlainText();
122     newSubjectStr = dlg->getSubject();
123     wikiData->modText(&plainTextStr);
124     wikiData->save();
125    
126     wikiData->modSubject(&newSubjectStr);
127 maloninc 1.1
128 maloninc 1.6 frame->showSearchResult(wiki);
129     delete dlg;
130 maloninc 1.1 }
131    
132     void mnController::handleRemoveButton(wxCommandEvent& event)
133     {
134     wxTreeItemData* item = frame->getSelectedItem();
135    
136     if(item){
137     ((WikiData*)(item))->removeDataFile();
138     }
139     else {
140     wiki->removeSearchStr(frame->getSelectedLabel());
141     }
142     frame->showSearchResult(wiki);
143     isEditing = FALSE;
144     }
145    
146     void mnController::handleTreeItemSelect(wxTreeEvent& event)
147     {
148     frame->showSelectedItemText(event);
149     isEditing = FALSE;
150     }
151    
152    
153     void mnController::handleTreeItemSelecting(wxTreeEvent& event)
154     {
155     saveData();
156    
157     if(frame->isNewItem(event.GetOldItem())) {
158     frame->showSearchResult(wiki);
159     event.Veto();
160     }
161     }
162    
163     void mnController::handleBeginLabelEdit(wxTreeEvent& event)
164     {
165     if(!frame->isEditableTreeLabel(event.GetItem())) event.Veto();
166     }
167    
168     void mnController::handleEndLabelEdit(wxTreeEvent& event)
169     {
170     wxString newSubject = event.GetLabel();
171     wxTreeItemData* item = frame->getSelectedItem();
172    
173     saveData();
174    
175     if(item == NULL) return ;
176 maloninc 1.2
177 maloninc 1.1 if(newSubject.Len() == 0) {
178 maloninc 1.2 event.Veto();
179 maloninc 1.1 frame->showSearchResult(wiki);
180     return;
181     }
182    
183     ((WikiData*)(item))->modSubject(&newSubject);
184 maloninc 1.2 if(frame->isNewItem(event.GetItem())){
185     return;
186     }
187    
188     event.Veto();
189 maloninc 1.1 frame->showSearchResult(wiki);
190     }
191    
192     void mnController::handleClose(wxCloseEvent& event)
193     {
194     saveData();
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     void mnController::saveData()
241     {
242 maloninc 1.3 #if 0
243 maloninc 1.1 wxTreeItemData* item = frame->getSelectedItem();
244     wxString plainTextStr = frame->getPlainText();
245     if(item == NULL) return ;
246    
247     ((WikiData*)(item))->modText(&plainTextStr);
248     ((WikiData*)(item))->save();
249     //frame->showSearchResult(wiki);
250 maloninc 1.3 #endif
251 maloninc 1.1 }

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