📄 control.c
字号:
/* | control.c | | $Header: /home/hugh/sources/aee/RCS/control.c,v 1.43 1999/02/01 01:10:02 hugh Exp $ *//* | Copyright (c) 1986 - 1988, 1991 - 1999 Hugh Mahon. */#include "aee.h"static char item_alpha[] = "abcdefghijklmnopqrstuvwxyz0123456789 ";#define max_alpha_char 36int menu_op(menu_list)struct menu_entries menu_list[];{ WINDOW *temp_win; int max_width, max_height; int x_off, y_off; int counter; int length; int input; int temp; int list_size; int top_offset; /* offset from top where menu items start */ int vert_pos; /* vertical position */ int vert_size; /* vertical size for menu list item display */ int off_start = 1; /* offset from start of menu items to start display */ /* | determine number and width of menu items */ list_size = 1; while (menu_list[list_size + 1].item_string != NULL) list_size++; max_width = 0; for (counter = 0; counter <= list_size; counter++) { if ((length = strlen(menu_list[counter].item_string)) > max_width) max_width = length; } max_width += 3; max_width = max(max_width, strlen(cancel_string)); max_width = max(max_width, max(strlen(more_above_str), strlen(more_below_str))); max_width += 6; /* | make sure that window is large enough to handle menu | if not, print error message and return to calling function */ if ((max_width > COLS) || ((list_size > LINES) && (LINES < 3))) { wmove(com_win, 0, 0); werase(com_win); wprintw(com_win, menu_too_lrg_msg); wrefresh(com_win); clr_cmd_line = TRUE; return(0); } top_offset = 0; if (list_size > LINES) { max_height = LINES; if (max_height > 11) vert_size = max_height - 8; else vert_size = max_height; } else { vert_size = list_size; max_height = list_size; } if (LINES >= (vert_size + 8)) { if (menu_list[0].argument != MENU_WARN) max_height = vert_size + 8; else max_height = vert_size + 7; top_offset = 4; } x_off = (COLS - max_width) / 2; y_off = (LINES - max_height - 1) / 2; temp_win = newwin(max_height, max_width, y_off, x_off); keypad(temp_win, TRUE); paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size); counter = 1; vert_pos = 0; do { if (off_start > 2) wmove(temp_win, (1 + counter + top_offset - off_start), 3); else wmove(temp_win, (counter + top_offset - off_start), 3); wrefresh(temp_win); get_input(temp_win); input = in; if (input == -1) exit(0); if (((tolower(input) >= 'a') && (tolower(input) <= 'z')) || ((input >= '0') && (input <= '9'))) { if ((tolower(input) >= 'a') && (tolower(input) <= 'z')) { temp = 1 + tolower(input) - 'a'; } else if ((input >= '0') && (input <= '9')) { temp = (2 + 'z' - 'a') + (input - '0'); } if (temp <= list_size) { input = '\n'; counter = temp; } } else { switch (input) { case ' ': /* space */ case '\004': /* ^d, down */ case KEY_RIGHT: case KEY_DOWN: counter++; if (counter > list_size) counter = 1; break; case '\010': /* ^h, backspace*/ case '\025': /* ^u, up */ case 127: /* ^?, delete */ case KEY_BACKSPACE: case KEY_LEFT: case KEY_UP: counter--; if (counter == 0) counter = list_size; break; case '\033': /* escape key */ if (menu_list[0].argument != MENU_WARN) counter = 0; break; case '\014': /* ^l */ case '\022': /* ^r, redraw */ paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size); break; default: break; } } if (((list_size - off_start) >= (vert_size - 1)) && (counter > (off_start + vert_size - 3)) && (off_start > 1)) { if (counter == list_size) off_start = (list_size - vert_size) + 2; else off_start++; paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size); } else if ((list_size != vert_size) && (counter > (off_start + vert_size - 2))) { if (counter == list_size) off_start = 2 + (list_size - vert_size); else if (off_start == 1) off_start = 3; else off_start++; paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size); } else if (counter < off_start) { if (counter <= 2) off_start = 1; else off_start = counter; paint_menu(menu_list, max_width, max_height, list_size, top_offset, temp_win, off_start, vert_size); } } while ((input != '\r') && (input != '\n') && (counter != 0)); werase(temp_win); wrefresh(temp_win); delwin(temp_win); if ((menu_list[counter].procedure != NULL) || (menu_list[counter].iprocedure != NULL) || (menu_list[counter].nprocedure != NULL)) { if (menu_list[counter].argument != -1) (*menu_list[counter].iprocedure)(menu_list[counter].argument); else if (menu_list[counter].ptr_argument != NULL) (*menu_list[counter].procedure)(menu_list[counter].ptr_argument); else (*menu_list[counter].nprocedure)(); } if (info_window) paint_info_win(); redraw(); return(counter);}void paint_menu(menu_list, max_width, max_height, list_size, top_offset, menu_win, off_start, vert_size)struct menu_entries menu_list[];int max_width, max_height, list_size, top_offset;WINDOW *menu_win;int off_start, vert_size;{ int counter, temp_int; werase(menu_win); /* | output top and bottom portions of menu box only if window | large enough */ if (max_height > vert_size) { wmove(menu_win, 1, 1); if (!nohighlight) wstandout(menu_win); waddch(menu_win, '+'); for (counter = 0; counter < (max_width - 4); counter++) waddch(menu_win, '-'); waddch(menu_win, '+'); wmove(menu_win, (max_height - 2), 1); waddch(menu_win, '+'); for (counter = 0; counter < (max_width - 4); counter++) waddch(menu_win, '-'); waddch(menu_win, '+'); wstandend(menu_win); wmove(menu_win, 2, 3); waddstr(menu_win, menu_list[0].item_string); wmove(menu_win, (max_height - 3), 3); if (menu_list[0].argument != MENU_WARN) waddstr(menu_win, cancel_string); } if (!nohighlight) wstandout(menu_win); for (counter = 0; counter < (vert_size + top_offset); counter++) { if (top_offset == 4) { temp_int = counter + 2; } else temp_int = counter; wmove(menu_win, temp_int, 1); waddch(menu_win, '|'); wmove(menu_win, temp_int, (max_width - 2)); waddch(menu_win, '|'); } wstandend(menu_win); if (list_size > vert_size) { if (off_start >= 3) { temp_int = 1; wmove(menu_win, top_offset, 3); waddstr(menu_win, more_above_str); } else temp_int = 0; for (counter = off_start; ((temp_int + counter - off_start) < (vert_size - 1)); counter++) { wmove(menu_win, (top_offset + temp_int + (counter - off_start)), 3); if (list_size > 1) wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]); waddstr(menu_win, menu_list[counter].item_string); } wmove(menu_win, (top_offset + (vert_size - 1)), 3); if (counter == list_size) { if (list_size > 1) wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]); wprintw(menu_win, menu_list[counter].item_string); } else wprintw(menu_win, more_below_str); } else { for (counter = 1; counter <= list_size; counter++) { wmove(menu_win, (top_offset + counter - 1), 3); if (list_size > 1) wprintw(menu_win, "%c) ", item_alpha[min((counter - 1), max_alpha_char)]); waddstr(menu_win, menu_list[counter].item_string); } }}void shell_op(){ char *string; if (((string = get_string(shell_cmd_prompt, TRUE)) != NULL) && (*string != (char) NULL)) { sh_command(string); free(string); }}void leave_op(){ int index; if ((num_of_bufs > 1) && (top_of_stack == NULL)) { index = menu_op(leave_menu_2); switch(index) { case 2: index = delete_all_buffers(); if (index == FALSE) return; break; case 1: default: repaint_screen(); return; } } if (first_buff->changed) { index = menu_op(leave_menu); repaint_screen(); switch (index) { case 1: finish(EXIT_str); break; case 2: first_buff->changed = FALSE; quit(QUIT_str); break; default: return; } } else { repaint_screen(); quit(QUIT_str); }}void spell_op() /* check spelling of words in the editor */{ if (restrict_mode()) { return; } top(); /* go to top of file */ insert_line(FALSE); /* create two blank lines */ insert_line(FALSE); top(); command(shell_echo_msg); adv_line(); wmove(com_win, 0, 0); wprintw(com_win, spell_in_prog_msg); wrefresh(com_win); command("<>!spell"); /* send contents of buffer to command 'spell' and read the results back into the editor */}void ispell_op(){ char name[128]; char string[256]; int pid; if (restrict_mode()) { return; } pid = getpid(); sprintf(name, "/tmp/ae.%d", pid); if (write_file(name)) { sprintf(string, "ispell %s", name); sh_command(string); delete_text(); tmp_file = name; recv_file = TRUE; check_fp(); unlink(name); }}void modes_op(){ int ret_value; int counter; char *string; int temp_int; modes_menu[17].item_string = mode_strings[17]; do { sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1], (expand ? ON : OFF)); sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2], (case_sen ? ON : OFF)); sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3], ( literal ? ON : OFF)); sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4], (forward ? "forward" : "reverse")); sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5], (observ_margins ? ON : OFF)); sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6], ( info_window ? ON : OFF)); sprintf(modes_menu[7].item_string, "%s %s", mode_strings[7], ( status_line ? ON : OFF)); sprintf(modes_menu[8].item_string, "%s %s", mode_strings[8], ( indent ? ON : OFF)); sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9], ( overstrike ? ON : OFF)); sprintf(modes_menu[10].item_string, "%s %s", mode_strings[10], ( auto_format ? ON : OFF)); sprintf(modes_menu[11].item_string, "%s %s", mode_strings[11], ( windows ? ON : OFF)); sprintf(modes_menu[12].item_string, "%s %3d", mode_strings[12], left_margin); sprintf(modes_menu[13].item_string, "%s %3d", mode_strings[13], right_margin); sprintf(modes_menu[14].item_string, "%s %3d", mode_strings[14], (info_win_height - 1)); sprintf(modes_menu[15].item_string, "%s %s", mode_strings[15], (text_only ? text_msg : binary_msg )); sprintf(modes_menu[16].item_string, "%s %s", mode_strings[16], (curr_buff->dos_file ? dos_msg : unix_msg )); ret_value = menu_op(modes_menu); switch (ret_value) { case 1: expand = !expand; break; case 2: case_sen = !case_sen; break; case 3: literal = !literal; break; case 4: forward = !forward; break; case 5: observ_margins = !observ_margins; break; case 6: info_op(); break; case 7: status_line = !status_line; break; case 8: indent = !indent; break; case 9: overstrike = !overstrike; break; case 10: auto_format = !auto_format; if (auto_format) { observ_margins = TRUE; indent = FALSE; } break; case 11: if (!windows) make_win(); else no_windows(); break; case 12: string = get_string(left_marg_prompt, TRUE); if (string != NULL) { counter = atoi(string);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -