r1218: Options changes...
[rox-filer.git] / ROX-Filer / src / minibuffer.c
blobd5bf0b4de89fe148c4f58402883df9c7889fd6bb
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* minibuffer.c - for handling the path entry box at the bottom */
24 #include "config.h"
26 #include <string.h>
27 #include <errno.h>
28 #include <ctype.h>
29 #include <glob.h>
30 #include <stdio.h>
32 #include <gtk/gtk.h>
33 #include <gdk/gdkkeysyms.h>
35 #include "global.h"
37 #include "options.h"
38 #include "collection.h"
39 #include "find.h"
40 #include "gui_support.h"
41 #include "support.h"
42 #include "minibuffer.h"
43 #include "filer.h"
44 #include "display.h"
45 #include "main.h"
46 #include "action.h"
47 #include "diritem.h"
48 #include "type.h"
50 static GList *shell_history = NULL;
52 /* Static prototypes */
53 static gint key_press_event(GtkWidget *widget,
54 GdkEventKey *event,
55 FilerWindow *filer_window);
56 static void changed(GtkEditable *mini, FilerWindow *filer_window);
57 static gboolean find_next_match(FilerWindow *filer_window,
58 char *pattern,
59 int dir);
60 static gboolean find_exact_match(FilerWindow *filer_window, char *pattern);
61 static gboolean matches(Collection *collection, int item, char *pattern);
62 static void search_in_dir(FilerWindow *filer_window, int dir);
63 static guchar *mini_contents(FilerWindow *filer_window);
64 static void show_help(FilerWindow *filer_window);
65 #ifdef GTK2
66 static gboolean grab_focus(GtkWidget *minibuffer);
67 #endif
69 /****************************************************************
70 * EXTERNAL INTERFACE *
71 ****************************************************************/
73 static Option o_filer_beep_fail, o_filer_beep_multi;
75 void minibuffer_init(void)
77 option_add_int(&o_filer_beep_fail, "filer_beep_fail", 1, NULL);
78 option_add_int(&o_filer_beep_multi, "filer_beep_multi", 1, NULL);
81 /* Creates the minibuffer widgets, setting the appropriate fields
82 * in filer_window.
84 void create_minibuffer(FilerWindow *filer_window)
86 GtkWidget *hbox, *label, *mini;
88 hbox = gtk_hbox_new(FALSE, 0);
90 gtk_box_pack_start(GTK_BOX(hbox),
91 new_help_button((HelpFunc) show_help, filer_window),
92 FALSE, TRUE, 0);
94 label = gtk_label_new("");
95 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 2);
97 mini = gtk_entry_new();
98 gtk_box_pack_start(GTK_BOX(hbox), mini, TRUE, TRUE, 0);
99 gtk_widget_set_name(mini, "fixed-style");
100 gtk_signal_connect(GTK_OBJECT(mini), "key_press_event",
101 GTK_SIGNAL_FUNC(key_press_event), filer_window);
102 gtk_signal_connect(GTK_OBJECT(mini), "changed",
103 GTK_SIGNAL_FUNC(changed), filer_window);
105 #ifdef GTK2
106 /* Grabbing focus musn't select the text... */
107 gtk_signal_connect_object(GTK_OBJECT(mini), "grab-focus",
108 GTK_SIGNAL_FUNC(grab_focus),
109 GTK_OBJECT(mini));
110 #endif
112 filer_window->minibuffer = mini;
113 filer_window->minibuffer_label = label;
114 filer_window->minibuffer_area = hbox;
117 void minibuffer_show(FilerWindow *filer_window, MiniType mini_type)
119 Collection *collection;
120 GtkEntry *mini;
121 int pos = -1, i;
123 g_return_if_fail(filer_window != NULL);
124 g_return_if_fail(filer_window->minibuffer != NULL);
126 mini = GTK_ENTRY(filer_window->minibuffer);
128 filer_window->mini_type = MINI_NONE;
129 gtk_label_set_text(GTK_LABEL(filer_window->minibuffer_label),
130 mini_type == MINI_PATH ? _("Goto:") :
131 mini_type == MINI_SHELL ? _("Shell:") :
132 mini_type == MINI_SELECT_IF ? _("Select If:") :
133 "?");
135 collection = filer_window->collection;
136 switch (mini_type)
138 case MINI_PATH:
139 collection_move_cursor(collection, 0, 0);
140 filer_window->mini_cursor_base =
141 MAX(collection->cursor_item, 0);
142 gtk_entry_set_text(mini,
143 make_path(filer_window->path, "")->str);
144 if (filer_window->temp_show_hidden)
146 display_set_hidden(filer_window, FALSE);
147 filer_window->temp_show_hidden = FALSE;
149 break;
150 case MINI_SELECT_IF:
151 gtk_entry_set_text(mini, "");
152 filer_window->mini_cursor_base = -1; /* History */
153 break;
154 case MINI_SHELL:
155 pos = 0;
156 i = collection->cursor_item;
157 if (collection->number_selected)
158 gtk_entry_set_text(mini, " \"$@\"");
159 else if (i > -1 && i < collection->number_of_items)
161 DirItem *item = (DirItem *)
162 collection->items[i].data;
163 guchar *tmp;
165 tmp = g_strconcat(" ", item->leafname, NULL);
166 gtk_entry_set_text(mini, tmp);
167 g_free(tmp);
169 else
170 gtk_entry_set_text(mini, "");
171 filer_window->mini_cursor_base = -1; /* History */
172 break;
173 default:
174 g_warning("Bad minibuffer type\n");
175 return;
178 filer_window->mini_type = mini_type;
180 gtk_entry_set_position(mini, pos);
182 gtk_widget_show_all(filer_window->minibuffer_area);
184 gtk_window_set_focus(GTK_WINDOW(filer_window->window),
185 filer_window->minibuffer);
188 void minibuffer_hide(FilerWindow *filer_window)
190 filer_window->mini_type = MINI_NONE;
192 gtk_widget_hide(filer_window->minibuffer_area);
193 gtk_window_set_focus(GTK_WINDOW(filer_window->window),
194 GTK_WIDGET(filer_window->collection));
196 if (filer_window->temp_show_hidden)
198 Collection *collection = filer_window->collection;
199 int i = collection->cursor_item;
200 DirItem *item = NULL;
202 if (i >= 0 && i < collection->number_of_items)
203 item = (DirItem *) collection->items[i].data;
205 if (item == NULL || item->leafname[0] != '.')
206 display_set_hidden(filer_window, FALSE);
207 filer_window->temp_show_hidden = FALSE;
211 /* Insert this leafname at the cursor (replacing the selection, if any).
212 * Must be in SHELL mode.
214 void minibuffer_add(FilerWindow *filer_window, guchar *leafname)
216 guchar *esc;
217 GtkEditable *edit = GTK_EDITABLE(filer_window->minibuffer);
218 GtkEntry *entry = GTK_ENTRY(edit);
219 int pos;
221 g_return_if_fail(filer_window->mini_type == MINI_SHELL);
223 esc = shell_escape(leafname);
225 gtk_editable_delete_selection(edit);
226 pos = gtk_editable_get_position(edit);
228 if (pos > 0 && gtk_entry_get_text(entry)[pos - 1] != ' ')
229 gtk_editable_insert_text(edit, " ", 1, &pos);
231 gtk_editable_insert_text(edit, esc, strlen(esc), &pos);
232 gtk_editable_set_position(edit, pos);
234 g_free(esc);
238 /****************************************************************
239 * INTERNAL FUNCTIONS *
240 ****************************************************************/
242 static void show_help(FilerWindow *filer_window)
244 guchar *message;
246 gtk_widget_grab_focus(filer_window->minibuffer);
248 switch (filer_window->mini_type)
250 case MINI_PATH:
251 message = _("Enter the name of a file and I'll display "
252 "it for you. Press Tab to fill in the longest "
253 "match. Escape to close the minibuffer.");
254 break;
255 case MINI_SHELL:
256 message = _("Enter a shell command to execute. Click "
257 "on a file to add it to the buffer.");
258 break;
259 case MINI_SELECT_IF:
260 show_condition_help(NULL);
261 return;
262 default:
263 message = "?!?";
264 break;
267 delayed_error("%s", message);
271 /* PATH ENTRY */
273 static void path_return_pressed(FilerWindow *filer_window, GdkEventKey *event)
275 Collection *collection = filer_window->collection;
276 int item = collection->cursor_item;
277 char *path, *pattern;
278 int flags = OPEN_FROM_MINI | OPEN_SAME_WINDOW;
280 path = gtk_entry_get_text(GTK_ENTRY(filer_window->minibuffer));
281 pattern = strrchr(path, '/');
282 if (pattern)
283 pattern++;
284 else
285 pattern = path;
287 if (item == -1 || item >= collection->number_of_items ||
288 !matches(collection, item, pattern))
290 gdk_beep();
291 return;
294 if ((event->state & GDK_SHIFT_MASK) != 0)
295 flags |= OPEN_SHIFT;
297 filer_openitem(filer_window, item, flags);
300 /* Use the cursor item to fill in the minibuffer.
301 * If there are multiple matches then fill in as much as possible and
302 * (possibly) beep.
304 static void complete(FilerWindow *filer_window)
306 GtkEntry *entry;
307 Collection *collection = filer_window->collection;
308 int cursor = collection->cursor_item;
309 DirItem *item;
310 int shortest_stem = -1;
311 int current_stem;
312 int other;
313 guchar *text, *leaf;
315 if (cursor < 0 || cursor >= collection->number_of_items)
317 gdk_beep();
318 return;
321 entry = GTK_ENTRY(filer_window->minibuffer);
323 item = (DirItem *) collection->items[cursor].data;
325 text = gtk_entry_get_text(entry);
326 leaf = strrchr(text, '/');
327 if (!leaf)
329 gdk_beep();
330 return;
333 leaf++;
334 if (!matches(collection, cursor, leaf))
336 gdk_beep();
337 return;
340 current_stem = strlen(leaf);
342 /* Find the longest other match of this name. It it's longer than
343 * the currently entered text then complete only up to that length.
345 for (other = 0; other < collection->number_of_items; other++)
347 DirItem *other_item = (DirItem *) collection->items[other].data;
348 int stem = 0;
350 if (other == cursor)
351 continue;
353 while (other_item->leafname[stem] && item->leafname[stem])
355 if (other_item->leafname[stem] != item->leafname[stem])
356 break;
357 stem++;
360 /* stem is the index of the first difference */
361 if (stem >= current_stem &&
362 (shortest_stem == -1 || stem < shortest_stem))
363 shortest_stem = stem;
366 if (current_stem == shortest_stem)
368 /* We didn't add anything... */
369 if (o_filer_beep_fail.int_value)
370 gdk_beep();
372 else if (current_stem < shortest_stem)
374 guchar *extra;
376 extra = g_strndup(item->leafname + current_stem,
377 shortest_stem - current_stem);
378 gtk_entry_append_text(entry, extra);
379 g_free(extra);
380 #ifdef GTK2
381 gtk_entry_set_position(entry, -1);
382 #endif
384 if (o_filer_beep_multi.int_value)
385 gdk_beep();
387 else
389 GString *new;
391 new = make_path(filer_window->path, item->leafname);
393 if (item->base_type == TYPE_DIRECTORY &&
394 (item->flags & ITEM_FLAG_APPDIR) == 0)
395 g_string_append_c(new, '/');
397 gtk_entry_set_text(entry, new->str);
398 #ifdef GTK2
399 gtk_entry_set_position(entry, -1);
400 #endif
404 /* This is an idle function because Gtk+ 2.0 changes text in a entry
405 * with two signals; one to blank it and one to put the new text in.
407 static gboolean path_changed(gpointer data)
409 FilerWindow *filer_window = (FilerWindow *) data;
410 GtkWidget *mini = filer_window->minibuffer;
411 char *new, *leaf;
412 char *path, *real;
414 new = gtk_entry_get_text(GTK_ENTRY(mini));
416 leaf = g_basename(new);
417 if (leaf == new)
418 path = g_strdup("/");
419 else
420 path = g_dirname(new);
421 real = pathdup(path);
422 g_free(path);
424 if (strcmp(real, filer_window->path) != 0)
426 /* The new path is in a different directory */
427 struct stat info;
429 if (mc_stat(real, &info) == 0 && S_ISDIR(info.st_mode))
430 filer_change_to(filer_window, real, leaf);
431 else
432 gdk_beep();
434 else
436 if (*leaf == '.')
438 if (!filer_window->show_hidden)
440 filer_window->temp_show_hidden = TRUE;
441 display_set_hidden(filer_window, TRUE);
444 else if (filer_window->temp_show_hidden)
446 display_set_hidden(filer_window, FALSE);
447 filer_window->temp_show_hidden = FALSE;
450 if (find_exact_match(filer_window, leaf) == FALSE &&
451 find_next_match(filer_window, leaf, 0) == FALSE)
452 gdk_beep();
455 g_free(real);
457 return FALSE;
460 /* Look for an exact match, and move the cursor to it if found.
461 * TRUE on success.
463 static gboolean find_exact_match(FilerWindow *filer_window, char *pattern)
465 Collection *collection = filer_window->collection;
466 int i;
468 for (i = 0; i < collection->number_of_items; i++)
470 DirItem *item = (DirItem *) collection->items[i].data;
472 if (strcmp(item->leafname, pattern) == 0)
474 collection_set_cursor_item(collection, i);
475 return TRUE;
479 return FALSE;
482 /* Find the next item in the collection that matches 'pattern'. Start from
483 * mini_cursor_base and loop at either end. dir is 1 for a forward search,
484 * -1 for backwards. 0 means forwards, but may stay the same.
486 * Does not automatically update mini_cursor_base.
488 * Returns TRUE if a match is found.
490 static gboolean find_next_match(FilerWindow *filer_window,
491 char *pattern,
492 int dir)
494 Collection *collection = filer_window->collection;
495 int base = filer_window->mini_cursor_base;
496 int item = base;
497 gboolean retval = TRUE;
499 if (collection->number_of_items < 1)
500 return FALSE;
502 if (base < 0 || base>= collection->number_of_items)
503 filer_window->mini_cursor_base = base = 0;
507 /* Step to the next item */
508 item += dir;
510 if (item >= collection->number_of_items)
511 item = 0;
512 else if (item < 0)
513 item = collection->number_of_items - 1;
515 if (dir == 0)
516 dir = 1;
517 else if (item == base)
519 retval = FALSE;
520 break; /* No (other) matches at all */
522 } while (!matches(collection, item, pattern));
524 collection_set_cursor_item(collection, item);
526 return retval;
529 static gboolean matches(Collection *collection, int item_number, char *pattern)
531 DirItem *item = (DirItem *) collection->items[item_number].data;
533 return strncmp(item->leafname, pattern, strlen(pattern)) == 0;
536 /* Find next match and set base for future matches. */
537 static void search_in_dir(FilerWindow *filer_window, int dir)
539 char *path, *pattern;
541 path = gtk_entry_get_text(GTK_ENTRY(filer_window->minibuffer));
542 pattern = strrchr(path, '/');
543 if (pattern)
544 pattern++;
545 else
546 pattern = path;
548 filer_window->mini_cursor_base = filer_window->collection->cursor_item;
549 find_next_match(filer_window, pattern, dir);
550 filer_window->mini_cursor_base = filer_window->collection->cursor_item;
553 /* SHELL COMMANDS */
555 static void add_to_history(guchar *line)
557 guchar *last;
559 last = shell_history ? (guchar *) shell_history->data : NULL;
561 if (last && strcmp(last, line) == 0)
562 return; /* Duplicating last entry */
564 shell_history = g_list_prepend(shell_history, g_strdup(line));
567 static void shell_done(FilerWindow *filer_window)
569 if (filer_exists(filer_window))
570 filer_update_dir(filer_window, TRUE);
573 /* Given a list of matches, return the longest stem. g_free() the result.
574 * Special chars are escaped. If there is only a single (non-dir) match
575 * then a trailing space is added.
577 static guchar *best_match(FilerWindow *filer_window, glob_t *matches)
579 gchar *first = matches->gl_pathv[0];
580 int i;
581 int longest, path_len;
582 guchar *path, *tmp;
584 longest = strlen(first);
586 for (i = 1; i < matches->gl_pathc; i++)
588 int j;
589 guchar *m = matches->gl_pathv[i];
591 for (j = 0; j < longest; j++)
592 if (m[j] != first[j])
593 longest = j;
596 path_len = strlen(filer_window->path);
597 if (strncmp(filer_window->path, first, path_len) == 0 &&
598 first[path_len] == '/' && first[path_len + 1])
600 path = g_strndup(first + path_len + 1, longest - path_len - 1);
602 else
603 path = g_strndup(first, longest);
605 tmp = shell_escape(path);
606 g_free(path);
608 if (matches->gl_pathc == 1 && tmp[strlen(tmp) - 1] != '/')
610 path = g_strdup_printf("%s ", tmp);
611 g_free(tmp);
612 return path;
615 return tmp;
618 static void shell_tab(FilerWindow *filer_window)
620 int i;
621 guchar *entry;
622 guchar quote;
623 int pos;
624 GString *leaf;
625 glob_t matches;
626 int leaf_start;
628 entry = gtk_entry_get_text(GTK_ENTRY(filer_window->minibuffer));
629 pos = gtk_editable_get_position(GTK_EDITABLE(filer_window->minibuffer));
630 leaf = g_string_new(NULL);
632 quote = '\0';
633 for (i = 0; i < pos; i++)
635 guchar c = entry[i];
637 if (leaf->len == 0)
638 leaf_start = i;
640 if (c == ' ')
642 g_string_truncate(leaf, 0);
643 continue;
645 else if (c == '\\' && i + 1 < pos)
646 c = entry[++i];
647 else if (c == '"' || c == '\'')
649 guchar cc;
651 for (++i; i < pos; i++)
653 cc = entry[i];
655 if (cc == '\\' && i + 1 < pos)
656 cc = entry[++i];
657 else if (entry[i] == c)
658 break;
659 g_string_append_c(leaf, entry[i]);
661 continue;
664 g_string_append_c(leaf, c);
667 if (leaf->len == 0)
668 leaf_start = pos;
670 if (leaf->str[0] != '/' && leaf->str[0] != '~')
672 g_string_prepend_c(leaf, '/');
673 g_string_prepend(leaf, filer_window->path);
676 g_string_append_c(leaf, '*');
678 if (glob(leaf->str,
679 #ifdef GLOB_TILDE
680 GLOB_TILDE |
681 #endif
682 GLOB_MARK, NULL, &matches) == 0)
684 if (matches.gl_pathc > 0)
686 guchar *best;
687 GtkEditable *edit =
688 GTK_EDITABLE(filer_window->minibuffer);
690 best = best_match(filer_window, &matches);
692 gtk_editable_delete_text(edit, leaf_start, pos);
693 gtk_editable_insert_text(edit, best, strlen(best),
694 &leaf_start);
695 gtk_editable_set_position(edit, leaf_start);
697 g_free(best);
699 if (matches.gl_pathc != 1)
700 gdk_beep();
702 globfree(&matches);
705 g_string_free(leaf, TRUE);
708 /* Either execute the command or make it the default run action */
709 static void shell_return_pressed(FilerWindow *filer_window)
711 GPtrArray *argv;
712 int i;
713 guchar *entry;
714 Collection *collection = filer_window->collection;
715 int child;
717 entry = mini_contents(filer_window);
719 if (!entry)
720 goto out;
722 add_to_history(entry);
724 argv = g_ptr_array_new();
725 g_ptr_array_add(argv, "sh");
726 g_ptr_array_add(argv, "-c");
727 g_ptr_array_add(argv, entry);
728 g_ptr_array_add(argv, "sh");
730 for (i = 0; i < collection->number_of_items; i++)
732 DirItem *item = (DirItem *) collection->items[i].data;
733 if (collection->items[i].selected)
734 g_ptr_array_add(argv, item->leafname);
737 g_ptr_array_add(argv, NULL);
739 child = fork();
741 switch (child)
743 case -1:
744 delayed_error(_("Failed to create child process"));
745 break;
746 case 0: /* Child */
747 /* Ensure output is noticed - send stdout to stderr */
748 dup2(STDERR_FILENO, STDOUT_FILENO);
749 close_on_exec(STDOUT_FILENO, FALSE);
750 if (chdir(filer_window->path))
751 g_printerr("chdir(%s) failed: %s\n",
752 filer_window->path,
753 g_strerror(errno));
754 execvp((char *) argv->pdata[0],
755 (char **) argv->pdata);
756 g_printerr("execvp(%s, ...) failed: %s\n",
757 (char *) argv->pdata[0],
758 g_strerror(errno));
759 _exit(0);
760 default:
761 on_child_death(child,
762 (CallbackFn) shell_done, filer_window);
763 break;
766 g_ptr_array_free(argv, TRUE);
768 out:
769 minibuffer_hide(filer_window);
772 /* Move through the shell history */
773 static void shell_recall(FilerWindow *filer_window, int dir)
775 guchar *command;
776 int pos = filer_window->mini_cursor_base;
778 pos += dir;
779 if (pos >= 0)
781 command = g_list_nth_data(shell_history, pos);
782 if (!command)
783 return;
785 else
786 command = "";
788 if (pos < -1)
789 pos = -1;
790 filer_window->mini_cursor_base = pos;
792 gtk_entry_set_text(GTK_ENTRY(filer_window->minibuffer), command);
795 /* SELECT IF */
797 static void select_return_pressed(FilerWindow *filer_window, guint etime)
799 FindCondition *cond;
800 int i, n;
801 guchar *entry;
802 Collection *collection = filer_window->collection;
803 FindInfo info;
805 entry = mini_contents(filer_window);
807 if (!entry)
808 goto out;
810 add_to_history(entry);
812 cond = find_compile(entry);
813 if (!cond)
815 delayed_error(_("Invalid Find condition"));
816 return;
819 info.now = time(NULL);
820 info.prune = FALSE; /* (don't care) */
821 n = collection->number_of_items;
823 collection->block_selection_changed++;
825 /* If an item at the start is selected then we could lose the
826 * primary selection after checking that item and then need to
827 * gain it again at the end. Therefore, if anything is selected
828 * then select the last item until the end of the search.
830 if (collection->number_selected)
831 collection_select_item(collection, n - 1);
833 for (i = 0; i < n; i++)
835 DirItem *item = (DirItem *) collection->items[i].data;
837 info.leaf = item->leafname;
838 info.fullpath = make_path(filer_window->path, info.leaf)->str;
840 if (lstat(info.fullpath, &info.stats) == 0 &&
841 find_test_condition(cond, &info))
842 collection_select_item(collection, i);
843 else
844 collection_unselect_item(collection, i);
847 find_condition_free(cond);
849 collection_unblock_selection_changed(collection, etime, TRUE);
850 out:
851 minibuffer_hide(filer_window);
855 /* EVENT HANDLERS */
857 static gint key_press_event(GtkWidget *widget,
858 GdkEventKey *event,
859 FilerWindow *filer_window)
861 if (event->keyval == GDK_Escape)
863 if (filer_window->mini_type == MINI_SHELL)
865 guchar *line;
867 line = mini_contents(filer_window);
868 if (line)
869 add_to_history(line);
872 minibuffer_hide(filer_window);
873 return TRUE;
876 switch (filer_window->mini_type)
878 case MINI_PATH:
879 switch (event->keyval)
881 case GDK_Up:
882 search_in_dir(filer_window, -1);
883 break;
884 case GDK_Down:
885 search_in_dir(filer_window, 1);
886 break;
887 case GDK_Return:
888 case GDK_KP_Enter:
889 path_return_pressed(filer_window,
890 event);
891 break;
892 case GDK_Tab:
893 complete(filer_window);
894 break;
895 default:
896 return FALSE;
898 break;
900 case MINI_SHELL:
901 switch (event->keyval)
903 case GDK_Up:
904 shell_recall(filer_window, 1);
905 break;
906 case GDK_Down:
907 shell_recall(filer_window, -1);
908 break;
909 case GDK_Tab:
910 shell_tab(filer_window);
911 break;
912 case GDK_Return:
913 case GDK_KP_Enter:
914 shell_return_pressed(filer_window);
915 break;
916 default:
917 return FALSE;
919 break;
920 case MINI_SELECT_IF:
921 switch (event->keyval)
923 case GDK_Up:
924 shell_recall(filer_window, 1);
925 break;
926 case GDK_Down:
927 shell_recall(filer_window, -1);
928 break;
929 case GDK_Tab:
930 break;
931 case GDK_Return:
932 case GDK_KP_Enter:
933 select_return_pressed(filer_window,
934 event->time);
935 break;
936 default:
937 return FALSE;
939 break;
940 default:
941 break;
944 #ifndef GTK2
945 gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event");
946 #endif
947 return TRUE;
950 static void changed(GtkEditable *mini, FilerWindow *filer_window)
952 switch (filer_window->mini_type)
954 case MINI_PATH:
955 gtk_idle_add(path_changed, filer_window);
956 return;
957 case MINI_SELECT_IF:
958 set_find_string_colour(GTK_WIDGET(mini),
959 gtk_entry_get_text(
960 GTK_ENTRY(filer_window->minibuffer)));
961 return;
962 default:
963 break;
967 /* Returns a string (which must NOT be freed), or NULL if the buffer
968 * is blank (whitespace only).
970 static guchar *mini_contents(FilerWindow *filer_window)
972 guchar *entry, *c;
974 entry = gtk_entry_get_text(GTK_ENTRY(filer_window->minibuffer));
976 for (c = entry; *c; c++)
977 if (!isspace(*c))
978 return entry;
980 return NULL;
983 #ifdef GTK2
984 static gboolean grab_focus(GtkWidget *minibuffer)
986 GtkWidgetClass *class;
988 class = GTK_WIDGET_CLASS(gtk_type_class(GTK_TYPE_WIDGET));
990 class->grab_focus(minibuffer);
992 gtk_signal_emit_stop_by_name(GTK_OBJECT(minibuffer), "grab_focus");
994 return 1;
996 #endif