mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Merge branch '3228_select_files_by_extension'
* 3228_select_files_by_extension: Ticket #3228 (select/unselect files with the same extension as the current file)
This commit is contained in:
commit
5bcc246ac2
@ -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},
|
||||
|
@ -182,6 +182,7 @@ enum
|
||||
CK_PutOtherTagged,
|
||||
CK_Select,
|
||||
CK_Unselect,
|
||||
CK_SelectExt,
|
||||
CK_SelectInvert,
|
||||
|
||||
/* panels */
|
||||
|
@ -97,6 +97,7 @@ EditNew = f14
|
||||
CopySingle = f15
|
||||
MoveSingle = f16
|
||||
DeleteSingle = f18
|
||||
# SelectExt =
|
||||
Select = alt-plus
|
||||
Unselect = alt-minus
|
||||
SelectInvert = alt-asterisk
|
||||
|
@ -97,6 +97,7 @@ EditNew = f14
|
||||
CopySingle = f15
|
||||
MoveSingle = f16
|
||||
DeleteSingle = f18
|
||||
# SelectExt =
|
||||
Select = alt-plus
|
||||
Unselect = alt-minus
|
||||
SelectInvert = alt-asterisk
|
||||
|
@ -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 = ¤t_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;
|
||||
|
Loading…
Reference in New Issue
Block a user