📄 xrolo.c
字号:
unsaved changes, if there are pending modifications to therolodex file.*/static int check_for_unsaved_changes(dialog_box)Dialog dialog_box;{ if (!entry_modified && !xrolo_db_is_modified()) return FALSE; dialog_activate(dialog_box); return TRUE;} /* check_for_unsaved_changes *//*load_next_rolodex_entry() simply requests that the next rolodexentry be loaded, checking for several special conditions.*/static void load_next_rolodex_entry(){ save_current_text(); if (xrolo_db_current_entry_is_last_entry()) return; if ((temp_entry = xrolo_db_next_entry()) != NULL) update_current_entry(temp_entry);} /* load_next_rolodex_entry *//*load_previous_rolodex_entry() simply requests that the previousrolodex entry be loaded, checking for several special conditions.*/static void load_previous_rolodex_entry(){ save_current_text(); if (xrolo_db_current_entry_is_first_entry()) return; if ((temp_entry = xrolo_db_previous_entry()) != NULL) update_current_entry(temp_entry);} /* load_previous_rolodex_entry *//*new_entry() clears the rolodex viewport and sets theinsertion point.*/static void new_entry(operation)int operation;{ if (!entry_modified && editing_new_entry) { user_message("Already editing new entry."); return; } save_current_text(); editing_new_entry = TRUE; editor_set_text(entryEditWindow, ""); entry_modified = FALSE; /* saved it before setting text */ /* want to add the new entry after current entry? */ if (operation == xrolo_ADD) { /* if already at the end, point to end of the database: */ if ((temp_entry = xrolo_db_next_entry()) == NULL) { current_entry = xrolo_db_past_last_entry(); } else current_entry = temp_entry; }} /* new_entry *//*save_current_text() handles both (1) text entered in theviewport after pressing "New/{Ins,Add}", and (2) changesto the current/existing entry. It is called by everymodule that initiates a high-level operation. It imposesthe following implicit policy: If the user has pressed"New/{Ins,Add}", but doesn't enter any text, an emptyentry is NOT added to the database.*/static int save_current_text(){ listShell_deactivate(entryIndex); /* must be rebuilt */ if (!entry_modified) { editing_new_entry = FALSE; /* may have been set, but no text entered */ return FALSE; } if (editing_new_entry || !current_entry) insert_new_db_entry(); else save_current_db_entry(); editing_new_entry = FALSE; return TRUE;} /* save_current_text *//*insert_new_db_entry() inserts the text from the viewport into therolodex file WITHOUT updating the entry viewport--useful afteradding new text with "New".*/static void insert_new_db_entry(){ if ((temp_entry = xrolo_db_insert_new_entry(editor_get_text(entryEditWindow))) == NULL) { fprintf(stderr, "xrolodex: can't insert new entry!\n"); user_message("Can't insert new entry!"); } else { current_entry = temp_entry; entry_modified = FALSE; } editing_new_entry = FALSE;} /* insert_new_db_entry *//*save_current_db_entry() saves the current viewport text by deletingthe current entry from the rolodex file and then inserting the textfrom the viewport. xrolo_db_delete_current_entry_no_undo() does NOTaffect the deletion history.*/static void save_current_db_entry(){ current_entry = xrolo_db_delete_current_entry_no_undo(); insert_new_db_entry();} /* save_current_db_entry *//*find_entry_containing_text_forward() searches forward through therolodex entries for the first entry containing the specified text.*/static void find_entry_containing_text_forward(){ char *search_text = XmTextGetString(findText); save_current_text(); if (xrolo_db_current_entry_is_last_entry()) { user_message("Search forward: currently at last entry."); XtFree(search_text); return; } if ((temp_entry = xrolo_db_find_entry_forward(search_text, case_sensitive_search)) != NULL) update_current_entry(temp_entry); else user_message("Search forward: no match."); XtFree(search_text);} /* find_entry_containing_text_forward *//*find_entry_containing_text_reverse() searches backward through therolodex entries for the first entry containing the specified text.*/static void find_entry_containing_text_reverse(){ char *search_text = XmTextGetString(findText); save_current_text(); if (xrolo_db_current_entry_is_first_entry()) { user_message("Search backward: currently at first entry."); XtFree(search_text); return; } if ((temp_entry = xrolo_db_find_entry_reverse(search_text, case_sensitive_search)) != NULL) update_current_entry(temp_entry); else user_message("Search backward: no match."); XtFree(search_text);} /* find_entry_containing_text_reverse *//*open_rolodex_file() opens the file and loads the first entry ifthe file exists; otherwise, it clears the current rolodex display.*/static void open_rolodex_file(filename)char *filename;{ Arg args[3]; int i; initialize_critical_variables(); i = 0; XtSetArg(args[i], XmNalignment, (XtArgVal) XmALIGNMENT_CENTER); i++; XtSetArg(args[i], XmNlabelString, XmStringCreateLtoR(filename, char_set)); i++; XtSetValues(databaseLabel, args, i); current_entry = xrolo_db_create(filename, delimiter); if (current_entry) editor_set_text(entryEditWindow, xrolo_db_get_text(current_entry)); else editor_set_text(entryEditWindow, ""); /* file doesn't yet exist */ entry_modified = FALSE;} /* open_rolodex_file *//*save_as_rolodex_file() manages the save-as process for savingthe rolodex file under a new filename.*/static void save_as_rolodex_file(){ if (file_exists(save_as_filename)) dialog_activate(overwriteDialog); else do_save_as_operation();} /* save_as_rolodex_file *//*do_save_as_operation() completes the save-as task, if thereis no file-write error, and updates the filename label.*/static void do_save_as_operation(){ Arg args[3]; int i; if (!xrolo_db_save_as(save_as_filename)) { user_message("Can't save file."); return; } initialize_critical_variables(); i = 0; XtSetArg(args[i], XmNalignment, (XtArgVal) XmALIGNMENT_CENTER); i++; XtSetArg(args[i], XmNlabelString, XmStringCreateLtoR(save_as_filename, char_set)); i++; XtSetValues(databaseLabel, args, i);} /* do_save_as_operation *//*save_first_time() is called before updatingthe rolodex file to ensure that a back-upis created.*/static void save_first_time(){ if (first_time) { first_time = FALSE; xrolo_db_save_backup(); }} /* save_first_time *//*update_current_entry() sets up the new current entry.*/static void update_current_entry(new_entry)EntryDB new_entry;{ current_entry = new_entry; editor_set_text(entryEditWindow, xrolo_db_get_text(current_entry)); entry_modified = FALSE; /* saved it before setting text */} /* update_current_entry *//*is_rolodex_active() is called before every operation that leadsto rolodex modification.*/static int is_rolodex_active(){ if (!xrolo_db_is_active()) { user_message( "First, use \"Open\" to establish a (new or existing) rolodex file."); return FALSE; } return TRUE;} /* is_rolodex_active *//*initialize_critical_variables() is called before openinga new rolodex file.*/static void initialize_critical_variables(){ editing_new_entry = FALSE; current_entry = NULL; entry_modified = FALSE; first_time = TRUE; listShell_deactivate(entryIndex);} /* initialize_critical_variables *//*cleanup_and_exit() is called by several functionswhen the application terminates.*/static void cleanup_and_exit(w)Widget w;{ if (save_as_filename)/* free(save_as_filename);*/ XtFree(save_as_filename); xrolo_index_destroy(); xrolo_db_destroy(); ctrlPanel_destroy(entryPanel); editor_destroy(entryEditWindow); listShell_destroy(entryIndex); XFreePixmap(XtDisplay(w), icon_pixmap); exit(0);} /* cleanup_and_exit *//*user_message() sets the message dialog box tohave the specified message and then mapsthe dialog box.*/static void user_message(msg)char *msg;{ dialog_set_prompt(messageDialog, msg); dialog_activate(messageDialog);} /* user_message *//*initialize_shell_icons() sets the icon for top-level windows.*/static void initialize_shell_icons(w, icon_name)Widget w;char *icon_name;{#include "xrolo.icon" Arg args[3]; int num_args = 1; icon_pixmap = XCreateBitmapFromData(XtDisplay(w), RootWindowOfScreen(XtScreen(w)), xrolo_bits, xrolo_width, xrolo_height); XtSetArg(args[0], XtNiconPixmap, (XtArgVal) icon_pixmap); if (icon_name) { XtSetArg(args[1], XtNiconName, (XtArgVal) icon_name); num_args++; } XtSetValues(w, args, num_args); XtSetValues(listShell_shell(entryIndex), args, num_args); XtSetValues(editor_replaceShell(entryEditWindow), args, num_args); XtSetValues(findShell, args, num_args); XtSetValues(help_shell(), args, num_args);} /* initialize_shell_icons *//*handle_close_buttons() accommodates the "Close" buttons. The actionsshould be hardcoded -- the user should not be allowed to override theXmUNMAP default for pop-ups.*/static void handle_close_buttons(w)Widget w;{ Atom xrolo_DELETE_WINDOW; Arg arg; xrolo_DELETE_WINDOW = XmInternAtom(XtDisplay(w), "WM_DELETE_WINDOW", False); XtSetArg(arg, XmNdeleteResponse, (XtArgVal) XmDO_NOTHING); XtSetValues(w, &arg, 1); XtSetValues(findShell, &arg, 1); XtSetValues(help_shell(), &arg, 1); XtSetValues(listShell_shell(entryIndex), &arg, 1); XtSetValues(editor_replaceShell(entryEditWindow), &arg, 1); XtSetValues(dialog_dialogShell(messageDialog), &arg, 1); XtSetValues(dialog_dialogShell(overwriteDialog), &arg, 1); XtSetValues(dialog_dialogShell(openUnsavedDialog), &arg, 1); XtSetValues(dialog_dialogShell(quitUnsavedDialog), &arg, 1); XtSetValues(XtParent(fileSelectionDialog), &arg, 1); XmAddWMProtocolCallback(w, xrolo_DELETE_WINDOW, Close, (caddr_t) w); XmAddWMProtocolCallback(findShell, xrolo_DELETE_WINDOW, UnmapWindow, (caddr_t) findShell); XmAddWMProtocolCallback(help_shell(), xrolo_DELETE_WINDOW, UnmapWindow, (caddr_t) help_shell()); XmAddWMProtocolCallback(listShell_shell(entryIndex), xrolo_DELETE_WINDOW, UnmapWindow, (caddr_t) listShell_shell(entryIndex)); XmAddWMProtocolCallback(editor_replaceShell(entryEditWindow), xrolo_DELETE_WINDOW, UnmapWindow, (caddr_t) editor_replaceShell(entryEditWindow)); XmAddWMProtocolCallback(dialog_dialogShell(messageDialog), xrolo_DELETE_WINDOW, DialogCancel, (caddr_t) messageDialog); XmAddWMProtocolCallback(dialog_dialogShell(overwriteDialog), xrolo_DELETE_WINDOW, DialogCancel, (caddr_t) overwriteDialog); XmAddWMProtocolCallback(dialog_dialogShell(openUnsavedDialog), xrolo_DELETE_WINDOW, DialogCancel, (caddr_t) openUnsavedDialog); XmAddWMProtocolCallback(dialog_dialogShell(quitUnsavedDialog), xrolo_DELETE_WINDOW, DialogCancel, (caddr_t) quitUnsavedDialog); XmAddWMProtocolCallback(XtParent(fileSelectionDialog), xrolo_DELETE_WINDOW, UnmanageWindow, (caddr_t) fileSelectionDialog);} /* handle_close_buttons */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -