annotate src/ui_tabcomp.c @ 1371:2c2f86e30f6c

Fix memleak in previous patch.
author zas_
date Mon, 02 Mar 2009 21:05:57 +0000
parents 0011d6859ec5
children 31a747f9d268
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
2 * (SLIK) SimpLIstic sKin functions
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
3 * (C) 2006 John Ellis
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1174
diff changeset
4 * Copyright (C) 2008 - 2009 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 #ifdef HAVE_CONFIG_H
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 # include "config.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "intl.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include <stdio.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include <stdlib.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include <string.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include <unistd.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include <sys/types.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23 #include <dirent.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 #include <gdk/gdk.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26 #include <gtk/gtk.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 #include <gdk-pixbuf/gdk-pixbuf.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 260
diff changeset
29 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30 #include "ui_tabcomp.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31
902
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents: 734
diff changeset
32 #include "history_list.h"
1022
9962b24b6b43 Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents: 991
diff changeset
33 #include "misc.h" /* expand_tilde() */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 #include "ui_spinner.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 #include "ui_utildlg.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 #include <gdk/gdkkeysyms.h> /* for key values */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 /* define this to enable a pop-up menu that shows possible matches
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 * #define TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 #define TAB_COMPLETION_ENABLE_POPUP_MENU 1
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 #define TAB_COMP_POPUP_MAX 500
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 #include "ui_menu.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 /* ----------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 Tab completion routines, can be connected to any gtkentry widget
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 using the tab_completion_add_to_entry() function.
726
a1dcef8cd1ae Use G_DIR_SEPARATOR where applicable.
zas_
parents: 722
diff changeset
55 Use remove_trailing_slash() to strip the trailing G_DIR_SEPARATOR.
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 ----------------------------------------------------------------*/
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 typedef struct _TabCompData TabCompData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 struct _TabCompData
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 GtkWidget *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 gchar *dir_path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 GList *file_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 void (*enter_func)(const gchar *, gpointer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 void (*tab_func)(const gchar *, gpointer);
1167
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
66 void (*tab_append_func)(const gchar *, gpointer, gint);
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
67
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 gpointer enter_data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 gpointer tab_data;
1167
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
70 gpointer tab_append_data;
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
71
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 GtkWidget *combo;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 gint has_history;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 gchar *history_key;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 gint history_levels;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 FileDialog *fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 gchar *fd_title;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 gint fd_folders_only;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 GtkWidget *fd_button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 static void tab_completion_select_show(TabCompData *td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 static void tab_completion_free_list(TabCompData *td)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 GList *list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 g_free(td->dir_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 td->dir_path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 list = td->file_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94
516
b7e99bfeadc9 Convert the minority of while() to while ().
zas_
parents: 475
diff changeset
95 while (list)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 g_free(list->data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 list = list->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 g_list_free(td->file_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 td->file_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 static void tab_completion_read_dir(TabCompData *td, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
107 DIR *dp;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
108 struct dirent *dir;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
109 GList *list = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 tab_completion_free_list(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 pathl = path_from_utf8(path);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
115 dp = opendir(pathl);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 if (!dp)
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
118 {
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
119 /* dir not found */
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
120 return;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
121 }
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
122 while ((dir = readdir(dp)) != NULL)
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
123 {
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
124 gchar *name = dir->d_name;
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
125 if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0)
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
126 {
1370
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
127 gchar *abspath = g_build_filename(path, name, NULL);
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
128
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
129 if (isdir(abspath))
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
130 {
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
131 gchar *dname = g_strconcat(name, G_DIR_SEPARATOR_S, NULL);
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
132 list = g_list_prepend(list, path_to_utf8(dname));
1371
2c2f86e30f6c Fix memleak in previous patch.
zas_
parents: 1370
diff changeset
133 g_free(dname);
1370
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
134 }
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
135 else
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
136 {
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
137 list = g_list_prepend(list, path_to_utf8(name));
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
138 }
0011d6859ec5 Add a directory separator at the end of names in tab completion list to indicate directories.
zas_
parents: 1365
diff changeset
139 g_free(abspath);
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
140 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
142 closedir(dp);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 td->dir_path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 td->file_list = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 static void tab_completion_destroy(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 tab_completion_free_list(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 g_free(td->history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 if (td->fd) file_dialog_close(td->fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 g_free(td->fd_title);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 g_free(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160
991
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
161 static gchar *tab_completion_get_text(TabCompData *td)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 gchar *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 text = g_strdup(gtk_entry_get_text(GTK_ENTRY(td->entry)));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 if (text[0] == '~')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 gchar *t = text;
720
d8a88f279aca Use expand_tilde() instead of simple concatenation, it allows correct expansion
zas_
parents: 673
diff changeset
170 text = expand_tilde(text);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 g_free(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173
991
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
174 return text;
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
175 }
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
176
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
177 static gint tab_completion_emit_enter_signal(TabCompData *td)
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
178 {
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
179 gchar *text;
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
180 if (!td->enter_func) return FALSE;
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
181
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
182 text = tab_completion_get_text(td);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 td->enter_func(text, td->enter_data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 g_free(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 static void tab_completion_emit_tab_signal(TabCompData *td)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 gchar *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 if (!td->tab_func) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193
991
185e6a74517d Slight code redundancy reduction.
zas_
parents: 902
diff changeset
194 text = tab_completion_get_text(td);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 td->tab_func(text, td->tab_data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 g_free(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 static gint tab_completion_popup_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 if (event->keyval == GDK_Tab ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 event->keyval == GDK_BackSpace ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 (event->keyval >= 0x20 && event->keyval <= 0xFF) )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 if (event->keyval >= 0x20 && event->keyval <= 0xFF)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211 gchar buf[2];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 gint p = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 buf[0] = event->keyval;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 buf[1] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 gtk_editable_insert_text(GTK_EDITABLE(td->entry), buf, 1, &p);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 gtk_editable_set_position(GTK_EDITABLE(td->entry), -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 /*close the menu */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 gtk_menu_popdown(GTK_MENU(widget));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 /* doing this does not emit the "selection done" signal, unref it ourselves */
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 1022
diff changeset
223 #if GTK_CHECK_VERSION(2,12,0)
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 1022
diff changeset
224 g_object_unref(widget);
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 1022
diff changeset
225 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 gtk_widget_unref(widget);
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 1022
diff changeset
227 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 static void tab_completion_popup_cb(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 gchar *name = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 td = g_object_get_data(G_OBJECT(widget), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 if (!td) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242
721
b736a2e3129b tab_completion_popup_cb(): use g_build_filename() and simplify code.
zas_
parents: 720
diff changeset
243 buf = g_build_filename(td->dir_path, name, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 tab_completion_emit_tab_signal(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 static void tab_completion_popup_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 gint height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 PangoLayout *layout;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 PangoRectangle strong_pos, weak_pos;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 gint length;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 gint xoffset, yoffset;
12
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
259 GtkRequisition req;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
260 GdkScreen *screen;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
261 gint monitor_num;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
262 GdkRectangle monitor;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 gdk_window_get_origin(td->entry->window, x, y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265
12
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
266 screen = gtk_widget_get_screen(GTK_WIDGET(menu));
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
267 monitor_num = gdk_screen_get_monitor_at_window(screen, td->entry->window);
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
268 gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor);
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
269
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
270 gtk_widget_size_request(GTK_WIDGET(menu), &req);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
272 length = strlen(gtk_entry_get_text(GTK_ENTRY(td->entry)));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 gtk_entry_get_layout_offsets(GTK_ENTRY(td->entry), &xoffset, &yoffset);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 layout = gtk_entry_get_layout(GTK_ENTRY(td->entry));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 pango_layout_get_cursor_pos(layout, length, &strong_pos, &weak_pos);
12
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
277
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 *x += strong_pos.x / PANGO_SCALE + xoffset;
12
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
279
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
280 height = MIN(td->entry->requisition.height, td->entry->allocation.height);
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
281
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
282 if (req.height > monitor.y + monitor.height - *y - height &&
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
283 *y - monitor.y > monitor.y + monitor.height - *y)
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
284 {
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
285 height = MIN(*y - monitor.y, req.height);
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
286 gtk_widget_set_size_request(GTK_WIDGET(menu), -1, height);
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
287 *y -= height;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
288 }
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
289 else
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
290 {
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
291 *y += height;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
292 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 static void tab_completion_popup_list(TabCompData *td, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 GtkWidget *menu;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 GdkEvent *event;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 guint32 etime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 gint ebutton;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302 gint count = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 if (!list) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 #if 0
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 * well, the menu would be too long anyway...
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 * (listing /dev causes gtk+ window allocation errors, -> too big a window)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 * this is why menu popups are disabled, this really should be a popup scrollable listview.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 if (g_list_length(list) > 200) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 menu = popup_menu_short_lived();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 while (work && count < TAB_COMP_POPUP_MAX)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 gchar *name = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 GtkWidget *item;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 item = menu_item_add_simple(menu, name, G_CALLBACK(tab_completion_popup_cb), name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 g_object_set_data(G_OBJECT(item), "tab_completion_data", td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 count++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 g_signal_connect(G_OBJECT(menu), "key_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 G_CALLBACK(tab_completion_popup_key_press), td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 /* peek at the current event to get the time, etc. */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 event = gtk_get_current_event();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 if (event && event->type == GDK_BUTTON_RELEASE)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 ebutton = event->button.button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 ebutton = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 if (event)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 etime = gdk_event_get_time(event);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 gdk_event_free(event);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 etime = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 tab_completion_popup_pos_cb, td, ebutton, etime);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 #ifndef CASE_SORT
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 #define CASE_SORT strcmp
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 static gint simple_sort(gconstpointer a, gconstpointer b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
365 return CASE_SORT((gchar *)a, (gchar *)b);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370 static gint tab_completion_do(TabCompData *td)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 const gchar *entry_text = gtk_entry_get_text(GTK_ENTRY(td->entry));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 const gchar *entry_file;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 gchar *entry_dir;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 gchar *ptr;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 gint home_exp = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 /* home dir expansion */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 if (entry_text[0] == '~')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 {
720
d8a88f279aca Use expand_tilde() instead of simple concatenation, it allows correct expansion
zas_
parents: 673
diff changeset
381 entry_dir = expand_tilde(entry_text);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 home_exp = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 entry_dir = g_strdup(entry_text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 entry_file = filename_from_path(entry_text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 if (isfile(entry_dir))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 if (home_exp)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(entry_dir));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 return home_exp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 }
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
401
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 if (isdir(entry_dir) && strcmp(entry_file, ".") != 0 && strcmp(entry_file, "..") != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 ptr = entry_dir + strlen(entry_dir) - 1;
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
405 if (ptr[0] == G_DIR_SEPARATOR)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 if (home_exp)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(entry_dir));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 tab_completion_read_dir(td, entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 td->file_list = g_list_sort(td->file_list, simple_sort);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 if (td->file_list && !td->file_list->next)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 const gchar *file;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 file = td->file_list->data;
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
421 buf = g_build_filename(entry_dir, file, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 if (isdir(buf))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 {
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
424 gchar *tmp = g_strconcat(buf, G_DIR_SEPARATOR_S, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 g_free(buf);
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
426 buf = tmp;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 tab_completion_popup_list(td, td->file_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 return home_exp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 {
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
446 gchar *buf = g_strconcat(entry_dir, G_DIR_SEPARATOR_S, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 ptr = (gchar *)filename_from_path(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 if (ptr > entry_dir) ptr--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 ptr[0] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 if (strlen(entry_dir) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 g_free(entry_dir);
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
462 entry_dir = g_strdup(G_DIR_SEPARATOR_S); /* FIXME: win32 */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 if (isdir(entry_dir))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 GList *list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468 GList *poss = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 gint l = strlen(entry_file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 if (!td->dir_path || !td->file_list || strcmp(td->dir_path, entry_dir) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 tab_completion_read_dir(td, entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
476 if (strcmp(entry_dir, G_DIR_SEPARATOR_S) == 0) entry_dir[0] = '\0'; /* FIXME: win32 */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 list = td->file_list;
516
b7e99bfeadc9 Convert the minority of while() to while ().
zas_
parents: 475
diff changeset
479 while (list)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 gchar *file = list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 if (strncmp(entry_file, file, l) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 poss = g_list_prepend(poss, file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 list = list->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 if (poss)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 if (!poss->next)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 gchar *file = poss->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
496 buf = g_build_filename(entry_dir, file, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 if (isdir(buf))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 {
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
500 gchar *tmp = g_strconcat(buf, G_DIR_SEPARATOR_S, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 g_free(buf);
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
502 buf = tmp;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 g_list_free(poss);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 {
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
513 gsize c = strlen(entry_file);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 gint done = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 gchar *test_file = poss->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 while (!done)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 list = poss;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 if (!list) done = TRUE;
516
b7e99bfeadc9 Convert the minority of while() to while ().
zas_
parents: 475
diff changeset
521 while (list && !done)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 gchar *file = list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 if (strlen(file) < c || strncmp(test_file, file, c) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 done = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 list = list->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 c++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532 c -= 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 if (c > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 gchar *file;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 file = g_strdup(test_file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 file[c] = '\0';
722
9a145206ec2c tab_completion_do(): use g_build_filename(), G_DIR_SEPARATOR, G_DIR_SEPARATOR_S.
zas_
parents: 721
diff changeset
539 buf = g_build_filename(entry_dir, file, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 poss = g_list_sort(poss, simple_sort);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 tab_completion_popup_list(td, poss);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 g_free(file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 g_list_free(poss);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 g_list_free(poss);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 static gint tab_completion_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 gint stop_signal = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 switch (event->keyval)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
573 case GDK_Tab:
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 if (!(event->state & GDK_CONTROL_MASK))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 if (tab_completion_do(td))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 tab_completion_emit_tab_signal(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 stop_signal = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 case GDK_Return: case GDK_KP_Enter:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 if (td->fd_button &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 (event->state & GDK_CONTROL_MASK))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 tab_completion_select_show(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 stop_signal = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590 else if (tab_completion_emit_enter_signal(td))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 stop_signal = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
594 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 default:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
599 if (stop_signal) g_signal_stop_emission_by_name(G_OBJECT(widget), "key_press_event");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 return (stop_signal);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604 static void tab_completion_button_pressed(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 GtkWidget *entry = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611 if (!td) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 if (!GTK_WIDGET_HAS_FOCUS(entry))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 gtk_widget_grab_focus(entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 if (tab_completion_do(td))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 tab_completion_emit_tab_signal(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 static void tab_completion_button_size_allocate(GtkWidget *button, GtkAllocation *allocation, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 GtkWidget *parent = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 if (allocation->height > parent->allocation.height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 GtkAllocation button_allocation;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
631
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 button_allocation = button->allocation;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 button_allocation.height = parent->allocation.height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 button_allocation.y = parent->allocation.y +
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 (parent->allocation.height - parent->allocation.height) / 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636 gtk_widget_size_allocate(button, &button_allocation);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640 static GtkWidget *tab_completion_create_complete_button(GtkWidget *entry, GtkWidget *parent)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642 GtkWidget *button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 GtkWidget *icon;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 GdkPixbuf *pixbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 button = gtk_button_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 g_signal_connect(G_OBJECT(button), "size_allocate",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 G_CALLBACK(tab_completion_button_size_allocate), parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 g_signal_connect(G_OBJECT(button), "clicked",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 G_CALLBACK(tab_completion_button_pressed), entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653 pixbuf = gdk_pixbuf_new_from_inline(-1, icon_tabcomp, FALSE, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 icon = gtk_image_new_from_pixbuf(pixbuf);
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 1022
diff changeset
655 g_object_unref(pixbuf);
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 1022
diff changeset
656
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 gtk_container_add(GTK_CONTAINER(button), icon);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 gtk_widget_show(icon);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 return button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664 *----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 * public interface
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 *----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 GtkWidget *tab_completion_new_with_history(GtkWidget **entry, const gchar *text,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670 const gchar *history_key, gint max_levels,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 void (*enter_func)(const gchar *, gpointer), gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 GtkWidget *box;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 GtkWidget *combo;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 GtkWidget *combo_entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 GtkWidget *button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 gint n = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 box = gtk_hbox_new(FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683 combo = gtk_combo_box_entry_new_text();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684 gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 gtk_widget_show(combo);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 combo_entry = GTK_BIN(combo)->child;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 #if 0
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
689 gtk_combo_set_case_sensitive(GTK_COMBO(combo), TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690 gtk_combo_set_use_arrows(GTK_COMBO(combo), FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693 button = tab_completion_create_complete_button(combo_entry, combo);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 gtk_widget_show(button);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697 tab_completion_add_to_entry(combo_entry, enter_func, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 td = g_object_get_data(G_OBJECT(combo_entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 if (!td) return NULL; /* this should never happen! */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 td->combo = combo;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703 td->has_history = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 td->history_key = g_strdup(history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705 td->history_levels = max_levels;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 work = history_list_get_by_key(td->history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 work = history_list_get_by_key(history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (gchar *)work->data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 if (text)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 gtk_entry_set_text(GTK_ENTRY(combo_entry), text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 else if (n > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
725
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726 if (entry) *entry = combo_entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 return box;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 const gchar *tab_completion_set_to_last_history(GtkWidget *entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 TabCompData *td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 const gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 if (!td || !td->has_history) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 buf = history_list_find_last_path_by_key(td->history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
738 if (buf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
742
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
743 return buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
746 void tab_completion_append_to_history(GtkWidget *entry, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 GtkTreeModel *store;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750 GList *work;
1167
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
751 gint n = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
753 td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
754
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 if (!path) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
757 if (!td || !td->has_history) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
758
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759 history_list_add_to_key(td->history_key, path, td->history_levels);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 gtk_combo_box_set_active(GTK_COMBO_BOX(td->combo), -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763 store = gtk_combo_box_get_model(GTK_COMBO_BOX(td->combo));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764 gtk_list_store_clear(GTK_LIST_STORE(store));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
765
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
766 work = history_list_get_by_key(td->history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
769 gtk_combo_box_append_text(GTK_COMBO_BOX(td->combo), (gchar *)work->data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770 work = work->next;
1167
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
771 n++;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 }
1167
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
773
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
774 if (td->tab_append_func) {
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
775 td->tab_append_func(path, td->tab_append_data, n);
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
776 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
777 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
778
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779 GtkWidget *tab_completion_new(GtkWidget **entry, const gchar *text,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780 void (*enter_func)(const gchar *, gpointer), gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
782 GtkWidget *hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783 GtkWidget *button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
784 GtkWidget *newentry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
785
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
786 hbox = gtk_hbox_new(FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
787
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
788 newentry = gtk_entry_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789 if (text) gtk_entry_set_text(GTK_ENTRY(newentry), text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
790 gtk_box_pack_start(GTK_BOX(hbox), newentry, TRUE, TRUE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
791 gtk_widget_show(newentry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
792
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
793 button = tab_completion_create_complete_button(newentry, newentry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
794 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
795 gtk_widget_show(button);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
796
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
797 tab_completion_add_to_entry(newentry, enter_func, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
798
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
799 if (entry) *entry = newentry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
800 return hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
801 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
802
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
803 void tab_completion_add_to_entry(GtkWidget *entry, void (*enter_func)(const gchar *, gpointer), gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
804 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
805 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
806 if (!entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
807 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 516
diff changeset
808 log_printf("Tab completion error: entry != NULL\n");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
809 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
810 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
811
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
812 td = g_new0(TabCompData, 1);
1365
249bf204004a When g_new0() is used, drop redundant initializations to NULL, FALSE or 0.
zas_
parents: 1284
diff changeset
813
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
814 td->entry = entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
815 td->enter_func = enter_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
816 td->enter_data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
817
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
818 g_object_set_data(G_OBJECT(td->entry), "tab_completion_data", td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
819
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
820 g_signal_connect(G_OBJECT(entry), "key_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
821 G_CALLBACK(tab_completion_key_pressed), td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
822 g_signal_connect(G_OBJECT(entry), "destroy",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
823 G_CALLBACK(tab_completion_destroy), td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
824 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
825
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
826 void tab_completion_add_tab_func(GtkWidget *entry, void (*tab_func)(const gchar *, gpointer), gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
827 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
828 TabCompData *td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
829
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
830 if (!td) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
831
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
832 td->tab_func = tab_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
833 td->tab_data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
834 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
835
1167
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
836 /* Add a callback function called when a new entry is appended to the list */
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
837 void tab_completion_add_append_func(GtkWidget *entry, void (*tab_append_func)(const gchar *, gpointer, gint), gpointer data)
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
838 {
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
839 TabCompData *td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
840
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
841 if (!td) return;
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
842
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
843 td->tab_append_func = tab_append_func;
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
844 td->tab_append_data = data;
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
845 }
e812b1a7adda Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
zas_
parents: 1055
diff changeset
846
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
847 gchar *remove_trailing_slash(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
848 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
849 gint l;
260
249a9a6cd27f Improve remove_trailing_slash() so it allocates no more than
zas_
parents: 254
diff changeset
850
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
851 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
852
260
249a9a6cd27f Improve remove_trailing_slash() so it allocates no more than
zas_
parents: 254
diff changeset
853 l = strlen(path);
726
a1dcef8cd1ae Use G_DIR_SEPARATOR where applicable.
zas_
parents: 722
diff changeset
854 while (l > 1 && path[l - 1] == G_DIR_SEPARATOR) l--;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
855
260
249a9a6cd27f Improve remove_trailing_slash() so it allocates no more than
zas_
parents: 254
diff changeset
856 return g_strndup(path, l);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
857 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
858
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
859 static void tab_completion_select_cancel_cb(FileDialog *fd, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
860 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
861 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
862
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
863 td->fd = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
864 file_dialog_close(fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
865 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
866
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
867 static void tab_completion_select_ok_cb(FileDialog *fd, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
868 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
869 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
870
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
871 gtk_entry_set_text(GTK_ENTRY(td->entry), gtk_entry_get_text(GTK_ENTRY(fd->entry)));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
872
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
873 tab_completion_select_cancel_cb(fd, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
874
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
875 tab_completion_emit_enter_signal(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
876 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
877
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
878 static void tab_completion_select_show(TabCompData *td)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
879 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
880 const gchar *title;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
881 const gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
882
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
883 if (td->fd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
884 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
885 gtk_window_present(GTK_WINDOW(GENERIC_DIALOG(td->fd)->dialog));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
886 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
887 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
888
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
889 title = (td->fd_title) ? td->fd_title : _("Select path");
1174
0bea79d87065 Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents: 1167
diff changeset
890 td->fd = file_dialog_new(title, "select_path", td->entry,
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
891 tab_completion_select_cancel_cb, td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
892 file_dialog_add_button(td->fd, GTK_STOCK_OK, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
893 tab_completion_select_ok_cb, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
894
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
895 generic_dialog_add_message(GENERIC_DIALOG(td->fd), NULL, title, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
896
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
897 path = gtk_entry_get_text(GTK_ENTRY(td->entry));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
898 if (strlen(path) == 0) path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
899 if (td->fd_folders_only)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
900 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
901 file_dialog_add_path_widgets(td->fd, NULL, path, td->history_key, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
902 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
903 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
904 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
905 file_dialog_add_path_widgets(td->fd, NULL, path, td->history_key, "*", _("All files"));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
906 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
907
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
908 gtk_widget_show(GENERIC_DIALOG(td->fd)->dialog);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
909 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
910
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
911 static void tab_completion_select_pressed(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
912 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
913 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
914
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
915 tab_completion_select_show(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
916 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
917
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
918 void tab_completion_add_select_button(GtkWidget *entry, const gchar *title, gint folders_only)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
919 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
920 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
921 GtkWidget *parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
922 GtkWidget *hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
923
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
924 td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
925
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
926 if (!td) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
927
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
928 g_free(td->fd_title);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
929 td->fd_title = g_strdup(title);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
930 td->fd_folders_only = folders_only;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
931
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
932 if (td->fd_button) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
933
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
934 parent = (td->combo) ? td->combo : td->entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
935
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
936 hbox = gtk_widget_get_parent(parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
937 if (!GTK_IS_BOX(hbox)) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
938
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
939 td->fd_button = gtk_button_new_with_label("...");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
940 g_signal_connect(G_OBJECT(td->fd_button), "size_allocate",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
941 G_CALLBACK(tab_completion_button_size_allocate), parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
942 g_signal_connect(G_OBJECT(td->fd_button), "clicked",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
943 G_CALLBACK(tab_completion_select_pressed), td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
944
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
945 gtk_box_pack_start(GTK_BOX(hbox), td->fd_button, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
946
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
947 gtk_widget_show(td->fd_button);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
948 }
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1043
diff changeset
949 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */