static gboolean learn_check_key (int c) { int i; for (i = 0; i < learn_total; i++) { if (key_name_conv_tab[i].code != c || learnkeys[i].ok) continue; dlg_select_widget (learnkeys[i].button); /* TRANSLATORS: This label appears near learned keys. Keep it short. */ label_set_text (LABEL (learnkeys[i].label), _("OK")); learnkeys[i].ok = TRUE; learnok++; if (learnok >= learn_total) { learn_dlg->ret_value = B_CANCEL; if (learnchanged) { if (query_dialog (learn_title, _ ("It seems that all your keys already\n" "work fine. That's great."), D_ERROR, 2, _("&Save"), _("&Discard")) == 0) learn_dlg->ret_value = B_ENTER; } else { message (D_ERROR, learn_title, _ ("Great! You have a complete terminal database!\n" "All your keys work well.")); } dlg_stop (learn_dlg); } return TRUE; } switch (c) { case KEY_LEFT: case 'h': return learn_move (FALSE); case KEY_RIGHT: case 'l': return learn_move (TRUE); case 'j': dlg_one_down (learn_dlg); return TRUE; case 'k': dlg_one_up (learn_dlg); return TRUE; } /* Prevent from disappearing if a non-defined sequence is pressed and contains a button hotkey. Only recognize hotkeys with ALT. */ return (c < 255 && g_ascii_isalnum (c)); }
static int learn_check_key (int c) { int i; for (i = 0; i < learn_total; i++) { if (key_name_conv_tab [i].code == c) { if (!learnkeys [i].ok) { dlg_select_widget (learn_dlg, learnkeys [i].button); label_set_text ((WLabel *) learnkeys [i].label, _("OK")); learnkeys [i].ok = 1; learnok++; if (learnok >= learn_total) { learn_dlg->ret_value = B_CANCEL; if (learnchanged) { if (query_dialog (learn_title, _("It seems that all your keys already\n" "work fine. That's great."), 1, 2, _("&Save"), _("&Discard")) == 0) learn_dlg->ret_value = B_ENTER; } else { message (1, learn_title, _("Great! You have a complete terminal database!\n" "All your keys work well.")); } dlg_stop (learn_dlg); } return 1; } } } switch (c) { case KEY_LEFT: case 'h': return learn_move (0); case KEY_RIGHT: case 'l': return learn_move (1); case 'j': dlg_one_down (learn_dlg); return 1; case 'k': dlg_one_up (learn_dlg); return 1; } /* Prevent from disappearing if a non-defined sequence is pressed and contains s or c. Use ALT('s') or ALT('c'). */ if (c < 255 && isalpha(c)) { c = toupper(c); for (i = 0; i < BUTTONS; i++) if (c == learn_but [i].hotkey) return 1; } return 0; }
static void dlg_key_event (WDialog * h, int d_key) { cb_ret_t handled; if (h->widgets == NULL) return; if (h->current == NULL) h->current = h->widgets; /* TAB used to cycle */ if ((h->flags & DLG_WANT_TAB) == 0) { if (d_key == '\t') { dlg_one_down (h); return; } else if ((d_key & ~(KEY_M_SHIFT | KEY_M_CTRL)) == '\t') { dlg_one_up (h); return; } } /* first can dlg_callback handle the key */ handled = send_message (h, NULL, MSG_KEY, d_key, NULL); /* next try the hotkey */ if (handled == MSG_NOT_HANDLED) handled = dlg_try_hotkey (h, d_key); if (handled == MSG_HANDLED) send_message (h, NULL, MSG_HOTKEY_HANDLED, 0, NULL); else /* not used - then try widget_callback */ handled = send_message (h->current->data, NULL, MSG_KEY, d_key, NULL); /* not used- try to use the unhandled case */ if (handled == MSG_NOT_HANDLED) handled = send_message (h, NULL, MSG_UNHANDLED_KEY, d_key, NULL); if (handled == MSG_NOT_HANDLED) handled = dlg_handle_key (h, d_key); (void) handled; send_message (h, NULL, MSG_POST_KEY, d_key, NULL); }
static cb_ret_t dlg_execute_cmd (WDialog * h, unsigned long command) { cb_ret_t ret = MSG_HANDLED; switch (command) { case CK_Ok: h->ret_value = B_ENTER; dlg_stop (h); break; case CK_Cancel: h->ret_value = B_CANCEL; dlg_stop (h); break; case CK_Up: case CK_Left: dlg_one_up (h); break; case CK_Down: case CK_Right: dlg_one_down (h); break; case CK_Help: { ev_help_t event_data = { NULL, h->help_ctx }; mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data); } break; case CK_Suspend: mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL); refresh_cmd (); break; case CK_Refresh: refresh_cmd (); break; case CK_ScreenList: if (!h->modal) dialog_switch_list (); else ret = MSG_NOT_HANDLED; break; case CK_ScreenNext: if (!h->modal) dialog_switch_next (); else ret = MSG_NOT_HANDLED; break; case CK_ScreenPrev: if (!h->modal) dialog_switch_prev (); else ret = MSG_NOT_HANDLED; break; default: ret = MSG_NOT_HANDLED; } return ret; }
static void do_enter_key (WDialog * h, int f_pos) { WListbox *chl_list; struct passwd *chl_pass; struct group *chl_grp; int fe; gboolean chl_end, is_owner; do { int result; WDialog *chl_dlg; const char *title; int lxx, lyy, b_pos; is_owner = (f_pos == 3); title = is_owner ? _("owner") : _("group"); lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53); lyy = (LINES - 13) / 2; chl_end = FALSE; chl_dlg = dlg_create (TRUE, lyy, lxx, 13, 17, WPOS_KEEP_DEFAULT, TRUE, dialog_colors, chl_callback, NULL, "[Advanced Chown]", title); /* get new listboxes */ chl_list = listbox_new (1, 1, 11, 15, FALSE, NULL); listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL, FALSE); if (is_owner) { /* get and put user names in the listbox */ setpwent (); while ((chl_pass = getpwent ()) != NULL) listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL, FALSE); endpwent (); fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid)); } else { /* get and put group names in the listbox */ setgrent (); while ((chl_grp = getgrent ()) != NULL) listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL, FALSE); endgrent (); fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid)); } listbox_select_entry (chl_list, fe); b_pos = chl_list->pos; add_widget (chl_dlg, chl_list); result = dlg_run (chl_dlg); if (result != B_CANCEL) { if (b_pos != chl_list->pos) { gboolean ok = FALSE; char *text; listbox_get_current (chl_list, &text, NULL); if (is_owner) { chl_pass = getpwnam (text); if (chl_pass != NULL) { ok = TRUE; sf_stat->st_uid = chl_pass->pw_uid; } } else { chl_grp = getgrnam (text); if (chl_grp != NULL) { sf_stat->st_gid = chl_grp->gr_gid; ok = TRUE; } } if (ok) { ch_flags[f_pos + 6] = '+'; update_ownership (); } dlg_focus (h); if (ok) print_flags (); } if (result == KEY_LEFT) { if (!is_owner) chl_end = TRUE; dlg_one_up (ch_dlg); f_pos--; } else if (result == KEY_RIGHT) { if (is_owner) chl_end = TRUE; dlg_one_down (ch_dlg); f_pos++; } } /* Here we used to redraw the window */ dlg_destroy (chl_dlg); } while (chl_end); }
static cb_ret_t edit_dialog_command_execute (WDialog * h, long command) { Widget *wh = WIDGET (h); gboolean ret = MSG_HANDLED; switch (command) { case CK_EditNew: edit_add_window (h, wh->y + 1, wh->x, wh->lines - 2, wh->cols, NULL, 0); break; case CK_EditFile: edit_load_cmd (h); break; case CK_EditSyntaxFile: edit_load_syntax_file (h); break; case CK_EditUserMenu: edit_load_menu_file (h); break; case CK_Close: /* if there are no opened files anymore, close MC editor */ if (edit_widget_is_editor (WIDGET (h->current->data)) && edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL) dlg_stop (h); break; case CK_Help: edit_help (); /* edit->force |= REDRAW_COMPLETELY; */ break; case CK_Menu: edit_menu_cmd (h); break; case CK_Quit: case CK_Cancel: { Widget *w = WIDGET (h->current->data); if (!edit_widget_is_editor (w) || ((WEdit *) w)->drag_state == MCEDIT_DRAG_NORMAL) dlg_stop (h); else edit_restore_size ((WEdit *) w); } break; case CK_About: edit_about (); break; case CK_SyntaxOnOff: edit_syntax_onoff_cmd (h); break; case CK_ShowTabTws: edit_show_tabs_tws_cmd (h); break; case CK_ShowMargin: edit_show_margin_cmd (h); break; case CK_ShowNumbers: edit_show_numbers_cmd (h); break; case CK_Refresh: edit_refresh_cmd (); break; case CK_Shell: view_other_cmd (); break; case CK_LearnKeys: learn_keys (); break; case CK_WindowMove: case CK_WindowResize: if (edit_widget_is_editor (WIDGET (h->current->data))) edit_handle_move_resize ((WEdit *) h->current->data, command); break; case CK_WindowList: edit_window_list (h); break; case CK_WindowNext: dlg_one_down (h); dlg_set_top_widget (h->current->data); break; case CK_WindowPrev: dlg_one_up (h); dlg_set_top_widget (h->current->data); break; case CK_Options: edit_options_dialog (h); break; case CK_OptionsSaveMode: edit_save_mode_cmd (); break; case CK_SaveSetup: save_setup_cmd (); break; default: ret = MSG_NOT_HANDLED; break; } return ret; }
static void do_enter_key (Dlg_head * h, int f_pos) { Dlg_head *chl_dlg; WListbox *chl_list; struct passwd *chl_pass; struct group *chl_grp; WLEntry *fe; int lxx, lyy, chl_end, b_pos; int is_owner; const char *title; do { is_owner = (f_pos == 3); title = is_owner ? _("owner") : _("group"); lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53); lyy = (LINES - 13) / 2; chl_end = 0; chl_dlg = create_dlg (lyy, lxx, 13, 17, dialog_colors, chl_callback, "[Advanced Chown]", title, DLG_COMPACT | DLG_REVERSE); /* get new listboxes */ chl_list = listbox_new (1, 1, 11, 15, NULL); listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL); if (is_owner) { /* get and put user names in the listbox */ setpwent (); while ((chl_pass = getpwent ())) { listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL); } endpwent (); fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid)); } else { /* get and put group names in the listbox */ setgrent (); while ((chl_grp = getgrent ())) { listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL); } endgrent (); fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid)); } if (fe) listbox_select_entry (chl_list, fe); b_pos = chl_list->pos; add_widget (chl_dlg, chl_list); run_dlg (chl_dlg); if (b_pos != chl_list->pos) { int ok = 0; if (is_owner) { chl_pass = getpwnam (chl_list->current->text); if (chl_pass) { ok = 1; sf_stat->st_uid = chl_pass->pw_uid; } } else { chl_grp = getgrnam (chl_list->current->text); if (chl_grp) { sf_stat->st_gid = chl_grp->gr_gid; ok = 1; } } if (ok) { ch_flags[f_pos + 6] = '+'; update_ownership (); } dlg_focus (h); if (ok) print_flags (); } if (chl_dlg->ret_value == KEY_LEFT) { if (!is_owner) chl_end = 1; dlg_one_up (ch_dlg); f_pos--; } else if (chl_dlg->ret_value == KEY_RIGHT) { if (is_owner) chl_end = 1; dlg_one_down (ch_dlg); f_pos++; } /* Here we used to redraw the window */ destroy_dlg (chl_dlg); } while (chl_end); }