/*
- * (SLIK) SimpLIstic sKin functions
- * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
*
* Author: John Ellis
*
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#endif
-/* ----------------------------------------------------------------
- Tab completion routines, can be connected to any gtkentry widget
- using the tab_completion_add_to_entry() function.
- Use remove_trailing_slash() to strip the trailing G_DIR_SEPARATOR.
- ----------------------------------------------------------------*/
+/**
+ * @file
+ * ----------------------------------------------------------------
+ * Tab completion routines, can be connected to any gtkentry widget
+ * using the tab_completion_add_to_entry() function.
+ *
+ * Use remove_trailing_slash() to strip the trailing G_DIR_SEPARATOR.
+ *
+ * ----------------------------------------------------------------
+ */
typedef struct _TabCompData TabCompData;
struct _TabCompData
gpointer enter_data;
gpointer tab_data;
gpointer tab_append_data;
-
+
GtkWidget *combo;
gboolean has_history;
gchar *history_key;
gchar *fd_title;
gboolean fd_folders_only;
GtkWidget *fd_button;
+ gchar *filter;
+ gchar *filter_desc;
guint choices;
};
while ((dir = readdir(dp)) != NULL)
{
gchar *name = dir->d_name;
- if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0)
+ if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0 &&
+ (name[0] != '.' || options->file_filter.show_hidden_files))
{
gchar *abspath = g_build_filename(pathl, name, NULL);
if (td->fd) file_dialog_close(td->fd);
g_free(td->fd_title);
+ g_free(td->filter);
+ g_free(td->filter_desc);
+
g_free(td);
}
TabCompData *td = data;
GtkWidget *child;
- if (!GTK_WIDGET_VISIBLE(widget)) return;
+ if (!gtk_widget_get_visible(widget)) return;
child = gtk_bin_get_child(GTK_BIN(widget));
if (GTK_IS_LABEL(child)) {
const gchar *entry_text = gtk_entry_get_text(GTK_ENTRY(td->entry));
const gchar *prefix = filename_from_path(entry_text);
guint prefix_len = strlen(prefix);
-
+
if (strlen(text) < prefix_len || strncmp(text, prefix, prefix_len))
{
/* Hide menu items not matching */
{
TabCompData *td = data;
- if (event->keyval == GDK_Tab ||
- event->keyval == GDK_BackSpace ||
+ if (event->keyval == GDK_KEY_Tab ||
+ event->keyval == GDK_KEY_BackSpace ||
(event->keyval >= 0x20 && event->keyval <= 0xFF) )
{
if (event->keyval >= 0x20 && event->keyval <= 0xFF)
buf[1] = '\0';
gtk_editable_insert_text(GTK_EDITABLE(td->entry), buf, 1, &p);
gtk_editable_set_position(GTK_EDITABLE(td->entry), -1);
-
+
/* Reduce the number of entries in the menu */
td->choices = 0;
gtk_container_foreach(GTK_CONTAINER(widget), tab_completion_iter_menu_items, (gpointer) td);
if (td->choices > 1) return TRUE; /* multiple choices */
if (td->choices > 0) tab_completion_do(td); /* one choice */
}
-
+
/* close the menu */
gtk_menu_popdown(GTK_MENU(widget));
/* doing this does not emit the "selection done" signal, unref it ourselves */
-#if GTK_CHECK_VERSION(2,12,0)
g_object_unref(widget);
-#else
- gtk_widget_unref(widget);
-#endif
return TRUE;
}
GdkScreen *screen;
gint monitor_num;
GdkRectangle monitor;
+ GtkRequisition requisition;
+ GtkAllocation allocation;
- gdk_window_get_origin(td->entry->window, x, y);
+ gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(td->entry)), x, y);
screen = gtk_widget_get_screen(GTK_WIDGET(menu));
- monitor_num = gdk_screen_get_monitor_at_window(screen, td->entry->window);
+ monitor_num = gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(GTK_WIDGET(td->entry)));
gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor);
gtk_widget_size_request(GTK_WIDGET(menu), &req);
*x += strong_pos.x / PANGO_SCALE + xoffset;
- height = MIN(td->entry->requisition.height, td->entry->allocation.height);
+ gtk_widget_get_requisition(td->entry, &requisition);
+ gtk_widget_get_allocation(td->entry, &allocation);
+
+ height = MIN(requisition.height, allocation.height);
if (req.height > monitor.y + monitor.height - *y - height &&
*y - monitor.y > monitor.y + monitor.height - *y)
if (entry_text[0] == '\0')
{
- entry_dir = g_strdup(G_DIR_SEPARATOR_S); /* FIXME: root directory win32 */
+ entry_dir = g_strdup(G_DIR_SEPARATOR_S); /** @FIXME root directory win32 */
gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(entry_dir));
g_free(entry_dir);
ptr = (gchar *)filename_from_path(entry_dir);
if (ptr > entry_dir) ptr--;
ptr[0] = '\0';
-
+
if (strlen(entry_dir) == 0)
{
g_free(entry_dir);
- entry_dir = g_strdup(G_DIR_SEPARATOR_S); /* FIXME: win32 */
+ entry_dir = g_strdup(G_DIR_SEPARATOR_S); /** @FIXME win32 */
}
if (isdir(entry_dir))
switch (event->keyval)
{
- case GDK_Tab:
+ case GDK_KEY_Tab:
if (!(event->state & GDK_CONTROL_MASK))
{
if (tab_completion_do(td))
stop_signal = TRUE;
}
break;
- case GDK_Return: case GDK_KP_Enter:
+ case GDK_KEY_Return: case GDK_KEY_KP_Enter:
if (td->fd_button &&
(event->state & GDK_CONTROL_MASK))
{
if (!td) return;
- if (!GTK_WIDGET_HAS_FOCUS(entry))
+ if (!gtk_widget_has_focus(entry))
{
gtk_widget_grab_focus(entry);
}
static void tab_completion_button_size_allocate(GtkWidget *button, GtkAllocation *allocation, gpointer data)
{
GtkWidget *parent = data;
+ GtkAllocation parent_allocation;
+ gtk_widget_get_allocation(parent, &parent_allocation);
- if (allocation->height > parent->allocation.height)
+ if (allocation->height > parent_allocation.height)
{
GtkAllocation button_allocation;
- button_allocation = button->allocation;
- button_allocation.height = parent->allocation.height;
- button_allocation.y = parent->allocation.y +
- (parent->allocation.height - parent->allocation.height) / 2;
+ gtk_widget_get_allocation(button, &button_allocation);
+ button_allocation.height = parent_allocation.height;
+ button_allocation.y = parent_allocation.y +
+ (parent_allocation.height - parent_allocation.height) / 2;
gtk_widget_size_allocate(button, &button_allocation);
}
}
GdkPixbuf *pixbuf;
button = gtk_button_new();
- GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus(button, FALSE);
g_signal_connect(G_OBJECT(button), "size_allocate",
G_CALLBACK(tab_completion_button_size_allocate), parent);
g_signal_connect(G_OBJECT(button), "clicked",
box = gtk_hbox_new(FALSE, 0);
- combo = gtk_combo_box_entry_new_text();
+ combo = gtk_combo_box_text_new_with_entry();
gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
gtk_widget_show(combo);
- combo_entry = GTK_BIN(combo)->child;
-#if 0
- gtk_combo_set_case_sensitive(GTK_COMBO(combo), TRUE);
- gtk_combo_set_use_arrows(GTK_COMBO(combo), FALSE);
-#endif
+ combo_entry = gtk_bin_get_child(GTK_BIN(combo));
button = tab_completion_create_complete_button(combo_entry, combo);
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
gtk_widget_show(button);
- tab_completion_add_to_entry(combo_entry, enter_func, data);
+ tab_completion_add_to_entry(combo_entry, enter_func, NULL, NULL, data);
td = g_object_get_data(G_OBJECT(combo_entry), "tab_completion_data");
if (!td) return NULL; /* this should never happen! */
work = history_list_get_by_key(history_key);
while (work)
{
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (gchar *)work->data);
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), (gchar *)work->data);
work = work->next;
n++;
}
work = history_list_get_by_key(td->history_key);
while (work)
{
- gtk_combo_box_append_text(GTK_COMBO_BOX(td->combo), (gchar *)work->data);
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(td->combo), (gchar *)work->data);
work = work->next;
n++;
}
}
GtkWidget *tab_completion_new(GtkWidget **entry, const gchar *text,
- void (*enter_func)(const gchar *, gpointer), gpointer data)
+ void (*enter_func)(const gchar *, gpointer), const gchar *filter, const gchar *filter_desc, gpointer data)
{
GtkWidget *hbox;
GtkWidget *button;
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
- tab_completion_add_to_entry(newentry, enter_func, data);
-
+ tab_completion_add_to_entry(newentry, enter_func, filter, filter_desc, data);
if (entry) *entry = newentry;
return hbox;
}
-void tab_completion_add_to_entry(GtkWidget *entry, void (*enter_func)(const gchar *, gpointer), gpointer data)
+void tab_completion_add_to_entry(GtkWidget *entry, void (*enter_func)(const gchar *, gpointer), const gchar *filter, const gchar *filter_desc, gpointer data)
{
TabCompData *td;
if (!entry)
td->entry = entry;
td->enter_func = enter_func;
td->enter_data = data;
+ td->filter = g_strdup(filter);
+ td->filter_desc = g_strdup(filter_desc);
g_object_set_data(G_OBJECT(td->entry), "tab_completion_data", td);
{
const gchar *title;
const gchar *path;
+ gchar *filter = NULL;
+ gchar *filter_desc = NULL;
if (td->fd)
{
file_dialog_add_button(td->fd, GTK_STOCK_OK, NULL,
tab_completion_select_ok_cb, TRUE);
- generic_dialog_add_message(GENERIC_DIALOG(td->fd), NULL, title, NULL);
+ generic_dialog_add_message(GENERIC_DIALOG(td->fd), NULL, title, NULL, FALSE);
+
+ if (td->filter)
+ {
+ filter = td->filter;
+ }
+ else
+ {
+ filter = "*";
+ }
+ if (td->filter_desc)
+ {
+ filter_desc = td->filter_desc;
+ }
+ else
+ {
+ filter_desc = _("All files");
+ }
path = gtk_entry_get_text(GTK_ENTRY(td->entry));
if (strlen(path) == 0) path = NULL;
}
else
{
- file_dialog_add_path_widgets(td->fd, NULL, path, td->history_key, "*", _("All files"));
+ file_dialog_add_path_widgets(td->fd, NULL, path, td->history_key, filter, filter_desc);
}
gtk_widget_show(GENERIC_DIALOG(td->fd)->dialog);