| 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) |
| 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) |
| 26 |
{ |
{ |
| 27 |
wiki = new mnModel(inWikiDir->mb_str()); |
wiki = new mnModel(inWikiDir->mb_str()); |
| 28 |
|
wiki->readAll(true); |
| 29 |
|
|
| 30 |
panel = inPanel; |
panel = inPanel; |
| 31 |
} |
} |
| 32 |
|
|
| 34 |
{ |
{ |
| 35 |
} |
} |
| 36 |
|
|
| 37 |
|
void mnNotePanelController::readAll() |
| 38 |
|
{ |
| 39 |
|
wiki->readAll(false); /* read wiki data in background */ |
| 40 |
|
} |
| 41 |
|
|
| 42 |
const wxString* mnNotePanelController::getWikiDataDir() |
const wxString* mnNotePanelController::getWikiDataDir() |
| 43 |
{ |
{ |
| 44 |
return wiki->getWikiDataDir(); |
return wiki->getWikiDataDir(); |
| 225 |
delete dlg; |
delete dlg; |
| 226 |
} |
} |
| 227 |
|
|
| 228 |
|
wxString mnNotePanelController::delPercent(const wxString& str) |
| 229 |
|
{ |
| 230 |
|
#ifdef __WXMAC__ |
| 231 |
|
wxURI uri; |
| 232 |
|
return uri.Unescape(str); |
| 233 |
|
#else |
| 234 |
|
return str; |
| 235 |
|
#endif |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
|
| 239 |
void mnNotePanelController::notifyUpdate(WikiData* data) |
void mnNotePanelController::notifyUpdate(WikiData* data) |
| 240 |
{ |
{ |
| 241 |
const wxArrayString* searchStrList= wiki->getSearchStrList(); |
const wxArrayString* searchStrList= wiki->getSearchStrList(); |
| 261 |
data->setOldSubjectFromCurrent(); // restore old subject |
data->setOldSubjectFromCurrent(); // restore old subject |
| 262 |
} |
} |
| 263 |
|
|
| 264 |
|
#ifdef __WXMAC__ |
| 265 |
|
void mnNotePanelController::handleLinkClick(wxWebKitStateChangedEvent &event) |
| 266 |
|
#else |
| 267 |
void mnNotePanelController::handleLinkClick(wxCommandEvent &event) |
void mnNotePanelController::handleLinkClick(wxCommandEvent &event) |
| 268 |
|
#endif |
| 269 |
{ |
{ |
| 270 |
|
wxString href; |
| 271 |
const wxString* wikiDataDir; |
const wxString* wikiDataDir; |
| 272 |
wxString href = event.GetString(); |
#ifdef __WXMAC__ |
| 273 |
wxString tag; |
href = event.GetURL(); |
| 274 |
wxString val; |
if (href.Find(wxT("file:///tmp/")) == -1 && |
| 275 |
wxString doc; |
href.Length() != 0 && |
| 276 |
wxStringTokenizer tkz(href, wxT(":")); |
event.GetState() == wxWEBKIT_STATE_NEGOTIATING){ |
| 277 |
|
((wxWebKitCtrl*)(event.GetEventObject()))->Stop(); // Stop native webkit loading |
| 278 |
tag = tkz.GetNextToken(); |
} |
| 279 |
val = tkz.GetNextToken(); |
else { |
| 280 |
if(tag.CmpNoCase(wxT("mnlink")) == 0) { |
event.Skip(); |
| 281 |
event.SetString(val); |
} |
| 282 |
|
#else |
| 283 |
|
href = event.GetString(); |
| 284 |
|
#endif |
| 285 |
|
|
| 286 |
|
if(href.Find(wxT("file:///tmp/")) != -1) { |
| 287 |
|
// do nothing |
| 288 |
|
} |
| 289 |
|
else if(href.Find(wxT(MNLINK)) != -1) { |
| 290 |
|
wxRegEx exp(wxT(MNLINK)); |
| 291 |
|
exp.Replace(&href, wxT("")); |
| 292 |
|
event.SetString((delPercent(href)).c_str()); |
| 293 |
handleSearch(event); |
handleSearch(event); |
| 294 |
} |
} |
| 295 |
else if(tag.CmpNoCase(wxT("mndoc")) == 0) { |
else if(href.Find(wxT(MNDOC)) != -1) { |
| 296 |
|
wxRegEx exp(wxT(MNDOC)); |
| 297 |
|
exp.Replace(&href, wxT("")); |
| 298 |
wikiDataDir = wiki->getWikiDataDir(); |
wikiDataDir = wiki->getWikiDataDir(); |
| 299 |
doc = *wikiDataDir + wxT("/docs/") + val; |
wxString doc = *wikiDataDir + wxT(DOCS_DIR) + delPercent(href); |
| 300 |
openDoc(doc); |
openDoc(doc); |
| 301 |
} |
} |
| 302 |
else { |
else { |
| 311 |
wxString docDir; |
wxString docDir; |
| 312 |
|
|
| 313 |
wikiDataDir = wiki->getWikiDataDir(); |
wikiDataDir = wiki->getWikiDataDir(); |
| 314 |
docDir = *wikiDataDir + wxT("/docs/"); |
docDir = *wikiDataDir + wxT(DOCS_DIR); |
| 315 |
|
|
| 316 |
/* create docs directory, anyway */ |
/* create docs directory, anyway */ |
| 317 |
cmd.sprintf(wxT("mkdir %s"), docDir.c_str()); |
cmd.sprintf(wxT(MKDIR), docDir.c_str()); |
| 318 |
wxExecute(cmd); |
wxExecute(cmd); |
| 319 |
|
|
| 320 |
/* open docs directory */ |
/* open docs directory */ |
| 321 |
openDoc(docDir); |
openDir(docDir); |
| 322 |
} |
} |
| 323 |
|
|
| 324 |
void mnNotePanelController::openUrl(wxString& url) |
void mnNotePanelController::openUrl(wxString& url) |
| 330 |
#endif |
#endif |
| 331 |
|
|
| 332 |
#ifdef __WXMAC__ |
#ifdef __WXMAC__ |
| 333 |
cmd.sprintf(wxT("open %s"), url.c_str()); |
cmd.sprintf(wxT("open \'%s\'"), url.c_str()); |
| 334 |
#endif |
#endif |
| 335 |
|
|
| 336 |
#ifdef __WXCOCOA__ |
#ifdef __WXCOCOA__ |
| 337 |
cmd.sprintf(wxT("open %s"), url.c_str()); |
cmd.sprintf(wxT("open \'%s\'"), url.c_str()); |
| 338 |
#endif |
#endif |
| 339 |
|
|
| 340 |
#ifdef __WXGTK__ |
#ifdef __WXGTK__ |
| 341 |
cmd.sprintf(wxT("gnome-open %s"), url.c_str()); |
cmd.sprintf(wxT("gnome-open \'%s\'"), url.c_str()); |
| 342 |
#endif |
#endif |
| 343 |
|
|
| 344 |
//wxExecute(argv); |
//wxExecute(argv); |
| 350 |
wxString cmd; |
wxString cmd; |
| 351 |
|
|
| 352 |
#ifdef __WXMSW__ |
#ifdef __WXMSW__ |
| 353 |
cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str()); |
#include <windows.h> |
| 354 |
|
ShellExecute(NULL, wxT("OPEN"), doc.c_str(), NULL, NULL, SW_SHOWNORMAL); |
| 355 |
|
return; |
| 356 |
#endif |
#endif |
| 357 |
|
|
| 358 |
#ifdef __WXMAC__ |
#ifdef __WXMAC__ |
| 359 |
cmd.sprintf(wxT("open %s"), doc.c_str()); |
cmd.sprintf(wxT("open \'%s\'"), doc.c_str()); |
| 360 |
#endif |
#endif |
| 361 |
|
|
| 362 |
#ifdef __WXCOCOA__ |
#ifdef __WXCOCOA__ |
| 363 |
cmd.sprintf(wxT("open %s"), doc.c_str()); |
cmd.sprintf(wxT("open \'%s\'"), doc.c_str()); |
| 364 |
#endif |
#endif |
| 365 |
|
|
| 366 |
#ifdef __WXGTK__ |
#ifdef __WXGTK__ |
| 367 |
cmd.sprintf(wxT("gnome-open %s"), doc.c_str()); |
cmd.sprintf(wxT("gnome-open \'%s\'"), doc.c_str()); |
| 368 |
#endif |
#endif |
| 369 |
|
|
| 370 |
wxExecute(cmd); |
wxExecute(cmd); |
| 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 |
| 380 |
|
|
| 381 |
|
#ifdef __WXMAC__ |
| 382 |
|
cmd.sprintf(wxT("open \'%s\'"), dir.c_str()); |
| 383 |
|
#endif |
| 384 |
|
|
| 385 |
|
#ifdef __WXCOCOA__ |
| 386 |
|
cmd.sprintf(wxT("open \'%s\'"), dir.c_str()); |
| 387 |
|
#endif |
| 388 |
|
|
| 389 |
|
#ifdef __WXGTK__ |
| 390 |
|
cmd.sprintf(wxT("gnome-open \'%s\'"), dir.c_str()); |
| 391 |
|
#endif |
| 392 |
|
|
| 393 |
|
wxExecute(cmd); |
| 394 |
|
} |
| 395 |
|
|
| 396 |
|
|