(panel_execute_cmd): concentrate handling of select/unselect files here.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
f72cf464c9
Коммит
9e0328ea54
@ -57,7 +57,6 @@
|
||||
#include "lib/tty/key.h" /* ALT() macro */
|
||||
#include "lib/tty/win.h" /* do_enter_ca_mode() */
|
||||
#include "lib/mcconfig.h"
|
||||
#include "lib/search.h"
|
||||
#include "lib/filehighlight.h" /* MC_FHL_INI_FILE */
|
||||
#include "lib/vfs/vfs.h"
|
||||
#include "lib/fileloc.h"
|
||||
@ -100,8 +99,6 @@
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifndef MAP_FILE
|
||||
@ -208,78 +205,6 @@ set_panel_filter (WPanel * p)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
select_unselect_cmd (const char *title, const char *history_name, gboolean do_select)
|
||||
{
|
||||
int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
|
||||
int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
|
||||
int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
|
||||
|
||||
char *reg_exp;
|
||||
mc_search_t *search;
|
||||
int i;
|
||||
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_INPUT (INPUT_LAST_TEXT, history_name, ®_exp, NULL,
|
||||
FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
|
||||
QUICK_START_COLUMNS,
|
||||
QUICK_CHECKBOX (N_("&Files only"), &files_only, NULL),
|
||||
QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns, NULL),
|
||||
QUICK_NEXT_COLUMN,
|
||||
QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens, NULL),
|
||||
QUICK_STOP_COLUMNS,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 50,
|
||||
title, "[Select/Unselect Files]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
if (quick_dialog (&qdlg) == B_CANCEL)
|
||||
return;
|
||||
|
||||
if (reg_exp == NULL || *reg_exp == '\0')
|
||||
{
|
||||
g_free (reg_exp);
|
||||
return;
|
||||
}
|
||||
|
||||
search = mc_search_new (reg_exp, -1, NULL);
|
||||
search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
|
||||
search->is_entire_line = TRUE;
|
||||
search->is_case_sensitive = case_sens != 0;
|
||||
|
||||
for (i = 0; i < current_panel->dir.len; i++)
|
||||
{
|
||||
if (DIR_IS_DOTDOT (current_panel->dir.list[i].fname))
|
||||
continue;
|
||||
if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0)
|
||||
continue;
|
||||
|
||||
if (mc_search_run (search, current_panel->dir.list[i].fname,
|
||||
0, current_panel->dir.list[i].fnamelen, NULL))
|
||||
do_file_mark (current_panel, i, do_select);
|
||||
}
|
||||
|
||||
mc_search_free (search);
|
||||
g_free (reg_exp);
|
||||
|
||||
/* result flags */
|
||||
select_flags = 0;
|
||||
if (case_sens != 0)
|
||||
select_flags |= SELECT_MATCH_CASE;
|
||||
if (files_only != 0)
|
||||
select_flags |= SELECT_FILES_ONLY;
|
||||
if (shell_patterns != 0)
|
||||
select_flags |= SELECT_SHELL_PATTERNS;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size)
|
||||
{
|
||||
@ -1036,38 +961,6 @@ reread_cmd (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
select_invert_cmd (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < current_panel->dir.len; i++)
|
||||
{
|
||||
file_entry_t *file = ¤t_panel->dir.list[i];
|
||||
|
||||
if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
|
||||
do_file_mark (current_panel, i, !file->f.marked);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
select_cmd (void)
|
||||
{
|
||||
select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
unselect_cmd (void)
|
||||
{
|
||||
select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
ext_cmd (void)
|
||||
{
|
||||
|
@ -20,21 +20,12 @@ typedef enum
|
||||
LINK_SYMLINK_RELATIVE
|
||||
} link_type_t;
|
||||
|
||||
/* selection flags */
|
||||
typedef enum
|
||||
{
|
||||
SELECT_FILES_ONLY = 1 << 0,
|
||||
SELECT_MATCH_CASE = 1 << 1,
|
||||
SELECT_SHELL_PATTERNS = 1 << 2
|
||||
} select_flags_t;
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
|
||||
#ifdef ENABLE_VFS_FTP
|
||||
void ftplink_cmd (void);
|
||||
#endif
|
||||
@ -85,9 +76,6 @@ void diff_view_cmd (void);
|
||||
void panel_tree_cmd (void);
|
||||
void link_cmd (link_type_t link_type);
|
||||
void edit_symlink_cmd (void);
|
||||
void select_invert_cmd (void);
|
||||
void unselect_cmd (void);
|
||||
void select_cmd (void);
|
||||
void swap_cmd (void);
|
||||
void view_other_cmd (void);
|
||||
void quick_cd_cmd (void);
|
||||
|
@ -1319,14 +1319,13 @@ midnight_execute_cmd (Widget * sender, unsigned long command)
|
||||
vfs_list ();
|
||||
break;
|
||||
#endif
|
||||
case CK_SelectInvert:
|
||||
select_invert_cmd ();
|
||||
break;
|
||||
case CK_SaveSetup:
|
||||
save_setup_cmd ();
|
||||
break;
|
||||
case CK_Select:
|
||||
select_cmd ();
|
||||
case CK_Unselect:
|
||||
case CK_SelectInvert:
|
||||
res = send_message (current_panel, midnight_dlg, MSG_ACTION, command, NULL);
|
||||
break;
|
||||
case CK_Shell:
|
||||
view_other_cmd ();
|
||||
@ -1378,9 +1377,6 @@ midnight_execute_cmd (Widget * sender, unsigned long command)
|
||||
undelete_cmd ();
|
||||
break;
|
||||
#endif
|
||||
case CK_Unselect:
|
||||
unselect_cmd ();
|
||||
break;
|
||||
case CK_UserMenu:
|
||||
user_file_menu_cmd ();
|
||||
break;
|
||||
@ -1501,46 +1497,31 @@ midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
|
||||
{
|
||||
/* Special treatement, since the input line will eat them */
|
||||
if (parm == '+')
|
||||
{
|
||||
select_cmd ();
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Select, NULL);
|
||||
|
||||
if (parm == '\\' || parm == '-')
|
||||
{
|
||||
unselect_cmd ();
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect,
|
||||
NULL);
|
||||
|
||||
if (parm == '*')
|
||||
{
|
||||
select_invert_cmd ();
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_SelectInvert,
|
||||
NULL);
|
||||
}
|
||||
else if (!command_prompt || !cmdline->buffer[0])
|
||||
else if (!command_prompt || cmdline->buffer[0] == '\0')
|
||||
{
|
||||
/* Special treatement '+', '-', '\', '*' only when this is
|
||||
* first char on input line
|
||||
*/
|
||||
|
||||
if (parm == '+')
|
||||
{
|
||||
select_cmd ();
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Select, NULL);
|
||||
|
||||
if (parm == '\\' || parm == '-')
|
||||
{
|
||||
unselect_cmd ();
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect,
|
||||
NULL);
|
||||
|
||||
if (parm == '*')
|
||||
{
|
||||
select_invert_cmd ();
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_SelectInvert,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "lib/mcconfig.h"
|
||||
#include "lib/vfs/vfs.h"
|
||||
#include "lib/unixcompat.h"
|
||||
#include "lib/search.h"
|
||||
#include "lib/timefmt.h" /* file_date() */
|
||||
#include "lib/util.h"
|
||||
#include "lib/widget.h"
|
||||
@ -309,6 +310,8 @@ panel_field_t panel_fields[] = {
|
||||
|
||||
mc_fhl_t *mc_filehighlight = NULL;
|
||||
|
||||
int select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS;
|
||||
|
||||
extern int saving_setup;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
@ -2409,6 +2412,110 @@ mark_file_left (WPanel * panel)
|
||||
do_file_mark (panel, panel->selected, state_mark);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panel_select_unselect_files (WPanel *panel, const char *title, const char *history_name,
|
||||
gboolean do_select)
|
||||
{
|
||||
int files_only = (select_flags & SELECT_FILES_ONLY) != 0;
|
||||
int case_sens = (select_flags & SELECT_MATCH_CASE) != 0;
|
||||
int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0;
|
||||
|
||||
char *reg_exp;
|
||||
mc_search_t *search;
|
||||
int i;
|
||||
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_INPUT (INPUT_LAST_TEXT, history_name, ®_exp, NULL,
|
||||
FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
|
||||
QUICK_START_COLUMNS,
|
||||
QUICK_CHECKBOX (N_("&Files only"), &files_only, NULL),
|
||||
QUICK_CHECKBOX (N_("&Using shell patterns"), &shell_patterns, NULL),
|
||||
QUICK_NEXT_COLUMN,
|
||||
QUICK_CHECKBOX (N_("&Case sensitive"), &case_sens, NULL),
|
||||
QUICK_STOP_COLUMNS,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 50,
|
||||
title, "[Select/Unselect Files]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
if (quick_dialog (&qdlg) == B_CANCEL)
|
||||
return;
|
||||
|
||||
if (reg_exp == NULL || *reg_exp == '\0')
|
||||
{
|
||||
g_free (reg_exp);
|
||||
return;
|
||||
}
|
||||
|
||||
search = mc_search_new (reg_exp, -1, NULL);
|
||||
search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
|
||||
search->is_entire_line = TRUE;
|
||||
search->is_case_sensitive = case_sens != 0;
|
||||
|
||||
for (i = 0; i < panel->dir.len; i++)
|
||||
{
|
||||
if (DIR_IS_DOTDOT (panel->dir.list[i].fname))
|
||||
continue;
|
||||
if (S_ISDIR (panel->dir.list[i].st.st_mode) && files_only != 0)
|
||||
continue;
|
||||
|
||||
if (mc_search_run (search, panel->dir.list[i].fname, 0, panel->dir.list[i].fnamelen, NULL))
|
||||
do_file_mark (panel, i, do_select);
|
||||
}
|
||||
|
||||
mc_search_free (search);
|
||||
g_free (reg_exp);
|
||||
|
||||
/* result flags */
|
||||
select_flags = 0;
|
||||
if (case_sens != 0)
|
||||
select_flags |= SELECT_MATCH_CASE;
|
||||
if (files_only != 0)
|
||||
select_flags |= SELECT_FILES_ONLY;
|
||||
if (shell_patterns != 0)
|
||||
select_flags |= SELECT_SHELL_PATTERNS;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panel_select_files (WPanel *panel)
|
||||
{
|
||||
panel_select_unselect_files (panel, _("Select"), ":select_cmd: Select ", TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panel_unselect_files (WPanel *panel)
|
||||
{
|
||||
panel_select_unselect_files (panel, _("Unselect"), ":unselect_cmd: Unselect ", FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panel_select_invert_files (WPanel *panel)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < panel->dir.len; i++)
|
||||
{
|
||||
file_entry_t *file = &panel->dir.list[i];
|
||||
|
||||
if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
|
||||
do_file_mark (panel, i, !file->f.marked);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Incremental search of a file name in the panel.
|
||||
* @param panel instance of WPanel structure
|
||||
@ -3256,13 +3363,13 @@ panel_execute_cmd (WPanel * panel, unsigned long command)
|
||||
rename_cmd_local ();
|
||||
break;
|
||||
case CK_SelectInvert:
|
||||
select_invert_cmd ();
|
||||
panel_select_invert_files (panel);
|
||||
break;
|
||||
case CK_Select:
|
||||
select_cmd ();
|
||||
panel_select_files (panel);
|
||||
break;
|
||||
case CK_Unselect:
|
||||
unselect_cmd ();
|
||||
panel_unselect_files (panel);
|
||||
break;
|
||||
case CK_PageDown:
|
||||
next_page (panel);
|
||||
|
@ -48,6 +48,14 @@ typedef enum
|
||||
UP_ONLY_CURRENT = 2
|
||||
} panel_update_flags_t;
|
||||
|
||||
/* selection flags */
|
||||
typedef enum
|
||||
{
|
||||
SELECT_FILES_ONLY = 1 << 0,
|
||||
SELECT_MATCH_CASE = 1 << 1,
|
||||
SELECT_SHELL_PATTERNS = 1 << 2
|
||||
} select_flags_t;
|
||||
|
||||
/* run mode and params */
|
||||
|
||||
enum cd_enum
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user