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.2 by maloninc, Wed Oct 5 04:55:48 2005 UTC revision 1.9 by maloninc, Fri Jan 20 12:49:54 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  END_EVENT_TABLE()  END_EVENT_TABLE()
24    
25  mnNotePanelController::mnNotePanelController(mnNotePanel* inPanel, wxString* inWikiDir)  mnNotePanelController::mnNotePanelController(mnNotePanel* inPanel, wxString* inWikiDir)
# Line 21  mnNotePanelController::mnNotePanelContro Line 28  mnNotePanelController::mnNotePanelContro
28          panel = inPanel;          panel = inPanel;
29  }  }
30    
31    mnNotePanelController::~mnNotePanelController()
32    {
33    }
34    
35    const wxString* mnNotePanelController::getWikiDataDir()
36    {
37            return  wiki->getWikiDataDir();
38    }
39    
40  void mnNotePanelController::handleSearch(wxCommandEvent& event)  void mnNotePanelController::handleSearch(wxCommandEvent& event)
41  {  {
42          wxString* str = new wxString(event.GetString());          wxString* str = new wxString(event.GetString());
# Line 202  void mnNotePanelController::handleEdit(w Line 218  void mnNotePanelController::handleEdit(w
218          delete dlg;          delete dlg;
219  }  }
220    
221    wxString mnNotePanelController::delPercent(const wxString& str)
222    {
223    #ifdef __WXMAC__
224            wxURI uri;
225            return uri.Unescape(str);
226    #else
227            return str;
228    #endif
229    }
230    
231    
232  void mnNotePanelController::notifyUpdate(WikiData* data)  void mnNotePanelController::notifyUpdate(WikiData* data)
233  {  {
234          const wxArrayString*  searchStrList= wiki->getSearchStrList();          const wxArrayString*  searchStrList= wiki->getSearchStrList();
# Line 227  void mnNotePanelController::notifyUpdate Line 254  void mnNotePanelController::notifyUpdate
254          data->setOldSubjectFromCurrent(); // restore old subject          data->setOldSubjectFromCurrent(); // restore old subject
255  }  }
256    
257    #ifdef __WXMAC__
258    void mnNotePanelController::handleLinkClick(wxWebKitStateChangedEvent &event)
259    #else
260  void mnNotePanelController::handleLinkClick(wxCommandEvent &event)  void mnNotePanelController::handleLinkClick(wxCommandEvent &event)
261    #endif
262  {  {
263            wxString href;
264          const wxString* wikiDataDir;          const wxString* wikiDataDir;
265          wxString href = event.GetString();  #ifdef __WXMAC__
266          wxString tag;          href = event.GetURL();
267          wxString val;          if (href.Find(wxT("file:///tmp/")) == -1 &&
268          wxString doc;          href.Length() != 0                   &&
269          wxStringTokenizer tkz(href, wxT(":"));          event.GetState() == wxWEBKIT_STATE_NEGOTIATING){
270                    ((wxWebKitCtrl*)(event.GetEventObject()))->Stop(); // Stop native webkit loading
271          tag = tkz.GetNextToken();                }
272          val = tkz.GetNextToken();          else {
273          if(tag.CmpNoCase(wxT("mnlink")) == 0) {                  event.Skip();
274                  event.SetString(val);          }
275    #else
276            href = event.GetString();
277    #endif
278    
279            if(href.Find(wxT("file:///tmp/")) != -1) {
280                    // do nothing
281            }
282            else if(href.Find(wxT(MNLINK)) != -1) {
283                    wxRegEx exp(wxT(MNLINK));
284                    exp.Replace(&href, wxT(""));
285                    event.SetString((delPercent(href)).c_str());
286                  handleSearch(event);                  handleSearch(event);
287          }          }
288          else if(tag.CmpNoCase(wxT("mndoc")) == 0) {          else if(href.Find(wxT(MNDOC)) != -1) {
289                    wxRegEx exp(wxT(MNDOC));
290                    exp.Replace(&href, wxT(""));
291                  wikiDataDir = wiki->getWikiDataDir();                  wikiDataDir = wiki->getWikiDataDir();
292                  doc = *wikiDataDir + wxT("/docs/") + val;                  wxString doc = *wikiDataDir + wxT(DOCS_DIR) + delPercent(href);
293                  openDoc(doc);                  openDoc(doc);
294          }          }
295          else {          else {
# Line 259  void mnNotePanelController::handleOpenDo Line 304  void mnNotePanelController::handleOpenDo
304          wxString docDir;          wxString docDir;
305    
306          wikiDataDir = wiki->getWikiDataDir();          wikiDataDir = wiki->getWikiDataDir();
307          docDir = *wikiDataDir + wxT("/docs/");          docDir = *wikiDataDir + wxT(DOCS_DIR);
308    
309          /* create docs directory, anyway */          /* create docs directory, anyway */
310          cmd.sprintf(wxT("mkdir %s"), docDir.c_str());          cmd.sprintf(wxT(MKDIR), docDir.c_str());
311          wxExecute(cmd);          wxExecute(cmd);
312    
313          /* open docs directory */          /* open docs directory */
314          openDoc(docDir);          openDir(docDir);
315  }  }
316    
317  void mnNotePanelController::openUrl(wxString& url)  void mnNotePanelController::openUrl(wxString& url)
# Line 278  void mnNotePanelController::openUrl(wxSt Line 323  void mnNotePanelController::openUrl(wxSt
323  #endif  #endif
324    
325  #ifdef __WXMAC__  #ifdef __WXMAC__
326          cmd.sprintf(wxT("open %s"), url.c_str());          cmd.sprintf(wxT("open \'%s\'"), url.c_str());
327  #endif  #endif
328    
329  #ifdef __WXCOCOA__  #ifdef __WXCOCOA__
330          cmd.sprintf(wxT("open %s"), url.c_str());          cmd.sprintf(wxT("open \'%s\'"), url.c_str());
331  #endif  #endif
332    
333  #ifdef __WXGTK__  #ifdef __WXGTK__
334          cmd.sprintf(wxT("gnome-open %s"), url.c_str());          cmd.sprintf(wxT("gnome-open \'%s\'"), url.c_str());
335  #endif  #endif
336    
337          //wxExecute(argv);          //wxExecute(argv);
# Line 298  void mnNotePanelController::openDoc(wxSt Line 343  void mnNotePanelController::openDoc(wxSt
343          wxString cmd;          wxString cmd;
344    
345  #ifdef __WXMSW__  #ifdef __WXMSW__
346          cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str());          wxString tempFile = wxFileName::CreateTempFileName(wxT("malonnote-temp"));
347            FILE* fp;
348    
349    wxLogMessage(wxT("temp:[%s]"), tempFile.c_str());
350    return;
351            fp = fopen(tempFile.mb_str(), "w");
352            fprintf(fp, "Set obj = CreateObject(\"Shell.Application\")\n");
353            fprintf(fp, "obj.Open \"%s\"", doc.mb_str());
354            fclose(fp);
355            ///cmd.sprintf(wxT("cscript \"%s\""), tempFile.c_str());
356    #endif
357    
358    #ifdef __WXMAC__
359            cmd.sprintf(wxT("open \'%s\'"), doc.c_str());
360    #endif
361    
362    #ifdef __WXCOCOA__
363            cmd.sprintf(wxT("open \'%s\'"), doc.c_str());
364    #endif
365    
366    #ifdef __WXGTK__
367            cmd.sprintf(wxT("gnome-open \'%s\'"), doc.c_str());
368    #endif
369    
370            wxExecute(cmd, wxEXEC_ASYNC);
371    }
372    
373    void mnNotePanelController::openDir(wxString& dir)
374    {
375            wxString cmd;
376    
377    #ifdef __WXMSW__
378            cmd.sprintf(wxT("explorer \"%s\""), dir.c_str());
379  #endif  #endif
380    
381  #ifdef __WXMAC__  #ifdef __WXMAC__
382          cmd.sprintf(wxT("open %s"), doc.c_str());          cmd.sprintf(wxT("open \'%s\'"), dir.c_str());
383  #endif  #endif
384    
385  #ifdef __WXCOCOA__  #ifdef __WXCOCOA__
386          cmd.sprintf(wxT("open %s"), doc.c_str());          cmd.sprintf(wxT("open \'%s\'"), dir.c_str());
387  #endif  #endif
388    
389  #ifdef __WXGTK__  #ifdef __WXGTK__
390          cmd.sprintf(wxT("gnome-open %s"), doc.c_str());          cmd.sprintf(wxT("gnome-open \'%s\'"), dir.c_str());
391  #endif  #endif
392    
393          wxExecute(cmd);          wxExecute(cmd);
394  }  }
395    
396    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.9

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