📄 nxnotepad.cxx
字号:
note_list_window->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X + 116, BUTTON_Y, BUTTON_WIDTH - 5, BUTTON_HEIGHT, "Delete"); o->callback(delete_note_callback); note_list_window->add((Fl_Widget *) o); }}voidNxNotepad::make_edit_window(){ note_edit_window = new NxPimWindow("Notes", note_edit_menu, note_db, CAT_DATABASE, NOTE_DATABASE, (void (*)(const char *)) set_category); add_window((Fl_Window *) note_edit_window->GetWindowPtr()); g_editor = new Fl_Editor(5, 30, W_W - 11, BUTTON_Y - 41); g_editor->movable(false); g_editor->box(FL_BORDER_BOX); g_editor->when(FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED); g_editor->callback(NxApp::Instance()->pasteTarget_callback, (void *) 1); g_editor->textsize(0x0C); note_edit_window->add((Fl_Widget *) g_editor); { NxButton *o = new NxButton(BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT, "Done"); o->callback(done_edit_callback); note_edit_window->add((Fl_Widget *) o); }}voidNxNotepad::make_delete_window(){ note_delete_window = new NxPimPopWindow("Delete"); add_window((Fl_Window *) note_delete_window->GetWindowPtr()); { NxBox *o = new NxBox(BUTTON_X, 43, W_W - BUTTON_X - 15, 0, "Delete current note ?"); o->box(FL_FLAT_BOX); o->align(FL_ALIGN_WRAP | FL_ALIGN_LEFT | FL_ALIGN_TOP); note_delete_window->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Yes"); o->callback(yes_delete_callback); note_delete_window->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X + 61, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "No"); o->callback(no_delete_callback); note_delete_window->add((Fl_Widget *) o); }}voidNxNotepad::make_lookup_window(){ note_lookup_window = new NxPimPopWindow("Search"); add_window((Fl_Window *) note_lookup_window->GetWindowPtr()); { NxBox *o = new NxBox(BUTTON_X, 43, W_W - BUTTON_X - 15, 0, "What are you looking for?"); o->box(FL_FLAT_BOX); o->align(FL_ALIGN_WRAP | FL_ALIGN_TOP | FL_ALIGN_LEFT); note_lookup_window->add((Fl_Widget *) o); } { NxInput *o = lookup_input = new NxInput(BUTTON_X, 60, W_W - BUTTON_WIDTH, 20); lookup_input->maximum_size(99); note_lookup_window->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Search"); o->callback(searchLookup_callback); note_lookup_window->add((Fl_Widget *) o); } { NxButton *o = new NxButton(BUTTON_X + 61, 90, BUTTON_WIDTH, BUTTON_HEIGHT, "Cancel"); o->callback(cancelLookup_callback); note_lookup_window->add((Fl_Widget *) o); }}voidNxNotepad::make_results_window(){ note_results_window = new NxPimPopWindow("Searh Results", NxApp::Instance()->getGlobalColor(APP_FG), 5, (W_W / 3), W_W - 10, (W_H - (W_W / 2))); add_window((Fl_Window *) note_results_window->GetWindowPtr()); { results_message = new NxOutput(4, 19, W_W - 19, 25); results_message->value("Nothing Found."); results_message->hide(); note_results_window->add((Fl_Widget *) results_message); } { results_table = new Flv_Table_Child(4, 19, (W_W - 19), (W_H - (W_W / 2) - 3 * (BUTTON_HEIGHT)), 0, (W_W - 25)); results_table->callback(view_callback); results_table->selection_color(NxApp::Instance()-> getGlobalColor(HILIGHT)); results_table->SetCols(1); note_results_window->add((Fl_Widget *) results_table); } { NxButton *o = new NxButton(BUTTON_X, (W_H - (W_W / 2) - BUTTON_HEIGHT - 9), BUTTON_WIDTH, BUTTON_HEIGHT, "Done"); o->callback(doneLookup_callback); note_results_window->add((Fl_Widget *) o); }}voidNxNotepad::add_items(Fl_Toggle_Tree * t, const char *szCategory){ int rec_array[MAX_RECS]; int cat_array[1]; char value[16]; char cat[16]; Fl_Toggle_Node *n; NxNote *note; int idx = 0; for (idx = 0; idx < MAX_RECS; idx++) { rec_array[idx] = -1; } cat_array[0] = -1; strcpy(value, ""); note_db->Select(CAT_DATABASE, const_cast < char *>(szCategory), CAT_DESC, cat_array, 1); if (0 <= cat_array[0]) { note_db->Extract(CAT_DATABASE, cat_array[0], CAT_INDEX, value); } if (0 == strcmp("All", szCategory)) { note_db->Select(NOTE_DATABASE, rec_array, MAX_RECS); } else { note_db->Select(NOTE_DATABASE, value, NOTE_CAT, rec_array, 255); } idx = 0; while (-1 != rec_array[idx]) { int j = -1; int jdx = rec_array[idx]; idx++; if ((0 <= cat_array[0]) || (0 == strcmp("All", szCategory))) { if (0 <= cat_array[0]) { note_db->Extract(NOTE_DATABASE, jdx, NOTE_CAT, cat); j = strcmp(value, cat); } if ((j == 0) || (0 == strcmp("All", szCategory))) { note = new NxNote; note->bDeleteMe = 0; int catid_array[1]; char catid[8]; catid_array[0] = -1; memset(note->szCategory, 0, CAT_LEN); note_db->Extract(NOTE_DATABASE, jdx, NOTE_CAT, catid); note_db->Select(CAT_DATABASE, catid, CAT_INDEX, catid_array, 1); if (-1 != catid_array[0]) note_db->Extract(CAT_DATABASE, catid_array[0], CAT_DESC, note->szCategory); else strcpy(note->szCategory, "Unfiled"); char str_key[16]; note_db->Extract(NOTE_DATABASE, jdx, NOTE_INDEX, str_key); note->key = atoi(str_key); note_db->Extract(NOTE_DATABASE, jdx, NOTE_FILE, note->szFile); note_db->Extract(NOTE_DATABASE, jdx, NOTE_DESC, note->szTitle); n = t->add_next(note->szTitle, 0, folderSmall); n->user_data(note); t->traverse_up(); } } } note_list->position(0, 0);}voidNxNotepad::select_note(NxNote * note){ Fl_Toggle_Node *node = tree->traverse_start(); while (NULL != node) { if (0 == strcmp(note->szFile, ((NxNote *) node->user_data())->szFile)) { tree->select_range(node, node, 0); break; } node = tree->traverse_forward(); }}voidNxNotepad::viewRecord(char *fileName){ NxApp::Instance()->set_catlist_window((Fl_Window *) note_edit_window-> GetEditCategoryWindowPtr()); NxNote *note = new NxNote; int rec_array[1]; rec_array[0] = -1; note_db->Select(NOTE_DATABASE, fileName, NOTE_FILE, rec_array, 1); int catid_array[1]; char catid[8]; catid_array[0] = -1; note_db->Extract(NOTE_DATABASE, rec_array[0], NOTE_CAT, catid); note_db->Select(CAT_DATABASE, catid, 0, catid_array, 1); if (-1 != catid_array[0]) note_db->Extract(CAT_DATABASE, catid_array[0], 1, note->szCategory); else strcpy(note->szCategory, "Unfiled"); strcpy(note->szFile, fileName); g_editor->Clear(); FILE *fd = fopen(note->szFile, "r"); g_editor->LoadFrom(fd); g_editor->MoveTo(0, 0); fclose(fd); g_SearchFlag = false; new_note_ = false; select_note(note); edit_category->label(note->szCategory); NxApp::Instance()->show_window(note_edit_window->GetWindowPtr()); delete note;}voidNxNotepad::view_callback(Fl_Widget * fl, void *o){ NxNote *n = 0; if (Fl::event_clicks()) { NxApp::Instance()->set_catlist_window((Fl_Window *) note_edit_window-> GetEditCategoryWindowPtr()); n = (NxNote *) results_table->selected(); if (n) { char tempCat[CAT_LEN]; memset(tempCat, 0, CAT_LEN); strcpy(tempCat, n->szCategory); if (!tempCat[0]) { strcpy(tempCat, "Unfiled"); } g_editor->Clear(); if (n->szFile[0] != '^') { FILE *fd = fopen(n->szFile, "r"); g_editor->LoadFrom(fd); g_editor->MoveTo(0, 0); fclose(fd); } edit_category->label(tempCat); } g_SearchFlag = false; new_note_ = false; select_note(n); NxApp::Instance()->show_window(note_edit_window->GetWindowPtr()); } Fl::event_clicks(0);}voidNxNotepad::note_tree_callback(Fl_Widget * fl, long l){ if (tree->selection_count() > 1) tree->unselect(); if (Fl::event_clicks()) { edit_callback(fl, l); } Fl::event_clicks(0);}voidNxNotepad::new_callback(Fl_Widget * fl, void *l){ char tempCat[CAT_LEN]; tree->unselect(); new_note_ = true; NxApp::Instance()->set_catlist_window((Fl_Window *) note_edit_window-> GetEditCategoryWindowPtr()); NxNote *n = new NxNote; memset(tempCat, 0, CAT_LEN); memset(n->szCategory, 0, CAT_LEN); memset(n->szTitle, 0, TITLE_LEN); strcpy(n->szFile, "^"); strcpy(n->szTitle, "Untitled"); if (0 == strcmp("All", note_category->label())) { AllFlag = true; strcpy(tempCat, "Unfiled"); } else { strcpy(tempCat, note_category->label()); } g_editor->Clear(); fill_categories(); edit_category->label(tempCat); edit_category->hide(); edit_category->show(); note_category->label(tempCat); delete(n); n = 0; NxApp::Instance()->show_window(note_edit_window->GetWindowPtr(), ACTIVATE);}voidNxNotepad::edit_callback(Fl_Widget * fl, long l){ Fl_Toggle_Node *node = tree->selected(); fill_categories(); NxApp::Instance()->set_catlist_window((Fl_Window *) note_edit_window-> GetEditCategoryWindowPtr()); if (node) { char tempCat[CAT_LEN]; memset(tempCat, 0, CAT_LEN); strcpy(tempCat, ((NxNote *) node->user_data())->szCategory); if (!tempCat[0]) { strcpy(tempCat, "Unfiled"); } g_editor->Clear(); DPRINT("Filename [%s]\n", ((NxNote *) node->user_data())->szFile);#ifdef DEBUG assert(((NxNote *) node->user_data())->szFile);#endif if (((NxNote *) node->user_data())->szFile[0] != '^') { FILE *fd = fopen(((NxNote *) node->user_data())->szFile, "r"); if (NULL == fd) { int tfd = 0; char tplate[128]; snprintf(tplate, sizeof(tplate), "%s/%sXXXXXX", nx_inidir, NX_INIFILE); tfd = mkstemp(tplate); if (tfd > 0) { // should always have a note! DPRINT("NO NOTE!\n"); strcpy(((NxNote *) node->user_data())->szFile, tplate); DPRINT("Opening [%s]\n", ((NxNote *) node->user_data())->szFile); fd = fdopen(tfd, "w+"); DPRINT("fd [%p]\n", fd); } } if (NULL != fd) { new_note_ = false; DPRINT("fd not null\n"); g_editor->LoadFrom(fd); g_editor->MoveTo(0, 0); fclose(fd); } else { DPRINT("fd is null\n"); ((NxNote *) node->user_data())->szFile[0] = '^'; } } edit_category->label(tempCat); if (0 == strcmp("All", note_category->label())) AllFlag = true; NxApp::Instance()->show_window(note_edit_window->GetWindowPtr()); }}voidNxNotepad::delete_note_callback(Fl_Widget * fl, void *l){ Fl_Toggle_Node *node = tree->selected(); if (0 == strcmp("All", note_category->label())) AllFlag = true; if (node) { NxApp::Instance()->show_window(note_delete_window->GetWindowPtr(), DEACTIVATE, note_list_window->GetWindowPtr()); }}voidNxNotepad::delete_callback(Fl_Widget * fl, long l){ Fl_Toggle_Node *node = tree->selected(); NxNote *n; int rec_array[1]; if (node) { n = (NxNote *) node->user_data(); char key_buf[255]; memset(key_buf, 0, sizeof(key_buf)); sprintf(key_buf, "%d", n->key); note_db->Select(NOTE_DATABASE, key_buf, NOTE_INDEX, rec_array, 1); note_db->DeleteRec(NOTE_DATABASE, rec_array[0]); unlink(n->szFile); if (AllFlag) { set_category("All"); AllFlag = false; } else set_category(n->szCategory); }}voidNxNotepad::category_callback(Fl_Widget * fl, void *l){ set_category((char *) l);}voidNxNotepad::list_callback(Fl_Widget * fl, void *l){ reset_category((char *) l);}voidNxNotepad::done_edit_callback(Fl_Widget * fl, void *l){ Fl_Toggle_Node *node = tree->selected(); NxNote *n = 0; bool delete_me = false; NxApp::Instance()->set_catlist_window((Fl_Window *) note_list_window-> GetEditCategoryWindowPtr()); if (!g_SearchFlag) { if (node && !new_note_) { DPRINT("not a new note\n"); n = ((NxNote *) node->user_data()); } else { DPRINT("have a new note\n"); n = new NxNote; delete_me = true; strcpy(n->szFile, "^"); new_note_ = false; } if (n) { char *f = n->szFile; FILE *fd = 0; if (f[0] == '^') { char tplate[128]; int tfd = 0; snprintf(tplate, sizeof(tplate), "%s/%sXXXXXX", nx_inidir, NX_INIFILE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -