📄 nxnotepad.cxx
字号:
tfd = mkstemp(tplate); n->key = -1; if (tfd > 0) { fd = fdopen(tfd, "w+"); strcpy(n->szFile, tplate); } } else fd = fopen(f, "w+"); if (fd) { g_editor->SaveTo(fd); fclose(fd); write_note(n); } else fprintf(stderr, "NOTEPAD - Unable to write the file\n"); if (delete_me) delete n; } } else { g_SearchFlag = false; } if (AllFlag) { set_category("All"); AllFlag = false; } else set_category(edit_category->label()); NxApp::Instance()->show_window(note_list_window->GetWindowPtr());}voidNxNotepad::yes_delete_callback(Fl_Widget * fl, void *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(note_category->label()); } NxApp::Instance()->show_window(note_list_window->GetWindowPtr(), ACTIVATE);}voidNxNotepad::no_delete_callback(Fl_Widget * fl, void *l){ NxApp::Instance()->show_window(note_list_window->GetWindowPtr(), ACTIVATE); save_archive_ = false;}voidNxNotepad::save_archive_callback(Fl_Widget * fl, void *l){ save_archive_ = true;}voidNxNotepad::lookup_callback(Fl_Widget * fl, void *l){ NxApp::Instance()->show_window(note_lookup_window->GetWindowPtr(), DEACTIVATE, note_list_window->GetWindowPtr()); lookup_input->value(""); Fl::focus((Fl_Widget *) lookup_input);}voidNxNotepad::cancelLookup_callback(Fl_Widget * fl, void *l){ NxApp::Instance()->show_window(note_list_window->GetWindowPtr(), ACTIVATE);}voidNxNotepad::doneLookup_callback(Fl_Widget * fl, void *l){ NxApp::Instance()->show_window(note_list_window->GetWindowPtr(), ACTIVATE);}char *NxNotepad::formatString(const NxNote * note, int pixels){ int width = 0; int dot_width = 0; int idx = 0; char *new_string = new char[TITLE_LEN + 3]; fl_font(DEFAULT_TEXT_FONT, DEFAULT_TEXT_SIZE); width = (int) fl_width(note->szTitle); dot_width = (int) fl_width("..."); if (width <= pixels) { return (char *) note->szTitle; } else { while (width > pixels) { idx++; memset(new_string, 0, TITLE_LEN + 3); strncpy(new_string, note->szTitle, strlen(note->szTitle) - idx); width = (int) fl_width(new_string) + dot_width; } sprintf(new_string, "%s...", new_string); return new_string; } return (char *) note->szTitle;}NxNote *NxNotepad::search(const char *searchVal){ static int cur_record = 0; static int rec_array[255]; int jdx; char *needle = strup(searchVal, strlen(searchVal)); if (0 == cur_record) { for (int idx = 0; idx < 255; idx++) { rec_array[idx] = -1; } // Select all records note_db->Select(NOTE_DATABASE, rec_array, 255); } if (255 == cur_record) { cur_record = 0; delete[]needle; needle = 0; return NULL; } bool found = false; NxNote *note = new NxNote; while (cur_record < 255) { int catid_array[1]; char catid[8]; found = false; catid_array[0] = -1; jdx = rec_array[cur_record]; if (-1 == jdx) { cur_record++; continue; } 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"); note_db->Extract(NOTE_DATABASE, jdx, NOTE_FILE, note->szFile); char *haystack = strup(note->szFile, FILE_LEN); //if (strstr(haystack, needle)) // found = true; //delete[] haystack; //haystack = 0; //also need to look through the file found |= searchFile(searchVal, note->szFile); note_db->Extract(NOTE_DATABASE, jdx, NOTE_DESC, note->szTitle); haystack = strup(note->szTitle, TITLE_LEN); if (strstr(haystack, needle)) found = true; delete[]haystack; haystack = 0; if (found) { cur_record++; delete[]needle; needle = 0; return note; } else { cur_record++; continue; } } cur_record = 0; delete[]note; note = 0; delete[]needle; needle = 0; return NULL;}voidNxNotepad::searchLookup_callback(Fl_Widget * fl, void *l){ int total_found = 0; char *searchVal = (char *) lookup_input->value(); char *needle = strup(searchVal, strlen(searchVal)); NxNote *note; results_table->Init(255); while ((note = search(searchVal)) != NULL) { results_table->Add(total_found, note); char *label = formatString(note, results_table->text_width()); results_table->set_value(total_found, 0, label); total_found++; } delete[]needle; needle = 0; results_table->rows(total_found); if (total_found == 0) { results_message->show(); results_table->hide(); } else { results_message->hide(); results_table->show(); } NxApp::Instance()->show_window(note_list_window->GetWindowPtr()); NxApp::Instance()->show_window(note_results_window->GetWindowPtr(), DEACTIVATE, note_list_window->GetWindowPtr());}voidNxNotepad::write_archive_copy(){ fprintf(stderr, "Would be doing write_archive_copy\n");}voidNxNotepad::write_note(NxNote * note){ char *buf = new char[MAXRECSIZ]; int rec_array[1]; int cat_array[1]; char value[50]; char title[TITLE_LEN]; FILE *fp; int c; int count = 0; bool all_space = true; unsigned int idx; rec_array[0] = -1; if (0 == strcmp("All", edit_category->label())) { strcpy(note->szCategory, "Unfiled"); } else { strcpy(note->szCategory, edit_category->label()); } char key_buf[255]; memset(key_buf, 0, sizeof(key_buf)); sprintf(key_buf, "%d", note->key); note_db->Select(NOTE_DATABASE, key_buf, NOTE_INDEX, rec_array, 1); DPRINT("key is [%d]\n", note->key); cat_array[0] = -1; note_db->Select(CAT_DATABASE, note->szCategory, CAT_DESC, cat_array, 1); note_db->Extract(CAT_DATABASE, cat_array[0], CAT_INDEX, value); fp = fopen(note->szFile, "r"); memset(title, 0, sizeof(title)); if (NULL != fp) { while ((c = fgetc(fp)) != EOF) { title[count] = c; if (c == '\n' || count >= TITLE_LEN - 1) { title[count] = '\0'; break; } count++; } if (title[0]) { strcpy(note->szTitle, title); } else { strcpy(note->szTitle, "Untitled"); } fclose(fp); } else { strcpy(note->szTitle, "Untitled"); } for (idx = 0; idx < strlen(title); idx++) { if (!isspace(title[idx])) { all_space = false; break; } } if (all_space) strcpy(note->szTitle, "Untitled"); if (-1 == rec_array[0]) { memset(buf, 0, MAXRECSIZ); note_key = NxApp::Instance()->GetKey(note_db, NOTE_DATABASE, NOTE_INDEX) + 1; put16(&buf[noteFields[NOTE_INDEX].offset], note_key); strcpy(&buf[noteFields[NOTE_FILE].offset], note->szFile); put16(&buf[noteFields[NOTE_CAT].offset], atoi(value)); strcpy(&buf[noteFields[NOTE_DESC].offset], note->szTitle); put16(&buf[noteFields[NOTE_ARCH].offset], 0); note_db->Insert(NOTE_DATABASE, buf); //fprintf(stderr, "Inserting: name[%s] cat[%s] title[%s] archive[%d]\n", // note->szFile, note->szCategory, note->szTitle, 0); } else { note_db->Extract(NOTE_DATABASE, rec_array[0], buf); put16(&buf[noteFields[NOTE_CAT].offset], atoi(value)); strcpy(&buf[noteFields[NOTE_DESC].offset], note->szTitle); note_db->Edit(NOTE_DATABASE, rec_array[0], buf); //fprintf(stderr, "Editing: name[%s] cat[%s] title[%s]\n", // note->szFile, note->szCategory, note->szTitle); } delete[]buf;}voidNxNotepad::clear_tree(){ Fl_Toggle_Node *n = tree->traverse_start(); while (n) { delete(char *) n->user_data(); tree->remove(n); n = tree->traverse_start(); }}voidNxNotepad::set_category(const char *szCat){ char szRealCategory[CAT_LEN]; memset(szRealCategory, 0, sizeof(szRealCategory)); if (!szCat[0]) { strcpy(szRealCategory, "All"); } else { strcpy(szRealCategory, szCat); } clear_tree(); add_items(tree, szRealCategory); fill_categories(); edit_category->label(szRealCategory); edit_category->hide(); edit_category->show(); note_category->label(szRealCategory); note_category->hide(); note_category->show();}voidNxNotepad::reset_category(char *szCat){ char szRealCategory[CAT_LEN]; memset(szRealCategory, 0, sizeof(szRealCategory)); if (!szCat[0]) { strcpy(szRealCategory, "All"); } else { strcpy(szRealCategory, szCat); } fill_categories(); edit_category->label(szRealCategory); edit_category->hide(); edit_category->show(); note_category->label(szRealCategory); note_category->hide(); note_category->show();}voidNxNotepad::insert_default_categories(){ char buf[MAXRECSIZ]; int idx = 0; memset(buf, 0, sizeof(buf)); put16(&buf[catFields[CAT_INDEX].offset], idx++); strcpy(&buf[catFields[CAT_DESC].offset], "Unfiled"); note_db->Insert(CAT_DATABASE, buf); memset(buf, 0, sizeof(buf)); put16(&buf[catFields[CAT_INDEX].offset], idx++); strcpy(&buf[catFields[CAT_DESC].offset], "Business"); note_db->Insert(CAT_DATABASE, buf); memset(buf, 0, sizeof(buf)); put16(&buf[catFields[CAT_INDEX].offset], idx++); strcpy(&buf[catFields[CAT_DESC].offset], "Personal"); note_db->Insert(CAT_DATABASE, buf);}voidNxNotepad::insert_default_note(){ char buf[MAXRECSIZ]; int cat_array[1]; FILE *fp; char file_name[FILE_LEN]; cat_array[0] = 0; memset(buf, 0, sizeof(buf)); put16(&buf[noteFields[NOTE_INDEX].offset], 0); sprintf(file_name, "%scen.txt", nx_inidir); strcpy(&buf[noteFields[NOTE_FILE].offset], file_name); put16(&buf[noteFields[NOTE_CAT].offset], 1); strcpy(&buf[noteFields[NOTE_DESC].offset], "How to get to Mount Doom"); put16(&buf[noteFields[NOTE_ARCH].offset], 0); note_db->Insert(NOTE_DATABASE, buf); fp = fopen(file_name, "w+"); if (fp) { fputs ("How to get to Mount Doom\nGo east through Gondor until you see Mordor. Get past the gate and throw the ring into the lava.", fp); fclose(fp); }}voidNxNotepad::open_cat_database(){ if (!note_db->Open(CAT_DATABASE, &catFile, catFields, CAT_INDEX)) { if (note_db->Create(CAT_DATABASE, &catFile, catFields, CAT_INDEX)) { if (!note_db->Open(CAT_DATABASE, &catFile, catFields, CAT_INDEX)) { exit(-1); } insert_default_categories(); } else { exit(-1); } }}voidNxNotepad::open_note_database(){ if (!note_db->Open(NOTE_DATABASE, ¬eFile, noteFields, NOTE_INDEX)) { if (note_db->Create(NOTE_DATABASE, ¬eFile, noteFields, NOTE_INDEX)) { if (!note_db-> Open(NOTE_DATABASE, ¬eFile, noteFields, NOTE_INDEX)) { exit(-1); }#ifdef CONFIG_SAMPLES insert_default_note();#endif } else { exit(-1); } }}voidNxNotepad::fill_categories(){ char ret_buf[CAT_LEN]; int rec_count = note_db->NumRecs(CAT_DATABASE); for (int idx = 0; idx < CAT_NUM; idx++) { cat_list[idx]->clear(); cat_list[idx]->add("All"); for (int jdx = 1; jdx <= rec_count; jdx++) { memset(ret_buf, 0, sizeof(ret_buf)); if (note_db->Extract(CAT_DATABASE, jdx, CAT_DESC, ret_buf)) { cat_list[idx]->add(ret_buf); } } cat_list[idx]->label(const_cast < char *>(cat_list[idx]->text(0))); } note_list_window->GetEditCategoryPtr()->clear_tree(); note_list_window->GetEditCategoryPtr()->add_items(note_list_window-> GetEditCategoryPtr()-> get_category_tree()); note_edit_window->GetEditCategoryPtr()->clear_tree(); note_edit_window->GetEditCategoryPtr()->add_items(note_edit_window-> GetEditCategoryPtr()-> get_category_tree());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -