From 7639b364afee7b87012f664b0251f001e97f2478 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT service" Date: Thu, 29 Jan 2009 19:17:43 +0100 Subject: [PATCH] added a new parameter for completion flags to input_new --- edit/editcmd.c | 2 +- src/Makefile.am | 2 +- src/boxes.c | 10 +++++----- src/command.c | 3 +-- src/complete.c | 12 ++++++++---- src/complete.h | 16 ---------------- src/find.c | 6 +++--- src/main.c | 1 - src/panelize.c | 2 +- src/widget.c | 7 ++----- src/widget.h | 20 +++++++++++++++++++- src/wtools.c | 3 +-- 12 files changed, 42 insertions(+), 42 deletions(-) delete mode 100644 src/complete.h diff --git a/edit/editcmd.c b/edit/editcmd.c index de8cf79f4..8b5f19fac 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -626,7 +626,7 @@ edit_raw_key_query (const char *heading, const char *query, int cancel) NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB); add_widget (raw_dlg, - input_new (3 - cancel, w - 5, INPUT_COLOR, 2, "", 0)); + input_new (3 - cancel, w - 5, INPUT_COLOR, 2, "", 0, INPUT_COMPLETE_DEFAULT)); add_widget (raw_dlg, label_new (3 - cancel, 2, query)); if (cancel) add_widget (raw_dlg, diff --git a/src/Makefile.am b/src/Makefile.am index a4713a625..11e165cb2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,7 +45,7 @@ CHARSET_SRC = charsets.c charsets.h selcodepage.c selcodepage.h SRCS = achown.c achown.h background.c background.h boxes.c boxes.h \ chmod.c chmod.h chown.c chown.h cmd.c cmd.h color.c color.h \ - command.c command.h complete.c complete.h cons.handler.c \ + command.c command.h complete.c cons.handler.c \ cons.saver.h dialog.c dialog.h dir.c dir.h \ eregex.h execute.c execute.h ext.c ext.h file.c filegui.c \ filegui.h file.h filenot.c fileopctx.c fileopctx.h find.c \ diff --git a/src/boxes.c b/src/boxes.c index b7652d853..0ff72d4d1 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -197,7 +197,7 @@ display_init (int radio_sel, char *init_text, int _check_status, status = input_new (10, 9, INPUT_COLOR, DISPLAY_X - 14, _status[radio_sel], - "mini-input"); + "mini-input", INPUT_COMPLETE_DEFAULT); add_widget (dd, status); input_set_point (status, 0); @@ -207,7 +207,7 @@ display_init (int radio_sel, char *init_text, int _check_status, user = input_new (7, 9, INPUT_COLOR, DISPLAY_X - 14, init_text, - "user-fmt-input"); + "user-fmt-input", INPUT_COMPLETE_DEFAULT); add_widget (dd, user); input_set_point (user, 0); @@ -1085,17 +1085,17 @@ vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, g_free (title); - in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name"); + in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT); add_widget (auth_dlg, in_user); - in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain"); + in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT); add_widget (auth_dlg, in_domain); add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0)); add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0)); - in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password"); + in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT); in_password->completion_flags = 0; in_password->is_password = 1; add_widget (auth_dlg, in_password); diff --git a/src/command.c b/src/command.c index baa0e6e81..4f9e9805d 100644 --- a/src/command.c +++ b/src/command.c @@ -34,7 +34,6 @@ #include "tty.h" #include "widget.h" /* WInput */ #include "command.h" -#include "complete.h" /* completion constants */ #include "wtools.h" /* message () */ #include "panel.h" /* view_tree enum. Also, needed by main.h */ #include "main.h" /* do_cd */ @@ -295,7 +294,7 @@ command_new (int y, int x, int cols) { WInput *cmd; - cmd = input_new (y, x, DEFAULT_COLOR, cols, "", "cmdline"); + cmd = input_new (y, x, DEFAULT_COLOR, cols, "", "cmdline", INPUT_COMPLETE_DEFAULT); /* Add our hooks */ cmd->widget.callback = command_callback; diff --git a/src/complete.c b/src/complete.c index fcc3b0844..b1ce52bb6 100644 --- a/src/complete.c +++ b/src/complete.c @@ -41,7 +41,6 @@ #include "dialog.h" #include "widget.h" #include "wtools.h" -#include "complete.h" #include "main.h" #include "util.h" #include "key.h" /* XCTRL and ALT macros */ @@ -58,6 +57,7 @@ static int look_for_executables = 0; static char * filename_completion_function (char *text, int state) { + fprintf(stderr, "filename_completion_function: text=\"%s\" state=%d\n", text, state); static DIR *directory; static char *filename = NULL; static char *dirname = NULL; @@ -89,6 +89,7 @@ filename_completion_function (char *text, int state) /* Save the version of the directory that the user typed. */ users_dirname = dirname; { + // FIXME: memleak ? dirname = tilde_expand (dirname); canonicalize_pathname (dirname); /* Here we should do something with variable expansion @@ -630,13 +631,15 @@ check_is_cd (const char *text, int start, int flags) static char ** try_complete (char *text, int *start, int *end, int flags) { - int in_command_position = 0, i; + int in_command_position = 0; char *word, c; char **matches = NULL; const char *command_separator_chars = ";|&{(`"; char *p = NULL, *q = NULL, *r = NULL; int is_cd = check_is_cd (text, *start, flags); + fprintf(stderr, "try_complete() text=\"%s\" start=%d end=%d flags=%d\n", text, *start, *end, flags); + ignore_filenames = 0; c = text [*end]; text [*end] = 0; @@ -648,7 +651,7 @@ try_complete (char *text, int *start, int *end, int flags) appears after a character that separates commands. And we have to be in a INPUT_COMPLETE_COMMANDS flagged Input line. */ if (!is_cd && (flags & INPUT_COMPLETE_COMMANDS)){ - i = *start - 1; + int i = *start - 1; for (i = *start - 1; i > -1; i--) { if (text[i] == ' ' || text[i] == '\t'){ if (i == 0 ) continue; @@ -691,7 +694,7 @@ try_complete (char *text, int *start, int *end, int flags) p = q + 1; q = NULL; } - + /* Command substitution? */ if (p > q && p > r){ matches = completion_matches (p + 1, command_completion_function); @@ -1035,6 +1038,7 @@ complete_engine (WInput *in, int what_to_do) return 0; } +//void complete (WInput *in, COMPLETION_STYLE style) void complete (WInput *in) { int engine_flags; diff --git a/src/complete.h b/src/complete.h deleted file mode 100644 index fe3152d10..000000000 --- a/src/complete.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MC_COMPLETE_H -#define MC_COMPLETE_H - -#define INPUT_COMPLETE_FILENAMES 1 -#define INPUT_COMPLETE_HOSTNAMES 2 -#define INPUT_COMPLETE_COMMANDS 4 -#define INPUT_COMPLETE_VARIABLES 8 -#define INPUT_COMPLETE_USERNAMES 16 -#define INPUT_COMPLETE_CD 32 - -#include "widget.h" - -void free_completions (WInput *); -void complete (WInput *); - -#endif diff --git a/src/find.c b/src/find.c index baf150494..4b9bc231a 100644 --- a/src/find.c +++ b/src/find.c @@ -275,16 +275,16 @@ find_parameters (char **start_dir, char **pattern, char **content) add_widget (find_dlg, case_sense); in_with = - input_new (8, istart, INPUT_COLOR, ilen, in_contents, "content"); + input_new (8, istart, INPUT_COLOR, ilen, in_contents, "content", INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_with); add_widget (find_dlg, recursively_cbox); in_name = - input_new (5, istart, INPUT_COLOR, ilen, in_start_name, "name"); + input_new (5, istart, INPUT_COLOR, ilen, in_start_name, "name", INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_name); in_start = - input_new (3, istart, INPUT_COLOR, ilen, in_start_dir, "start"); + input_new (3, istart, INPUT_COLOR, ilen, in_start_dir, "start", INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_start); add_widget (find_dlg, label_new (8, 3, labs[2])); diff --git a/src/main.c b/src/main.c index 14a13b732..e23831cb6 100644 --- a/src/main.c +++ b/src/main.c @@ -66,7 +66,6 @@ #include "widget.h" #include "command.h" #include "wtools.h" -#include "complete.h" /* For the free_completion */ #include "chmod.h" #include "chown.h" diff --git a/src/panelize.c b/src/panelize.c index 3deb0210a..ef80619a2 100644 --- a/src/panelize.c +++ b/src/panelize.c @@ -165,7 +165,7 @@ init_panelize (void) pname = input_new (UY + 14, UX, INPUT_COLOR, panelize_dlg->cols - 10, "", - "in"); + "in", INPUT_COMPLETE_DEFAULT); add_widget (panelize_dlg, pname); add_widget (panelize_dlg, label_new (UY + 13, UX, _("Command"))); diff --git a/src/widget.c b/src/widget.c index 83f31690a..bc30bb18b 100644 --- a/src/widget.c +++ b/src/widget.c @@ -42,7 +42,6 @@ #include "dialog.h" #include "widget.h" #include "win.h" -#include "complete.h" #include "key.h" /* XCTRL and ALT macros */ #include "profile.h" /* for history loading and saving */ #include "wtools.h" /* For common_dialog_repaint() */ @@ -1659,7 +1658,7 @@ input_event (Gpm_Event * event, void *data) WInput * input_new (int y, int x, int color, int len, const char *def_text, - const char *histname) + const char *histname, int completion_flags) { WInput *in = g_new (WInput, 1); int initial_buffer_len; @@ -1688,9 +1687,7 @@ input_new (int y, int x, int color, int len, const char *def_text, initial_buffer_len = 1 + max ((size_t) len, strlen (def_text)); in->widget.options |= W_IS_INPUT; in->completions = NULL; - in->completion_flags = - INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_HOSTNAMES | - INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES; + in->completion_flags = completion_flags; in->current_max_len = initial_buffer_len; in->buffer = g_malloc (initial_buffer_len); in->color = color; diff --git a/src/widget.h b/src/widget.h index 309983012..9e60dc7c9 100644 --- a/src/widget.h +++ b/src/widget.h @@ -122,12 +122,14 @@ typedef struct WGroupbox { char *title; } WGroupbox; +/* default completion flags for input widgets */ + /* Constructors */ WButton *button_new (int y, int x, int action, int flags, const char *text, bcback callback); WRadio *radio_new (int y, int x, int count, const char **text); WCheck *check_new (int y, int x, int state, const char *text); -WInput *input_new (int y, int x, int color, int len, const char *text, const char *histname); +WInput *input_new (int y, int x, int color, int len, const char *text, const char *histname, int completion_flags); WLabel *label_new (int y, int x, const char *text); WGauge *gauge_new (int y, int x, int shown, int max, int current); WListbox *listbox_new (int x, int y, int width, int height, lcback callback); @@ -200,4 +202,20 @@ void buttonbar_set_label_data (Dlg_head *h, int idx, const char *text, void buttonbar_set_visible (WButtonBar *, gboolean); void buttonbar_redraw (Dlg_head *h); +/* Completion stuff */ + +#define INPUT_COMPLETE_FILENAMES 1 +#define INPUT_COMPLETE_HOSTNAMES 2 +#define INPUT_COMPLETE_COMMANDS 4 +#define INPUT_COMPLETE_VARIABLES 8 +#define INPUT_COMPLETE_USERNAMES 16 +#define INPUT_COMPLETE_CD 32 + +#define INPUT_COMPLETE_DEFAULT \ + ( INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_HOSTNAMES | \ + INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES ) + +void free_completions (WInput *); +void complete (WInput *); + #endif diff --git a/src/wtools.c b/src/wtools.c index 97e142826..ba317e9cf 100644 --- a/src/wtools.c +++ b/src/wtools.c @@ -36,7 +36,6 @@ #include "widget.h" #include "wtools.h" #include "key.h" /* mi_getch() */ -#include "complete.h" /* INPUT_COMPLETE_CD */ #include "background.h" /* parent_call */ @@ -361,7 +360,7 @@ quick_dialog_skip (QuickDialog *qd, int nskip) case quick_input: input = input_new (ypos, xpos, INPUT_COLOR, qw->hotkey_pos, - qw->text, qw->histname); + qw->text, qw->histname, INPUT_COMPLETE_DEFAULT); input->is_password = qw->value == 1; input->point = 0; if (qw->value & 2)