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.6 by maloninc, Sun Jul 31 22:22:14 2005 UTC revision 1.10 by maloninc, Sat Aug 13 06:12:05 2005 UTC
# Line 4  Line 4 
4  #include "mnDef.h"  #include "mnDef.h"
5  #include "mnController.h"  #include "mnController.h"
6  #include <wx/config.h>  #include <wx/config.h>
7    #include <wx/tokenzr.h>
8    #include <wx/utils.h>
9    
10  BEGIN_EVENT_TABLE(mnController, wxEvtHandler)  BEGIN_EVENT_TABLE(mnController, wxEvtHandler)
11          EVT_TEXT_ENTER(ID_SearchTextCtrl, mnController::handleSearch)          EVT_TEXT_ENTER(ID_SearchTextCtrl, mnController::handleSearch)
# Line 18  BEGIN_EVENT_TABLE(mnController, wxEvtHan Line 20  BEGIN_EVENT_TABLE(mnController, wxEvtHan
20          EVT_MENU(ID_MenuFileConfig, mnController::handleConfig)          EVT_MENU(ID_MenuFileConfig, mnController::handleConfig)
21          EVT_MENU(wxID_ABOUT, mnController::handleAbout)          EVT_MENU(wxID_ABOUT, mnController::handleAbout)
22          EVT_CLOSE(mnController::handleClose)          EVT_CLOSE(mnController::handleClose)
23            EVT_COMMAND(ID_HtmlTextCtrl, mnEVT_LINK_CLICK, mnController::handleLinkClick)
24  END_EVENT_TABLE()  END_EVENT_TABLE()
25    
26  mnController::mnController(mnFrame* inframe)  mnController::mnController(mnFrame* inframe)
# Line 27  mnController::mnController(mnFrame* infr Line 30  mnController::mnController(mnFrame* infr
30          wxDirDialog* dlg;          wxDirDialog* dlg;
31    
32          frame = inframe;          frame = inframe;
         isEditing = FALSE;  
33    
34          /* create wiki model */          /* create wiki model */
35          wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));          wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
# Line 56  void mnController::handleConfig(wxComman Line 58  void mnController::handleConfig(wxComman
58          wxString gotDirName;          wxString gotDirName;
59          wxString* dirName = new wxString();          wxString* dirName = new wxString();
60    
         saveData();  
   
61          wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));          wxConfig* config = new wxConfig(wxT(CONF_APP_NAME));
62    
63          if(config->Read(wxT(CONF_WIKI_DIR), dirName)) {          if(config->Read(wxT(CONF_WIKI_DIR), dirName)) {
64                  if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){                  if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){
65                          delete config;                          delete config;
                         isEditing = FALSE;  
66                          return;                          return;
67                  }                  }
68          }                }      
# Line 78  void mnController::handleConfig(wxComman Line 77  void mnController::handleConfig(wxComman
77          delete config;          delete config;
78    
79          frame->showSearchResult(wiki);          frame->showSearchResult(wiki);
         isEditing = FALSE;  
80  }  }
81    
82  void mnController::handleSearch(wxCommandEvent& event)  void mnController::handleSearch(wxCommandEvent& event)
# Line 87  void mnController::handleSearch(wxComman Line 85  void mnController::handleSearch(wxComman
85          WikiList*       wikiList;          WikiList*       wikiList;
86          WikiList::Node* node;          WikiList::Node* node;
87    
         saveData();  
   
88          wikiList = wiki->search(str->mb_str());          wikiList = wiki->search(str->mb_str());
89    
90          node = wikiList->GetFirst();          node = wikiList->GetFirst();
# Line 99  void mnController::handleSearch(wxComman Line 95  void mnController::handleSearch(wxComman
95    
96          wiki->addSearchStr(str);          wiki->addSearchStr(str);
97          frame->showSearchResult(wiki);          frame->showSearchResult(wiki);
         isEditing = FALSE;  
98  }  }
99    
100  void mnController::handleNewButton(wxCommandEvent& event)  void mnController::handleNewButton(wxCommandEvent& event)
# Line 140  void mnController::handleRemoveButton(wx Line 135  void mnController::handleRemoveButton(wx
135                  wiki->removeSearchStr(frame->getSelectedLabel());                  wiki->removeSearchStr(frame->getSelectedLabel());
136          }          }
137          frame->showSearchResult(wiki);          frame->showSearchResult(wiki);
         isEditing = FALSE;  
138  }  }
139    
140  void mnController::handleTreeItemSelect(wxTreeEvent& event)  void mnController::handleTreeItemSelect(wxTreeEvent& event)
141  {  {
142          frame->showSelectedItemText(event);          frame->showSelectedItemText(event);
         isEditing = FALSE;  
143  }  }
144    
145    
146  void mnController::handleTreeItemSelecting(wxTreeEvent& event)  void mnController::handleTreeItemSelecting(wxTreeEvent& event)
147  {  {
         saveData();  
   
         if(frame->isNewItem(event.GetOldItem())) {  
                 frame->showSearchResult(wiki);  
                 event.Veto();  
         }  
148  }  }
149    
150  void mnController::handleBeginLabelEdit(wxTreeEvent& event)  void mnController::handleBeginLabelEdit(wxTreeEvent& event)
# Line 170  void mnController::handleEndLabelEdit(wx Line 157  void mnController::handleEndLabelEdit(wx
157          wxString newSubject   = event.GetLabel();          wxString newSubject   = event.GetLabel();
158          wxTreeItemData* item  = frame->getSelectedItem();          wxTreeItemData* item  = frame->getSelectedItem();
159    
160          saveData();          if(item == NULL) {
161                    return ;
162          if(item == NULL) return ;          }
163                    
164          if(newSubject.Len() == 0) {          if(newSubject.Len() == 0) {
165                  event.Veto();                  event.Veto();
# Line 181  void mnController::handleEndLabelEdit(wx Line 168  void mnController::handleEndLabelEdit(wx
168          }          }
169    
170          ((WikiData*)(item))->modSubject(&newSubject);          ((WikiData*)(item))->modSubject(&newSubject);
         if(frame->isNewItem(event.GetItem())){  
                 return;  
         }  
171    
172          event.Veto();          event.Veto();
173          frame->showSearchResult(wiki);          frame->showSearchResult(wiki);
# Line 191  void mnController::handleEndLabelEdit(wx Line 175  void mnController::handleEndLabelEdit(wx
175    
176  void mnController::handleClose(wxCloseEvent& event)  void mnController::handleClose(wxCloseEvent& event)
177  {  {
         saveData();  
178          frame->Destroy();          frame->Destroy();
179  }  }
180    
# Line 237  void mnController::handleEditButton(wxCo Line 220  void mnController::handleEditButton(wxCo
220          delete dlg;          delete dlg;
221  }  }
222    
223  void mnController::saveData()  void mnController::handleLinkClick(wxCommandEvent &event)
224    {
225            const wxString* wikiDataDir;
226            wxString href = event.GetString();
227            wxString tag;
228            wxString val;
229            wxString doc;
230            wxStringTokenizer tkz(href, wxT(":"));
231    
232            tag = tkz.GetNextToken();      
233            val = tkz.GetNextToken();
234            if(tag.CmpNoCase(wxT("mnlink")) == 0) {
235                    event.SetString(val);
236                    handleSearch(event);
237            }
238            else if(tag.CmpNoCase(wxT("mndoc")) == 0) {
239                    wikiDataDir = wiki->getWikiDataDir();
240                    doc = *wikiDataDir + wxT("/docs/") + val;
241                    openDoc(doc);
242            }
243            else {
244                    openUrl(href);
245            }
246    }
247    
248    void mnController::openUrl(wxString& url)
249    {
250            wxString cmd;
251    
252    #ifdef __WXMSW__
253            cmd.sprintf(wxT("explorer %s"), url.c_str());
254    #endif
255    
256    #ifdef __WXMAC__
257            cmd.sprintf(wxT("open %s"), url.c_str());
258    #endif
259    
260    #ifdef __WXCOCOA__
261            cmd.sprintf(wxT("open %s"), url.c_str());
262    #endif
263    
264    #ifdef __WXGTK__
265            wxLogMessage(wxT("Ooops!, I don't know how to launch %s"), url.c_str());
266            return;
267    #endif
268    
269            //wxExecute(argv);
270            wxExecute(cmd);
271    }
272    
273    void mnController::openDoc(wxString& doc)
274  {  {
275  #if 0          wxString cmd;
276          wxTreeItemData* item         = frame->getSelectedItem();  
277          wxString        plainTextStr = frame->getPlainText();  #ifdef __WXMSW__
278          if(item == NULL) return ;          cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());
   
         ((WikiData*)(item))->modText(&plainTextStr);  
         ((WikiData*)(item))->save();  
         //frame->showSearchResult(wiki);  
279  #endif  #endif
280    
281    #ifdef __WXMAC__
282            cmd.sprintf(wxT("open %s"), doc.c_str());
283    #endif
284    
285    #ifdef __WXCOCOA__
286            cmd.sprintf(wxT("open %s"), doc.c_str());
287    #endif
288    
289    #ifdef __WXGTK__
290            wxLogMessage(wxT("Ooops!, I don't know how to launch %s"), doc.c_str());
291            return;
292    #endif
293    
294            //wxExecute(argv);
295            wxExecute(cmd);
296  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.10

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