Re: [PATCH] Do not select symlinked dirs as files
- From: David Sterba <dave jikos cz>
- To: Pavel Roskin <proski gnu org>
- Cc: mc-devel gnome org
- Subject: Re: [PATCH] Do not select symlinked dirs as files
- Date: Wed, 18 Jun 2003 19:04:47 +0200
Hi,
> I think it's a wrong place. Whether you want to select symlinks to
> directories depends on the data you are working with, not on what kind
> of user you are.
Yes, I agree.
> This should be in the select dialog.
Done.
Select/Unselect input dialog now shows the option.
I added new functions to handle the extended input dialog and let
(only) the select/unselect dialog to use it. Other input dialogs are left
unchanged (layout, contents and calling functions).
See changelog for details.
David
diff -S ChangeLog -X .diffignore -urNp mc/src/ChangeLog mc-sel/src/ChangeLog
--- mc/src/ChangeLog Sun Jun 15 21:15:13 2003
+++ mc-sel/src/ChangeLog Wed Jun 18 12:19:37 2003
@@ -0,0 +1,18 @@
+2003-06-18 David Sterba <dave jikos cz>
+
+ * background.c: Set number of supported arguments for background
+ jobs to 6 due to extensions of quick dialog.
+ (background_attention): Handle the count.
+ (message_3s): Fix the incorrect number of params passed.
+ (input_dialog_help): Adjust call to real_input_dialog_help.
+ (input_dialog_help_ext): New function.
+ * cmd.c (select_cmd, unselect_cmd, reverse_selection_cmd):
+ Handle symlinked directories as directories in file selections
+ if wanted. Add a variable for it.
+ (unselect_cmd, select_cmd): Add extended option to selection dialog.
+ * main.h: Extern the variable.
+ * wtools.c (real_input_dialog_help): New param for dlg extension.
+ Split widget sets into basic and extended. Update layout of dialog.
+ (input_dialog_ext): New function. Extends the basic input dialog.
+ * wtools.h: Add new functions and extension enum.
+
diff -S ChangeLog -X .diffignore -urNp mc/src/background.c mc-sel/src/background.c
--- mc/src/background.c Mon Jun 2 20:13:43 2003
+++ mc-sel/src/background.c Wed Jun 18 12:09:20 2003
@@ -66,7 +66,7 @@ int socketpair(int, int, int, int fd[2])
/* File descriptor for talking to our parent */
static int parent_fd;
-#define MAXCALLARGS 4 /* Number of arguments supported */
+#define MAXCALLARGS 6 /* Number of arguments supported */
#define mymsg "Desde el hijo\n\r"
struct TaskList *task_list = NULL;
@@ -330,6 +330,14 @@ background_attention (int fd, void *clos
result = (*(int (*)(int, char *, char *, char *, char *))routine)
(Background, data [0], data [1], data [2], data [3]);
break;
+ case 5:
+ result = (*(int (*)(int, char *, char *, char *, char *, char *))routine)
+ (Background, data [0], data [1], data [2], data [3], data [4]);
+ break;
+ case 6:
+ result = (*(int (*)(int, char *, char *, char *, char *, char *, char *))routine)
+ (Background, data [0], data [1], data [2], data [3], data [4], data [5]);
+ break;
}
else
switch (argc){
@@ -349,6 +357,14 @@ background_attention (int fd, void *clos
result = (*(int (*)(FileOpContext *, int, char *, char *, char *, char *))routine)
(ctx, Background, data [0], data [1], data [2], data [3]);
break;
+ case 5:
+ result = (*(int (*)(FileOpContext *, int, char *, char *, char *, char *, char *))routine)
+ (ctx, Background, data [0], data [1], data [2], data [3], data [4]);
+ break;
+ case 6:
+ result = (*(int (*)(FileOpContext *, int, char *, char *, char *, char *, char *, char *))routine)
+ (ctx, Background, data [0], data [1], data [2], data [3], data [4], data [5]);
+ break;
}
/* Send the result code and the value for shared variables */
@@ -378,6 +394,14 @@ background_attention (int fd, void *clos
resstr = (*(char * (*)(char *, char *, char *, char *))routine)
(data [0], data [1], data [2], data [3]);
break;
+ case 5:
+ resstr = (*(char * (*)(char *, char *, char *, char *, char *))routine)
+ (data [0], data [1], data [2], data [3], data [4]);
+ break;
+ case 6:
+ resstr = (*(char * (*)(char *, char *, char *, char *, char *, char*))routine)
+ (data [0], data [1], data [2], data [3], data [4], data [5]);
+ break;
default: g_assert_not_reached();
}
if (resstr){
@@ -509,7 +533,7 @@ message_3s (int flags, char *title, cons
const char *str2, const char *str3)
{
if (we_are_background)
- parent_call ((void *)real_message_3s, NULL, 3, sizeof (flags), &flags,
+ parent_call ((void *)real_message_3s, NULL, 5, sizeof (flags), &flags,
strlen (title), title, strlen (str1), str1,
strlen (str2), str2, strlen (str3), str3);
else
@@ -526,7 +550,21 @@ input_dialog_help (char *header, char *t
strlen (help), help,
strlen (def_text), def_text);
else
- return real_input_dialog_help (header, text, help, def_text);
+ return real_input_dialog_help (0, header, text, help, def_text);
+}
+
+char *
+input_dialog_help_ext (DlgExtensions ext, char *header, char *text, char *help, char *def_text)
+{
+ if (we_are_background)
+ return parent_call_string ((void *)real_input_dialog_help, 5,
+ sizeof (ext), &ext,
+ strlen (header), header,
+ strlen (text), text,
+ strlen (help), help,
+ strlen (def_text), def_text);
+ else
+ return real_input_dialog_help (ext, header, text, help, def_text);
}
#else /* Else => No background code support */
diff -S ChangeLog -X .diffignore -urNp mc/src/cmd.c mc-sel/src/cmd.c
--- mc/src/cmd.c Tue Feb 18 06:25:45 2003
+++ mc-sel/src/cmd.c Wed Jun 18 11:56:02 2003
@@ -83,6 +83,9 @@ int source_route = 0;
/* If set, use the builtin editor */
int use_internal_edit = 1;
+/* If symlinked dirs should be selected as dirs */
+int select_symlinked_dir_as_dir = 0;
+
/*
* Execute command on a filename that can be on VFS.
@@ -502,7 +505,9 @@ void reverse_selection_cmd (void)
for (i = 0; i < cpanel->count; i++){
file = &cpanel->dir.list [i];
- if (S_ISDIR (file->buf.st_mode))
+ if (S_ISDIR (file->buf.st_mode) ||
+ (select_symlinked_dir_as_dir &&
+ link_isdir ( &(cpanel->dir.list [i])) ))
continue;
do_file_mark (cpanel, i, !file->f.marked);
}
@@ -516,7 +521,7 @@ void select_cmd (void)
int c;
int dirflag = 0;
- reg_exp = input_dialog (_(" Select "), "", easy_patterns ? "*" : ".");
+ reg_exp = input_dialog_ext (DLGEXT_SYMDIR, _(" Select "), "", easy_patterns ? "*" : ".");
if (!reg_exp)
return;
@@ -535,7 +540,9 @@ void select_cmd (void)
for (i = 0; i < cpanel->count; i++){
if (!strcmp (cpanel->dir.list [i].fname, ".."))
continue;
- if (S_ISDIR (cpanel->dir.list [i].buf.st_mode)){
+ if (S_ISDIR (cpanel->dir.list [i].buf.st_mode) ||
+ (select_symlinked_dir_as_dir &&
+ link_isdir ( &(cpanel->dir.list [i])) )) {
if (!dirflag)
continue;
} else {
@@ -563,7 +570,7 @@ void unselect_cmd (void)
int c;
int dirflag = 0;
- reg_exp = input_dialog (_(" Unselect "),"", easy_patterns ? "*" : ".");
+ reg_exp = input_dialog_ext (DLGEXT_SYMDIR, _(" Unselect "),"", easy_patterns ? "*" : ".");
if (!reg_exp)
return;
@@ -579,9 +586,11 @@ void unselect_cmd (void)
reg_exp_t [strlen(reg_exp_t) - 1] = 0;
}
for (i = 0; i < cpanel->count; i++){
- if (!strcmp (cpanel->dir.list [i].fname, ".."))
+ if (!strcmp (cpanel->dir.list [i].fname, ".."))
continue;
- if (S_ISDIR (cpanel->dir.list [i].buf.st_mode)){
+ if (S_ISDIR (cpanel->dir.list [i].buf.st_mode) ||
+ (select_symlinked_dir_as_dir &&
+ link_isdir ( &(cpanel->dir.list [i])) )) {
if (!dirflag)
continue;
} else {
diff -S ChangeLog -X .diffignore -urNp mc/src/main.h mc-sel/src/main.h
--- mc/src/main.h Mon May 5 17:30:43 2003
+++ mc-sel/src/main.h Wed Jun 11 21:36:17 2003
@@ -47,6 +47,7 @@ extern int clear_before_exec;
extern int mou_auto_repeat;
extern char *other_dir;
extern int mouse_move_pages;
+extern int select_symlinked_dir_as_dir;
#ifdef HAVE_CHARSET
extern int source_codepage;
diff -S ChangeLog -X .diffignore -urNp mc/src/wtools.c mc-sel/src/wtools.c
--- mc/src/wtools.c Thu Nov 14 08:25:19 2002
+++ mc-sel/src/wtools.c Wed Jun 18 11:54:43 2003
@@ -45,6 +45,7 @@
#include "key.h" /* For mi_getch() */
#include "dialog.h" /* For do_refresh() */
#include "complete.h" /* INPUT_COMPLETE_CD */
+#include "main.h"
/* }}} */
@@ -387,12 +388,13 @@ int quick_dialog (QuickDialog *qd)
/* {{{ Input routines */
#define INPUT_INDEX 2
+#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0]))
char *
-real_input_dialog_help (char *header, char *text, char *help,
- char *def_text)
+real_input_dialog_help (DlgExtensions ext, char *header, char *text,
+ char *help, char *def_text)
{
QuickDialog Quick_input;
- QuickWidget quick_widgets[] = {
+ static QuickWidget simple_widgets[] = {
{quick_button, 6, 10, 1, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
"button-cancel"},
{quick_button, 3, 10, 1, 0, N_("&OK"), 0, B_ENTER, 0, 0,
@@ -401,20 +403,49 @@ real_input_dialog_help (char *header, ch
{quick_label, 4, 80, 2, 0, "", 0, 0, 0, 0, "label"},
{0}
};
+ static QuickWidget ext_widgets[] = {
+ {quick_checkbox, 4, 80, 5, 0, "Select symlinked dirs as dirs", 0, 0,
+ 0, 0, 0},
+ };
+ static QuickWidget quick_widgets [8];
int len;
int i;
int lines;
int ret;
+ int wid_count, ext_count;
char *my_str;
char tk_name[64] = "inp|";
+ /* Copy all basic widgets */
+ ext_count = 0;
+ wid_count = ARRAY_LENGTH (simple_widgets) - 1;
+ for(i=0; i < wid_count; i++)
+ quick_widgets[i] = simple_widgets[i];
+
+ if (ext == DLGEXT_SYMDIR) {
+ ext_count++;
+ ext_widgets[0].result = &select_symlinked_dir_as_dir;
+ quick_widgets[wid_count++] = ext_widgets[0];
+ }
+
+ /* List terminator */
+ quick_widgets[wid_count] = simple_widgets[4];
+
+ /* Reposition buttons */
+ if (ext_count) {
+ ext_count++; /* One empty line between buttons and the checkbox */
+ ext_count++; /* One empty line between checkbox and the rest */
+ quick_widgets[0].relative_y += ext_count;
+ quick_widgets[1].relative_y += ext_count;
+ }
+
/* we need a unique name for tkname because widget.c:history_tool()
needs a unique name for each dialog - using the header is ideal */
strncpy (tk_name + 3, header, 60);
tk_name[63] = '\0';
- quick_widgets[2].tkname = tk_name;
+ quick_widgets[INPUT_INDEX].tkname = tk_name;
len = max (strlen (header), msglen (text, &lines)) + 4;
len = max (len, 64);
@@ -448,23 +479,28 @@ real_input_dialog_help (char *header, ch
quick_widgets[INPUT_INDEX + 1].text = g_strstrip (g_strdup (text));
quick_widgets[INPUT_INDEX].text = def_text;
- for (i = 0; i < 4; i++)
- quick_widgets[i].y_divisions = lines + 6;
- Quick_input.ylen = lines + 6;
+ for (i = 0; i < wid_count; i++)
+ quick_widgets[i].y_divisions = lines + 6 + ext_count;
+ Quick_input.ylen = lines + 6 + ext_count;
- for (i = 0; i < 3; i++)
+ for (i = 0; i < wid_count - 1; i++)
quick_widgets[i].relative_y += 2 + lines;
quick_widgets[INPUT_INDEX].str_result = &my_str;
Quick_input.widgets = quick_widgets;
- ret = quick_dialog (&Quick_input);
+ ret = quick_dialog_skip (&Quick_input, 1);
g_free (quick_widgets[INPUT_INDEX + 1].text);
if (ret != B_CANCEL) {
return *(quick_widgets[INPUT_INDEX].str_result);
} else
return 0;
+}
+
+char *input_dialog_ext (DlgExtensions ext, char *header, char *text, char *def_text)
+{
+ return input_dialog_help_ext (ext, header, text, "[Input Line Keys]", def_text);
}
char *input_dialog (char *header, char *text, char *def_text)
diff -S ChangeLog -X .diffignore -urNp mc/src/wtools.h mc-sel/src/wtools.h
--- mc/src/wtools.h Thu Nov 14 08:25:19 2002
+++ mc-sel/src/wtools.h Tue Jun 17 21:07:21 2003
@@ -23,6 +23,10 @@ enum {
quick_label, quick_radio
} /* quick_t */;
+typedef enum {
+ DLGEXT_SYMDIR = 1<<0
+} DlgExtensions;
+
/* The widget is placed on relative_?/divisions_? of the parent widget */
/* Please note that the contents of the fields in the union are just */
/* used for setting up the dialog. They are a convenient place to put */
@@ -61,10 +65,12 @@ int quick_dialog_skip (QuickDialog *qd,
#define INPUT_PASSWORD ((char *) -1)
char *input_dialog (char *header, char *text, char *def_text);
+char *input_dialog_ext (DlgExtensions ext, char *header, char *text, char *def_text);
char *input_dialog_help (char *header, char *text, char *help, char *def_text);
+char *input_dialog_help_ext (DlgExtensions ext, char *header, char *text, char *help, char *def_text);
char *input_expand_dialog (char *header, char *text, char *def_text);
char *real_input_dialog (char *header, char *text, char *def_text);
-char *real_input_dialog_help (char *header, char *text, char *help, char *def_text);
+char *real_input_dialog_help (DlgExtensions ext, char *header, char *text, char *help, char *def_text);
void query_set_sel (int new_sel);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]