| 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) |
| 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) |
| 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(wxID_ABOUT, mnController::handleAbout) |
EVT_MENU(wxID_ABOUT, mnController::handleAbout) |
| 23 |
EVT_CLOSE(mnController::handleClose) |
EVT_CLOSE(mnController::handleClose) |
| 24 |
|
EVT_COMMAND(ID_HtmlTextCtrl, mnEVT_LINK_CLICK, mnController::handleLinkClick) |
| 25 |
END_EVENT_TABLE() |
END_EVENT_TABLE() |
| 26 |
|
|
| 27 |
mnController::mnController(mnFrame* inframe) |
mnController::mnController(mnFrame* inframe) |
| 31 |
wxDirDialog* dlg; |
wxDirDialog* dlg; |
| 32 |
|
|
| 33 |
frame = inframe; |
frame = inframe; |
|
isEditing = FALSE; |
|
| 34 |
|
|
| 35 |
/* create wiki model */ |
/* create wiki model */ |
| 36 |
wxConfig* config = new wxConfig(wxT(CONF_APP_NAME)); |
wxConfig* config = new wxConfig(wxT(CONF_APP_NAME)); |
| 59 |
wxString gotDirName; |
wxString gotDirName; |
| 60 |
wxString* dirName = new wxString(); |
wxString* dirName = new wxString(); |
| 61 |
|
|
|
saveData(); |
|
|
|
|
| 62 |
wxConfig* config = new wxConfig(wxT(CONF_APP_NAME)); |
wxConfig* config = new wxConfig(wxT(CONF_APP_NAME)); |
| 63 |
|
|
| 64 |
if(config->Read(wxT(CONF_WIKI_DIR), dirName)) { |
if(config->Read(wxT(CONF_WIKI_DIR), dirName)) { |
| 65 |
if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){ |
if(wxMessageBox(*dirName, wxT("Change data directory?"), wxYES_NO|wxICON_QUESTION) == wxNO){ |
| 66 |
delete config; |
delete config; |
|
isEditing = FALSE; |
|
| 67 |
return; |
return; |
| 68 |
} |
} |
| 69 |
} |
} |
| 78 |
delete config; |
delete config; |
| 79 |
|
|
| 80 |
frame->showSearchResult(wiki); |
frame->showSearchResult(wiki); |
|
isEditing = FALSE; |
|
| 81 |
} |
} |
| 82 |
|
|
| 83 |
void mnController::handleSearch(wxCommandEvent& event) |
void mnController::handleSearch(wxCommandEvent& event) |
| 86 |
WikiList* wikiList; |
WikiList* wikiList; |
| 87 |
WikiList::Node* node; |
WikiList::Node* node; |
| 88 |
|
|
|
saveData(); |
|
|
|
|
| 89 |
wikiList = wiki->search(str->mb_str()); |
wikiList = wiki->search(str->mb_str()); |
| 90 |
|
|
| 91 |
node = wikiList->GetFirst(); |
node = wikiList->GetFirst(); |
| 96 |
|
|
| 97 |
wiki->addSearchStr(str); |
wiki->addSearchStr(str); |
| 98 |
frame->showSearchResult(wiki); |
frame->showSearchResult(wiki); |
|
isEditing = FALSE; |
|
| 99 |
} |
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
void mnController::handleNewButton(wxCommandEvent& event) |
void mnController::handleNewButton(wxCommandEvent& event) |
| 103 |
{ |
{ |
| 104 |
if(isEditing) return; |
int ans; |
|
|
|
| 105 |
WikiData* wikiData = wiki->newWikiData(); |
WikiData* wikiData = wiki->newWikiData(); |
| 106 |
frame->showNewItem(wikiData); |
wxString plainTextStr; |
| 107 |
saveData(); |
wxString newSubjectStr; |
| 108 |
isEditing = TRUE; |
mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note")); |
| 109 |
|
const wxString* wikiText = wikiData->getText(); |
| 110 |
|
const wxString* subject = wikiData->getSubject(); |
| 111 |
|
|
| 112 |
|
dlg->setSubject(*subject); |
| 113 |
|
dlg->setPlainText(*wikiText); |
| 114 |
|
ans = dlg->ShowModal(); |
| 115 |
|
|
| 116 |
|
if(ans != wxID_OK) return ; |
| 117 |
|
|
| 118 |
|
plainTextStr = dlg->getPlainText(); |
| 119 |
|
newSubjectStr = dlg->getSubject(); |
| 120 |
|
wikiData->modText(&plainTextStr); |
| 121 |
|
wikiData->save(); |
| 122 |
|
|
| 123 |
|
wikiData->modSubject(&newSubjectStr); |
| 124 |
|
|
| 125 |
|
frame->showSearchResult(wiki); |
| 126 |
|
delete dlg; |
| 127 |
} |
} |
| 128 |
|
|
| 129 |
void mnController::handleRemoveButton(wxCommandEvent& event) |
void mnController::handleRemoveButton(wxCommandEvent& event) |
| 131 |
wxTreeItemData* item = frame->getSelectedItem(); |
wxTreeItemData* item = frame->getSelectedItem(); |
| 132 |
|
|
| 133 |
if(item){ |
if(item){ |
| 134 |
((WikiData*)(item))->removeDataFile(); |
if(wxMessageBox(wxT("Do you realy remove this memo?\n") + frame->getSelectedLabel(), wxT("Realy?"), wxYES_NO|wxICON_QUESTION) == wxYES){ |
| 135 |
|
((WikiData*)(item))->removeDataFile(); |
| 136 |
|
} |
| 137 |
} |
} |
| 138 |
else { |
else { |
| 139 |
wiki->removeSearchStr(frame->getSelectedLabel()); |
wiki->removeSearchStr(frame->getSelectedLabel()); |
| 140 |
} |
} |
| 141 |
frame->showSearchResult(wiki); |
frame->showSearchResult(wiki); |
|
isEditing = FALSE; |
|
| 142 |
} |
} |
| 143 |
|
|
| 144 |
|
void mnController::handleHighlightButton(wxCommandEvent& event) |
| 145 |
|
{ |
| 146 |
|
frame->highlightSelectedItem(); |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
void mnController::handleTreeItemSelect(wxTreeEvent& event) |
void mnController::handleTreeItemSelect(wxTreeEvent& event) |
| 151 |
{ |
{ |
| 152 |
frame->showSelectedItemText(event); |
frame->showSelectedItemText(event); |
|
isEditing = FALSE; |
|
| 153 |
} |
} |
| 154 |
|
|
| 155 |
|
|
| 156 |
void mnController::handleTreeItemSelecting(wxTreeEvent& event) |
void mnController::handleTreeItemSelecting(wxTreeEvent& event) |
| 157 |
{ |
{ |
|
saveData(); |
|
|
|
|
|
if(frame->isNewItem(event.GetOldItem())) { |
|
|
frame->showSearchResult(wiki); |
|
|
event.Veto(); |
|
|
} |
|
| 158 |
} |
} |
| 159 |
|
|
| 160 |
void mnController::handleBeginLabelEdit(wxTreeEvent& event) |
void mnController::handleBeginLabelEdit(wxTreeEvent& event) |
| 167 |
wxString newSubject = event.GetLabel(); |
wxString newSubject = event.GetLabel(); |
| 168 |
wxTreeItemData* item = frame->getSelectedItem(); |
wxTreeItemData* item = frame->getSelectedItem(); |
| 169 |
|
|
| 170 |
saveData(); |
if(item == NULL) { |
| 171 |
|
return ; |
| 172 |
if(item == NULL) return ; |
} |
| 173 |
|
|
| 174 |
if(newSubject.Len() == 0) { |
if(newSubject.Len() == 0) { |
| 175 |
event.Veto(); |
event.Veto(); |
| 178 |
} |
} |
| 179 |
|
|
| 180 |
((WikiData*)(item))->modSubject(&newSubject); |
((WikiData*)(item))->modSubject(&newSubject); |
|
if(frame->isNewItem(event.GetItem())){ |
|
|
return; |
|
|
} |
|
| 181 |
|
|
| 182 |
event.Veto(); |
event.Veto(); |
| 183 |
frame->showSearchResult(wiki); |
frame->showSearchResult(wiki); |
| 185 |
|
|
| 186 |
void mnController::handleClose(wxCloseEvent& event) |
void mnController::handleClose(wxCloseEvent& event) |
| 187 |
{ |
{ |
|
saveData(); |
|
| 188 |
frame->Destroy(); |
frame->Destroy(); |
| 189 |
} |
} |
| 190 |
|
|
| 200 |
} |
} |
| 201 |
|
|
| 202 |
|
|
| 203 |
|
void mnController::handleEditButton(wxCommandEvent& event) |
| 204 |
|
{ |
| 205 |
|
wxString plainTextStr; |
| 206 |
|
wxString newSubjectStr; |
| 207 |
|
wxTreeItemData* itemData = frame->getSelectedItem(); |
| 208 |
|
wxString subject = frame->getSelectedLabel(); |
| 209 |
|
mnWikiDataEntryDialog* dlg = new mnWikiDataEntryDialog(frame, -1, wxT("Malon Note")); |
| 210 |
|
int ans; |
| 211 |
|
|
| 212 |
|
if(itemData == NULL) return; |
| 213 |
|
const wxString* wikiText = ((WikiData*)(itemData))->getText(); |
| 214 |
|
|
| 215 |
|
dlg->setSubject(subject); |
| 216 |
|
dlg->setPlainText(*wikiText); |
| 217 |
|
ans = dlg->ShowModal(); |
| 218 |
|
|
| 219 |
|
if(ans != wxID_OK) return ; |
| 220 |
|
if(itemData == NULL) return ; |
| 221 |
|
|
| 222 |
|
plainTextStr = dlg->getPlainText(); |
| 223 |
|
newSubjectStr = dlg->getSubject(); |
| 224 |
|
((WikiData*)(itemData))->modText(&plainTextStr); |
| 225 |
|
((WikiData*)(itemData))->save(); |
| 226 |
|
|
| 227 |
|
((WikiData*)(itemData))->modSubject(&newSubjectStr); |
| 228 |
|
|
| 229 |
|
frame->showSearchResult(wiki); |
| 230 |
|
delete dlg; |
| 231 |
|
} |
| 232 |
|
|
| 233 |
|
void mnController::handleLinkClick(wxCommandEvent &event) |
| 234 |
|
{ |
| 235 |
|
const wxString* wikiDataDir; |
| 236 |
|
wxString href = event.GetString(); |
| 237 |
|
wxString tag; |
| 238 |
|
wxString val; |
| 239 |
|
wxString doc; |
| 240 |
|
wxStringTokenizer tkz(href, wxT(":")); |
| 241 |
|
|
| 242 |
|
tag = tkz.GetNextToken(); |
| 243 |
|
val = tkz.GetNextToken(); |
| 244 |
|
if(tag.CmpNoCase(wxT("mnlink")) == 0) { |
| 245 |
|
event.SetString(val); |
| 246 |
|
handleSearch(event); |
| 247 |
|
} |
| 248 |
|
else if(tag.CmpNoCase(wxT("mndoc")) == 0) { |
| 249 |
|
wikiDataDir = wiki->getWikiDataDir(); |
| 250 |
|
doc = *wikiDataDir + wxT("/docs/") + val; |
| 251 |
|
openDoc(doc); |
| 252 |
|
} |
| 253 |
|
else { |
| 254 |
|
openUrl(href); |
| 255 |
|
} |
| 256 |
|
} |
| 257 |
|
|
| 258 |
|
void mnController::openUrl(wxString& url) |
| 259 |
|
{ |
| 260 |
|
wxString cmd; |
| 261 |
|
|
| 262 |
|
#ifdef __WXMSW__ |
| 263 |
|
cmd.sprintf(wxT("explorer %s"), url.c_str()); |
| 264 |
|
#endif |
| 265 |
|
|
| 266 |
|
#ifdef __WXMAC__ |
| 267 |
|
cmd.sprintf(wxT("open %s"), url.c_str()); |
| 268 |
|
#endif |
| 269 |
|
|
| 270 |
|
#ifdef __WXCOCOA__ |
| 271 |
|
cmd.sprintf(wxT("open %s"), url.c_str()); |
| 272 |
|
#endif |
| 273 |
|
|
| 274 |
|
#ifdef __WXGTK__ |
| 275 |
|
cmd.sprintf(wxT("gnome-open %s"), url.c_str()); |
| 276 |
|
#endif |
| 277 |
|
|
| 278 |
|
//wxExecute(argv); |
| 279 |
|
wxExecute(cmd); |
| 280 |
|
} |
| 281 |
|
|
| 282 |
void mnController::saveData() |
void mnController::openDoc(wxString& doc) |
| 283 |
{ |
{ |
| 284 |
wxTreeItemData* item = frame->getSelectedItem(); |
wxString cmd; |
| 285 |
wxString plainTextStr = frame->getPlainText(); |
|
| 286 |
if(item == NULL) return ; |
#ifdef __WXMSW__ |
| 287 |
|
cmd.sprintf(wxT("cmd /c \"start %s\""), doc.c_str()); |
| 288 |
((WikiData*)(item))->modText(&plainTextStr); |
#endif |
| 289 |
((WikiData*)(item))->save(); |
|
| 290 |
//frame->showSearchResult(wiki); |
#ifdef __WXMAC__ |
| 291 |
|
cmd.sprintf(wxT("open %s"), doc.c_str()); |
| 292 |
|
#endif |
| 293 |
|
|
| 294 |
|
#ifdef __WXCOCOA__ |
| 295 |
|
cmd.sprintf(wxT("open %s"), doc.c_str()); |
| 296 |
|
#endif |
| 297 |
|
|
| 298 |
|
#ifdef __WXGTK__ |
| 299 |
|
cmd.sprintf(wxT("gnome-open %s"), doc.c_str()); |
| 300 |
|
#endif |
| 301 |
|
|
| 302 |
|
wxExecute(cmd); |
| 303 |
} |
} |