Ticket #3228 (select/unselect files with the same extension as the current file)

Add Action 'SelectExt' for select/unselect files with the same extension as the current file.

Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
This commit is contained in:
Ilia Maslakov 2014-06-25 18:23:35 +04:00
parent 1f7a807eea
commit 94a1c98aea
5 changed files with 53 additions and 0 deletions

View File

@ -211,6 +211,7 @@ static name_keymap_t command_names[] = {
{"Unselect", CK_Unselect},
/* panel */
{"SelectExt", CK_SelectExt},
{"ScrollLeft", CK_ScrollLeft},
{"ScrollRight", CK_ScrollRight},
{"PanelOtherCd", CK_PanelOtherCd},

View File

@ -182,6 +182,7 @@ enum
CK_PutOtherTagged,
CK_Select,
CK_Unselect,
CK_SelectExt,
CK_SelectInvert,
/* panels */

View File

@ -97,6 +97,7 @@ EditNew = f14
CopySingle = f15
MoveSingle = f16
DeleteSingle = f18
# SelectExt =
Select = alt-plus
Unselect = alt-minus
SelectInvert = alt-asterisk

View File

@ -97,6 +97,7 @@ EditNew = f14
CopySingle = f15
MoveSingle = f16
DeleteSingle = f18
# SelectExt =
Select = alt-plus
Unselect = alt-minus
SelectInvert = alt-asterisk

View File

@ -2016,6 +2016,52 @@ unselect_item (WPanel * panel)
repaint_file (panel, panel->selected, TRUE, 2 * selection (panel)->f.marked, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/** Select/unselect all the files like a current file by extension */
static void
panel_select_ext_cmd (void)
{
gboolean do_select = !selection (current_panel)->f.marked;
char *filename = selection (current_panel)->fname;
char *reg_exp, *cur_file_ext;
mc_search_t *search;
int i;
if (filename == NULL)
return;
cur_file_ext = strutils_regex_escape (extension (filename));
if (cur_file_ext[0] != '\0')
reg_exp = g_strconcat ("^.*\\.", cur_file_ext, "$", (char *) NULL);
else
reg_exp = g_strdup ("^[^\\.]+$");
g_free (cur_file_ext);
search = mc_search_new (reg_exp, -1, NULL);
search->search_type = MC_SEARCH_T_REGEX;
search->is_case_sensitive = FALSE;
for (i = 0; i < current_panel->dir.len; i++)
{
file_entry_t *file_entry = &current_panel->dir.list[i];
if (DIR_IS_DOTDOT (file_entry->fname) || S_ISDIR (file_entry->st.st_mode))
continue;
if (!mc_search_run (search, file_entry->fname, 0, file_entry->fnamelen, NULL))
continue;
do_file_mark (current_panel, i, do_select);
}
mc_search_free (search);
g_free (reg_exp);
}
/* --------------------------------------------------------------------------------------------- */
static void
@ -3366,6 +3412,9 @@ panel_execute_cmd (WPanel * panel, unsigned long command)
case CK_Select:
panel_select_files (panel);
break;
case CK_SelectExt:
panel_select_ext_cmd ();
break;
case CK_Unselect:
panel_unselect_files (panel);
break;