r1476: Options to forward button-3 clicks on the pinboard to the window manager
[rox-filer.git] / ROX-Filer / src / minibuffer.c
blob0dbc7de9c03b92b338a3d5b59b60b92db230ed49
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 const char *pattern,
59 int dir);
60 static gboolean find_exact_match(FilerWindow *filer_window,
61 const gchar *pattern);
62 static gboolean matches(Collection *collection, int item, const char *pattern);
63 static void search_in_dir(FilerWindow *filer_window, int dir);
64 static const gchar *mini_contents(FilerWindow *filer_window);
65 static void show_help(FilerWindow *filer_window);
66 static gboolean grab_focus(GtkWidget *minibuffer);
68 /****************************************************************
69 * EXTERNAL INTERFACE *
70 ****************************************************************/
72 static Option o_filer_beep_fail, o_filer_beep_multi;
74 void minibuffer_init(void)
76 option_add_int(&o_filer_beep_fail, "filer_beep_fail", 1);
77 option_add_int(&o_filer_beep_multi, "filer_beep_multi", 1);
80 /* Creates the minibuffer widgets, setting the appropriate fields
81 * in filer_window.
83 void create_minibuffer(FilerWindow *filer_window)
85 GtkWidget *hbox, *label, *mini;
87 hbox = gtk_hbox_new(FALSE, 0);
89 gtk_box_pack_start(GTK_BOX(hbox),
90 new_help_button((HelpFunc) show_help, filer_window),
91 FALSE, TRUE, 0);
93 label = gtk_label_new("");
94 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 2);
96 mini = gtk_entry_new();
97 gtk_box_pack_start(GTK_BOX(hbox), mini, TRUE, TRUE, 0);
98 gtk_widget_set_name(mini, "fixed-style");
99 g_signal_connect(mini, "key_press_event",
100 G_CALLBACK(key_press_event), filer_window);
101 g_signal_connect(mini, "changed", G_CALLBACK(changed), filer_window);
103 /* Grabbing focus musn't select the text... */
104 g_signal_connect_swapped(mini, "grab-focus",
105 G_CALLBACK(grab_focus), mini);
107 filer_window->minibuffer = mini;
108 filer_window->minibuffer_label = label;
109 filer_window->minibuffer_area = hbox;
112 void minibuffer_show(FilerWindow *filer_window, MiniType mini_type)
114 Collection *collection;
115 GtkEntry *mini;
116 int pos = -1, i;
118 g_return_if_fail(filer_window != NULL);
119 g_return_if_fail(filer_window->minibuffer != NULL);
121 mini = GTK_ENTRY(filer_window->minibuffer);
122 entry_set_error(filer_window->minibuffer, FALSE);
124 filer_window->mini_type = MINI_NONE;
125 gtk_label_set_text(GTK_LABEL(filer_window->minibuffer_label),
126 mini_type == MINI_PATH ? _("Goto:") :
127 mini_type == MINI_SHELL ? _("Shell:") :
128 mini_type == MINI_SELECT_IF ? _("Select If:") :
129 "?");
131 collection = filer_window->collection;
132 switch (mini_type)
134 case MINI_PATH:
135 collection_move_cursor(collection, 0, 0);
136 filer_window->mini_cursor_base =
137 MAX(collection->cursor_item, 0);
138 gtk_entry_set_text(mini,
139 make_path(filer_window->sym_path, "")->str);
140 if (filer_window->temp_show_hidden)
142 display_set_hidden(filer_window, FALSE);
143 filer_window->temp_show_hidden = FALSE;
145 break;
146 case MINI_SELECT_IF:
147 gtk_entry_set_text(mini, "");
148 filer_window->mini_cursor_base = -1; /* History */
149 break;
150 case MINI_SHELL:
151 pos = 0;
152 i = collection->cursor_item;
153 if (collection->number_selected)
154 gtk_entry_set_text(mini, " \"$@\"");
155 else if (i > -1 && i < collection->number_of_items)
157 DirItem *item = (DirItem *)
158 collection->items[i].data;
159 guchar *tmp;
161 tmp = g_strconcat(" ", item->leafname, NULL);
162 gtk_entry_set_text(mini, tmp);
163 g_free(tmp);
165 else
166 gtk_entry_set_text(mini, "");
167 filer_window->mini_cursor_base = -1; /* History */
168 break;
169 default:
170 g_warning("Bad minibuffer type\n");
171 return;
174 filer_window->mini_type = mini_type;
176 gtk_editable_set_position(GTK_EDITABLE(mini), pos);
178 gtk_widget_show_all(filer_window->minibuffer_area);
180 gtk_window_set_focus(GTK_WINDOW(filer_window->window),
181 filer_window->minibuffer);
184 void minibuffer_hide(FilerWindow *filer_window)
186 filer_window->mini_type = MINI_NONE;
188 gtk_widget_hide(filer_window->minibuffer_area);
189 gtk_window_set_focus(GTK_WINDOW(filer_window->window),
190 GTK_WIDGET(filer_window->collection));
192 if (filer_window->temp_show_hidden)
194 Collection *collection = filer_window->collection;
195 int i = collection->cursor_item;
196 DirItem *item = NULL;
198 if (i >= 0 && i < collection->number_of_items)
199 item = (DirItem *) collection->items[i].data;
201 if (item == NULL || item->leafname[0] != '.')
202 display_set_hidden(filer_window, FALSE);
203 filer_window->temp_show_hidden = FALSE;
207 /* Insert this leafname at the cursor (replacing the selection, if any).
208 * Must be in SHELL mode.
210 void minibuffer_add(FilerWindow *filer_window, const gchar *leafname)
212 guchar *esc;
213 GtkEditable *edit = GTK_EDITABLE(filer_window->minibuffer);
214 GtkEntry *entry = GTK_ENTRY(edit);
215 int pos;
217 g_return_if_fail(filer_window->mini_type == MINI_SHELL);
219 esc = shell_escape(leafname);
221 gtk_editable_delete_selection(edit);
222 pos = gtk_editable_get_position(edit);
224 if (pos > 0 && gtk_entry_get_text(entry)[pos - 1] != ' ')
225 gtk_editable_insert_text(edit, " ", 1, &pos);
227 gtk_editable_insert_text(edit, esc, strlen(esc), &pos);
228 gtk_editable_set_position(edit, pos);
230 g_free(esc);
234 /****************************************************************
235 * INTERNAL FUNCTIONS *
236 ****************************************************************/
238 static void show_help(FilerWindow *filer_window)
240 switch (filer_window->mini_type)
242 case MINI_PATH:
243 info_message(
244 _("Enter the name of a file and I'll display "
245 "it for you. Press Tab to fill in the longest "
246 "match. Escape to close the minibuffer."));
247 break;
248 case MINI_SHELL:
249 info_message(
250 _("Enter a shell command to execute. Click "
251 "on a file to add it to the buffer."));
252 break;
253 case MINI_SELECT_IF:
254 show_condition_help(NULL);
255 break;
256 default:
257 g_warning("Unknown minibuffer type!");
258 break;
263 /* PATH ENTRY */
265 static void path_return_pressed(FilerWindow *filer_window, GdkEventKey *event)
267 Collection *collection = filer_window->collection;
268 int item = collection->cursor_item;
269 const gchar *path, *pattern;
270 int flags = OPEN_FROM_MINI | OPEN_SAME_WINDOW;
272 path = gtk_entry_get_text(GTK_ENTRY(filer_window->minibuffer));
273 pattern = g_basename(path);
275 if (item == -1 || item >= collection->number_of_items ||
276 !matches(collection, item, pattern))
278 gdk_beep();
279 return;
282 if ((event->state & GDK_SHIFT_MASK) != 0)
283 flags |= OPEN_SHIFT;
285 filer_openitem(filer_window, item, flags);
288 /* Use the cursor item to fill in the minibuffer.
289 * If there are multiple matches then fill in as much as possible and
290 * (possibly) beep.
292 static void complete(FilerWindow *filer_window)
294 GtkEntry *entry;
295 Collection *collection = filer_window->collection;
296 int cursor = collection->cursor_item;
297 DirItem *item;
298 int shortest_stem = -1;
299 int current_stem;
300 int other;
301 const gchar *text, *leaf;
303 if (cursor < 0 || cursor >= collection->number_of_items)
305 gdk_beep();
306 return;
309 entry = GTK_ENTRY(filer_window->minibuffer);
311 item = (DirItem *) collection->items[cursor].data;
313 text = gtk_entry_get_text(entry);
314 leaf = strrchr(text, '/');
315 if (!leaf)
317 gdk_beep();
318 return;
321 leaf++;
322 if (!matches(collection, cursor, leaf))
324 gdk_beep();
325 return;
328 current_stem = strlen(leaf);
330 /* Find the longest other match of this name. It it's longer than
331 * the currently entered text then complete only up to that length.
333 for (other = 0; other < collection->number_of_items; other++)
335 DirItem *other_item = (DirItem *) collection->items[other].data;
336 int stem = 0;
338 if (other == cursor)
339 continue;
341 while (other_item->leafname[stem] && item->leafname[stem])
343 if (other_item->leafname[stem] != item->leafname[stem])
344 break;
345 stem++;
348 /* stem is the index of the first difference */
349 if (stem >= current_stem &&
350 (shortest_stem == -1 || stem < shortest_stem))
351 shortest_stem = stem;
354 if (current_stem == shortest_stem)
356 /* We didn't add anything... */
357 if (o_filer_beep_fail.int_value)
358 gdk_beep();
360 else if (current_stem < shortest_stem)
362 guchar *extra;
363 gint tmp_pos;
365 extra = g_strndup(item->leafname + current_stem,
366 shortest_stem - current_stem);
368 tmp_pos = entry->text_length;
369 gtk_editable_insert_text(GTK_EDITABLE(entry), extra, -1,
370 &tmp_pos);
372 g_free(extra);
373 gtk_editable_set_position(GTK_EDITABLE(entry), -1);
375 if (o_filer_beep_multi.int_value)
376 gdk_beep();
378 else
380 GString *new;
382 new = make_path(filer_window->sym_path, item->leafname);
384 if (item->base_type == TYPE_DIRECTORY &&
385 (item->flags & ITEM_FLAG_APPDIR) == 0)
386 g_string_append_c(new, '/');
388 gtk_entry_set_text(entry, new->str);
389 gtk_editable_set_position(GTK_EDITABLE(entry), -1);
393 /* This is an idle function because Gtk+ 2.0 changes text in a entry
394 * with two signals; one to blank it and one to put the new text in.
396 static gboolean path_changed(gpointer data)
398 FilerWindow *filer_window = (FilerWindow *) data;
399 GtkWidget *mini = filer_window->minibuffer;
400 const char *new, *leaf;
401 char *path;
402 gboolean error = FALSE;
404 new = gtk_entry_get_text(GTK_ENTRY(mini));
406 leaf = g_basename(new);
407 if (leaf == new)
408 path = g_strdup("/");
409 else
410 path = g_dirname(new);
412 if (strcmp(path, filer_window->sym_path) != 0)
414 /* The new path is in a different directory */
415 struct stat info;
417 if (mc_stat(path, &info) == 0 && S_ISDIR(info.st_mode))
418 filer_change_to(filer_window, path, leaf);
419 else
420 error = TRUE;
422 else
424 if (*leaf == '.')
426 if (!filer_window->show_hidden)
428 filer_window->temp_show_hidden = TRUE;
429 display_set_hidden(filer_window, TRUE);
432 else if (filer_window->temp_show_hidden)
434 display_set_hidden(filer_window, FALSE);
435 filer_window->temp_show_hidden = FALSE;
438 if (find_exact_match(filer_window, leaf) == FALSE &&
439 find_next_match(filer_window, leaf, 0) == FALSE)
440 error = TRUE;
443 g_free(path);
445 entry_set_error(mini, error);
447 return FALSE;
450 /* Look for an exact match, and move the cursor to it if found.
451 * TRUE on success.
453 static gboolean find_exact_match(FilerWindow *filer_window,
454 const gchar *pattern)
456 Collection *collection = filer_window->collection;
457 int i;
459 for (i = 0; i < collection->number_of_items; i++)
461 DirItem *item = (DirItem *) collection->items[i].data;
463 if (strcmp(item->leafname, pattern) == 0)
465 collection_set_cursor_item(collection, i);
466 return TRUE;
470 return FALSE;
473 /* Find the next item in the collection that matches 'pattern'. Start from
474 * mini_cursor_base and loop at either end. dir is 1 for a forward search,
475 * -1 for backwards. 0 means forwards, but may stay the same.
477 * Does not automatically update mini_cursor_base.
479 * Returns TRUE if a match is found.
481 static gboolean find_next_match(FilerWindow *filer_window,
482 const char *pattern,
483 int dir)
485 Collection *collection = filer_window->collection;
486 int base = filer_window->mini_cursor_base;
487 int item = base;
488 gboolean retval = TRUE;
490 if (collection->number_of_items < 1)
491 return FALSE;
493 if (base < 0 || base>= collection->number_of_items)
494 filer_window->mini_cursor_base = base = 0;
498 /* Step to the next item */
499 item += dir;
501 if (item >= collection->number_of_items)
502 item = 0;
503 else if (item < 0)
504 item = collection->number_of_items - 1;
506 if (dir == 0)
507 dir = 1;
508 else if (item == base)
510 retval = FALSE;
511 break; /* No (other) matches at all */
513 } while (!matches(collection, item, pattern));
515 collection_set_cursor_item(collection, item);
517 return retval;
520 static gboolean matches(Collection *collection,
521 int item_number, const char *pattern)
523 DirItem *item = (DirItem *) collection->items[item_number].data;
525 return strncmp(item->leafname, pattern, strlen(pattern)) == 0;
528 /* Find next match and set base for future matches. */
529 static void search_in_dir(FilerWindow *filer_window, int dir)
531 const char *path, *pattern;
533 path = gtk_entry_get_text(GTK_ENTRY(filer_window->minibuffer));
534 pattern = g_basename(path);
536 filer_window->mini_cursor_base = filer_window->collection->cursor_item;
537 find_next_match(filer_window, pattern, dir);
538 filer_window->mini_cursor_base = filer_window->collection->cursor_item;
541 /* SHELL COMMANDS */
543 static void add_to_history(const gchar *line)
545 guchar *last;
547 last = shell_history ? (guchar *) shell_history->data : NULL;
549 if (last && strcmp(last, line) == 0)
550 return; /* Duplicating last entry */
552 shell_history = g_list_prepend(shell_history, g_strdup(line));
555 static void shell_done(FilerWindow *filer_window)
557 if (filer_exists(filer_window))
558 filer_update_dir(filer_window, TRUE);
561 /* Given a list of matches, return the longest stem. g_free() the result.
562 * Special chars are escaped. If there is only a single (non-dir) match
563 * then a trailing space is added.
565 static guchar *best_match(FilerWindow *filer_window, glob_t *matches)
567 gchar *first = matches->gl_pathv[0];
568 int i;
569 int longest, path_len;
570 guchar *path, *tmp;
572 longest = strlen(first);
574 for (i = 1; i < matches->gl_pathc; i++)
576 int j;
577 guchar *m = matches->gl_pathv[i];
579 for (j = 0; j < longest; j++)
580 if (m[j] != first[j])
581 longest = j;
584 path_len = strlen(filer_window->sym_path);
585 if (strncmp(filer_window->sym_path, first, path_len) == 0 &&
586 first[path_len] == '/' && first[path_len + 1])
588 path = g_strndup(first + path_len + 1, longest - path_len - 1);
590 else
591 path = g_strndup(first, longest);
593 tmp = shell_escape(path);
594 g_free(path);
596 if (matches->gl_pathc == 1 && tmp[strlen(tmp) - 1] != '/')
598 path = g_strdup_printf("%s ", tmp);
599 g_free(tmp);
600 return path;
603 return tmp;
606 static void shell_tab(FilerWindow *filer_window)
608 const gchar *entry;
609 int i;
610 int pos;
611 GString *leaf;
612 glob_t matches;
613 int leaf_start;
615 entry = gtk_entry_get_text(GTK_ENTRY(filer_window->minibuffer));
616 pos = gtk_editable_get_position(GTK_EDITABLE(filer_window->minibuffer));
617 leaf = g_string_new(NULL);
619 for (i = 0; i < pos; i++)
621 guchar c = entry[i];
623 if (leaf->len == 0)
624 leaf_start = i;
626 if (c == ' ')
628 g_string_truncate(leaf, 0);
629 continue;
631 else if (c == '\\' && i + 1 < pos)
632 c = entry[++i];
633 else if (c == '"' || c == '\'')
635 for (++i; i < pos; i++)
637 guchar cc = entry[i];
639 if (cc == '\\' && i + 1 < pos)
640 cc = entry[++i];
641 else if (cc == c)
642 break;
643 g_string_append_c(leaf, cc);
645 continue;
648 g_string_append_c(leaf, c);
651 if (leaf->len == 0)
652 leaf_start = pos;
654 if (leaf->str[0] != '/' && leaf->str[0] != '~')
656 g_string_prepend_c(leaf, '/');
657 g_string_prepend(leaf, filer_window->sym_path);
660 g_string_append_c(leaf, '*');
662 if (glob(leaf->str,
663 #ifdef GLOB_TILDE
664 GLOB_TILDE |
665 #endif
666 GLOB_MARK, NULL, &matches) == 0)
668 if (matches.gl_pathc > 0)
670 guchar *best;
671 GtkEditable *edit =
672 GTK_EDITABLE(filer_window->minibuffer);
674 best = best_match(filer_window, &matches);
676 gtk_editable_delete_text(edit, leaf_start, pos);
677 gtk_editable_insert_text(edit, best, strlen(best),
678 &leaf_start);
679 gtk_editable_set_position(edit, leaf_start);
681 g_free(best);
683 if (matches.gl_pathc != 1)
684 gdk_beep();
686 globfree(&matches);
689 g_string_free(leaf, TRUE);
692 /* Either execute the command or make it the default run action */
693 static void shell_return_pressed(FilerWindow *filer_window)
695 GPtrArray *argv;
696 int i;
697 const gchar *entry;
698 Collection *collection = filer_window->collection;
699 pid_t child;
701 entry = mini_contents(filer_window);
703 if (!entry)
704 goto out;
706 add_to_history(entry);
708 argv = g_ptr_array_new();
709 g_ptr_array_add(argv, "sh");
710 g_ptr_array_add(argv, "-c");
711 g_ptr_array_add(argv, (gchar *) entry);
712 g_ptr_array_add(argv, "sh");
714 for (i = 0; i < collection->number_of_items; i++)
716 DirItem *item = (DirItem *) collection->items[i].data;
717 if (collection->items[i].selected)
718 g_ptr_array_add(argv, item->leafname);
721 g_ptr_array_add(argv, NULL);
723 /* XXX: Use spawn */
725 child = fork();
727 switch (child)
729 case -1:
730 delayed_error(_("Failed to create child process"));
731 break;
732 case 0: /* Child */
733 /* Ensure output is noticed - send stdout to stderr */
734 dup2(STDERR_FILENO, STDOUT_FILENO);
735 close_on_exec(STDOUT_FILENO, FALSE);
736 if (chdir(filer_window->sym_path))
737 g_printerr("chdir(%s) failed: %s\n",
738 filer_window->sym_path,
739 g_strerror(errno));
740 execvp((char *) argv->pdata[0],
741 (char **) argv->pdata);
742 g_printerr("execvp(%s, ...) failed: %s\n",
743 (char *) argv->pdata[0],
744 g_strerror(errno));
745 _exit(0);
746 default:
747 on_child_death(child,
748 (CallbackFn) shell_done, filer_window);
749 break;
752 g_ptr_array_free(argv, TRUE);
754 out:
755 minibuffer_hide(filer_window);
758 /* Move through the shell history */
759 static void shell_recall(FilerWindow *filer_window, int dir)
761 guchar *command;
762 int pos = filer_window->mini_cursor_base;
764 pos += dir;
765 if (pos >= 0)
767 command = g_list_nth_data(shell_history, pos);
768 if (!command)
769 return;
771 else
772 command = "";
774 if (pos < -1)
775 pos = -1;
776 filer_window->mini_cursor_base = pos;
778 gtk_entry_set_text(GTK_ENTRY(filer_window->minibuffer), command);
781 /* SELECT IF */
783 static void select_return_pressed(FilerWindow *filer_window, guint etime)
785 FindCondition *cond;
786 int i, n;
787 const gchar *entry;
788 Collection *collection = filer_window->collection;
789 FindInfo info;
791 entry = mini_contents(filer_window);
793 if (!entry)
794 goto out;
796 add_to_history(entry);
798 cond = find_compile(entry);
799 if (!cond)
801 delayed_error(_("Invalid Find condition"));
802 return;
805 info.now = time(NULL);
806 info.prune = FALSE; /* (don't care) */
807 n = collection->number_of_items;
809 collection->block_selection_changed++;
811 /* If an item at the start is selected then we could lose the
812 * primary selection after checking that item and then need to
813 * gain it again at the end. Therefore, if anything is selected
814 * then select the last item until the end of the search.
816 if (collection->number_selected)
817 collection_select_item(collection, n - 1);
819 for (i = 0; i < n; i++)
821 DirItem *item = (DirItem *) collection->items[i].data;
823 info.leaf = item->leafname;
824 info.fullpath =
825 make_path(filer_window->sym_path, info.leaf)->str;
827 if (lstat(info.fullpath, &info.stats) == 0 &&
828 find_test_condition(cond, &info))
829 collection_select_item(collection, i);
830 else
831 collection_unselect_item(collection, i);
834 find_condition_free(cond);
836 collection_unblock_selection_changed(collection, etime, TRUE);
837 out:
838 minibuffer_hide(filer_window);
842 /* EVENT HANDLERS */
844 static gint key_press_event(GtkWidget *widget,
845 GdkEventKey *event,
846 FilerWindow *filer_window)
848 if (event->keyval == GDK_Escape)
850 if (filer_window->mini_type == MINI_SHELL)
852 const gchar *line;
854 line = mini_contents(filer_window);
855 if (line)
856 add_to_history(line);
859 minibuffer_hide(filer_window);
860 return TRUE;
863 switch (filer_window->mini_type)
865 case MINI_PATH:
866 switch (event->keyval)
868 case GDK_Up:
869 search_in_dir(filer_window, -1);
870 break;
871 case GDK_Down:
872 search_in_dir(filer_window, 1);
873 break;
874 case GDK_Return:
875 case GDK_KP_Enter:
876 path_return_pressed(filer_window,
877 event);
878 break;
879 case GDK_Tab:
880 complete(filer_window);
881 break;
882 default:
883 return FALSE;
885 break;
887 case MINI_SHELL:
888 switch (event->keyval)
890 case GDK_Up:
891 shell_recall(filer_window, 1);
892 break;
893 case GDK_Down:
894 shell_recall(filer_window, -1);
895 break;
896 case GDK_Tab:
897 shell_tab(filer_window);
898 break;
899 case GDK_Return:
900 case GDK_KP_Enter:
901 shell_return_pressed(filer_window);
902 break;
903 default:
904 return FALSE;
906 break;
907 case MINI_SELECT_IF:
908 switch (event->keyval)
910 case GDK_Up:
911 shell_recall(filer_window, 1);
912 break;
913 case GDK_Down:
914 shell_recall(filer_window, -1);
915 break;
916 case GDK_Tab:
917 break;
918 case GDK_Return:
919 case GDK_KP_Enter:
920 select_return_pressed(filer_window,
921 event->time);
922 break;
923 default:
924 return FALSE;
926 break;
927 default:
928 break;
931 return TRUE;
934 static void changed(GtkEditable *mini, FilerWindow *filer_window)
936 switch (filer_window->mini_type)
938 case MINI_PATH:
939 gtk_idle_add(path_changed, filer_window);
940 return;
941 case MINI_SELECT_IF:
942 set_find_string_colour(GTK_WIDGET(mini),
943 gtk_entry_get_text(
944 GTK_ENTRY(filer_window->minibuffer)));
945 return;
946 default:
947 break;
951 /* Returns a string (which must NOT be freed), or NULL if the buffer
952 * is blank (whitespace only).
954 static const gchar *mini_contents(FilerWindow *filer_window)
956 const gchar *entry, *c;
958 entry = gtk_entry_get_text(GTK_ENTRY(filer_window->minibuffer));
960 for (c = entry; *c; c++)
961 if (!isspace(*c))
962 return entry;
964 return NULL;
967 /* This is a really ugly hack to get around Gtk+-2.0's broken auto-select
968 * behaviour.
970 static gboolean grab_focus(GtkWidget *minibuffer)
972 GtkWidgetClass *class;
974 class = GTK_WIDGET_CLASS(gtk_type_class(GTK_TYPE_WIDGET));
976 class->grab_focus(minibuffer);
978 g_signal_stop_emission(minibuffer,
979 g_signal_lookup("grab_focus", G_OBJECT_TYPE(minibuffer)), 0);
982 return 1;