Handle CK_Filter command in the file panel level.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2022-04-03 18:20:30 +03:00
parent 450993fff6
commit 63e870867e
7 changed files with 43 additions and 54 deletions

View File

@ -127,6 +127,7 @@ Bottom = alt-gt; end; c1
# SortByExt =
# SortBySize =
# SortByMTime =
# Filter =
# ScrollLeft =
# ScrollRight =

View File

@ -127,6 +127,7 @@ Bottom = alt-gt; end; c1
# SortByExt =
# SortBySize =
# SortByMTime =
# Filter =
# ScrollLeft =
# ScrollRight =

View File

@ -167,40 +167,6 @@ do_edit (const vfs_path_t * what_vpath)
/* --------------------------------------------------------------------------------------------- */
static void
set_panel_filter_to (WPanel * p, char *filter)
{
MC_PTR_FREE (p->filter);
/* Three ways to clear filter: NULL, "", "*" */
if (filter == NULL || filter[0] == '\0' || (filter[0] == '*' && filter[1] == '\0'))
g_free (filter);
else
p->filter = filter;
reread_cmd ();
}
/* --------------------------------------------------------------------------------------------- */
/** Set a given panel filter expression */
static void
set_panel_filter (WPanel * p)
{
char *reg_exp;
const char *x;
x = p->filter != NULL ? p->filter : easy_patterns ? "*" : ".";
reg_exp = input_dialog_help (_("Filter"),
_("Set expression for filtering filenames"),
"[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x, FALSE,
INPUT_COMPLETE_FILENAMES);
if (reg_exp != NULL)
set_panel_filter_to (p, reg_exp);
}
/* --------------------------------------------------------------------------------------------- */
static int
compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
{
@ -818,21 +784,6 @@ mkdir_cmd (WPanel * panel)
g_free (dir);
}
/* --------------------------------------------------------------------------------------------- */
/** Invoked from the left/right menus */
void
filter_cmd (void)
{
if (SELECTED_IS_PANEL)
{
WPanel *p;
p = MENU_PANEL;
set_panel_filter (p);
}
}
/* --------------------------------------------------------------------------------------------- */
void
@ -1426,7 +1377,7 @@ listing_cmd (void)
p = PANEL (get_panel_widget (MENU_PANEL_IDX));
p->is_panelized = FALSE;
set_panel_filter_to (p, NULL); /* including panel reload */
panel_set_filter (p, NULL); /* including panel reload */
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -58,7 +58,6 @@ void edit_cmd_new (void);
void edit_cmd_force_internal (const WPanel * panel);
#endif
void mkdir_cmd (WPanel * panel);
void filter_cmd (void);
void reread_cmd (void);
void vfs_list (WPanel * panel);
void ext_cmd (void);

View File

@ -1240,9 +1240,6 @@ midnight_execute_cmd (Widget * sender, long command)
case CK_ExternalPanelize:
external_panelize ();
break;
case CK_Filter:
filter_cmd ();
break;
case CK_ViewFiltered:
view_filtered_cmd (current_panel);
break;
@ -1360,6 +1357,7 @@ midnight_execute_cmd (Widget * sender, long command)
case CK_Select:
case CK_Unselect:
case CK_SelectInvert:
case CK_Filter:
res = send_message (current_panel, filemanager, MSG_ACTION, command, NULL);
break;
case CK_Shell:

View File

@ -2658,6 +2658,24 @@ panel_select_invert_files (WPanel * panel)
}
}
/* --------------------------------------------------------------------------------------------- */
static void
panel_do_set_filter (WPanel * panel)
{
char *reg_exp;
const char *x;
x = panel->filter != NULL ? panel->filter : easy_patterns ? "*" : ".";
reg_exp = input_dialog_help (_("Filter"),
_("Set expression for filtering filenames"),
"[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x, FALSE,
INPUT_COMPLETE_FILENAMES);
if (reg_exp != NULL)
panel_set_filter (panel, reg_exp);
}
/* --------------------------------------------------------------------------------------------- */
/** Incremental search of a file name in the panel.
* @param panel instance of WPanel structure
@ -3509,6 +3527,9 @@ panel_execute_cmd (WPanel * panel, long command)
case CK_Unselect:
panel_unselect_files (panel);
break;
case CK_Filter:
panel_do_set_filter (panel);
break;
case CK_PageDown:
next_page (panel);
break;
@ -4572,6 +4593,22 @@ set_panel_formats (WPanel * p)
/* --------------------------------------------------------------------------------------------- */
void
panel_set_filter (WPanel * panel, char *filter)
{
MC_PTR_FREE (panel->filter);
/* Three ways to clear filter: NULL, "", "*" */
if (filter == NULL || filter[0] == '\0' || (filter[0] == '*' && filter[1] == '\0'))
g_free (filter);
else
panel->filter = filter;
reread_cmd ();
}
/* --------------------------------------------------------------------------------------------- */
/* Select current item and readjust the panel */
void
select_item (WPanel * panel)

View File

@ -179,6 +179,8 @@ vfs_path_t *remove_encoding_from_path (const vfs_path_t * vpath);
void update_panels (panel_update_flags_t flags, const char *current_file);
int set_panel_formats (WPanel * p);
void panel_set_filter (WPanel * panel, char *filter);
void try_to_select (WPanel * panel, const char *name);
void unmark_files (WPanel * panel);