📄 textsw_menu.c
字号:
} } menu_show_using_fd(textsw->menu, view->window_fd, ie);}static inttextsw_do_menu_action(cmd_menu, cmd_item) Menu cmd_menu; Menu_item cmd_item;{ extern void textsw_find_selection_and_normalize(); extern void textsw_reset(); pkg_private void textsw_move_caret(); extern int textsw_match_selection_and_normalize(); Textsw abstract = (Textsw)LINT_CAST( menu_get(cmd_item, MENU_CLIENT_DATA, 0)); register Textsw_view view; register Textsw_folio textsw; Textsw_menu_cmd cmd = (Textsw_menu_cmd) menu_get(cmd_item, MENU_VALUE, 0); register Event *ie = (Event *)LINT_CAST( menu_get(cmd_menu, MENU_FIRST_EVENT, 0) ); register int locx, locy; Event event; register long unsigned find_options = 0; Es_index first, last_plus_one; char current_selection[200], err_msg[300]; if AN_ERROR(abstract == 0) return; view = VIEW_ABS_TO_REP(abstract); textsw = FOLIO_FOR_VIEW(view); if AN_ERROR(ie == 0) { locx = locy = 0; } else { locx = ie->ie_locx; locy = ie->ie_locy; } /* initialize arrays */ current_selection[0] = 0; err_msg[0] = 0; switch (cmd) { case TEXTSW_MENU_RESET: textsw_empty_document(abstract, ie); break; case TEXTSW_MENU_LOAD: textsw_load_file_as_menu(abstract, ie); break; case TEXTSW_MENU_SAVE_CLOSE: textsw_notify(view, TEXTSW_ACTION_TOOL_CLOSE, 0); /* Fall through */ case TEXTSW_MENU_SAVE: if (cmd == TEXTSW_MENU_SAVE) { Es_handle original; original = (Es_handle)LINT_CAST( es_get(textsw->views->esh, ES_PS_ORIGINAL) ); if ((TXTSW_IS_READ_ONLY(textsw)) || (original == ES_NULL) || (Es_enum)LINT_CAST(es_get( original, ES_TYPE)) != ES_TYPE_FILE) { Event alert_event; (void) alert_prompt( (Frame)window_get(WINDOW_FROM_VIEW(view), WIN_OWNER), &alert_event, ALERT_MESSAGE_STRINGS, "Unable to Save Current File.", "You are not currently editing a file.", "Use \"Store as New File\" to save your work.", 0, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, 0); break; } } case TEXTSW_MENU_SAVE_QUIT: case TEXTSW_MENU_SAVE_RESET: { Es_status status; status = (Es_status)textsw_save(VIEW_REP_TO_ABS(view), locx, locy); if (status == ES_SUCCESS) { if (cmd == TEXTSW_MENU_SAVE_QUIT) { textsw_notify( view, TEXTSW_ACTION_TOOL_DESTROY, (char *)ie, 0); } else if (cmd == TEXTSW_MENU_SAVE_RESET) { textsw_reset(abstract, locx, locy); break; } } break; } case TEXTSW_MENU_STORE_CLOSE: textsw_notify(view, TEXTSW_ACTION_TOOL_CLOSE, 0); case TEXTSW_MENU_STORE: case TEXTSW_MENU_STORE_QUIT: { Es_status status; status = textsw_store_to_selection(textsw, locx, locy); if ((status == ES_SUCCESS) && (cmd == TEXTSW_MENU_STORE_QUIT)) { textsw_notify(view, TEXTSW_ACTION_TOOL_DESTROY, (char *)ie, 0); } break; } case TEXTSW_MENU_CREATE_VIEW: { int result, my_x, my_y; Rect *my_place; Frame base_frame = (Frame)window_get(WINDOW_FROM_VIEW(view), WIN_OWNER); if (!base_frame) { (void)textsw_alert_for_old_interface(view); return; } result = alert_prompt(base_frame, &event, ALERT_NO_BEEPING, 1, ALERT_NO_IMAGE, 1, ALERT_MESSAGE_STRINGS, "Move pointer to where new view should", "begin, then click the left mouse button.", " ", "Otherwise, push \"Cancel Split View\".", 0, ALERT_BUTTON_NO, "Cancel Split View", ALERT_TRIGGER, MS_LEFT, 0); if (result != ALERT_TRIGGERED) break; my_place = (Rect *)window_get(WINDOW_FROM_VIEW(view), WIN_RECT); my_x = (event.ie_locx - my_place->r_left); my_y = (event.ie_locy - my_place->r_top - (2*TOOL_BORDERWIDTH)); (void) textsw_split_view(VIEW_REP_TO_ABS(view), my_x, my_y); break; } case TEXTSW_MENU_DESTROY_VIEW: { (void) textsw_destroy_split(VIEW_REP_TO_ABS(view), locx, locy); break; } case TEXTSW_MENU_CLIP_LINES: textsw_set(VIEW_REP_TO_ABS(view), TEXTSW_LINE_BREAK_ACTION, TEXTSW_CLIP, 0); break; case TEXTSW_MENU_WRAP_LINES_AT_CHAR: textsw_set(VIEW_REP_TO_ABS(view), TEXTSW_LINE_BREAK_ACTION, TEXTSW_WRAP_AT_CHAR, 0); break; case TEXTSW_MENU_WRAP_LINES_AT_WORD: textsw_set(VIEW_REP_TO_ABS(view), TEXTSW_LINE_BREAK_ACTION, TEXTSW_WRAP_AT_WORD, 0); break; case TEXTSW_MENU_NORMALIZE_INSERTION: { extern Es_index ev_get_insert(); Es_index insert; int upper_context; insert = ev_get_insert(textsw->views); if (insert != ES_INFINITY) { upper_context = (int)LINT_CAST( ev_get(textsw->views, EV_CHAIN_UPPER_CONTEXT) ); textsw_normalize_internal(view, insert, insert, upper_context, 0, TXTSW_NI_DEFAULT); } break; } case TEXTSW_MENU_NORMALIZE_BOTTOM: { (void) textsw_move_caret(view, TXTSW_DOCUMENT_END); break; } case TEXTSW_MENU_NORMALIZE_TOP: { (void) textsw_move_caret(view, TXTSW_DOCUMENT_START); break; }#ifdef TEXTSW_MENU_NORMALIZE_SELECTION case TEXTSW_MENU_NORMALIZE_SELECTION: { ev_get_selection( textsw->views, &first, &last_plus_one, EV_SEL_PRIMARY); if (first != ES_INFINITY) { textsw_normalize_view(VIEW_REP_TO_ABS(view), first); } break; }#endif case TEXTSW_MENU_NORMALIZE_LINE: { Es_index prev; char buf[10]; unsigned buf_fill_len; int line_number; line_number = textsw_get_selection_as_int(textsw, EV_SEL_PRIMARY, 0); if (line_number == 0) goto Out_Of_Range; else { buf[0] = '\n'; buf_fill_len = 1; if (line_number == 1) { prev = 0; } else { ev_find_in_esh(textsw->views->esh, buf, buf_fill_len, (Es_index)0, (u_int)line_number-1, 0, &first, &prev); if (first == ES_CANNOT_SET) goto Out_Of_Range; } ev_find_in_esh(textsw->views->esh, buf, buf_fill_len, prev, 1, 0, &first, &last_plus_one); if (first == ES_CANNOT_SET) goto Out_Of_Range; textsw_possibly_normalize_and_set_selection( VIEW_REP_TO_ABS(view), prev, last_plus_one, EV_SEL_PRIMARY); (void) textsw_set_insert(textsw, last_plus_one); }Out_Of_Range: break; } case TEXTSW_MENU_COUNT_TO_LINE: { char msg[200]; int result, count; ev_get_selection( textsw->views, &first, &last_plus_one, EV_SEL_PRIMARY); if (first >= last_plus_one) break; count = ev_newlines_in_esh(textsw->views->esh, 0, first); (void) sprintf(msg, "Selection starts in line %d.", count+1); result = alert_prompt( (Frame)window_get(WINDOW_FROM_VIEW(view), WIN_OWNER), &event, ALERT_NO_BEEPING, 1, ALERT_NO_IMAGE, 1, ALERT_MESSAGE_STRINGS, msg, "Press \"Continue\" to proceed.", 0, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, 0); break; } case TEXTSW_MENU_FILE_STUFF:{ textsw_file_stuff(view, locx, locy); break; } case TEXTSW_MENU_CD: { textsw_cd(textsw, locx, locy); break; } case TEXTSW_MENU_FIND_BACKWARD: find_options = TFSAN_BACKWARD; /* Fall through */ case TEXTSW_MENU_FIND: find_options |= (EV_SEL_PRIMARY | TFSAN_SHELF_ALSO); textsw_find_selection_and_normalize(view, locx, locy, find_options); break; case TEXTSW_MENU_FIND_SHELF_BACKWARD: find_options = TFSAN_BACKWARD; /* Fall through */ case TEXTSW_MENU_FIND_SHELF: find_options |= EV_SEL_SHELF; textsw_find_selection_and_normalize(view, locx, locy, find_options); break; case TEXTSW_MENU_SEL_ENCLOSE_FIELD: { int first, last_plus_one; first = last_plus_one = ev_get_insert(textsw->views); (void) textsw_match_field_and_normalize(view, &first, &last_plus_one, "<|", 2, TEXTSW_FIELD_ENCLOSE, FALSE); break; } case TEXTSW_MENU_SEL_NEXT_FIELD: (void) textsw_match_selection_and_normalize(view, "|>", TEXTSW_FIELD_FORWARD); break; case TEXTSW_MENU_SEL_PREV_FIELD: (void) textsw_match_selection_and_normalize(view, "<|", TEXTSW_FIELD_BACKWARD); break; case TEXTSW_MENU_SEL_MARK_TEXT: (void) textsw_create_match_frame(view); break; #ifdef _TEXTSW_FIND_RE case TEXTSW_MENU_FIND_RE_BACKWARD: find_options = TFSAN_BACKWARD; /* Fall through */ case TEXTSW_MENU_FIND_RE: find_options |= (EV_SEL_PRIMARY | TFSAN_REG_EXP | TFSAN_SHELF_ALSO); textsw_find_selection_and_normalize(view, locx, locy, find_options); break; case TEXTSW_MENU_FIND_TAG_BACKWARD: find_options = TFSAN_BACKWARD; /* Fall through */ case TEXTSW_MENU_FIND_TAG: find_options |= (EV_SEL_PRIMARY | TFSAN_REG_EXP | TFSAN_SHELF_ALSO | TFSAN_TAG); textsw_find_selection_and_normalize(view, locx, locy, find_options); break;#endif case TEXTSW_MENU_PUT_THEN_GET: textsw_put_then_get(view); break; case TEXTSW_MENU_FIND_AND_REPLACE: (void) textsw_create_search_frame(view); break; case TEXTSW_MENU_MATCH_FIELD: { char *start_marker; (void) textsw_match_selection_and_normalize(view, start_marker, TEXTSW_NOT_A_FIELD); break; } case TEXTSW_MENU_AGAIN: textsw_again(view, locx, locy); break; case TEXTSW_MENU_UNDO: textsw_undo(textsw); break; case TEXTSW_MENU_UNDO_ALL: { int result; if (textsw_has_been_modified(abstract)) { result = alert_prompt( (Frame)window_get(WINDOW_FROM_VIEW(view), WIN_OWNER), &event, ALERT_MESSAGE_STRINGS, "Undo All Edits will discard unsaved edits.", "Please confirm.", 0, ALERT_BUTTON_YES, "Confirm, discard edits", ALERT_BUTTON_NO, "Cancel", ALERT_NO_BEEPING, 1, 0); if (result == ALERT_YES) textsw_reset_2(abstract, locx, locy, TRUE, TRUE); } break; } case TEXTSW_MENU_SHOW_CLIPBOARD_FROM_EDIT: /* fall through */ case TEXTSW_MENU_SHOW_CLIPBOARD_FROM_FIND: stuff_clipboard(); break; case TEXTSW_MENU_CUT: textsw_function_delete(view); break; case TEXTSW_MENU_COPY: textsw_put(view); break; case TEXTSW_MENU_PASTE: (void) textsw_function_get(view); break; default: break; }}pkg_private intawait_neg_event(windowfd, event) int windowfd; struct inputevent *event;{ struct fullscreen *fsh; struct inputevent new_event; fsh = fullscreen_init(windowfd); if (fsh == 0) return(1); FOREVER { if AN_ERROR(input_readevent(windowfd, &new_event) == -1) { break; } if (event_action(&new_event) == event_action(event) && win_inputnegevent(&new_event)) break; } fullscreen_destroy(fsh); return(0);}/* ARGSUSED */extern Textswtextsw_split_view(abstract, locx, locy) Textsw abstract; int locx, locy; /* locx currently unused */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -