Develop and Download Open Source Software

Browse CVS Repository

Diff of /malonnote/mnNotePanelController.cpp

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

revision 1.4 by maloninc, Fri Oct 7 12:49:26 2005 UTC revision 1.13 by maloninc, Mon Oct 23 08:00:09 2006 UTC
# Line 1  Line 1 
1  #include "mnID.h"  #include "mnID.h"
2  #include "mnDef.h"  #include "mnDef.h"
3    #include "mnNotePanel.h"
4  #include "mnNotePanelController.h"  #include "mnNotePanelController.h"
5    #include <wx/uri.h>
6  #include <wx/config.h>  #include <wx/config.h>
7  #include <wx/tokenzr.h>  #include <wx/regex.h>
8  #include <wx/utils.h>  #include <wx/utils.h>
9  #include <wx/xrc/xmlres.h>  #include <wx/xrc/xmlres.h>
10    #include <wx/tokenzr.h>
11    
12  BEGIN_EVENT_TABLE(mnNotePanelController, wxEvtHandler)  BEGIN_EVENT_TABLE(mnNotePanelController, wxEvtHandler)
13          EVT_TEXT_ENTER(XRCID("searchTextCtrl"), mnNotePanelController::handleSearch)          EVT_TEXT_ENTER(XRCID("searchTextCtrl"), mnNotePanelController::handleSearch)
# Line 12  BEGIN_EVENT_TABLE(mnNotePanelController, Line 15  BEGIN_EVENT_TABLE(mnNotePanelController,
15          EVT_TREE_SEL_CHANGING(XRCID("searchTree"), mnNotePanelController::handleTreeItemSelecting)          EVT_TREE_SEL_CHANGING(XRCID("searchTree"), mnNotePanelController::handleTreeItemSelecting)
16          EVT_TREE_BEGIN_LABEL_EDIT(XRCID("searchTree"), mnNotePanelController::handleBeginLabelEdit)          EVT_TREE_BEGIN_LABEL_EDIT(XRCID("searchTree"), mnNotePanelController::handleBeginLabelEdit)
17          EVT_TREE_END_LABEL_EDIT(XRCID("searchTree"), mnNotePanelController::handleEndLabelEdit)          EVT_TREE_END_LABEL_EDIT(XRCID("searchTree"), mnNotePanelController::handleEndLabelEdit)
18    #ifdef __WXMAC__
19        EVT_WEBKIT_STATE_CHANGED(mnNotePanelController::handleLinkClick)
20    #else
21          EVT_COMMAND(XRCID("wikiHtmlTextCtrl"), mnEVT_LINK_CLICK, mnNotePanelController::handleLinkClick)          EVT_COMMAND(XRCID("wikiHtmlTextCtrl"), mnEVT_LINK_CLICK, mnNotePanelController::handleLinkClick)
22    #endif
23            EVT_TIMER(wxID_ANY, mnNotePanelController::readAll)
24  END_EVENT_TABLE()  END_EVENT_TABLE()
25    
26  mnNotePanelController::mnNotePanelController(mnNotePanel* inPanel, wxString* inWikiDir)  mnNotePanelController::mnNotePanelController(mnNotePanel* inPanel, wxString* inWikiDir)
27  {  {
28          wiki = new mnModel(inWikiDir->mb_str());          wiki = new mnModel(inWikiDir->mb_str());
29            wiki->readAll(true);
30    
31            wxTimer* timer = new wxTimer(this);
32            timer->Start(MN_READ_INTERVAL);
33    
34          panel = inPanel;          panel = inPanel;
35  }  }
36    
# Line 25  mnNotePanelController::~mnNotePanelContr Line 38  mnNotePanelController::~mnNotePanelContr
38  {  {
39  }  }
40    
41    void mnNotePanelController::readAll(wxTimerEvent& event)
42    {
43            wiki->readAll(false); /* read wiki data in background */
44    }
45    
46  const wxString* mnNotePanelController::getWikiDataDir()  const wxString* mnNotePanelController::getWikiDataDir()
47  {  {
48          return  wiki->getWikiDataDir();          return  wiki->getWikiDataDir();
# Line 211  void mnNotePanelController::handleEdit(w Line 229  void mnNotePanelController::handleEdit(w
229          delete dlg;          delete dlg;
230  }  }
231    
232    wxString mnNotePanelController::delPercent(const wxString& str)
233    {
234    #ifdef __WXMAC__
235            wxURI uri;
236            return uri.Unescape(str);
237    #else
238            return str;
239    #endif
240    }
241    
242    
243  void mnNotePanelController::notifyUpdate(WikiData* data)  void mnNotePanelController::notifyUpdate(WikiData* data)
244  {  {
245          const wxArrayString*  searchStrList= wiki->getSearchStrList();          const wxArrayString*  searchStrList= wiki->getSearchStrList();
# Line 236  void mnNotePanelController::notifyUpdate Line 265  void mnNotePanelController::notifyUpdate
265          data->setOldSubjectFromCurrent(); // restore old subject          data->setOldSubjectFromCurrent(); // restore old subject
266  }  }
267    
268    #ifdef __WXMAC__
269    void mnNotePanelController::handleLinkClick(wxWebKitStateChangedEvent &event)
270    #else
271  void mnNotePanelController::handleLinkClick(wxCommandEvent &event)  void mnNotePanelController::handleLinkClick(wxCommandEvent &event)
272    #endif
273  {  {
274            wxString href;
275          const wxString* wikiDataDir;          const wxString* wikiDataDir;
276          wxString href = event.GetString();  #ifdef __WXMAC__
277          wxString tag;          href = event.GetURL();
278          wxString val;          if (href.Find(wxT("file:///tmp/")) == -1 &&
279          wxString doc;          href.Length() != 0                   &&
280          wxStringTokenizer tkz(href, wxT(":"));          event.GetState() == wxWEBKIT_STATE_NEGOTIATING){
281                    ((wxWebKitCtrl*)(event.GetEventObject()))->Stop(); // Stop native webkit loading
282          tag = tkz.GetNextToken();                }
283          val = tkz.GetNextToken();          else {
284          if(tag.CmpNoCase(wxT("mnlink")) == 0) {                  event.Skip();
285                  event.SetString(val);          }
286    #else
287            href = event.GetString();
288    #endif
289    
290            if(href.Find(wxT("file:///tmp/")) != -1) {
291                    // do nothing
292            }
293            else if(href.Find(wxT(MNLINK)) != -1) {
294                    wxRegEx exp(wxT(MNLINK));
295                    exp.Replace(&href, wxT(""));
296                    event.SetString((delPercent(href)).c_str());
297                  handleSearch(event);                  handleSearch(event);
298          }          }
299          else if(tag.CmpNoCase(wxT("mndoc")) == 0) {          else if(href.Find(wxT(MNDOC)) != -1) {
300                    wxRegEx exp(wxT(MNDOC));
301                    exp.Replace(&href, wxT(""));
302                  wikiDataDir = wiki->getWikiDataDir();                  wikiDataDir = wiki->getWikiDataDir();
303                  doc = *wikiDataDir + wxT("/docs/") + val;                  wxString doc = *wikiDataDir + wxT(DOCS_DIR) + delPercent(href);
304                  openDoc(doc);                  openDoc(doc);
305          }          }
306          else {          else {
# Line 268  void mnNotePanelController::handleOpenDo Line 315  void mnNotePanelController::handleOpenDo
315          wxString docDir;          wxString docDir;
316    
317          wikiDataDir = wiki->getWikiDataDir();          wikiDataDir = wiki->getWikiDataDir();
318          docDir = *wikiDataDir + wxT("/docs/");          docDir = *wikiDataDir + wxT(DOCS_DIR);
319    
320          /* create docs directory, anyway */          /* create docs directory, anyway */
321          cmd.sprintf(wxT("mkdir %s"), docDir.c_str());          cmd.sprintf(wxT(MKDIR), docDir.c_str());
322          wxExecute(cmd);          wxExecute(cmd);
323    
324          /* open docs directory */          /* open docs directory */
325          openDoc(docDir);          openDir(docDir);
326  }  }
327    
328  void mnNotePanelController::openUrl(wxString& url)  void mnNotePanelController::openUrl(wxString& url)
# Line 287  void mnNotePanelController::openUrl(wxSt Line 334  void mnNotePanelController::openUrl(wxSt
334  #endif  #endif
335    
336  #ifdef __WXMAC__  #ifdef __WXMAC__
337          cmd.sprintf(wxT("open %s"), url.c_str());          cmd.sprintf(wxT("open \'%s\'"), url.c_str());
338  #endif  #endif
339    
340  #ifdef __WXCOCOA__  #ifdef __WXCOCOA__
341          cmd.sprintf(wxT("open %s"), url.c_str());          cmd.sprintf(wxT("open \'%s\'"), url.c_str());
342  #endif  #endif
343    
344  #ifdef __WXGTK__  #ifdef __WXGTK__
345          cmd.sprintf(wxT("gnome-open %s"), url.c_str());          cmd.sprintf(wxT("gnome-open \'%s\'"), url.c_str());
346  #endif  #endif
347    
348          //wxExecute(argv);          //wxExecute(argv);
# Line 307  void mnNotePanelController::openDoc(wxSt Line 354  void mnNotePanelController::openDoc(wxSt
354          wxString cmd;          wxString cmd;
355    
356  #ifdef __WXMSW__  #ifdef __WXMSW__
357          cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());  #include <windows.h>
358            ShellExecute(NULL, wxT("OPEN"), doc.c_str(), NULL, NULL, SW_SHOWNORMAL);
359            return;
360  #endif  #endif
361    
362  #ifdef __WXMAC__  #ifdef __WXMAC__
363          cmd.sprintf(wxT("open %s"), doc.c_str());          cmd.sprintf(wxT("open \'%s\'"), doc.c_str());
364  #endif  #endif
365    
366  #ifdef __WXCOCOA__  #ifdef __WXCOCOA__
367          cmd.sprintf(wxT("open %s"), doc.c_str());          cmd.sprintf(wxT("open \'%s\'"), doc.c_str());
368  #endif  #endif
369    
370  #ifdef __WXGTK__  #ifdef __WXGTK__
371          cmd.sprintf(wxT("gnome-open %s"), doc.c_str());          cmd.sprintf(wxT("gnome-open \'%s\'"), doc.c_str());
372  #endif  #endif
373    
374          wxExecute(cmd);          wxExecute(cmd);
375  }  }
376    
377    void mnNotePanelController::openDir(wxString& dir)
378    {
379            wxString cmd;
380    
381    #ifdef __WXMSW__
382            cmd.sprintf(wxT("explorer \"%s\""), dir.c_str());
383    #endif
384    
385    #ifdef __WXMAC__
386            cmd.sprintf(wxT("open \'%s\'"), dir.c_str());
387    #endif
388    
389    #ifdef __WXCOCOA__
390            cmd.sprintf(wxT("open \'%s\'"), dir.c_str());
391    #endif
392    
393    #ifdef __WXGTK__
394            cmd.sprintf(wxT("gnome-open \'%s\'"), dir.c_str());
395    #endif
396    
397            wxExecute(cmd);
398    }
399    
400    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.13

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