From 87428aa8ea449163eab1c63115162d7ca9e7e7e1 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Wed, 28 Mar 2012 22:29:02 +0400 Subject: [PATCH] added new keybindings (F3, F4) in history list. Signed-off-by: Ilia Maslakov --- lib/widget/history.c | 49 ++++++++++++++++++++++++++++++++++++-- lib/widget/history.h | 2 +- lib/widget/input.c | 2 +- src/filemanager/midnight.c | 29 +++++++++++++++++++--- src/filemanager/panel.c | 2 +- 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/lib/widget/history.c b/lib/widget/history.c index fb2b064a0..e01b5b2ca 100644 --- a/lib/widget/history.c +++ b/lib/widget/history.c @@ -57,6 +57,9 @@ int num_history_items_recorded = 60; /*** file scope macro definitions ****************************************************************/ +#define B_VIEW (B_USER + 1) +#define B_EDIT (B_USER + 2) + /*** file scope type declarations ****************************************************************/ typedef struct @@ -114,6 +117,28 @@ history_dlg_reposition (WDialog * dlg_head) /* --------------------------------------------------------------------------------------------- */ +static inline cb_ret_t +history_handle_key (WDialog * h, int key) +{ + switch (key) + { + case KEY_F (3): + h->ret_value = B_VIEW; + dlg_stop (h); + return MSG_HANDLED; + + case KEY_F (4): + h->ret_value = B_EDIT; + dlg_stop (h); + return MSG_HANDLED; + + default: + return MSG_NOT_HANDLED; + } +} + +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t history_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { @@ -122,6 +147,9 @@ history_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v case MSG_RESIZE: return history_dlg_reposition (DIALOG (w)); + case MSG_UNHANDLED_KEY: + return history_handle_key (DIALOG (w), parm); + default: return dlg_default_callback (w, sender, msg, parm, data); } @@ -285,7 +313,7 @@ history_save (mc_config_t * cfg, const char *name, GList * h) /* --------------------------------------------------------------------------------------------- */ char * -history_show (GList ** history, Widget * widget, int current) +history_show (GList ** history, Widget * widget, int current, int *action) { GList *z, *hlist = NULL, *hi; size_t maxlen, count = 0; @@ -293,6 +321,7 @@ history_show (GList ** history, Widget * widget, int current) WDialog *query_dlg; WListbox *query_list; history_dlg_data hist_data; + int dlg_ret; if (*history == NULL) return NULL; @@ -356,10 +385,26 @@ history_show (GList ** history, Widget * widget, int current) listbox_select_entry (query_list, current); } - if (dlg_run (query_dlg) != B_CANCEL) + dlg_ret = dlg_run (query_dlg); + if (dlg_ret != B_CANCEL) { char *q; + if (action != NULL) + { + switch (dlg_ret) + { + case B_EDIT: + *action = CK_Edit; + break; + case B_VIEW: + *action = CK_View; + break; + default: + *action = CK_CdChild; + } + } + listbox_get_current (query_list, &q, NULL); r = g_strdup (q); } diff --git a/lib/widget/history.h b/lib/widget/history.h index 101ffd411..48038de3d 100644 --- a/lib/widget/history.h +++ b/lib/widget/history.h @@ -28,7 +28,7 @@ GList *history_load (mc_config_t * cfg, const char *name); void history_save (mc_config_t * cfg, const char *name, GList * h); /* for repositioning of history dialog we should pass widget to this * function, as position of history dialog depends on widget's position */ -char *history_show (GList ** history, Widget * widget, int current); +char *history_show (GList ** history, Widget * widget, int current, int *action); /*** inline functions ****************************************************************************/ diff --git a/lib/widget/input.c b/lib/widget/input.c index 20abe8bf9..8ec57a4de 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -176,7 +176,7 @@ do_show_hist (WInput * in) len = get_history_length (in->history.list); r = history_show (&in->history.list, WIDGET (in), - g_list_position (in->history.list, in->history.list)); + g_list_position (in->history.list, in->history.list), NULL); if (r != NULL) { input_assign_text (in, r); diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 76fb08519..2dbf5487b 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -1014,6 +1014,7 @@ show_editor_history_list (void) GList *file_list = NULL; char *s; WPanel *panel = current_panel; + int act; /* open file with positions */ fn = mc_config_get_full_path (MC_FILEPOS_FILE); @@ -1035,15 +1036,37 @@ show_editor_history_list (void) fclose (f); file_list = g_list_last (file_list); - s = history_show (&file_list, WIDGET (panel)); + s = history_show (&file_list, WIDGET (panel), 0, &act); if (s != NULL) { vfs_path_t *s_vpath; - s_vpath = vfs_path_from_str (s); + switch (act) + { + case CK_Edit: + s_vpath = vfs_path_from_str (s); + edit_file_at_line (s_vpath, use_internal_edit, 0); + break; + + case CK_View: + s_vpath = vfs_path_from_str (s); + view_file (s_vpath, use_internal_view, 0); + break; + + default: + { + char *d; + + d = g_path_get_dirname (s); + s_vpath = vfs_path_from_str (d); + do_cd (s_vpath, cd_exact); + try_to_select (current_panel, s); + g_free (d); + } + } + g_free (s); - do_edit_at_line (s_vpath, use_internal_edit, 0); vfs_path_free (s_vpath); } diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 476d21219..347575f51 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -3355,7 +3355,7 @@ directory_history_list (WPanel * panel) pos = g_list_position (panel->dir_history_current, panel->dir_history); - s = history_show (&panel->dir_history, WIDGET (panel), pos); + s = history_show (&panel->dir_history, WIDGET (panel), pos, NULL); if (s != NULL) { vfs_path_t *s_vpath;