Merge branch '3815_quickview_return'

* 3815_quickview_return:
  TreeView should mute the command-line.
  QuickView shouldn't consume all keys.
  Factor out handle_cmdline_enter().
  Ticket #3815: Factor out is_cmdline_mute().
This commit is contained in:
Mooffie 2017-04-24 18:35:07 +03:00
commit 9df3933a4a
2 changed files with 53 additions and 26 deletions

View File

@ -1400,6 +1400,54 @@ midnight_execute_cmd (Widget * sender, long command)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/**
* Whether the command-line should not respond to key events.
*
* This is TRUE if a QuickView or TreeView have the focus, as they're going
* to consume some keys and there's no sense in passing to the command-line
* just the leftovers.
*/
static gboolean
is_cmdline_mute (void)
{
/* When one of panels is other than view_listing,
current_panel points to view_listing panel all time independently of
it's activity. Thus, we can't use get_current_type() here.
current_panel should point to actualy current active panel
independently of it's type. */
return (current_panel->active == 0
&& (get_other_type () == view_quick || get_other_type () == view_tree));
}
/* --------------------------------------------------------------------------------------------- */
/**
* Handles the Enter key on the command-line.
*
* Returns TRUE if non-whitespace was indeed processed.
*/
static gboolean
handle_cmdline_enter (void)
{
size_t i;
for (i = 0; cmdline->buffer[i] != '\0' && whitespace (cmdline->buffer[i]); i++)
;
if (cmdline->buffer[i] != '\0')
{
send_message (cmdline, NULL, MSG_KEY, '\n', NULL);
return TRUE;
}
input_insert (cmdline, "", FALSE);
cmdline->point = 0;
return FALSE;
}
/* --------------------------------------------------------------------------------------------- */
static cb_ret_t static cb_ret_t
midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
@ -1455,31 +1503,11 @@ midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
if (widget_get_state (WIDGET (the_menubar), WST_FOCUSED)) if (widget_get_state (WIDGET (the_menubar), WST_FOCUSED))
return MSG_NOT_HANDLED; return MSG_NOT_HANDLED;
if (parm == '\n') if (parm == '\n' && !is_cmdline_mute ())
{ {
size_t i; if (handle_cmdline_enter ())
/* HACK: don't execute command in the command line if Enter was pressed
in the quick viewer panel. */
/* TODO: currently, when one of panels is other than view_listing,
current_panel points to view_listing panel all time independently of
it's activity. Thus, we can't use get_current_type() here.
current_panel should point to actualy current active panel
independently of it's type. */
if (current_panel->active == 0 && get_other_type () == view_quick)
return MSG_NOT_HANDLED;
for (i = 0; cmdline->buffer[i] != '\0' && whitespace (cmdline->buffer[i]); i++)
;
if (cmdline->buffer[i] != '\0')
{
send_message (cmdline, NULL, MSG_KEY, parm, NULL);
return MSG_HANDLED; return MSG_HANDLED;
} /* Else: the panel will handle it. */
input_insert (cmdline, "", FALSE);
cmdline->point = 0;
} }
if ((!mc_global.tty.alternate_plus_minus if ((!mc_global.tty.alternate_plus_minus
@ -1542,7 +1570,7 @@ midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
if (command != CK_IgnoreKey) if (command != CK_IgnoreKey)
v = midnight_execute_cmd (NULL, command); v = midnight_execute_cmd (NULL, command);
if (v == MSG_NOT_HANDLED && command_prompt) if (v == MSG_NOT_HANDLED && command_prompt && !is_cmdline_mute ())
v = send_message (cmdline, NULL, MSG_KEY, parm, NULL); v = send_message (cmdline, NULL, MSG_KEY, parm, NULL);
return v; return v;

View File

@ -674,8 +674,7 @@ mcview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *
case MSG_KEY: case MSG_KEY:
i = mcview_handle_key (view, parm); i = mcview_handle_key (view, parm);
mcview_update (view); mcview_update (view);
/* don't pass any chars to command line in QuickView mode */ return i;
return mcview_is_in_panel (view) ? MSG_HANDLED : i;
case MSG_ACTION: case MSG_ACTION:
i = mcview_execute_cmd (view, parm); i = mcview_execute_cmd (view, parm);