📄 filer.c
字号:
char buf[MAX_FILENAME_LEN+11]; /* big enough for message */ sprintf(buf, "%s not found.", this_file); msg(buf, 1); return 0; } return 1;}voidedit_proc(){ void edit_file_proc(), edit_sel_proc(); int file_mode = (int)panel_get_value(filing_mode_item); if (file_mode) { (void)edit_sel_proc(); } else { (void)edit_file_proc(); }}voidedit_file_proc(){ char *filename; /* return if no selection */ if (!strlen(filename = (char *)panel_get_value(fname_item))) { msg("Please enter a value for \"File:\".", 1); return; } /* return if file not found */ if (!stat_file(filename)) return; window_set(editsw, TEXTSW_FILE, filename, 0); window_set(edit_frame, FRAME_LABEL, filename, WIN_SHOW, TRUE, 0);}voidedit_sel_proc(){ char *filename; /* return if no selection */ if (!strlen(filename = get_selection())) { msg("Please select a file to edit.", 0); return; } /* return if file not found */ if (!stat_file(filename)) return; window_set(editsw, TEXTSW_FILE, filename, 0); window_set(edit_frame, FRAME_LABEL, filename, WIN_SHOW, TRUE, 0);}voiddel_proc(){ char buf[300]; char *filename; int result; Event event; /* unused */ int file_mode = (int)panel_get_value(filing_mode_item); /* return if no selection */ if (file_mode) { if (!strlen(filename = get_selection())) { msg("Please select a file to delete.", 1); return; } } else { if (!strlen(filename = (char *)panel_get_value(fname_item))) { msg("Please enter a file name to delete.", 1); return; } } /* return if file not found */ if (!stat_file(filename)) return; /* user must confirm the delete */ result = alert_prompt(base_frame, &event, ALERT_MESSAGE_STRINGS, "Ok to delete file:", filename, 0, ALERT_BUTTON_YES, "Confirm, delete file", ALERT_BUTTON_NO, "Cancel", 0); switch (result) { case ALERT_YES: unlink(filename); sprintf(buf, "%s deleted.", filename); msg(buf, 0); break; case ALERT_NO: break; case ALERT_FAILED: /* not likely to happen unless out of memory */ sprintf(buf, "Ok to delete file %s?", filename); result = confirm_yes(buf); if (result) { unlink(filename); sprintf(buf, "%s deleted.", filename); msg(buf, 1); } break; }}intconfirm_quit(){ int result; Event event; /* unused */ char *msg = "Are you sure you want to Quit?"; result = alert_prompt(base_frame, &event, ALERT_MESSAGE_STRINGS, "Are you sure you want to Quit?", 0, ALERT_BUTTON_YES, "Confirm", ALERT_BUTTON_NO, "Cancel", 0); switch (result) { case ALERT_YES: break; case ALERT_NO: return 0; case ALERT_FAILED: /* not likely to happen unless out of memory */ result = confirm_yes(msg); if (!result) { return 0; } break; } return 1;}static Notify_valuefiler_destroy_func(client, status) Notify_client client; Destroy_status status;{ if (status == DESTROY_CHECKING) { if (quit_confirmed_from_panel) { return(notify_next_destroy_func(client, status)); } else if (confirm_quit() == 0) { (void) notify_veto_destroy((Notify_client)(LINT_CAST(client))); return(NOTIFY_DONE); } } return(notify_next_destroy_func(client, status));}voidquit_proc(){ if (confirm_quit()) { quit_confirmed_from_panel = 1; window_destroy(base_frame); }}msg(msg, beep) char *msg; int beep;{ char buf[300]; int result; Event event; /* unused */ char *contine_msg = "Press \"Continue\" to proceed."; result = alert_prompt(base_frame, &event, ALERT_MESSAGE_STRINGS, msg, contine_msg, 0, ALERT_NO_BEEPING, (beep) ? 0:1, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, /* allow either YES or NO answer */ 0); switch (result) { case ALERT_YES: case ALERT_TRIGGERED: /* result of ACTION_STOP trigger */ break; case ALERT_FAILED: /* not likely to happen unless out of memory */ sprintf(buf, "%s Press \"Continue\" to proceed.", msg); result = confirm_ok(buf); break; }}/* confirmer routines to be used if alert fails for any reason */static Frame init_confirmer();static int confirm();static void yes_no_ok();intconfirm_yes(message) char *message;{ return confirm(message, FALSE);}intconfirm_ok(message) char *message;{ return confirm(message, TRUE);}static intconfirm(message, ok_only) char *message; int ok_only;{ Frame confirmer; int answer; /* create the confirmer */ confirmer = init_confirmer(message, ok_only); /* make the user answer */ answer = (int) window_loop(confirmer); /* destroy the confirmer */ window_set(confirmer, FRAME_NO_CONFIRM, TRUE, 0); window_destroy(confirmer); return answer;}static Frameinit_confirmer(message, ok_only) char *message; int ok_only;{ Frame confirmer; Panel panel; Panel_item message_item; int left, top, width, height; Rect *r; struct pixrect *pr; confirmer = window_create(0, FRAME, FRAME_SHOW_LABEL, FALSE, 0); panel = window_create(confirmer, PANEL, 0); message_item = panel_create_item(panel, PANEL_MESSAGE, PANEL_LABEL_STRING, message, 0); if (ok_only) { pr = panel_button_image(panel, "Continue", 8, 0); width = pr->pr_width; } else { pr = panel_button_image(panel, "Cancel", 8, 0); width = 2 * pr->pr_width + 10; } /* center the yes/no or ok buttons under the message */ r = (Rect *) panel_get(message_item, PANEL_ITEM_RECT); left = (r->r_width - width) / 2; if (left < 0) left = 0; top = rect_bottom(r) + 5; if (ok_only) { panel_create_item(panel, PANEL_BUTTON, PANEL_ITEM_X, left, PANEL_ITEM_Y, top, PANEL_LABEL_IMAGE, pr, PANEL_CLIENT_DATA, 1, PANEL_NOTIFY_PROC, yes_no_ok, 0); } else { panel_create_item(panel, PANEL_BUTTON, PANEL_ITEM_X, left, PANEL_ITEM_Y, top, PANEL_LABEL_IMAGE, pr, PANEL_CLIENT_DATA, 0, PANEL_NOTIFY_PROC, yes_no_ok, 0); panel_create_item(panel, PANEL_BUTTON, PANEL_LABEL_IMAGE, panel_button_image(panel, "Confirm", 8, 0), PANEL_CLIENT_DATA, 1, PANEL_NOTIFY_PROC, yes_no_ok, 0); } window_fit(panel); window_fit(confirmer); /* center the confirmer frame on the screen */ r = (Rect *) window_get(confirmer, WIN_SCREEN_RECT); width = (int) window_get(confirmer, WIN_WIDTH); height = (int) window_get(confirmer, WIN_HEIGHT); left = (r->r_width - width) / 2; top = (r->r_height - height) / 2; if (left < 0) left = 0; if (top < 0) top = 0; window_set(confirmer, WIN_X, left, WIN_Y, top, 0); return confirmer;}static voidyes_no_ok(item, event) Panel_item item; Event *event;{ window_return(panel_get(item, PANEL_CLIENT_DATA));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -