Develop and Download Open Source Software

Browse CVS Repository

Diff of /malonnote/mnController.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.8 by maloninc, Tue Aug 2 07:21:38 2005 UTC revision 1.17 by maloninc, Thu Sep 15 03:02:37 2005 UTC
# Line 15  BEGIN_EVENT_TABLE(mnController, wxEvtHan Line 15  BEGIN_EVENT_TABLE(mnController, wxEvtHan
15          EVT_TREE_END_LABEL_EDIT(ID_SearchTree, mnController::handleEndLabelEdit)          EVT_TREE_END_LABEL_EDIT(ID_SearchTree, mnController::handleEndLabelEdit)
16          EVT_MENU(ID_MenuFileNew, mnController::handleNewButton)          EVT_MENU(ID_MenuFileNew, mnController::handleNewButton)
17          EVT_MENU(ID_MenuFileRemove, mnController::handleRemoveButton)          EVT_MENU(ID_MenuFileRemove, mnController::handleRemoveButton)
18            EVT_MENU(ID_MenuFileHighlight, mnController::handleHighlightButton)
19          EVT_MENU(ID_MenuFileEdit, mnController::handleEditButton)          EVT_MENU(ID_MenuFileEdit, mnController::handleEditButton)
20          EVT_MENU(ID_MenuFileExit, mnController::handleExit)          EVT_MENU(ID_MenuFileExit, mnController::handleExit)
21          EVT_MENU(ID_MenuFileConfig, mnController::handleConfig)          EVT_MENU(ID_MenuFileConfig, mnController::handleConfig)
22            EVT_MENU(ID_MenuFileGroup, mnController::handleGroup)
23            EVT_MENU(ID_MenuTreeExpand, mnController::handleTreeExpand)
24            EVT_MENU(ID_MenuTreeCollapse, mnController::handleTreeCollapse)
25            EVT_MENU(ID_MenuTreeDisableUpdate, mnController::handleTreeDisableUpdate)
26            EVT_MENU(ID_MenuTreeClear, mnController::handleTreeClear)
27          EVT_MENU(wxID_ABOUT, mnController::handleAbout)          EVT_MENU(wxID_ABOUT, mnController::handleAbout)
28          EVT_CLOSE(mnController::handleClose)          EVT_CLOSE(mnController::handleClose)
29          EVT_COMMAND(ID_HtmlTextCtrl, mnEVT_LINK_CLICK, mnController::handleLinkClick)          EVT_COMMAND(ID_HtmlTextCtrl, mnEVT_LINK_CLICK, mnController::handleLinkClick)
# Line 30  mnController::mnController(mnFrame* infr Line 36  mnController::mnController(mnFrame* infr
36          wxDirDialog* dlg;          wxDirDialog* dlg;
37    
38          frame = inframe;          frame = inframe;
         isEditing = FALSE;  
39    
40          /* create wiki model */          /* create wiki model */
41          wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));          wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
# Line 50  mnController::mnController(mnFrame* infr Line 55  mnController::mnController(mnFrame* infr
55                  wiki = new mnModel(dirName->mb_str());                  wiki = new mnModel(dirName->mb_str());
56          }          }
57    
58            autoUpdateMode = true;
59          delete config;          delete config;
60  }  }
61    
# Line 64  void mnController::handleConfig(wxComman Line 70  void mnController::handleConfig(wxComman
70          if(config->Read(wxT(CONF_WIKI_DIR), dirName)) {          if(config->Read(wxT(CONF_WIKI_DIR), dirName)) {
71                  if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){                  if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){
72                          delete config;                          delete config;
                         isEditing = FALSE;  
73                          return;                          return;
74                  }                  }
75          }                }      
# Line 78  void mnController::handleConfig(wxComman Line 83  void mnController::handleConfig(wxComman
83          }          }
84          delete config;          delete config;
85    
86          frame->showSearchResult(wiki);          if(autoUpdateMode)
87          isEditing = FALSE;                  frame->showSearchResult(wiki);
88  }  }
89    
90  void mnController::handleSearch(wxCommandEvent& event)  void mnController::handleSearch(wxCommandEvent& event)
# Line 97  void mnController::handleSearch(wxComman Line 102  void mnController::handleSearch(wxComman
102          }          }
103    
104          wiki->addSearchStr(str);          wiki->addSearchStr(str);
105          frame->showSearchResult(wiki);  
106          isEditing = FALSE;          if(autoUpdateMode)
107                    frame->showSearchResult(wiki);
108            else
109                    frame->addSearchResult(wiki, str);
110    }
111    
112    void mnController::handleGroup(wxCommandEvent& event)
113    {
114            wiki->group();
115            
116            if(autoUpdateMode)
117                    frame->showSearchResult(wiki, false);
118            else
119                    wxLogMessage(wxT("Pleas enable AutoUpdate"));
120  }  }
121    
122    
123  void mnController::handleNewButton(wxCommandEvent& event)  void mnController::handleNewButton(wxCommandEvent& event)
124  {  {
125          int             ans;          int             ans;
# Line 124  void mnController::handleNewButton(wxCom Line 143  void mnController::handleNewButton(wxCom
143    
144          wikiData->modSubject(&newSubjectStr);          wikiData->modSubject(&newSubjectStr);
145    
146          frame->showSearchResult(wiki);          if(autoUpdateMode)
147                    frame->showSearchResult(wiki);
148          delete dlg;          delete dlg;
149  }  }
150    
# Line 133  void mnController::handleRemoveButton(wx Line 153  void mnController::handleRemoveButton(wx
153          wxTreeItemData* item = frame->getSelectedItem();          wxTreeItemData* item = frame->getSelectedItem();
154    
155          if(item){          if(item){
156                  ((WikiData*)(item))->removeDataFile();                  if(wxMessageBox(wxT("Do you realy remove this memo?\n") + frame->getSelectedLabel(), wxT("Realy?"), wxYES_NO|wxICON_QUESTION) == wxYES){
157                            ((WikiData*)(item))->removeDataFile();
158                    }
159                    else {
160                            return;
161                    }
162          }          }
163          else {          else {
164                  wiki->removeSearchStr(frame->getSelectedLabel());                  wiki->removeSearchStr(frame->getSelectedLabel());
165          }          }
166          frame->showSearchResult(wiki);  
167          isEditing = FALSE;          if(autoUpdateMode)
168                    frame->showSearchResult(wiki);
169            else
170                    frame->removeSelectedItem();
171  }  }
172    
173    void mnController::handleHighlightButton(wxCommandEvent& event)
174    {
175            frame->highlightSelectedItem();
176    }
177    
178    
179  void mnController::handleTreeItemSelect(wxTreeEvent& event)  void mnController::handleTreeItemSelect(wxTreeEvent& event)
180  {  {
181          frame->showSelectedItemText(event);          frame->showSelectedItemText(event);
         isEditing = FALSE;  
182  }  }
183    
184    
185  void mnController::handleTreeItemSelecting(wxTreeEvent& event)  void mnController::handleTreeItemSelecting(wxTreeEvent& event)
186  {  {
         if(frame->isNewItem(event.GetOldItem())) {  
                 frame->showSearchResult(wiki);  
                 event.Veto();  
         }  
187  }  }
188    
189  void mnController::handleBeginLabelEdit(wxTreeEvent& event)  void mnController::handleBeginLabelEdit(wxTreeEvent& event)
# Line 167  void mnController::handleEndLabelEdit(wx Line 196  void mnController::handleEndLabelEdit(wx
196          wxString newSubject   = event.GetLabel();          wxString newSubject   = event.GetLabel();
197          wxTreeItemData* item  = frame->getSelectedItem();          wxTreeItemData* item  = frame->getSelectedItem();
198    
199          if(item == NULL) return ;          if(item == NULL) {
200                    return ;
201            }
202                    
203          if(newSubject.Len() == 0) {          if(newSubject.Len() == 0) {
204                  event.Veto();                  event.Veto();
205                  frame->showSearchResult(wiki);                  if(autoUpdateMode)
206                            frame->showSearchResult(wiki);
207                  return;                  return;
208          }          }
209    
210          ((WikiData*)(item))->modSubject(&newSubject);          ((WikiData*)(item))->modSubject(&newSubject);
         if(frame->isNewItem(event.GetItem())){  
                 return;  
         }  
211    
212          event.Veto();          event.Veto();
213          frame->showSearchResult(wiki);  
214            if(autoUpdateMode)
215                    frame->showSearchResult(wiki);
216  }  }
217    
218  void mnController::handleClose(wxCloseEvent& event)  void mnController::handleClose(wxCloseEvent& event)
# Line 194  void mnController::handleExit(wxCommandE Line 225  void mnController::handleExit(wxCommandE
225          frame->Close();          frame->Close();
226  }  }
227    
228    void mnController::handleTreeExpand(wxCommandEvent& event)
229    {
230            frame->expandAllTree();
231    }
232    
233    void mnController::handleTreeCollapse(wxCommandEvent& event)
234    {
235            frame->collapseAllTree();
236    }
237    
238    void mnController::handleTreeClear(wxCommandEvent& event)
239    {
240            frame->clearAllTree();
241    }
242    
243    void mnController::handleTreeDisableUpdate(wxCommandEvent& event)
244    {
245            autoUpdateMode = (autoUpdateMode) ? false : true;
246            if(autoUpdateMode)
247                    frame->showSearchResult(wiki);
248    }
249    
250  void mnController::handleAbout(wxCommandEvent& event)  void mnController::handleAbout(wxCommandEvent& event)
251  {  {
# Line 227  void mnController::handleEditButton(wxCo Line 279  void mnController::handleEditButton(wxCo
279    
280          ((WikiData*)(itemData))->modSubject(&newSubjectStr);          ((WikiData*)(itemData))->modSubject(&newSubjectStr);
281    
282          frame->showSearchResult(wiki);          if(autoUpdateMode)
283                    frame->showSearchResult(wiki);
284          delete dlg;          delete dlg;
285  }  }
286    
287  void mnController::handleLinkClick(wxCommandEvent &event)  void mnController::handleLinkClick(wxCommandEvent &event)
288  {  {
289            const wxString* wikiDataDir;
290          wxString href = event.GetString();          wxString href = event.GetString();
291          wxString tag;          wxString tag;
292          wxString url;          wxString val;
293            wxString doc;
294          wxStringTokenizer tkz(href, wxT(":"));          wxStringTokenizer tkz(href, wxT(":"));
295    
296          tag = tkz.GetNextToken();                tag = tkz.GetNextToken();      
297          url = tkz.GetNextToken();          val = tkz.GetNextToken();
298            if(tag.CmpNoCase(wxT("mnlink")) == 0) {
299          if(tag.Cmp(wxT("mnlink")) == 0) {                  event.SetString(val);
                 event.SetString(url);  
300                  handleSearch(event);                  handleSearch(event);
301          }          }
302            else if(tag.CmpNoCase(wxT("mndoc")) == 0) {
303                    wikiDataDir = wiki->getWikiDataDir();
304                    doc = *wikiDataDir + wxT("/docs/") + val;
305                    openDoc(doc);
306            }
307          else {          else {
308                  openUrl(href);                  openUrl(href);
309          }          }
# Line 252  void mnController::handleLinkClick(wxCom Line 311  void mnController::handleLinkClick(wxCom
311    
312  void mnController::openUrl(wxString& url)  void mnController::openUrl(wxString& url)
313  {  {
         wxChar* argv[5];  
314          wxString cmd;          wxString cmd;
315    
316  #ifdef __WXMSW__  #ifdef __WXMSW__
         argv[0] = wxT("explorer");  
         argv[1] = (wxChar*)url.c_str();  
         argv[2] = NULL;  
317          cmd.sprintf(wxT("explorer %s"), url.c_str());          cmd.sprintf(wxT("explorer %s"), url.c_str());
318  #endif  #endif
319    
# Line 271  void mnController::openUrl(wxString& url Line 326  void mnController::openUrl(wxString& url
326  #endif  #endif
327    
328  #ifdef __WXGTK__  #ifdef __WXGTK__
329          wxLogMessage(wxT("Ooops!, I don't know how to launch %s"), url.c_str());          cmd.sprintf(wxT("gnome-open %s"), url.c_str());
         return;  
330  #endif  #endif
331    
332          //wxExecute(argv);          //wxExecute(argv);
333          wxExecute(cmd);          wxExecute(cmd);
334  }  }
335    
336    void mnController::openDoc(wxString& doc)
337    {
338            wxString cmd;
339    
340    #ifdef __WXMSW__
341            cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());
342    #endif
343    
344    #ifdef __WXMAC__
345            cmd.sprintf(wxT("open %s"), doc.c_str());
346    #endif
347    
348    #ifdef __WXCOCOA__
349            cmd.sprintf(wxT("open %s"), doc.c_str());
350    #endif
351    
352    #ifdef __WXGTK__
353            cmd.sprintf(wxT("gnome-open %s"), doc.c_str());
354    #endif
355    
356            wxExecute(cmd);
357    }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.17

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