| 25 |
EVT_MENU(XRCID("Quit"), mnFrameController::handleExit) |
EVT_MENU(XRCID("Quit"), mnFrameController::handleExit) |
| 26 |
EVT_MENU(wxID_ABOUT, mnFrameController::handleAbout) |
EVT_MENU(wxID_ABOUT, mnFrameController::handleAbout) |
| 27 |
EVT_CLOSE(mnFrameController::handleClose) |
EVT_CLOSE(mnFrameController::handleClose) |
| 28 |
|
EVT_NOTEBOOK_PAGE_CHANGED(XRCID("noteBook"), mnFrameController::handlePageChange) |
| 29 |
|
EVT_TIMER(1, mnFrameController::readAll) |
| 30 |
END_EVENT_TABLE() |
END_EVENT_TABLE() |
| 31 |
|
|
| 32 |
mnFrameController::mnFrameController(mnFrame* inframe) |
mnFrameController::mnFrameController(mnFrame* inframe) |
| 33 |
{ |
{ |
|
wxString* dirName = new wxString(); |
|
|
wxString gotDirName; |
|
|
wxDirDialog* dlg; |
|
|
|
|
| 34 |
frame = inframe; |
frame = inframe; |
| 35 |
|
|
| 36 |
/* create wiki model */ |
wxTimer* timer = new wxTimer(this, 1); |
| 37 |
wxConfig* config = new wxConfig(wxT(CONF_APP_NAME)); |
timer->Start(MN_READ_INTERVAL, wxTIMER_CONTINUOUS); |
| 38 |
if(config->Read(wxT(CONF_WIKI_DIR), dirName) == FALSE) { |
} |
|
delete dirName; |
|
|
dlg = new wxDirDialog(frame); |
|
|
if(dlg->ShowModal() == wxID_OK) { |
|
|
gotDirName = dlg->GetPath(); |
|
|
config->Write(wxT(CONF_WIKI_DIR), gotDirName.c_str()); |
|
|
frame->addNotePanel(&gotDirName); |
|
|
} |
|
|
else { |
|
|
frame->Close(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
frame->addNotePanel(dirName); |
|
| 39 |
|
|
| 40 |
wxString testDir(wxT("C:\\wiki_test")); |
void mnFrameController::readAll(wxTimerEvent& event) |
| 41 |
frame->addNotePanel(&testDir); |
{ |
| 42 |
|
int count = 0; |
| 43 |
|
mnNotePanel* panel; |
| 44 |
|
mnNotePanelController* controller; |
| 45 |
|
|
| 46 |
|
count = frame->getNotebook()->GetPageCount(); |
| 47 |
|
for(int i = 0; i < count; i++) |
| 48 |
|
{ |
| 49 |
|
panel = (mnNotePanel*)frame->getNotebook()->GetPage(i); |
| 50 |
|
controller = panel->getController(); |
| 51 |
|
controller->readAll(); |
| 52 |
} |
} |
|
|
|
|
delete config; |
|
| 53 |
} |
} |
| 54 |
|
|
| 55 |
void mnFrameController::handleConfig(wxCommandEvent& event) |
void mnFrameController::handleConfig(wxCommandEvent& event) |
| 125 |
|
|
| 126 |
void mnFrameController::handleAddDir(wxCommandEvent& event) |
void mnFrameController::handleAddDir(wxCommandEvent& event) |
| 127 |
{ |
{ |
|
/* |
|
| 128 |
wxDirDialog* dlg; |
wxDirDialog* dlg; |
| 129 |
wxString gotDirName; |
wxString gotDirName; |
| 130 |
wxString* dirName = new wxString(); |
wxString* dirName = new wxString(); |
| 131 |
|
|
| 132 |
|
dlg = new wxDirDialog(frame); |
| 133 |
|
if(dlg->ShowModal() == wxID_OK) { |
| 134 |
|
gotDirName = dlg->GetPath(); |
| 135 |
|
if(isExistConfig(&gotDirName) == false){ |
| 136 |
|
frame->addNotePanel(&gotDirName); |
| 137 |
|
} |
| 138 |
|
else { |
| 139 |
|
wxMessageBox(wxT("It already exist in MalonNote"), wxT("Already exist"), wxOK|wxICON_INFORMATION); |
| 140 |
|
return; |
| 141 |
|
} |
| 142 |
|
} |
| 143 |
|
updateConfig(); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
void mnFrameController::handleRemoveDir(wxCommandEvent& event) |
| 147 |
|
{ |
| 148 |
|
frame->removeSelectedNotePanel(); |
| 149 |
|
updateConfig(); |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
void mnFrameController::updateConfig() |
| 153 |
|
{ |
| 154 |
wxString confKey; |
wxString confKey; |
| 155 |
|
wxNotebook* notebook; |
| 156 |
|
mnNotePanel* panel; |
| 157 |
|
|
| 158 |
wxConfig* config = new wxConfig(wxT(CONF_APP_NAME)); |
wxConfig* config = new wxConfig(wxT(CONF_APP_NAME)); |
| 159 |
|
config->DeleteAll(); |
| 160 |
|
delete config; |
| 161 |
|
config = new wxConfig(wxT(CONF_APP_NAME)); // recreate config object |
| 162 |
|
notebook = frame->getNotebook(); |
| 163 |
|
int count = notebook->GetPageCount(); |
| 164 |
|
for(int i = 0; i < count; i++) { |
| 165 |
|
panel = (mnNotePanel*)notebook->GetPage(i); |
| 166 |
|
const wxString* dataDir = panel->getController()->getWikiDataDir(); |
| 167 |
|
|
| 168 |
dlg = new wxDirDialog(frame); |
if(i == 0){ |
| 169 |
if(dlg->ShowModal() == wxID_OK) { |
config->Write(wxT(CONF_WIKI_DIR), dataDir->c_str()); |
| 170 |
gotDirName = dlg->GetPath(); |
} |
| 171 |
confKey.sprintf(wxT(CONF_WIKI_DIR) "%d", numOfMemoDir); |
else{ |
| 172 |
config->Write(wxT(CONF_WIKI_DIR), gotDirName.c_str()); |
confKey.sprintf(wxT(CONF_WIKI_DIR) "%d", i); |
| 173 |
|
config->Write(confKey.c_str(), dataDir->c_str()); |
| 174 |
|
} |
| 175 |
} |
} |
| 176 |
delete config; |
delete config; |
|
*/ |
|
|
/* |
|
|
* frame->addNotePanel を最終的に呼び出せばよい |
|
|
* その後、frame->noteBook内の情報をNotePanel毎に一つずつ取り出し |
|
|
* 一つ目をCONF_WIKI_DIR, 二つ目からCONF_WIKI_DIR+1のように設定ファイルに |
|
|
* 記録すればよい |
|
|
* 記録前に以前の記録をすべて削除するために、DeleteAllを呼ぶこと |
|
|
*/ |
|
| 177 |
} |
} |
| 178 |
|
|
| 179 |
void mnFrameController::handleRemoveDir(wxCommandEvent& event) |
bool mnFrameController::isExistConfig(wxString* dir) |
| 180 |
|
{ |
| 181 |
|
wxString* dirName = new wxString(); |
| 182 |
|
wxString gotDirName; |
| 183 |
|
wxDirDialog* dlg; |
| 184 |
|
wxString confKey; |
| 185 |
|
|
| 186 |
|
wxConfig* config = new wxConfig(wxT(CONF_APP_NAME)); |
| 187 |
|
for(int i = 0; ;i++) { |
| 188 |
|
if(i == 0) { |
| 189 |
|
confKey.sprintf(wxT(CONF_WIKI_DIR)); |
| 190 |
|
} |
| 191 |
|
else { |
| 192 |
|
confKey.sprintf(wxT(CONF_WIKI_DIR) "%d", i); |
| 193 |
|
} |
| 194 |
|
if(config->Read(confKey.c_str(), dirName)) { |
| 195 |
|
if(*dir == *dirName) return true; /* Exist */ |
| 196 |
|
} |
| 197 |
|
else { |
| 198 |
|
break; |
| 199 |
|
} |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
delete dirName; |
| 203 |
|
delete config; |
| 204 |
|
|
| 205 |
|
return false; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
|
void mnFrameController::handlePageChange(wxNotebookEvent& event) |
| 210 |
{ |
{ |
| 211 |
|
wxNotebook* notebook; |
| 212 |
|
mnNotePanel* panel; |
| 213 |
|
|
| 214 |
|
notebook = frame->getNotebook(); |
| 215 |
|
panel = (mnNotePanel*)notebook->GetPage(event.GetSelection()); |
| 216 |
|
const wxString* dataDir = panel->getController()->getWikiDataDir(); |
| 217 |
|
|
| 218 |
|
frame->GetStatusBar()->SetStatusText(*dataDir); |
| 219 |
} |
} |