From f6f02a0295aa674e7889533c016e17eff0b9ab37 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Fri, 20 Sep 2002 19:36:55 +0000 Subject: [PATCH] * command.c: Make `command' a standard WInput widget, just change its callback. Eliminate input_w(). Adjust all dependencies. * widget.c (input_callback): Remove static attribute. --- src/ChangeLog | 7 +++++ src/cmd.c | 26 ++++++++--------- src/command.c | 80 +++++++++++++++++++++++++-------------------------- src/command.h | 13 ++------- src/hotlist.c | 2 +- src/layout.c | 75 +++++++++++++++++++++++------------------------ src/main.c | 32 ++++++++++----------- src/widget.c | 2 +- src/widget.h | 1 + 9 files changed, 119 insertions(+), 119 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0d1669c8e..e8ecb9b5e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2002-09-20 Pavel Roskin + + * command.c: Make `command' a standard WInput widget, just + change its callback. Eliminate input_w(). Adjust all + dependencies. + * widget.c (input_callback): Remove static attribute. + 2002-09-19 Pavel Roskin * main.c (argument_table): Improve help for "+number" - it has diff --git a/src/cmd.c b/src/cmd.c index 00f11a714..5543e5dc9 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -56,7 +56,7 @@ #include "dlg.h" /* required by wtools.h */ #include "widget.h" /* required by wtools.h */ #include "wtools.h" /* listbox */ -#include "command.h" /* for input_w */ +#include "command.h" /* for cmdline */ #include "win.h" /* do_exit_ca_mode */ #include "layout.h" /* get_current/other_type */ #include "ext.h" /* regex_command */ @@ -883,27 +883,27 @@ void compare_dirs_cmd (void) } } -void history_cmd (void) +void +history_cmd (void) { Listbox *listbox; Hist *current; - if (input_w (cmdline)->need_push){ - if (push_history (input_w (cmdline), input_w (cmdline)->buffer) == 2) - input_w (cmdline)->need_push = 0; + if (cmdline->need_push) { + if (push_history (cmdline, cmdline->buffer) == 2) + cmdline->need_push = 0; } - if (!input_w (cmdline)->history){ + if (!cmdline->history) { message (1, MSG_ERROR, _(" The command history is empty ")); return; } - current = input_w (cmdline)->history; + current = cmdline->history; while (current->prev) current = current->prev; listbox = create_listbox_window (60, 10, _(" Command history "), "[Command Menu]"); - while (current){ - LISTBOX_APPEND_TEXT (listbox, 0, current->text, - current); + while (current) { + LISTBOX_APPEND_TEXT (listbox, 0, current->text, current); current = current->next; } run_dlg (listbox->dlg); @@ -916,9 +916,9 @@ void history_cmd (void) if (!current) return; - input_w (cmdline)->history = current; - assign_text (input_w (cmdline), input_w (cmdline)->history->text); - update_input (input_w (cmdline), 1); + cmdline->history = current; + assign_text (cmdline, cmdline->history->text); + update_input (cmdline, 1); } void swap_cmd (void) diff --git a/src/command.c b/src/command.c index 99fef4ce4..24de5a6bd 100644 --- a/src/command.c +++ b/src/command.c @@ -42,7 +42,7 @@ #include "../vfs/vfs.h" /* This holds the command line */ -WCommand *cmdline; +WInput *cmdline; /*Tries variable substitution, and if a variable CDPATH of the form e.g. CDPATH=".:~:/usr" exists, we try then all the paths which @@ -174,57 +174,61 @@ void do_cd_command (char *cmd) } /* Returns 1 if the we could handle the enter, 0 if not */ -static int enter (WCommand *cmdline) +static int +enter (WInput * cmdline) { Dlg_head *old_dlg; - - if (command_prompt && strlen (input_w (cmdline)->buffer)){ + + if (command_prompt && strlen (cmdline->buffer)) { char *cmd; /* Any initial whitespace should be removed at this point */ - cmd = input_w (cmdline)->buffer; + cmd = cmdline->buffer; while (*cmd == ' ' || *cmd == '\t' || *cmd == '\n') cmd++; - if (strncmp (cmd, "cd ", 3) == 0 || strcmp (cmd, "cd") == 0){ + if (strncmp (cmd, "cd ", 3) == 0 || strcmp (cmd, "cd") == 0) { do_cd_command (cmd); - new_input (input_w (cmdline)); + new_input (cmdline); return MSG_HANDLED; } else { char *command, *s; int i, j; if (!vfs_current_is_local ()) { - message (1, MSG_ERROR, _(" You can not execute commands on non-local filesystems")); - + message (1, MSG_ERROR, + _ + (" You can not execute commands on non-local filesystems")); + return MSG_NOT_HANDLED; } command = g_malloc (strlen (cmd) + 1); - command [0] = 0; - for (i = j = 0; i < strlen (cmd); i ++){ - if (cmd [i] == '%'){ - i ++; - s = expand_format (NULL, cmd [i], 1); - command = g_realloc (command, strlen (command) + strlen (s) - + strlen (cmd) - i + 1); + command[0] = 0; + for (i = j = 0; i < strlen (cmd); i++) { + if (cmd[i] == '%') { + i++; + s = expand_format (NULL, cmd[i], 1); + command = + g_realloc (command, strlen (command) + strlen (s) + + strlen (cmd) - i + 1); strcat (command, s); g_free (s); j = strlen (command); } else { - command [j] = cmd [i]; - j ++; + command[j] = cmd[i]; + j++; } - command [j] = 0; + command[j] = 0; } old_dlg = current_dlg; current_dlg = 0; - new_input (input_w (cmdline)); + new_input (cmdline); execute (command); g_free (command); - + #ifdef HAVE_SUBSHELL_SUPPORT - if (quit & SUBSHELL_EXIT){ - quiet_quit_cmd (); + if (quit & SUBSHELL_EXIT) { + quiet_quit_cmd (); return MSG_HANDLED; } if (use_subshell) @@ -237,38 +241,34 @@ static int enter (WCommand *cmdline) return MSG_HANDLED; } -static int command_callback (Dlg_head *h, WCommand *cmd, int msg, int par) +static int +command_callback (Dlg_head * h, WInput * cmd, int msg, int par) { - switch (msg){ + switch (msg) { case WIDGET_FOCUS: - /* We refuse the focus always: needed not to unselect the panel */ + /* Never accept focus, otherwise panels will be unselected */ return MSG_NOT_HANDLED; case WIDGET_KEY: /* Special case: we handle the enter key */ - if (par == '\n'){ + if (par == '\n') { return enter (cmd); } } - return (*cmd->old_callback)(h, cmd, msg, par); + return input_callback (h, cmd, msg, par); } -WCommand *command_new (int y, int x, int cols) +WInput * +command_new (int y, int x, int cols) { - WInput *in; - WCommand *cmd = g_new (WCommand, 1); + WInput *cmd = g_new (WInput, 1); - in = input_new (y, x, DEFAULT_COLOR, cols, "", "cmdline"); - cmd->input = *in; - g_free (in); + cmd = input_new (y, x, DEFAULT_COLOR, cols, "", "cmdline"); /* Add our hooks */ - cmd->old_callback = (callback_fn) cmd->input.widget.callback; - cmd->input.widget.callback = (int (*) (Dlg_head *, void *, int, int)) - command_callback; - - cmd->input.completion_flags |= INPUT_COMPLETE_COMMANDS; + cmd->widget.callback = (callback_fn) command_callback; + cmd->completion_flags |= INPUT_COMPLETE_COMMANDS; + return cmd; } - diff --git a/src/command.h b/src/command.h index 8804a54c7..c26466dfe 100644 --- a/src/command.h +++ b/src/command.h @@ -1,18 +1,9 @@ #ifndef __COMMAND_H #define __COMMAND_H -typedef struct { - WInput input; - callback_fn old_callback; -} WCommand; - -WCommand *command_new (int y, int x, int len); - -/* Return the Input * from a WCommand */ -#define input_w(x) (&(x->input)) - -extern WCommand *cmdline; +extern WInput *cmdline; +WInput *command_new (int y, int x, int len); void do_cd_command (char *cmd); #endif /* __COMMAND_H */ diff --git a/src/hotlist.c b/src/hotlist.c index 8e58dbea5..099f13c34 100644 --- a/src/hotlist.c +++ b/src/hotlist.c @@ -419,7 +419,7 @@ l1: struct hotlist *hlp = (struct hotlist*) l_hotlist->current->data; if (hlp->type == HL_TYPE_ENTRY) { char *tmp = g_strconcat ( "cd ", hlp->directory, NULL); - stuff (input_w (cmdline), tmp, 0); + stuff (cmdline, tmp, 0); g_free (tmp); dlg_stop (h); h->ret_value = B_CANCEL; diff --git a/src/layout.c b/src/layout.c index 1a4df1e2b..b4cd0f14a 100644 --- a/src/layout.c +++ b/src/layout.c @@ -632,85 +632,86 @@ panel_do_cols (int index) } } -void setup_panels (void) +void +setup_panels (void) { int start_y; int promptl; /* the prompt len */ - if (console_flag){ + if (console_flag) { int minimum; if (output_lines < 0) output_lines = 0; height = LINES - keybar_visible - command_prompt - menubar_visible - - output_lines - message_visible; - if (message_visible && xterm_hintbar && xterm_flag) height++; + - output_lines - message_visible; + if (message_visible && xterm_hintbar && xterm_flag) + height++; minimum = MINHEIGHT * (1 + horizontal_split); - if (height < minimum){ + if (height < minimum) { output_lines -= minimum - height; height = minimum; } } else { height = LINES - menubar_visible - command_prompt - keybar_visible - message_visible; - if (message_visible && xterm_hintbar && xterm_flag) height++; + if (message_visible && xterm_hintbar && xterm_flag) + height++; } check_split (); start_y = menubar_visible; /* The column computing is defered until panel_do_cols */ - if (horizontal_split){ - widget_set_size (panels [0].widget, start_y, 0, + if (horizontal_split) { + widget_set_size (panels[0].widget, start_y, 0, first_panel_size, 0); - - widget_set_size (panels [1].widget, start_y+first_panel_size, 0, - height-first_panel_size, 0); + + widget_set_size (panels[1].widget, start_y + first_panel_size, 0, + height - first_panel_size, 0); } else { int first_x = first_panel_size; - widget_set_size (panels [0].widget, start_y, 0, - height, 0); + widget_set_size (panels[0].widget, start_y, 0, height, 0); + + widget_set_size (panels[1].widget, start_y, first_x, height, 0); - widget_set_size (panels [1].widget, start_y, first_x, - height, 0); - } panel_do_cols (0); panel_do_cols (1); - + promptl = strlen (prompt); widget_set_size (&the_menubar->widget, 0, 0, 1, COLS); if (command_prompt) { - widget_set_size (&cmdline->input.widget, - LINES-1-keybar_visible, promptl, - 1, COLS-promptl-(keybar_visible ? 0 : 1)); - winput_set_origin (&cmdline->input, promptl, COLS-promptl-(keybar_visible ? 0 : 1)); - widget_set_size (&the_prompt->widget, - LINES-1-keybar_visible, 0, - 1, promptl); + widget_set_size (&cmdline->widget, LINES - 1 - keybar_visible, + promptl, 1, + COLS - promptl - (keybar_visible ? 0 : 1)); + winput_set_origin (cmdline, promptl, + COLS - promptl - (keybar_visible ? 0 : 1)); + widget_set_size (&the_prompt->widget, LINES - 1 - keybar_visible, + 0, 1, promptl); } else { - widget_set_size (&cmdline->input.widget, 0, 0, 0, 0); - winput_set_origin (&cmdline->input, 0, 0); - widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0); - } + widget_set_size (&cmdline->widget, 0, 0, 0, 0); + winput_set_origin (cmdline, 0, 0); + widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0); + } - widget_set_size (&the_bar->widget, LINES-1, 0, keybar_visible, COLS); + widget_set_size (&the_bar->widget, LINES - 1, 0, keybar_visible, COLS); the_bar->visible = keybar_visible; - + /* Output window */ - if (console_flag && output_lines){ - output_start_y = LINES -command_prompt-keybar_visible- + if (console_flag && output_lines) { + output_start_y = LINES - command_prompt - keybar_visible - output_lines; show_console_contents (output_start_y, - LINES-output_lines-keybar_visible-1, - LINES-keybar_visible-1); - } + LINES - output_lines - keybar_visible - 1, + LINES - keybar_visible - 1); + } if (message_visible && (!xterm_hintbar || !xterm_flag)) - widget_set_size (&the_hint->widget, height+start_y, 0, 1,COLS); + widget_set_size (&the_hint->widget, height + start_y, 0, 1, COLS); else widget_set_size (&the_hint->widget, 0, 0, 0, 0); - + load_hint (); } diff --git a/src/main.c b/src/main.c index 42527300e..2a9b461dc 100644 --- a/src/main.c +++ b/src/main.c @@ -600,7 +600,7 @@ execute (char *command) void change_panel (void) { - free_completions (input_w (cmdline)); + free_completions (cmdline); dlg_one_down (midnight_dlg); } @@ -767,7 +767,7 @@ _do_panel_cd (WPanel *panel, char *new_dir, enum cd_enum cd_type) /* Success: save previous directory, shutdown status of previous dir */ strcpy (panel->lwd, olddir); - free_completions (input_w (cmdline)); + free_completions (cmdline); mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2); @@ -888,7 +888,7 @@ int maybe_cd (int char_code, int move_up_dir) { if (navigate_with_arrows){ - if (!input_w (cmdline)->buffer [0]){ + if (!cmdline->buffer [0]){ if (!move_up_dir){ do_cd ("..", cd_exact); return 1; @@ -1254,9 +1254,9 @@ static void copy_current_pathname (void) if (!command_prompt) return; - stuff (input_w (cmdline), cpanel->cwd, 0); + stuff (cmdline, cpanel->cwd, 0); if (cpanel->cwd [strlen (cpanel->cwd) - 1] != PATH_SEP) - stuff (input_w (cmdline), PATH_SEP_STR, 0); + stuff (cmdline, PATH_SEP_STR, 0); } static void copy_other_pathname (void) @@ -1267,9 +1267,9 @@ static void copy_other_pathname (void) if (!command_prompt) return; - stuff (input_w (cmdline), opanel->cwd, 0); + stuff (cmdline, opanel->cwd, 0); if (cpanel->cwd [strlen (opanel->cwd) - 1] != PATH_SEP) - stuff (input_w (cmdline), PATH_SEP_STR, 0); + stuff (cmdline, PATH_SEP_STR, 0); } static void copy_readlink (WPanel *panel) @@ -1285,7 +1285,7 @@ static void copy_readlink (WPanel *panel) g_free (p); if (i > 0) { buffer [i] = 0; - stuff (input_w (cmdline), buffer, 0); + stuff (cmdline, buffer, 0); } } } @@ -1315,7 +1315,7 @@ void copy_prog_name (void) tmp = name_quote (tree->selected_ptr->name, 1); } else tmp = name_quote (selection (cpanel)->fname, 1); - stuff (input_w (cmdline), tmp, 1); + stuff (cmdline, tmp, 1); g_free (tmp); } @@ -1325,20 +1325,20 @@ static void copy_tagged (WPanel *panel) if (!command_prompt) return; - input_disable_update (input_w (cmdline)); + input_disable_update (cmdline); if (panel->marked){ for (i = 0; i < panel->count; i++) if (panel->dir.list [i].f.marked) { char *tmp = name_quote (panel->dir.list [i].fname, 1); - stuff (input_w (cmdline), tmp, 1); + stuff (cmdline, tmp, 1); g_free (tmp); } } else { char *tmp = name_quote (panel->dir.list [panel->selected].fname, 1); - stuff (input_w (cmdline), tmp, 1); + stuff (cmdline, tmp, 1); g_free (tmp); } - input_enable_update (input_w (cmdline)); + input_enable_update (cmdline); } static void copy_current_tagged (void) @@ -1704,7 +1704,7 @@ midnight_callback (struct Dlg_head *h, int id, int msg) } if (id == '\t') - free_completions (input_w (cmdline)); + free_completions (cmdline); /* On Linux, we can tell the difference */ if (id == '\n' && ctrl_pressed ()){ @@ -1712,7 +1712,7 @@ midnight_callback (struct Dlg_head *h, int id, int msg) return MSG_HANDLED; } - if (id == '\n' && input_w (cmdline)->buffer [0]){ + if (id == '\n' && cmdline->buffer [0]){ send_message_to (h, (Widget *) cmdline, WIDGET_KEY, id); return MSG_HANDLED; } @@ -1735,7 +1735,7 @@ midnight_callback (struct Dlg_head *h, int id, int msg) reverse_selection_cmd (); return MSG_HANDLED; } - } else if (command_prompt && !strlen (input_w (cmdline)->buffer)) { + } else if (command_prompt && !strlen (cmdline->buffer)) { /* Special treatement '+', '-', '\', '*' only when this is * first char on input line */ diff --git a/src/widget.c b/src/widget.c index ff164991c..c13809ff2 100644 --- a/src/widget.c +++ b/src/widget.c @@ -1518,7 +1518,7 @@ input_set_point (WInput *in, int pos) update_input (in, 1); } -static int +int input_callback (Dlg_head *h, WInput *in, int Msg, int Par) { switch (Msg){ diff --git a/src/widget.h b/src/widget.h index 32c269a8d..a08f91073 100644 --- a/src/widget.h +++ b/src/widget.h @@ -170,6 +170,7 @@ void input_enable_update (WInput *in); void input_set_point (WInput *in, int pos); void input_show_cursor (WInput *in); void assign_text (WInput *in, char *text); +int input_callback (Dlg_head *h, WInput *in, int Msg, int Par); /* Labels */ void label_set_text (WLabel *label, char *text);