annotate src/ui_tabcomp.c @ 442:4b2d7f9af171

Big whitespaces cleanup: - drop whitespaces at end of lines - convert eight spaces to tab at start of lines - drop spurious spaces mixed with tabs - remove empty lines at end of files
author zas_
date Sun, 20 Apr 2008 13:04:57 +0000
parents 9995c5fb202a
children ddabc4873a3f
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
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
4 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * 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
10 */
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 #ifdef HAVE_CONFIG_H
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 # include "config.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #include "intl.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17 #include <stdio.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include <stdlib.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include <string.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include <unistd.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include <sys/types.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include <dirent.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24 #include <gdk/gdk.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 #include <gtk/gtk.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26 #include <gdk-pixbuf/gdk-pixbuf.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 260
diff changeset
28 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 #include "ui_tabcomp.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 #include "ui_bookmark.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 #include "ui_spinner.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 #include "ui_utildlg.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 #include <gdk/gdkkeysyms.h> /* for key values */
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 /* define this to enable a pop-up menu that shows possible matches
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40 * #define TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 #define TAB_COMPLETION_ENABLE_POPUP_MENU 1
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 #define TAB_COMP_POPUP_MAX 500
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 #include "ui_menu.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49
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 Tab completion routines, can be connected to any gtkentry widget
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 using the tab_completion_add_to_entry() function.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 Use remove_trailing_slash() to strip the trailing '/'.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 ----------------------------------------------------------------*/
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 typedef struct _TabCompData TabCompData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 struct _TabCompData
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 GtkWidget *entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 gchar *dir_path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 GList *file_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 void (*enter_func)(const gchar *, gpointer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 void (*tab_func)(const gchar *, gpointer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 gpointer enter_data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 gpointer tab_data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 GtkWidget *combo;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 gint has_history;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 gchar *history_key;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70 gint history_levels;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 FileDialog *fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 gchar *fd_title;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 gint fd_folders_only;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 GtkWidget *fd_button;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 static void tab_completion_select_show(TabCompData *td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 static void tab_completion_free_list(TabCompData *td)
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 GList *list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85 g_free(td->dir_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 td->dir_path = NULL;
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 list = td->file_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 while(list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 g_free(list->data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 list = list->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 g_list_free(td->file_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 td->file_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 }
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 static void tab_completion_read_dir(TabCompData *td, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
102 DIR *dp;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
103 struct dirent *dir;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
104 GList *list = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 tab_completion_free_list(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 pathl = path_from_utf8(path);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
110 dp = opendir(pathl);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 if (!dp)
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
113 {
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
114 /* dir not found */
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
115 return;
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
116 }
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
117 while ((dir = readdir(dp)) != NULL)
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
118 {
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
119 gchar *name = dir->d_name;
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
120 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
121 {
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
122 list = g_list_prepend(list, path_to_utf8(name));
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
123 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
125 closedir(dp);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 td->dir_path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 td->file_list = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 static void tab_completion_destroy(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 tab_completion_free_list(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 g_free(td->history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 if (td->fd) file_dialog_close(td->fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 g_free(td->fd_title);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 g_free(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 }
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 static gint tab_completion_emit_enter_signal(TabCompData *td)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 gchar *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 if (!td->enter_func) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 text = g_strdup(gtk_entry_get_text(GTK_ENTRY(td->entry)));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 if (text[0] == '~')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 gchar *t = text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 text = g_strconcat(homedir(), t + 1, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 g_free(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 }
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 td->enter_func(text, td->enter_data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 g_free(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 static void tab_completion_emit_tab_signal(TabCompData *td)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 gchar *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 if (!td->tab_func) return;
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 text = g_strdup(gtk_entry_get_text(GTK_ENTRY(td->entry)));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 if (text[0] == '~')
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 gchar *t = text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 text = g_strconcat(homedir(), t + 1, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 g_free(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 td->tab_func(text, td->tab_data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 g_free(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 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
185 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 TabCompData *td = data;
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 if (event->keyval == GDK_Tab ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 event->keyval == GDK_BackSpace ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 (event->keyval >= 0x20 && event->keyval <= 0xFF) )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 if (event->keyval >= 0x20 && event->keyval <= 0xFF)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 gchar buf[2];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 gint p = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 buf[0] = event->keyval;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 buf[1] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 gtk_editable_insert_text(GTK_EDITABLE(td->entry), buf, 1, &p);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 gtk_editable_set_position(GTK_EDITABLE(td->entry), -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 }
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 /*close the menu */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 gtk_menu_popdown(GTK_MENU(widget));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 /* doing this does not emit the "selection done" signal, unref it ourselves */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 gtk_widget_unref(widget);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
207
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 }
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 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 }
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 static void tab_completion_popup_cb(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 gchar *name = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 gchar *ptr;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 td = g_object_get_data(G_OBJECT(widget), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 if (!td) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 ptr = td->dir_path + strlen(td->dir_path) - 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 buf = g_strconcat(td->dir_path, (ptr[0] == '/') ? "" : "/", name, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 g_free(buf);
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 tab_completion_emit_tab_signal(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 }
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 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
234 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 gint height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 PangoLayout *layout;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 PangoRectangle strong_pos, weak_pos;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 gint length;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 gint xoffset, yoffset;
12
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
241 GtkRequisition req;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
242 GdkScreen *screen;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
243 gint monitor_num;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
244 GdkRectangle monitor;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 gdk_window_get_origin(td->entry->window, x, y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247
12
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
248 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
249 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
250 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
251
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
252 gtk_widget_size_request(GTK_WIDGET(menu), &req);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 length = strlen(gtk_entry_get_text(GTK_ENTRY(td->entry)));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 gtk_entry_get_layout_offsets(GTK_ENTRY(td->entry), &xoffset, &yoffset);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 layout = gtk_entry_get_layout(GTK_ENTRY(td->entry));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 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
259
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 *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
261
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
262 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
263
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
264 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
265 *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
266 {
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
267 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
268 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
269 *y -= height;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
270 }
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
271 else
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
272 {
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
273 *y += height;
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
274 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 static void tab_completion_popup_list(TabCompData *td, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 GtkWidget *menu;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 GdkEvent *event;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 guint32 etime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283 gint ebutton;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 gint count = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 if (!list) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 #if 0
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 * well, the menu would be too long anyway...
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 * (listing /dev causes gtk+ window allocation errors, -> too big a window)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 * 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
293 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 if (g_list_length(list) > 200) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 #endif
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 menu = popup_menu_short_lived();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 while (work && count < TAB_COMP_POPUP_MAX)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302 gchar *name = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 GtkWidget *item;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 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
306 g_object_set_data(G_OBJECT(item), "tab_completion_data", td);
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 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 count++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 }
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 g_signal_connect(G_OBJECT(menu), "key_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 G_CALLBACK(tab_completion_popup_key_press), td);
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 /* peek at the current event to get the time, etc. */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 event = gtk_get_current_event();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 if (event && event->type == GDK_BUTTON_RELEASE)
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 ebutton = event->button.button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 ebutton = 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 if (event)
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 etime = gdk_event_get_time(event);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 gdk_event_free(event);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 etime = 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 tab_completion_popup_pos_cb, td, ebutton, etime);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 #ifndef CASE_SORT
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 #define CASE_SORT strcmp
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 #endif
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 static gint simple_sort(gconstpointer a, gconstpointer b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
347 return CASE_SORT((gchar *)a, (gchar *)b);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 }
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 #endif
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 static gint tab_completion_do(TabCompData *td)
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 const gchar *entry_text = gtk_entry_get_text(GTK_ENTRY(td->entry));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 const gchar *entry_file;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 gchar *entry_dir;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 gchar *ptr;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 gint home_exp = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 /* home dir expansion */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 if (entry_text[0] == '~')
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 entry_dir = g_strconcat(homedir(), entry_text + 1, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 home_exp = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 else
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 entry_dir = g_strdup(entry_text);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 entry_file = filename_from_path(entry_text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 if (isfile(entry_dir))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 if (home_exp)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(entry_dir));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 return home_exp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 if (isdir(entry_dir) && strcmp(entry_file, ".") != 0 && strcmp(entry_file, "..") != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 ptr = entry_dir + strlen(entry_dir) - 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 if (ptr[0] == '/')
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 if (home_exp)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 tab_completion_read_dir(td, entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 td->file_list = g_list_sort(td->file_list, simple_sort);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 if (td->file_list && !td->file_list->next)
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 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 const gchar *file;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 file = td->file_list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 buf = g_strconcat(entry_dir, file, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 if (isdir(buf))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 buf = g_strconcat(entry_dir, file, "/", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 g_free(buf);
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 #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 else
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 tab_completion_popup_list(td, td->file_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 return home_exp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 gchar *buf = g_strconcat(entry_dir, "/", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 return TRUE;
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 }
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 ptr = (gchar *)filename_from_path(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 if (ptr > entry_dir) ptr--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 ptr[0] = '\0';
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 if (strlen(entry_dir) == 0)
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 entry_dir = g_strdup("/");
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 if (isdir(entry_dir))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 GList *list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 GList *poss = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 gint l = strlen(entry_file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 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
452 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 tab_completion_read_dir(td, entry_dir);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 if (strcmp(entry_dir, "/") == 0) entry_dir[0] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 list = td->file_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 while(list)
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 gchar *file = list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 if (strncmp(entry_file, file, l) == 0)
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 poss = g_list_prepend(poss, file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 list = list->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 if (poss)
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 (!poss->next)
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 gchar *file = poss->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 buf = g_strconcat(entry_dir, "/", file, NULL);
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 if (isdir(buf))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 buf = g_strconcat(entry_dir, "/", file, "/", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 g_list_free(poss);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 gint c = strlen(entry_file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 gint done = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 gchar *test_file = poss->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 while (!done)
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 list = poss;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 if (!list) done = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 while(list && !done)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502 gchar *file = list->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503 if (strlen(file) < c || strncmp(test_file, file, c) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 done = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 list = list->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 c++;
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 c -= 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 if (c > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 gchar *file;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 file = g_strdup(test_file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 file[c] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 buf = g_strconcat(entry_dir, "/", file, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 poss = g_list_sort(poss, simple_sort);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 tab_completion_popup_list(td, poss);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 g_free(file);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 g_list_free(poss);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 return TRUE;
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 g_list_free(poss);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 g_free(entry_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 }
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 static gint tab_completion_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 gint stop_signal = FALSE;
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 switch (event->keyval)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
552 case GDK_Tab:
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 if (!(event->state & GDK_CONTROL_MASK))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 if (tab_completion_do(td))
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 tab_completion_emit_tab_signal(td);
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 stop_signal = TRUE;
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 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 case GDK_Return: case GDK_KP_Enter:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 if (td->fd_button &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 (event->state & GDK_CONTROL_MASK))
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 tab_completion_select_show(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 stop_signal = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 else if (tab_completion_emit_enter_signal(td))
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 stop_signal = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 default:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 }
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 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
579
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 return (stop_signal);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 static void tab_completion_button_pressed(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 GtkWidget *entry = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
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 if (!td) return;
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 if (!GTK_WIDGET_HAS_FOCUS(entry))
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 gtk_widget_grab_focus(entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 if (tab_completion_do(td))
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 tab_completion_emit_tab_signal(td);
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 }
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 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
604 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 GtkWidget *parent = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 if (allocation->height > parent->allocation.height)
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 GtkAllocation button_allocation;
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 button_allocation = button->allocation;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 button_allocation.height = parent->allocation.height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 button_allocation.y = parent->allocation.y +
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 (parent->allocation.height - parent->allocation.height) / 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 gtk_widget_size_allocate(button, &button_allocation);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 static GtkWidget *tab_completion_create_complete_button(GtkWidget *entry, GtkWidget *parent)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 GtkWidget *button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 GtkWidget *icon;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 GdkPixbuf *pixbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 button = gtk_button_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 g_signal_connect(G_OBJECT(button), "size_allocate",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 G_CALLBACK(tab_completion_button_size_allocate), parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 g_signal_connect(G_OBJECT(button), "clicked",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 G_CALLBACK(tab_completion_button_pressed), entry);
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 pixbuf = gdk_pixbuf_new_from_inline(-1, icon_tabcomp, FALSE, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 icon = gtk_image_new_from_pixbuf(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 gdk_pixbuf_unref(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 gtk_container_add(GTK_CONTAINER(button), icon);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636 gtk_widget_show(icon);
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 return button;
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
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 *----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 * public interface
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 *----------------------------------------------------------------------------
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 GtkWidget *tab_completion_new_with_history(GtkWidget **entry, const gchar *text,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 const gchar *history_key, gint max_levels,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 void (*enter_func)(const gchar *, gpointer), gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 GtkWidget *box;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 GtkWidget *combo;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653 GtkWidget *combo_entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 GtkWidget *button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 gint n = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659 box = gtk_hbox_new(FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 combo = gtk_combo_box_entry_new_text();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662 gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 gtk_widget_show(combo);
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 combo_entry = GTK_BIN(combo)->child;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 #if 0
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 gtk_combo_set_case_sensitive(GTK_COMBO(combo), TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 gtk_combo_set_use_arrows(GTK_COMBO(combo), FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 button = tab_completion_create_complete_button(combo_entry, combo);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 gtk_widget_show(button);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 tab_completion_add_to_entry(combo_entry, enter_func, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 td = g_object_get_data(G_OBJECT(combo_entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 if (!td) return NULL; /* this should never happen! */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 td->combo = combo;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 td->has_history = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 td->history_key = g_strdup(history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683 td->history_levels = max_levels;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 work = history_list_get_by_key(td->history_key);
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 work = history_list_get_by_key(history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
689 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (gchar *)work->data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 if (text)
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 gtk_entry_set_text(GTK_ENTRY(combo_entry), text);
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 else if (n > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 if (entry) *entry = combo_entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705 return box;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 const gchar *tab_completion_set_to_last_history(GtkWidget *entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 TabCompData *td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711 const gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 if (!td || !td->has_history) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 buf = history_list_find_last_path_by_key(td->history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 if (buf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 }
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 return buf;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 void tab_completion_append_to_history(GtkWidget *entry, const gchar *path)
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 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 GtkTreeModel *store;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 GList *work;
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 td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
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 if (!path) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734 if (!td || !td->has_history) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 history_list_add_to_key(td->history_key, path, td->history_levels);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
738 gtk_combo_box_set_active(GTK_COMBO_BOX(td->combo), -1);
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 store = gtk_combo_box_get_model(GTK_COMBO_BOX(td->combo));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741 gtk_list_store_clear(GTK_LIST_STORE(store));
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 work = history_list_get_by_key(td->history_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744 while (work)
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 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
747 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
751 GtkWidget *tab_completion_new(GtkWidget **entry, const gchar *text,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752 void (*enter_func)(const gchar *, gpointer), gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
753 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
754 GtkWidget *hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 GtkWidget *button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756 GtkWidget *newentry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
757
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
758 hbox = gtk_hbox_new(FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760 newentry = gtk_entry_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 if (text) gtk_entry_set_text(GTK_ENTRY(newentry), text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762 gtk_box_pack_start(GTK_BOX(hbox), newentry, TRUE, TRUE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763 gtk_widget_show(newentry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
765 button = tab_completion_create_complete_button(newentry, newentry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
766 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767 gtk_widget_show(button);
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 tab_completion_add_to_entry(newentry, enter_func, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771 if (entry) *entry = newentry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 return hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
773 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
774
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
775 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
776 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
777 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
778 if (!entry)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780 printf("Tab completion error: entry != NULL\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
782 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
784 td = g_new0(TabCompData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
785 td->entry = entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
786 td->dir_path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
787 td->file_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
788 td->enter_func = enter_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789 td->enter_data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
790 td->tab_func = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
791 td->tab_data = NULL;
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 td->has_history = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
794 td->history_key = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
795 td->history_levels = 0;
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 g_object_set_data(G_OBJECT(td->entry), "tab_completion_data", td);
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 g_signal_connect(G_OBJECT(entry), "key_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
800 G_CALLBACK(tab_completion_key_pressed), td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
801 g_signal_connect(G_OBJECT(entry), "destroy",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
802 G_CALLBACK(tab_completion_destroy), td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
803 }
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 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
806 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
807 TabCompData *td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
808
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
809 if (!td) 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 td->tab_func = tab_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
812 td->tab_data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
813 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
814
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
815 gchar *remove_trailing_slash(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
816 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
817 gint l;
260
249a9a6cd27f Improve remove_trailing_slash() so it allocates no more than
zas_
parents: 254
diff changeset
818
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
819 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
820
260
249a9a6cd27f Improve remove_trailing_slash() so it allocates no more than
zas_
parents: 254
diff changeset
821 l = strlen(path);
249a9a6cd27f Improve remove_trailing_slash() so it allocates no more than
zas_
parents: 254
diff changeset
822 while (l > 1 && path[l - 1] == '/') l--;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
823
260
249a9a6cd27f Improve remove_trailing_slash() so it allocates no more than
zas_
parents: 254
diff changeset
824 return g_strndup(path, l);
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
827 static void tab_completion_select_cancel_cb(FileDialog *fd, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
828 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
829 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
830
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
831 td->fd = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
832 file_dialog_close(fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
833 }
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 static void tab_completion_select_ok_cb(FileDialog *fd, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
836 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
837 TabCompData *td = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
838
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
839 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
840
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
841 tab_completion_select_cancel_cb(fd, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
842
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
843 tab_completion_emit_enter_signal(td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
844 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
845
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
846 static void tab_completion_select_show(TabCompData *td)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
847 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
848 const gchar *title;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
849 const gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
850
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
851 if (td->fd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
852 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
853 gtk_window_present(GTK_WINDOW(GENERIC_DIALOG(td->fd)->dialog));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
854 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
855 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
856
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
857 title = (td->fd_title) ? td->fd_title : _("Select path");
254
9faf34f047b1 Make the wmclass value unique among the code by defining
zas_
parents: 138
diff changeset
858 td->fd = file_dialog_new(title, GQ_WMCLASS, "select_path", td->entry,
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
859 tab_completion_select_cancel_cb, td);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
860 file_dialog_add_button(td->fd, GTK_STOCK_OK, NULL,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
861 tab_completion_select_ok_cb, TRUE);
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 generic_dialog_add_message(GENERIC_DIALOG(td->fd), NULL, title, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
864
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
865 path = gtk_entry_get_text(GTK_ENTRY(td->entry));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
866 if (strlen(path) == 0) path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
867 if (td->fd_folders_only)
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 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
870 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
871 else
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 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
874 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
875
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
876 gtk_widget_show(GENERIC_DIALOG(td->fd)->dialog);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
879 static void tab_completion_select_pressed(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
880 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
881 TabCompData *td = data;
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 tab_completion_select_show(td);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
886 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
887 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
888 TabCompData *td;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
889 GtkWidget *parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
890 GtkWidget *hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
891
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
892 td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
893
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
894 if (!td) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
895
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
896 g_free(td->fd_title);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
897 td->fd_title = g_strdup(title);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
898 td->fd_folders_only = folders_only;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
899
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
900 if (td->fd_button) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
901
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
902 parent = (td->combo) ? td->combo : td->entry;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
903
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
904 hbox = gtk_widget_get_parent(parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
905 if (!GTK_IS_BOX(hbox)) return;
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 td->fd_button = gtk_button_new_with_label("...");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
908 g_signal_connect(G_OBJECT(td->fd_button), "size_allocate",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
909 G_CALLBACK(tab_completion_button_size_allocate), parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
910 g_signal_connect(G_OBJECT(td->fd_button), "clicked",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
911 G_CALLBACK(tab_completion_select_pressed), td);
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 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
914
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
915 gtk_widget_show(td->fd_button);
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