[Xfce4-commits] <xfce4-appfinder:andrzejr/plugin> Refactoring appfinder-window into window and widget classes.
Andrzej
noreply at xfce.org
Thu Feb 16 07:22:08 CET 2012
Updating branch refs/heads/andrzejr/plugin
to f59b76ccf43ce3c3a72a4e1159b9abfd8232aa46 (commit)
from 52051abb426d2b4bb6f37275aa70d33610433b1d (commit)
commit f59b76ccf43ce3c3a72a4e1159b9abfd8232aa46
Author: Andrzej <ndrwrdck at gmail.com>
Date: Thu Feb 16 15:19:41 2012 +0900
Refactoring appfinder-window into window and widget classes.
src/Makefile.am | 2 +
src/appfinder-widget.c | 795 ++++++++++++---------------
src/appfinder-widget.h | 28 +-
src/appfinder-window.c | 1426 +++---------------------------------------------
4 files changed, 445 insertions(+), 1806 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 1c08eb9..705277c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,6 +22,8 @@ xfce4_appfinder_SOURCES = \
appfinder-preferences.c \
appfinder-preferences.h \
appfinder-private.h \
+ appfinder-widget.c \
+ appfinder-widget.h \
appfinder-window.c \
appfinder-window.h \
main.c
diff --git a/src/appfinder-widget.c b/src/appfinder-widget.c
index a57786d..ce8f7df 100644
--- a/src/appfinder-widget.c
+++ b/src/appfinder-widget.c
@@ -33,7 +33,7 @@
#include <xfconf/xfconf.h>
#include <glib/gstdio.h>
-#include <src/appfinder-window.h>
+#include <src/appfinder-widget.h>
#include <src/appfinder-model.h>
#include <src/appfinder-category-model.h>
#include <src/appfinder-preferences.h>
@@ -48,76 +48,67 @@
#endif
-
-#define DEFAULT_WINDOW_WIDTH 400
-#define DEFAULT_WINDOW_HEIGHT 400
#define DEFAULT_PANED_POSITION 180
-
-static void xfce_appfinder_window_finalize (GObject *object);
-static void xfce_appfinder_window_unmap (GtkWidget *widget);
-static gboolean xfce_appfinder_window_key_press_event (GtkWidget *widget,
+static void xfce_appfinder_widget_finalize (GObject *object);
+static gboolean xfce_appfinder_widget_key_press_event (GtkWidget *widget,
GdkEventKey *event);
-static void xfce_appfinder_window_view (XfceAppfinderWindow *window);
-static gboolean xfce_appfinder_window_popup_menu (GtkWidget *view,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_set_padding (GtkWidget *entry,
+static void xfce_appfinder_widget_view (XfceAppfinderWidget *appfinder_widget);
+static gboolean xfce_appfinder_widget_popup_menu (GtkWidget *view,
+ XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_set_padding (GtkWidget *entry,
GtkWidget *align);
-static gboolean xfce_appfinder_window_completion_match_func (GtkEntryCompletion *completion,
+static gboolean xfce_appfinder_widget_completion_match_func (GtkEntryCompletion *completion,
const gchar *key,
GtkTreeIter *iter,
gpointer data);
-static void xfce_appfinder_window_entry_changed (XfceAppfinderWindow *window);
-static void xfce_appfinder_window_entry_activate (GtkEditable *entry,
- XfceAppfinderWindow *window);
-static gboolean xfce_appfinder_window_entry_key_press_event (GtkWidget *entry,
+static void xfce_appfinder_widget_entry_changed (XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_entry_activate (GtkEditable *entry,
+ XfceAppfinderWidget *appfinder_widget);
+static gboolean xfce_appfinder_widget_entry_key_press_event (GtkWidget *entry,
GdkEventKey *event,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_entry_icon_released (GtkEntry *entry,
+ XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_entry_icon_released (GtkEntry *entry,
GtkEntryIconPosition icon_pos,
GdkEvent *event,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_drag_begin (GtkWidget *widget,
+ XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_drag_begin (GtkWidget *widget,
GdkDragContext *drag_context,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_drag_data_get (GtkWidget *widget,
+ XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_drag_data_get (GtkWidget *widget,
GdkDragContext *drag_context,
GtkSelectionData *data,
guint info,
guint drag_time,
- XfceAppfinderWindow *window);
-static gboolean xfce_appfinder_window_treeview_key_press_event (GtkWidget *widget,
+ XfceAppfinderWidget *appfinder_widget);
+static gboolean xfce_appfinder_widget_treeview_key_press_event (GtkWidget *widget,
GdkEventKey *event,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_category_changed (GtkTreeSelection *selection,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_category_set_categories (XfceAppfinderModel *model,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_preferences (GtkWidget *button,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_property_changed (XfconfChannel *channel,
+ XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_category_changed (GtkTreeSelection *selection,
+ XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_category_set_categories (XfceAppfinderModel *model,
+ XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_property_changed (XfconfChannel *channel,
const gchar *prop,
const GValue *value,
- XfceAppfinderWindow *window);
-static gboolean xfce_appfinder_window_item_visible (GtkTreeModel *model,
+ XfceAppfinderWidget *appfinder_widget);
+static gboolean xfce_appfinder_widget_item_visible (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
-static void xfce_appfinder_window_item_changed (XfceAppfinderWindow *window);
-static void xfce_appfinder_window_row_activated (XfceAppfinderWindow *window);
-static void xfce_appfinder_window_icon_theme_changed (XfceAppfinderWindow *window);
-static void xfce_appfinder_window_execute (XfceAppfinderWindow *window);
-
+static void xfce_appfinder_widget_item_changed (XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_row_activated (XfceAppfinderWidget *appfinder_widget);
+static void xfce_appfinder_widget_icon_theme_changed (XfceAppfinderWidget *appfinder_widget);
-struct _XfceAppfinderWindowClass
+struct _XfceAppfinderWidgetClass
{
- GtkWindowClass __parent__;
+ GtkVBoxClass __parent__;
};
-struct _XfceAppfinderWindow
+struct _XfceAppfinderWidget
{
- GtkWindow __parent__;
+ GtkVBox __parent__;
XfceAppfinderModel *model;
@@ -138,9 +129,6 @@ struct _XfceAppfinderWindow
GdkPixbuf *icon_find;
- GtkWidget *bbox;
- GtkWidget *button_launch;
- GtkWidget *button_preferences;
GtkWidget *bin_collapsed;
GtkWidget *bin_expanded;
@@ -149,10 +137,10 @@ struct _XfceAppfinderWindow
guint idle_entry_changed_id;
- gint last_window_height;
-
gulong property_watch_id;
gulong categories_changed_id;
+
+ gboolean item_selected;
};
static const GtkTargetEntry target_list[] =
@@ -160,32 +148,59 @@ static const GtkTargetEntry target_list[] =
{ "text/uri-list", 0, 0 }
};
+enum
+{
+ SELECTION_CHANGED,
+ EXPANSION_CHANGED,
+ LAST_SIGNAL
+};
+
+
+
+static guint appfinder_widget_signals[LAST_SIGNAL];
+
-G_DEFINE_TYPE (XfceAppfinderWindow, xfce_appfinder_window, GTK_TYPE_WINDOW)
+G_DEFINE_TYPE (XfceAppfinderWidget, xfce_appfinder_widget, GTK_TYPE_VBOX)
static void
-xfce_appfinder_window_class_init (XfceAppfinderWindowClass *klass)
+xfce_appfinder_widget_class_init (XfceAppfinderWidgetClass *klass)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *gtkwidget_class;
+ GObjectClass *gobject_class;
+ GtkWidgetClass *gtkwidget_class;
gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->finalize = xfce_appfinder_window_finalize;
+ gobject_class->finalize = xfce_appfinder_widget_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
- gtkwidget_class->unmap = xfce_appfinder_window_unmap;
- gtkwidget_class->key_press_event = xfce_appfinder_window_key_press_event;
+ gtkwidget_class->key_press_event = xfce_appfinder_widget_key_press_event;
+
+ appfinder_widget_signals[SELECTION_CHANGED] =
+ g_signal_new (g_intern_static_string ("selection-changed"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ appfinder_widget_signals[EXPANSION_CHANGED] =
+ g_signal_new (g_intern_static_string ("expansion-changed"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
}
static void
-xfce_appfinder_window_init (XfceAppfinderWindow *window)
+xfce_appfinder_widget_init (XfceAppfinderWidget *widget)
{
- GtkWidget *vbox, *vbox2;
+ GtkWidget *vbox2;
GtkWidget *entry;
GtkWidget *pane;
GtkWidget *scroll;
@@ -196,46 +211,34 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
GtkTreeSelection *selection;
- GtkWidget *bbox;
- GtkWidget *button;
GtkEntryCompletion *completion;
GtkIconTheme *icon_theme;
gint integer;
- window->channel = xfconf_channel_get ("xfce4-appfinder");
- window->last_window_height = xfconf_channel_get_int (window->channel, "/last/window-height", DEFAULT_WINDOW_HEIGHT);
-
- window->category_model = xfce_appfinder_category_model_new ();
- xfconf_g_property_bind (window->channel, "/category-icon-size", G_TYPE_UINT,
- G_OBJECT (window->category_model), "icon-size");
+ widget->channel = xfconf_channel_get ("xfce4-appfinder");
- window->model = xfce_appfinder_model_get ();
- xfconf_g_property_bind (window->channel, "/item-icon-size", G_TYPE_UINT,
- G_OBJECT (window->model), "icon-size");
+ widget->category_model = xfce_appfinder_category_model_new ();
+ xfconf_g_property_bind (widget->channel, "/category-icon-size", G_TYPE_UINT,
+ G_OBJECT (widget->category_model), "icon-size");
- gtk_window_set_title (GTK_WINDOW (window), _("Application Finder"));
- integer = xfconf_channel_get_int (window->channel, "/last/window-width", DEFAULT_WINDOW_WIDTH);
- gtk_window_set_default_size (GTK_WINDOW (window), integer, -1);
- gtk_window_set_icon_name (GTK_WINDOW (window), GTK_STOCK_EXECUTE);
+ widget->model = xfce_appfinder_model_get ();
+ xfconf_g_property_bind (widget->channel, "/item-icon-size", G_TYPE_UINT,
+ G_OBJECT (widget->model), "icon-size");
- if (xfconf_channel_get_bool (window->channel, "/always-center", FALSE))
- gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
+ widget->item_selected = FALSE;
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_container_add (GTK_CONTAINER (window), vbox);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
- gtk_widget_show (vbox);
+ gtk_container_set_border_width (GTK_CONTAINER (widget), 1);
hbox = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (widget), hbox, FALSE, TRUE, 0);
gtk_widget_show (hbox);
align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), align, FALSE, FALSE, 0);
gtk_widget_show (align);
- window->icon_find = xfce_appfinder_model_load_pixbuf (GTK_STOCK_FIND, XFCE_APPFINDER_ICON_SIZE_48);
- window->image = image = gtk_image_new_from_pixbuf (window->icon_find);
+ widget->icon_find = xfce_appfinder_model_load_pixbuf (GTK_STOCK_FIND, XFCE_APPFINDER_ICON_SIZE_48);
+ widget->image = image = gtk_image_new_from_pixbuf (widget->icon_find);
gtk_container_add (GTK_CONTAINER (align), image);
gtk_widget_show (image);
@@ -247,18 +250,18 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
gtk_box_pack_start (GTK_BOX (vbox2), align, TRUE, TRUE, 0);
gtk_widget_show (align);
- window->entry = entry = gtk_entry_new ();
+ widget->entry = entry = gtk_entry_new ();
gtk_container_add (GTK_CONTAINER (align), entry);
g_signal_connect (G_OBJECT (entry), "icon-release",
- G_CALLBACK (xfce_appfinder_window_entry_icon_released), window);
+ G_CALLBACK (xfce_appfinder_widget_entry_icon_released), widget);
g_signal_connect (G_OBJECT (entry), "realize",
- G_CALLBACK (xfce_appfinder_window_set_padding), align);
+ G_CALLBACK (xfce_appfinder_widget_set_padding), align);
g_signal_connect_swapped (G_OBJECT (entry), "changed",
- G_CALLBACK (xfce_appfinder_window_entry_changed), window);
+ G_CALLBACK (xfce_appfinder_widget_entry_changed), widget);
g_signal_connect (G_OBJECT (entry), "activate",
- G_CALLBACK (xfce_appfinder_window_entry_activate), window);
+ G_CALLBACK (xfce_appfinder_widget_entry_activate), widget);
g_signal_connect (G_OBJECT (entry), "key-press-event",
- G_CALLBACK (xfce_appfinder_window_entry_key_press_event), window);
+ G_CALLBACK (xfce_appfinder_widget_entry_key_press_event), widget);
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
GTK_ENTRY_ICON_SECONDARY,
GTK_STOCK_GO_DOWN);
@@ -267,21 +270,21 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
_("Toggle view mode"));
gtk_widget_show (entry);
- window->completion = completion = gtk_entry_completion_new ();
- gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (window->model));
- gtk_entry_completion_set_match_func (completion, xfce_appfinder_window_completion_match_func, window, NULL);
+ widget->completion = completion = gtk_entry_completion_new ();
+ gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (widget->model));
+ gtk_entry_completion_set_match_func (completion, xfce_appfinder_widget_completion_match_func, widget, NULL);
gtk_entry_completion_set_text_column (completion, XFCE_APPFINDER_MODEL_COLUMN_COMMAND);
gtk_entry_completion_set_popup_completion (completion, TRUE);
gtk_entry_completion_set_popup_single_match (completion, FALSE);
gtk_entry_completion_set_inline_completion (completion, TRUE);
- window->bin_collapsed = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_box_pack_start (GTK_BOX (vbox2), window->bin_collapsed, FALSE, TRUE, 0);
- gtk_widget_show (window->bin_collapsed);
+ widget->bin_collapsed = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+ gtk_box_pack_start (GTK_BOX (vbox2), widget->bin_collapsed, FALSE, TRUE, 0);
+ gtk_widget_show (widget->bin_collapsed);
- window->paned = pane = gtk_hpaned_new ();
- gtk_box_pack_start (GTK_BOX (vbox), pane, TRUE, TRUE, 0);
- integer = xfconf_channel_get_int (window->channel, "/last/pane-position", DEFAULT_PANED_POSITION);
+ widget->paned = pane = gtk_hpaned_new ();
+ gtk_box_pack_start (GTK_BOX (widget), pane, TRUE, TRUE, 0);
+ integer = xfconf_channel_get_int (widget->channel, "/last/pane-position", DEFAULT_PANED_POSITION);
gtk_paned_set_position (GTK_PANED (pane), integer);
g_object_set (G_OBJECT (pane), "position-set", TRUE, NULL);
@@ -291,13 +294,13 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_widget_show (scroll);
- sidepane = window->sidepane = gtk_tree_view_new_with_model (GTK_TREE_MODEL (window->category_model));
+ sidepane = widget->sidepane = gtk_tree_view_new_with_model (GTK_TREE_MODEL (widget->category_model));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (sidepane), FALSE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (sidepane), FALSE);
g_signal_connect_swapped (G_OBJECT (sidepane), "start-interactive-search",
G_CALLBACK (gtk_widget_grab_focus), entry);
g_signal_connect (G_OBJECT (sidepane), "key-press-event",
- G_CALLBACK (xfce_appfinder_window_treeview_key_press_event), window);
+ G_CALLBACK (xfce_appfinder_widget_treeview_key_press_event), widget);
gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (sidepane),
xfce_appfinder_category_model_row_separator_func, NULL, NULL);
gtk_container_add (GTK_CONTAINER (scroll), sidepane);
@@ -306,7 +309,7 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sidepane));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (G_OBJECT (selection), "changed",
- G_CALLBACK (xfce_appfinder_window_category_changed), window);
+ G_CALLBACK (xfce_appfinder_widget_category_changed), widget);
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
@@ -323,124 +326,86 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
"text", XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_NAME, NULL);
- window->viewscroll = scroll = gtk_scrolled_window_new (NULL, NULL);
+ widget->viewscroll = scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_paned_add2 (GTK_PANED (pane), scroll);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_widget_show (scroll);
/* set the icon or tree view */
- xfce_appfinder_window_view (window);
-
- window->bin_expanded = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_box_pack_start (GTK_BOX (vbox), window->bin_expanded, FALSE, TRUE, 0);
- gtk_widget_show (window->bin_expanded);
+ xfce_appfinder_widget_view (widget);
- window->bbox = hbox = gtk_hbox_new (FALSE, 6);
- gtk_widget_show (hbox);
+ widget->bin_expanded = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+ gtk_box_pack_start (GTK_BOX (widget), widget->bin_expanded, FALSE, TRUE, 0);
+ gtk_widget_show (widget->bin_expanded);
- window->button_preferences = button = gtk_button_new_from_stock (GTK_STOCK_PREFERENCES);
- gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
- g_signal_connect (G_OBJECT (button), "clicked",
- G_CALLBACK (xfce_appfinder_window_preferences), window);
-
- bbox = gtk_hbutton_box_new ();
- gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
- gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), 6);
- gtk_box_pack_start (GTK_BOX (hbox), bbox, TRUE, TRUE, 0);
- gtk_widget_show (bbox);
-
- button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
- gtk_container_add (GTK_CONTAINER (bbox), button);
- g_signal_connect_swapped (G_OBJECT (button), "clicked",
- G_CALLBACK (gtk_widget_destroy), window);
- gtk_widget_show (button);
-
- window->button_launch = button = gtk_button_new_with_mnemonic ("La_unch");
- gtk_container_add (GTK_CONTAINER (bbox), button);
- g_signal_connect_swapped (G_OBJECT (button), "clicked",
- G_CALLBACK (xfce_appfinder_window_execute), window);
- gtk_widget_set_sensitive (button, FALSE);
- gtk_widget_show (button);
-
- image = gtk_image_new_from_stock (GTK_STOCK_EXECUTE, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (button), image);
-
- icon_theme = gtk_icon_theme_get_for_screen (gtk_window_get_screen (GTK_WINDOW (window)));
+ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (widget)));
g_signal_connect_swapped (G_OBJECT (icon_theme), "changed",
- G_CALLBACK (xfce_appfinder_window_icon_theme_changed), window);
+ G_CALLBACK (xfce_appfinder_widget_icon_theme_changed), widget);
/* load categories in the model */
- xfce_appfinder_window_category_set_categories (NULL, window);
- window->categories_changed_id =
- g_signal_connect (G_OBJECT (window->model), "categories-changed",
- G_CALLBACK (xfce_appfinder_window_category_set_categories),
- window);
+ xfce_appfinder_widget_category_set_categories (NULL, widget);
+ widget->categories_changed_id =
+ g_signal_connect (G_OBJECT (widget->model), "categories-changed",
+ G_CALLBACK (xfce_appfinder_widget_category_set_categories),
+ widget);
/* monitor xfconf property changes */
- window->property_watch_id =
- g_signal_connect (G_OBJECT (window->channel), "property-changed",
- G_CALLBACK (xfce_appfinder_window_property_changed), window);
+ widget->property_watch_id =
+ g_signal_connect (G_OBJECT (widget->channel), "property-changed",
+ G_CALLBACK (xfce_appfinder_widget_property_changed), widget);
- APPFINDER_DEBUG ("constructed window");
+ APPFINDER_DEBUG ("constructed widget");
}
static void
-xfce_appfinder_window_finalize (GObject *object)
+xfce_appfinder_widget_finalize (GObject *object)
{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (object);
+ XfceAppfinderWidget *widget = XFCE_APPFINDER_WIDGET (object);
- if (window->idle_entry_changed_id != 0)
- g_source_remove (window->idle_entry_changed_id);
+ if (widget->idle_entry_changed_id != 0)
+ g_source_remove (widget->idle_entry_changed_id);
- g_signal_handler_disconnect (window->channel, window->property_watch_id);
- g_signal_handler_disconnect (window->model, window->categories_changed_id);
+ g_signal_handler_disconnect (widget->channel, widget->property_watch_id);
+ g_signal_handler_disconnect (widget->model, widget->categories_changed_id);
- g_object_unref (G_OBJECT (window->model));
- g_object_unref (G_OBJECT (window->category_model));
- g_object_unref (G_OBJECT (window->completion));
- g_object_unref (G_OBJECT (window->icon_find));
+ g_object_unref (G_OBJECT (widget->model));
+ g_object_unref (G_OBJECT (widget->category_model));
+ g_object_unref (G_OBJECT (widget->completion));
+ g_object_unref (G_OBJECT (widget->icon_find));
- if (window->actions != NULL)
- g_object_unref (G_OBJECT (window->actions));
+ if (widget->actions != NULL)
+ g_object_unref (G_OBJECT (widget->actions));
- if (window->filter_category != NULL)
- g_object_unref (G_OBJECT (window->filter_category));
- g_free (window->filter_text);
+ if (widget->filter_category != NULL)
+ g_object_unref (G_OBJECT (widget->filter_category));
+ g_free (widget->filter_text);
- (*G_OBJECT_CLASS (xfce_appfinder_window_parent_class)->finalize) (object);
+ (*G_OBJECT_CLASS (xfce_appfinder_widget_parent_class)->finalize) (object);
}
-static void
-xfce_appfinder_window_unmap (GtkWidget *widget)
+void
+xfce_appfinder_widget_save_settings (XfceAppfinderWidget *widget)
{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (widget);
- gint width, height;
gint position;
- position = gtk_paned_get_position (GTK_PANED (window->paned));
- gtk_window_get_size (GTK_WINDOW (window), &width, &height);
- if (!gtk_widget_get_visible (window->paned))
- height = window->last_window_height;
+ position = gtk_paned_get_position (GTK_PANED (widget->paned));
+ xfconf_channel_set_int (widget->channel, "/last/pane-position", position);
- (*GTK_WIDGET_CLASS (xfce_appfinder_window_parent_class)->unmap) (widget);
-
- xfconf_channel_set_int (window->channel, "/last/window-height", height);
- xfconf_channel_set_int (window->channel, "/last/window-width", width);
- xfconf_channel_set_int (window->channel, "/last/pane-position", position);
+ APPFINDER_DEBUG ("saved widget settings");
}
static gboolean
-xfce_appfinder_window_key_press_event (GtkWidget *widget,
+xfce_appfinder_widget_key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (widget);
+ XfceAppfinderWidget *appfinder_widget = XFCE_APPFINDER_WIDGET (widget);
GtkWidget *entry;
XfceAppfinderIconSize icon_size = XFCE_APPFINDER_ICON_SIZE_DEFAULT_ITEM;
@@ -454,7 +419,7 @@ xfce_appfinder_window_key_press_event (GtkWidget *widget,
switch (event->keyval)
{
case GDK_l:
- entry = XFCE_APPFINDER_WINDOW (widget)->entry;
+ entry = appfinder_widget->entry;
gtk_widget_grab_focus (entry);
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
@@ -464,7 +429,7 @@ xfce_appfinder_window_key_press_event (GtkWidget *widget,
case GDK_1:
case GDK_2:
/* toggle between icon and tree view */
- xfconf_channel_set_bool (window->channel, "/icon-view",
+ xfconf_channel_set_bool (appfinder_widget->channel, "/icon-view",
event->keyval == GDK_1);
return TRUE;
@@ -472,7 +437,7 @@ xfce_appfinder_window_key_press_event (GtkWidget *widget,
case GDK_minus:
case GDK_KP_Add:
case GDK_KP_Subtract:
- g_object_get (G_OBJECT (window->model), "icon-size", &icon_size, NULL);
+ g_object_get (G_OBJECT (appfinder_widget->model), "icon-size", &icon_size, NULL);
if ((event->keyval == GDK_plus || event->keyval == GDK_KP_Add))
{
if (icon_size < XFCE_APPFINDER_ICON_SIZE_LARGEST)
@@ -485,18 +450,18 @@ xfce_appfinder_window_key_press_event (GtkWidget *widget,
case GDK_0:
case GDK_KP_0:
- g_object_set (G_OBJECT (window->model), "icon-size", icon_size, NULL);
+ g_object_set (G_OBJECT (appfinder_widget->model), "icon-size", icon_size, NULL);
return TRUE;
}
}
- return (*GTK_WIDGET_CLASS (xfce_appfinder_window_parent_class)->key_press_event) (widget, event);
+ return (*GTK_WIDGET_CLASS (xfce_appfinder_widget_parent_class)->key_press_event) (widget, event);
}
static void
-xfce_appfinder_window_set_item_width (XfceAppfinderWindow *window)
+xfce_appfinder_widget_set_item_width (XfceAppfinderWidget *widget)
{
gint width;
XfceAppfinderIconSize icon_size;
@@ -504,9 +469,9 @@ xfce_appfinder_window_set_item_width (XfceAppfinderWindow *window)
GList *renderers;
GList *li;
- appfinder_return_if_fail (GTK_IS_ICON_VIEW (window->view));
+ appfinder_return_if_fail (GTK_IS_ICON_VIEW (widget->view));
- g_object_get (G_OBJECT (window->model), "icon-size", &icon_size, NULL);
+ g_object_get (G_OBJECT (widget->model), "icon-size", &icon_size, NULL);
/* some hard-coded values for the cell size that seem to work fine */
switch (icon_size)
@@ -540,23 +505,23 @@ xfce_appfinder_window_set_item_width (XfceAppfinderWindow *window)
break;
}
- if (xfconf_channel_get_bool (window->channel, "/text-beside-icons", FALSE))
+ if (xfconf_channel_get_bool (widget->channel, "/text-beside-icons", FALSE))
{
item_orientation = GTK_ORIENTATION_HORIZONTAL;
width *= 2;
}
#if GTK_CHECK_VERSION (2, 22, 0)
- gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (window->view), item_orientation);
+ gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (widget->view), item_orientation);
#else
- gtk_icon_view_set_orientation (GTK_ICON_VIEW (window->view), item_orientation);
+ gtk_icon_view_set_orientation (GTK_ICON_VIEW (widget->view), item_orientation);
#endif
- gtk_icon_view_set_item_width (GTK_ICON_VIEW (window->view), width);
+ gtk_icon_view_set_item_width (GTK_ICON_VIEW (widget->view), width);
if (item_orientation == GTK_ORIENTATION_HORIZONTAL)
{
/* work around the yalign = 0.0 gtk uses */
- renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (window->view));
+ renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (widget->view));
for (li = renderers; li != NULL; li = li->next)
g_object_set (li->data, "yalign", 0.5, NULL);
g_list_free (renderers);
@@ -566,9 +531,9 @@ xfce_appfinder_window_set_item_width (XfceAppfinderWindow *window)
static gboolean
-xfce_appfinder_window_view_button_press_event (GtkWidget *widget,
+xfce_appfinder_widget_view_button_press_event (GtkWidget *widget,
GdkEventButton *event,
- XfceAppfinderWindow *window)
+ XfceAppfinderWidget *appfinder_widget)
{
gint x, y;
GtkTreePath *path;
@@ -602,7 +567,7 @@ xfce_appfinder_window_view_button_press_event (GtkWidget *widget,
}
if (have_selection)
- return xfce_appfinder_window_popup_menu (widget, window);
+ return xfce_appfinder_widget_popup_menu (widget, appfinder_widget);
}
return FALSE;
@@ -611,7 +576,7 @@ xfce_appfinder_window_view_button_press_event (GtkWidget *widget,
static void
-xfce_appfinder_window_view (XfceAppfinderWindow *window)
+xfce_appfinder_widget_view (XfceAppfinderWidget *widget)
{
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
@@ -620,48 +585,48 @@ xfce_appfinder_window_view (XfceAppfinderWindow *window)
GtkWidget *view;
gboolean icon_view;
- icon_view = xfconf_channel_get_bool (window->channel, "/icon-view", FALSE);
- if (window->view != NULL)
+ icon_view = xfconf_channel_get_bool (widget->channel, "/icon-view", FALSE);
+ if (widget->view != NULL)
{
- if (icon_view && GTK_IS_ICON_VIEW (window->view))
+ if (icon_view && GTK_IS_ICON_VIEW (widget->view))
return;
- gtk_widget_destroy (window->view);
+ gtk_widget_destroy (widget->view);
}
- filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (window->model), NULL);
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model), xfce_appfinder_window_item_visible, window, NULL);
+ filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (widget->model), NULL);
+ gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model), xfce_appfinder_widget_item_visible, widget, NULL);
if (icon_view)
{
- window->view = view = gtk_icon_view_new_with_model (filter_model);
+ widget->view = view = gtk_icon_view_new_with_model (filter_model);
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (view), GTK_SELECTION_BROWSE);
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (view), XFCE_APPFINDER_MODEL_COLUMN_ICON);
gtk_icon_view_set_text_column (GTK_ICON_VIEW (view), XFCE_APPFINDER_MODEL_COLUMN_TITLE);
gtk_icon_view_set_tooltip_column (GTK_ICON_VIEW (view), XFCE_APPFINDER_MODEL_COLUMN_TOOLTIP);
- xfce_appfinder_window_set_item_width (window);
+ xfce_appfinder_widget_set_item_width (widget);
g_signal_connect_swapped (G_OBJECT (view), "selection-changed",
- G_CALLBACK (xfce_appfinder_window_item_changed), window);
+ G_CALLBACK (xfce_appfinder_widget_item_changed), widget);
g_signal_connect_swapped (G_OBJECT (view), "item-activated",
- G_CALLBACK (xfce_appfinder_window_row_activated), window);
+ G_CALLBACK (xfce_appfinder_widget_row_activated), widget);
}
else
{
- window->view = view = gtk_tree_view_new_with_model (filter_model);
+ widget->view = view = gtk_tree_view_new_with_model (filter_model);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), FALSE);
gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (view), XFCE_APPFINDER_MODEL_COLUMN_TOOLTIP);
g_signal_connect_swapped (G_OBJECT (view), "row-activated",
- G_CALLBACK (xfce_appfinder_window_row_activated), window);
+ G_CALLBACK (xfce_appfinder_widget_row_activated), widget);
g_signal_connect_swapped (G_OBJECT (view), "start-interactive-search",
- G_CALLBACK (gtk_widget_grab_focus), window->entry);
+ G_CALLBACK (gtk_widget_grab_focus), widget->entry);
g_signal_connect (G_OBJECT (view), "key-press-event",
- G_CALLBACK (xfce_appfinder_window_treeview_key_press_event), window);
+ G_CALLBACK (xfce_appfinder_widget_treeview_key_press_event), widget);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect_swapped (G_OBJECT (selection), "changed",
- G_CALLBACK (xfce_appfinder_window_item_changed), window);
+ G_CALLBACK (xfce_appfinder_widget_item_changed), widget);
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_spacing (column, 2);
@@ -683,14 +648,14 @@ xfce_appfinder_window_view (XfceAppfinderWindow *window)
gtk_drag_source_set (view, GDK_BUTTON1_MASK, target_list,
G_N_ELEMENTS (target_list), GDK_ACTION_COPY);
g_signal_connect (G_OBJECT (view), "drag-begin",
- G_CALLBACK (xfce_appfinder_window_drag_begin), window);
+ G_CALLBACK (xfce_appfinder_widget_drag_begin), widget);
g_signal_connect (G_OBJECT (view), "drag-data-get",
- G_CALLBACK (xfce_appfinder_window_drag_data_get), window);
+ G_CALLBACK (xfce_appfinder_widget_drag_data_get), widget);
g_signal_connect (G_OBJECT (view), "popup-menu",
- G_CALLBACK (xfce_appfinder_window_popup_menu), window);
+ G_CALLBACK (xfce_appfinder_widget_popup_menu), widget);
g_signal_connect (G_OBJECT (view), "button-press-event",
- G_CALLBACK (xfce_appfinder_window_view_button_press_event), window);
- gtk_container_add (GTK_CONTAINER (window->viewscroll), view);
+ G_CALLBACK (xfce_appfinder_widget_view_button_press_event), widget);
+ gtk_container_add (GTK_CONTAINER (widget->viewscroll), view);
gtk_widget_show (view);
g_object_unref (G_OBJECT (filter_model));
@@ -699,7 +664,7 @@ xfce_appfinder_window_view (XfceAppfinderWindow *window)
static gboolean
-xfce_appfinder_window_view_get_selected (XfceAppfinderWindow *window,
+xfce_appfinder_widget_view_get_selected (XfceAppfinderWidget *widget,
GtkTreeModel **model,
GtkTreeIter *iter)
{
@@ -707,22 +672,22 @@ xfce_appfinder_window_view_get_selected (XfceAppfinderWindow *window,
gboolean have_iter;
GList *items;
- appfinder_return_val_if_fail (XFCE_IS_APPFINDER_WINDOW (window), FALSE);
+ appfinder_return_val_if_fail (XFCE_IS_APPFINDER_WIDGET (widget), FALSE);
appfinder_return_val_if_fail (model != NULL, FALSE);
appfinder_return_val_if_fail (iter != NULL, FALSE);
- if (GTK_IS_TREE_VIEW (window->view))
+ if (GTK_IS_TREE_VIEW (widget->view))
{
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (window->view));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->view));
have_iter = gtk_tree_selection_get_selected (selection, model, iter);
}
else
{
- items = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (window->view));
+ items = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (widget->view));
appfinder_assert (g_list_length (items) <= 1);
if (items != NULL)
{
- *model = gtk_icon_view_get_model (GTK_ICON_VIEW (window->view));
+ *model = gtk_icon_view_get_model (GTK_ICON_VIEW (widget->view));
have_iter = gtk_tree_model_get_iter (*model, iter, items->data);
gtk_tree_path_free (items->data);
@@ -740,8 +705,8 @@ xfce_appfinder_window_view_get_selected (XfceAppfinderWindow *window,
static void
-xfce_appfinder_window_popup_menu_edit (GtkWidget *mi,
- XfceAppfinderWindow *window)
+xfce_appfinder_widget_popup_menu_edit (GtkWidget *mi,
+ XfceAppfinderWidget *widget)
{
GError *error = NULL;
gchar *cmd;
@@ -749,16 +714,16 @@ xfce_appfinder_window_popup_menu_edit (GtkWidget *mi,
GtkWidget *menu = gtk_widget_get_parent (mi);
appfinder_return_if_fail (GTK_IS_MENU (menu));
- appfinder_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window));
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_WIDGET (widget));
uri = g_object_get_data (G_OBJECT (menu), "uri");
if (G_LIKELY (uri != NULL))
{
cmd = g_strdup_printf ("exo-desktop-item-edit --xid=0x%x '%s'",
- APPFINDER_WIDGET_XID (window), uri);
+ APPFINDER_WIDGET_XID (widget), uri);
if (!g_spawn_command_line_async (cmd, &error))
{
- xfce_dialog_show_error (GTK_WINDOW (window), error,
+ xfce_dialog_show_error (NULL, error,
_("Failed to launch desktop item editor"));
g_error_free (error);
}
@@ -769,8 +734,8 @@ xfce_appfinder_window_popup_menu_edit (GtkWidget *mi,
static void
-xfce_appfinder_window_popup_menu_revert (GtkWidget *mi,
- XfceAppfinderWindow *window)
+xfce_appfinder_widget_popup_menu_revert (GtkWidget *mi,
+ XfceAppfinderWidget *widget)
{
const gchar *uri;
const gchar *name;
@@ -778,13 +743,13 @@ xfce_appfinder_window_popup_menu_revert (GtkWidget *mi,
GtkWidget *menu = gtk_widget_get_parent (mi);
appfinder_return_if_fail (GTK_IS_MENU (menu));
- appfinder_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window));
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_WIDGET (widget));
name = g_object_get_data (G_OBJECT (menu), "name");
if (name == NULL)
return;
- if (xfce_dialog_confirm (GTK_WINDOW (window), GTK_STOCK_REVERT_TO_SAVED, NULL,
+ if (xfce_dialog_confirm (NULL, GTK_STOCK_REVERT_TO_SAVED, NULL,
_("This will permanently remove the custom desktop file from your home directory."),
_("Are you sure you want to revert \"%s\"?"), name))
{
@@ -795,7 +760,7 @@ xfce_appfinder_window_popup_menu_revert (GtkWidget *mi,
{
error = g_error_new (G_FILE_ERROR, g_file_error_from_errno (errno),
"%s: %s", uri + 7, g_strerror (errno));
- xfce_dialog_show_error (GTK_WINDOW (window), error,
+ xfce_dialog_show_error (NULL, error,
_("Failed to remove desktop file"));
g_error_free (error);
}
@@ -806,8 +771,8 @@ xfce_appfinder_window_popup_menu_revert (GtkWidget *mi,
static void
-xfce_appfinder_window_popup_menu_hide (GtkWidget *mi,
- XfceAppfinderWindow *window)
+xfce_appfinder_widget_popup_menu_hide (GtkWidget *mi,
+ XfceAppfinderWidget *widget)
{
const gchar *uri;
const gchar *name;
@@ -820,7 +785,7 @@ xfce_appfinder_window_popup_menu_hide (GtkWidget *mi,
XfceRc *rc;
appfinder_return_if_fail (GTK_IS_MENU (menu));
- appfinder_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window));
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_WIDGET (widget));
name = g_object_get_data (G_OBJECT (menu), "name");
if (name == NULL)
@@ -834,7 +799,7 @@ xfce_appfinder_window_popup_menu_hide (GtkWidget *mi,
"open the file in the same directory and "
"remove the line \"%s\"."), path, "Hidden=true");
- if (xfce_dialog_confirm (GTK_WINDOW (window), NULL, _("_Hide"), message,
+ if (xfce_dialog_confirm (NULL, NULL, _("_Hide"), message,
_("Are you sure you want to hide \"%s\"?"), name))
{
uri = g_object_get_data (G_OBJECT (menu), "uri");
@@ -869,8 +834,8 @@ xfce_appfinder_window_popup_menu_hide (GtkWidget *mi,
static gboolean
-xfce_appfinder_window_popup_menu (GtkWidget *view,
- XfceAppfinderWindow *window)
+xfce_appfinder_widget_popup_menu (GtkWidget *view,
+ XfceAppfinderWidget *widget)
{
GtkWidget *menu;
GtkTreeModel *model;
@@ -881,7 +846,7 @@ xfce_appfinder_window_popup_menu (GtkWidget *view,
gchar *path;
gboolean uri_is_local;
- if (xfce_appfinder_window_view_get_selected (window, &model, &iter))
+ if (xfce_appfinder_widget_view_get_selected (widget, &model, &iter))
{
gtk_tree_model_get (model, &iter,
XFCE_APPFINDER_MODEL_COLUMN_TITLE, &title,
@@ -907,13 +872,13 @@ xfce_appfinder_window_popup_menu (GtkWidget *view,
mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_EDIT, NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
g_signal_connect (G_OBJECT (mi), "activate",
- G_CALLBACK (xfce_appfinder_window_popup_menu_edit), window);
+ G_CALLBACK (xfce_appfinder_widget_popup_menu_edit), widget);
gtk_widget_show (mi);
mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_REVERT_TO_SAVED, NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
g_signal_connect (G_OBJECT (mi), "activate",
- G_CALLBACK (xfce_appfinder_window_popup_menu_revert), window);
+ G_CALLBACK (xfce_appfinder_widget_popup_menu_revert), widget);
path = xfce_resource_save_location (XFCE_RESOURCE_DATA, "applications/", FALSE);
gtk_widget_set_sensitive (mi, uri_is_local && g_str_has_prefix (uri + 7, path));
gtk_widget_show (mi);
@@ -923,7 +888,7 @@ xfce_appfinder_window_popup_menu (GtkWidget *view,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
gtk_widget_set_sensitive (mi, uri_is_local);
g_signal_connect (G_OBJECT (mi), "activate",
- G_CALLBACK (xfce_appfinder_window_popup_menu_hide), window);
+ G_CALLBACK (xfce_appfinder_widget_popup_menu_hide), widget);
gtk_widget_show (mi);
gtk_menu_popup (GTK_MENU (menu),
@@ -939,21 +904,21 @@ xfce_appfinder_window_popup_menu (GtkWidget *view,
static void
-xfce_appfinder_window_update_image (XfceAppfinderWindow *window,
+xfce_appfinder_widget_update_image (XfceAppfinderWidget *widget,
GdkPixbuf *pixbuf)
{
if (pixbuf == NULL)
- pixbuf = window->icon_find;
+ pixbuf = widget->icon_find;
/* gtk doesn't check this */
- if (gtk_image_get_pixbuf (GTK_IMAGE (window->image)) != pixbuf)
- gtk_image_set_from_pixbuf (GTK_IMAGE (window->image), pixbuf);
+ if (gtk_image_get_pixbuf (GTK_IMAGE (widget->image)) != pixbuf)
+ gtk_image_set_from_pixbuf (GTK_IMAGE (widget->image), pixbuf);
}
static void
-xfce_appfinder_window_set_padding (GtkWidget *entry,
+xfce_appfinder_widget_set_padding (GtkWidget *entry,
GtkWidget *align)
{
gint padding;
@@ -966,32 +931,32 @@ xfce_appfinder_window_set_padding (GtkWidget *entry,
static gboolean
-xfce_appfinder_window_completion_match_func (GtkEntryCompletion *completion,
+xfce_appfinder_widget_completion_match_func (GtkEntryCompletion *completion,
const gchar *key,
GtkTreeIter *iter,
gpointer data)
{
const gchar *text;
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);
+ XfceAppfinderWidget *widget = XFCE_APPFINDER_WIDGET (data);
appfinder_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
- appfinder_return_val_if_fail (XFCE_IS_APPFINDER_WINDOW (data), FALSE);
- appfinder_return_val_if_fail (GTK_TREE_MODEL (window->model)
+ appfinder_return_val_if_fail (XFCE_IS_APPFINDER_WIDGET (data), FALSE);
+ appfinder_return_val_if_fail (GTK_TREE_MODEL (widget->model)
== gtk_entry_completion_get_model (completion), FALSE);
/* don't use the casefolded key generated by gtk */
- text = gtk_entry_get_text (GTK_ENTRY (window->entry));
+ text = gtk_entry_get_text (GTK_ENTRY (widget->entry));
- return xfce_appfinder_model_get_visible_command (window->model, iter, text);
+ return xfce_appfinder_model_get_visible_command (widget->model, iter, text);
}
static gboolean
-xfce_appfinder_window_entry_changed_idle (gpointer data)
+xfce_appfinder_widget_entry_changed_idle (gpointer data)
{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);
+ XfceAppfinderWidget *widget = XFCE_APPFINDER_WIDGET (data);
const gchar *text;
GdkPixbuf *pixbuf;
gchar *normalized;
@@ -999,36 +964,34 @@ xfce_appfinder_window_entry_changed_idle (gpointer data)
GDK_THREADS_ENTER ();
- text = gtk_entry_get_text (GTK_ENTRY (window->entry));
+ text = gtk_entry_get_text (GTK_ENTRY (widget->entry));
- if (gtk_widget_get_visible (window->paned))
+ if (gtk_widget_get_visible (widget->paned))
{
- g_free (window->filter_text);
+ g_free (widget->filter_text);
if (IS_STRING (text))
{
normalized = g_utf8_normalize (text, -1, G_NORMALIZE_ALL);
- window->filter_text = g_utf8_casefold (normalized, -1);
+ widget->filter_text = g_utf8_casefold (normalized, -1);
g_free (normalized);
}
else
{
- window->filter_text = NULL;
+ widget->filter_text = NULL;
}
APPFINDER_DEBUG ("refilter entry");
- if (GTK_IS_TREE_VIEW (window->view))
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (window->view));
+ if (GTK_IS_TREE_VIEW (widget->view))
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget->view));
else
- model = gtk_icon_view_get_model (GTK_ICON_VIEW (window->view));
+ model = gtk_icon_view_get_model (GTK_ICON_VIEW (widget->view));
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
}
else
{
- gtk_widget_set_sensitive (window->button_launch, IS_STRING (text));
-
- pixbuf = xfce_appfinder_model_get_icon_for_command (window->model, text);
- xfce_appfinder_window_update_image (window, pixbuf);
+ pixbuf = xfce_appfinder_model_get_icon_for_command (widget->model, text);
+ xfce_appfinder_widget_update_image (widget, pixbuf);
if (pixbuf != NULL)
g_object_unref (G_OBJECT (pixbuf));
}
@@ -1041,70 +1004,70 @@ xfce_appfinder_window_entry_changed_idle (gpointer data)
static void
-xfce_appfinder_window_entry_changed_idle_destroyed (gpointer data)
+xfce_appfinder_widget_entry_changed_idle_destroyed (gpointer data)
{
- XFCE_APPFINDER_WINDOW (data)->idle_entry_changed_id = 0;
+ XFCE_APPFINDER_WIDGET (data)->idle_entry_changed_id = 0;
}
static void
-xfce_appfinder_window_entry_changed (XfceAppfinderWindow *window)
+xfce_appfinder_widget_entry_changed (XfceAppfinderWidget *widget)
{
- if (window->idle_entry_changed_id != 0)
- g_source_remove (window->idle_entry_changed_id);
+ if (widget->idle_entry_changed_id != 0)
+ g_source_remove (widget->idle_entry_changed_id);
- window->idle_entry_changed_id =
- g_idle_add_full (G_PRIORITY_DEFAULT, xfce_appfinder_window_entry_changed_idle,
- window, xfce_appfinder_window_entry_changed_idle_destroyed);
+ widget->idle_entry_changed_id =
+ g_idle_add_full (G_PRIORITY_DEFAULT, xfce_appfinder_widget_entry_changed_idle,
+ widget, xfce_appfinder_widget_entry_changed_idle_destroyed);
}
static void
-xfce_appfinder_window_entry_activate (GtkEditable *entry,
- XfceAppfinderWindow *window)
+xfce_appfinder_widget_entry_activate (GtkEditable *entry,
+ XfceAppfinderWidget *widget)
{
GtkTreePath *path;
- if (gtk_widget_get_visible (window->paned))
+ if (gtk_widget_get_visible (widget->paned))
{
- if (GTK_IS_TREE_VIEW (window->view))
+ if (GTK_IS_TREE_VIEW (widget->view))
{
- if (gtk_tree_view_get_visible_range (GTK_TREE_VIEW (window->view), &path, NULL))
+ if (gtk_tree_view_get_visible_range (GTK_TREE_VIEW (widget->view), &path, NULL))
{
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (window->view), path, NULL, FALSE);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (widget->view), path, NULL, FALSE);
gtk_tree_path_free (path);
}
}
- else if (gtk_icon_view_get_visible_range (GTK_ICON_VIEW (window->view), &path, NULL))
+ else if (gtk_icon_view_get_visible_range (GTK_ICON_VIEW (widget->view), &path, NULL))
{
- gtk_icon_view_select_path (GTK_ICON_VIEW (window->view), path);
- gtk_icon_view_set_cursor (GTK_ICON_VIEW (window->view), path, NULL, FALSE);
+ gtk_icon_view_select_path (GTK_ICON_VIEW (widget->view), path);
+ gtk_icon_view_set_cursor (GTK_ICON_VIEW (widget->view), path, NULL, FALSE);
gtk_tree_path_free (path);
}
- gtk_widget_grab_focus (window->view);
+ gtk_widget_grab_focus (widget->view);
}
- else if (gtk_widget_get_sensitive (window->button_launch))
+ else if (widget->item_selected)
{
- gtk_button_clicked (GTK_BUTTON (window->button_launch));
+ xfce_appfinder_widget_execute (widget);
}
}
static gboolean
-xfce_appfinder_window_entry_key_press_event (GtkWidget *entry,
+xfce_appfinder_widget_entry_key_press_event (GtkWidget *entry,
GdkEventKey *event,
- XfceAppfinderWindow *window)
+ XfceAppfinderWidget *widget)
{
gboolean expand, is_expanded;
if (event->keyval == GDK_Up || event->keyval == GDK_Down)
{
expand = (event->keyval == GDK_Down);
- is_expanded = gtk_widget_get_visible (window->paned);
+ is_expanded = gtk_widget_get_visible (widget->paned);
if (is_expanded != expand)
{
/* don't break entry completion navigation in collapsed mode */
@@ -1112,7 +1075,7 @@ xfce_appfinder_window_entry_key_press_event (GtkWidget *entry,
&& gdk_pointer_is_grabbed ())
return FALSE;
- xfce_appfinder_window_set_expanded (window, expand);
+ xfce_appfinder_widget_set_expanded (widget, expand);
return TRUE;
}
}
@@ -1123,15 +1086,15 @@ xfce_appfinder_window_entry_key_press_event (GtkWidget *entry,
static void
-xfce_appfinder_window_drag_begin (GtkWidget *widget,
+xfce_appfinder_widget_drag_begin (GtkWidget *widget,
GdkDragContext *drag_context,
- XfceAppfinderWindow *window)
+ XfceAppfinderWidget *appfinder_widget)
{
GtkTreeModel *model;
GtkTreeIter iter;
GdkPixbuf *pixbuf;
- if (xfce_appfinder_window_view_get_selected (window, &model, &iter))
+ if (xfce_appfinder_widget_view_get_selected (appfinder_widget, &model, &iter))
{
gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_ICON_LARGE, &pixbuf, -1);
if (G_LIKELY (pixbuf != NULL))
@@ -1149,18 +1112,18 @@ xfce_appfinder_window_drag_begin (GtkWidget *widget,
static void
-xfce_appfinder_window_drag_data_get (GtkWidget *widget,
+xfce_appfinder_widget_drag_data_get (GtkWidget *widget,
GdkDragContext *drag_context,
GtkSelectionData *data,
guint info,
guint drag_time,
- XfceAppfinderWindow *window)
+ XfceAppfinderWidget *appfinder_widget)
{
GtkTreeModel *model;
GtkTreeIter iter;
gchar *uris[2];
- if (xfce_appfinder_window_view_get_selected (window, &model, &iter))
+ if (xfce_appfinder_widget_view_get_selected (appfinder_widget, &model, &iter))
{
uris[1] = NULL;
gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_URI, &uris[0], -1);
@@ -1172,23 +1135,23 @@ xfce_appfinder_window_drag_data_get (GtkWidget *widget,
static gboolean
-xfce_appfinder_window_treeview_key_press_event (GtkWidget *widget,
+xfce_appfinder_widget_treeview_key_press_event (GtkWidget *widget,
GdkEventKey *event,
- XfceAppfinderWindow *window)
+ XfceAppfinderWidget *appfinder_widget)
{
- if (widget == window->view)
+ if (widget == appfinder_widget->view)
{
if (event->keyval == GDK_Left)
{
- gtk_widget_grab_focus (window->sidepane);
+ gtk_widget_grab_focus (appfinder_widget->sidepane);
return TRUE;
}
}
- else if (widget == window->sidepane)
+ else if (widget == appfinder_widget->sidepane)
{
if (event->keyval == GDK_Right)
{
- gtk_widget_grab_focus (window->view);
+ gtk_widget_grab_focus (appfinder_widget->view);
return TRUE;
}
}
@@ -1199,20 +1162,28 @@ xfce_appfinder_window_treeview_key_press_event (GtkWidget *widget,
static void
-xfce_appfinder_window_entry_icon_released (GtkEntry *entry,
+xfce_appfinder_widget_entry_icon_released (GtkEntry *entry,
GtkEntryIconPosition icon_pos,
GdkEvent *event,
- XfceAppfinderWindow *window)
+ XfceAppfinderWidget *widget)
{
+ gboolean is_expanded;
+
if (icon_pos == GTK_ENTRY_ICON_SECONDARY)
- xfce_appfinder_window_set_expanded (window, !gtk_widget_get_visible (window->paned));
+ {
+ is_expanded = gtk_widget_get_visible (widget->paned);
+
+ xfce_appfinder_widget_set_expanded (widget, !is_expanded);
+ g_signal_emit (G_OBJECT (widget), appfinder_widget_signals[EXPANSION_CHANGED], 0,
+ !is_expanded);
+ }
}
static void
-xfce_appfinder_window_category_changed (GtkTreeSelection *selection,
- XfceAppfinderWindow *window)
+xfce_appfinder_widget_category_changed (GtkTreeSelection *selection,
+ XfceAppfinderWidget *widget)
{
GtkTreeIter iter;
GtkTreeModel *model;
@@ -1225,28 +1196,28 @@ xfce_appfinder_window_category_changed (GtkTreeSelection *selection,
XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_DIRECTORY, &category,
XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_NAME, &name, -1);
- if (window->filter_category != category)
+ if (widget->filter_category != category)
{
- if (window->filter_category != NULL)
- g_object_unref (G_OBJECT (window->filter_category));
+ if (widget->filter_category != NULL)
+ g_object_unref (G_OBJECT (widget->filter_category));
if (category == NULL)
- window->filter_category = NULL;
+ widget->filter_category = NULL;
else
- window->filter_category = g_object_ref (G_OBJECT (category));
+ widget->filter_category = g_object_ref (G_OBJECT (category));
APPFINDER_DEBUG ("refilter category");
/* update visible items */
- if (GTK_IS_TREE_VIEW (window->view))
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (window->view));
+ if (GTK_IS_TREE_VIEW (widget->view))
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget->view));
else
- model = gtk_icon_view_get_model (GTK_ICON_VIEW (window->view));
+ model = gtk_icon_view_get_model (GTK_ICON_VIEW (widget->view));
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
/* store last category */
- if (xfconf_channel_get_bool (window->channel, "/remember-category", FALSE))
- xfconf_channel_set_string (window->channel, "/last/category", name);
+ if (xfconf_channel_get_bool (widget->channel, "/remember-category", FALSE))
+ xfconf_channel_set_string (widget->channel, "/last/category", name);
}
g_free (name);
@@ -1258,8 +1229,8 @@ xfce_appfinder_window_category_changed (GtkTreeSelection *selection,
static void
-xfce_appfinder_window_category_set_categories (XfceAppfinderModel *signal_from_model,
- XfceAppfinderWindow *window)
+xfce_appfinder_widget_category_set_categories (XfceAppfinderModel *signal_from_model,
+ XfceAppfinderWidget *widget)
{
GSList *categories;
GtkTreePath *path;
@@ -1268,29 +1239,29 @@ xfce_appfinder_window_category_set_categories (XfceAppfinderModel *signal_from_
GtkTreeIter iter;
GtkTreeSelection *selection;
- appfinder_return_if_fail (GTK_IS_TREE_VIEW (window->sidepane));
+ appfinder_return_if_fail (GTK_IS_TREE_VIEW (widget->sidepane));
if (signal_from_model != NULL)
{
/* reload from the model, make sure we restore the selected category */
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (window->sidepane));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->sidepane));
if (gtk_tree_selection_get_selected (selection, &model, &iter))
gtk_tree_model_get (model, &iter, XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_NAME, &name, -1);
}
/* update the categories */
- categories = xfce_appfinder_model_get_categories (window->model);
+ categories = xfce_appfinder_model_get_categories (widget->model);
if (categories != NULL)
- xfce_appfinder_category_model_set_categories (window->category_model, categories);
+ xfce_appfinder_category_model_set_categories (widget->category_model, categories);
g_slist_free (categories);
- if (name == NULL && xfconf_channel_get_bool (window->channel, "/remember-category", FALSE))
- name = xfconf_channel_get_string (window->channel, "/last/category", NULL);
+ if (name == NULL && xfconf_channel_get_bool (widget->channel, "/remember-category", FALSE))
+ name = xfconf_channel_get_string (widget->channel, "/last/category", NULL);
- path = xfce_appfinder_category_model_find_category (window->category_model, name);
+ path = xfce_appfinder_category_model_find_category (widget->category_model, name);
if (path != NULL)
{
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (window->sidepane), path, NULL, FALSE);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (widget->sidepane), path, NULL, FALSE);
gtk_tree_path_free (path);
}
@@ -1300,85 +1271,72 @@ xfce_appfinder_window_category_set_categories (XfceAppfinderModel *signal_from_
static void
-xfce_appfinder_window_preferences (GtkWidget *button,
- XfceAppfinderWindow *window)
-{
- appfinder_return_if_fail (GTK_IS_WIDGET (button));
-
- /* preload the actions, to make sure there are default values */
- if (window->actions == NULL)
- window->actions = xfce_appfinder_actions_get ();
-
- xfce_appfinder_preferences_show (gtk_widget_get_screen (button));
-}
-
-
-
-static void
-xfce_appfinder_window_property_changed (XfconfChannel *channel,
+xfce_appfinder_widget_property_changed (XfconfChannel *channel,
const gchar *prop,
const GValue *value,
- XfceAppfinderWindow *window)
+ XfceAppfinderWidget *widget)
{
- appfinder_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window));
- appfinder_return_if_fail (window->channel == channel);
+ appfinder_return_if_fail (XFCE_IS_APPFINDER_WIDGET (widget));
+ appfinder_return_if_fail (widget->channel == channel);
if (g_strcmp0 (prop, "/icon-view") == 0)
{
- xfce_appfinder_window_view (window);
+ xfce_appfinder_widget_view (widget);
}
else if (g_strcmp0 (prop, "/item-icon-size") == 0)
{
- if (GTK_IS_ICON_VIEW (window->view))
- xfce_appfinder_window_set_item_width (window);
+ if (GTK_IS_ICON_VIEW (widget->view))
+ xfce_appfinder_widget_set_item_width (widget);
}
else if (g_strcmp0 (prop, "/text-beside-icons") == 0)
{
- if (GTK_IS_ICON_VIEW (window->view))
- xfce_appfinder_window_set_item_width (window);
+ if (GTK_IS_ICON_VIEW (widget->view))
+ xfce_appfinder_widget_set_item_width (widget);
}
}
static gboolean
-xfce_appfinder_window_item_visible (GtkTreeModel *model,
+xfce_appfinder_widget_item_visible (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);
+ XfceAppfinderWidget *widget = XFCE_APPFINDER_WIDGET (data);
return xfce_appfinder_model_get_visible (XFCE_APPFINDER_MODEL (model), iter,
- window->filter_category, window->filter_text);
+ widget->filter_category, widget->filter_text);
}
static void
-xfce_appfinder_window_item_changed (XfceAppfinderWindow *window)
+xfce_appfinder_widget_item_changed (XfceAppfinderWidget *widget)
{
GtkTreeIter iter;
GtkTreeModel *model;
gboolean can_launch;
GdkPixbuf *pixbuf;
- if (gtk_widget_get_visible (window->paned))
+ if (gtk_widget_get_visible (widget->paned))
{
- can_launch = xfce_appfinder_window_view_get_selected (window, &model, &iter);
- gtk_widget_set_sensitive (window->button_launch, can_launch);
+ can_launch = xfce_appfinder_widget_view_get_selected (widget, &model, &iter);
+ widget->item_selected = can_launch;
+ g_signal_emit (G_OBJECT (widget), appfinder_widget_signals[SELECTION_CHANGED], 0, can_launch);
+
if (can_launch)
{
gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_ICON_LARGE, &pixbuf, -1);
if (G_LIKELY (pixbuf != NULL))
{
- xfce_appfinder_window_update_image (window, pixbuf);
+ xfce_appfinder_widget_update_image (widget, pixbuf);
g_object_unref (G_OBJECT (pixbuf));
}
}
else
{
- xfce_appfinder_window_update_image (window, NULL);
+ xfce_appfinder_widget_update_image (widget, NULL);
}
}
}
@@ -1386,36 +1344,38 @@ xfce_appfinder_window_item_changed (XfceAppfinderWindow *window)
static void
-xfce_appfinder_window_row_activated (XfceAppfinderWindow *window)
+xfce_appfinder_widget_row_activated (XfceAppfinderWidget *widget)
{
- if (gtk_widget_get_sensitive (window->button_launch))
- gtk_button_clicked (GTK_BUTTON (window->button_launch));
+ if (widget->item_selected)
+ {
+ xfce_appfinder_widget_execute (widget);
+ }
}
static void
-xfce_appfinder_window_icon_theme_changed (XfceAppfinderWindow *window)
+xfce_appfinder_widget_icon_theme_changed (XfceAppfinderWidget *widget)
{
- if (window->icon_find != NULL)
- g_object_unref (G_OBJECT (window->icon_find));
- window->icon_find = xfce_appfinder_model_load_pixbuf (GTK_STOCK_FIND, XFCE_APPFINDER_ICON_SIZE_48);
+ if (widget->icon_find != NULL)
+ g_object_unref (G_OBJECT (widget->icon_find));
+ widget->icon_find = xfce_appfinder_model_load_pixbuf (GTK_STOCK_FIND, XFCE_APPFINDER_ICON_SIZE_48);
/* drop cached pixbufs */
- xfce_appfinder_model_icon_theme_changed (window->model);
- xfce_appfinder_category_model_icon_theme_changed (window->category_model);
+ xfce_appfinder_model_icon_theme_changed (widget->model);
+ xfce_appfinder_category_model_icon_theme_changed (widget->category_model);
/* update state */
- xfce_appfinder_window_entry_changed (window);
- xfce_appfinder_window_item_changed (window);
+ xfce_appfinder_widget_entry_changed (widget);
+ xfce_appfinder_widget_item_changed (widget);
}
static gboolean
-xfce_appfinder_window_execute_command (const gchar *text,
+xfce_appfinder_widget_execute_command (const gchar *text,
GdkScreen *screen,
- XfceAppfinderWindow *window,
+ XfceAppfinderWidget *widget,
gboolean *save_cmd,
GError **error)
{
@@ -1429,11 +1389,11 @@ xfce_appfinder_window_execute_command (const gchar *text,
if (!IS_STRING (text))
return TRUE;
- if (window->actions == NULL)
- window->actions = xfce_appfinder_actions_get ();
+ if (widget->actions == NULL)
+ widget->actions = xfce_appfinder_actions_get ();
/* try to match a custom action */
- action_cmd = xfce_appfinder_actions_execute (window->actions, text, save_cmd, error);
+ action_cmd = xfce_appfinder_actions_execute (widget->actions, text, save_cmd, error);
if (*error != NULL)
return FALSE;
else if (action_cmd != NULL)
@@ -1457,8 +1417,8 @@ xfce_appfinder_window_execute_command (const gchar *text,
-static void
-xfce_appfinder_window_execute (XfceAppfinderWindow *window)
+void
+xfce_appfinder_widget_execute (XfceAppfinderWidget *widget)
{
GtkTreeModel *model;
GtkTreeIter iter, orig;
@@ -1470,42 +1430,42 @@ xfce_appfinder_window_execute (XfceAppfinderWindow *window)
gboolean regular_command = FALSE;
gboolean save_cmd;
- if (!gtk_widget_get_sensitive (window->button_launch))
+ if (!widget->item_selected)
return;
- screen = gtk_window_get_screen (GTK_WINDOW (window));
- if (gtk_widget_get_visible (window->paned))
+ screen = gtk_widget_get_screen (GTK_WIDGET (widget));
+ if (gtk_widget_get_visible (widget->paned))
{
- if (xfce_appfinder_window_view_get_selected (window, &model, &iter))
+ if (xfce_appfinder_widget_view_get_selected (widget, &model, &iter))
{
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &orig, &iter);
- result = xfce_appfinder_model_execute (window->model, &orig, screen, ®ular_command, &error);
+ result = xfce_appfinder_model_execute (widget->model, &orig, screen, ®ular_command, &error);
if (!result && regular_command)
{
gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_COMMAND, &cmd, -1);
- result = xfce_appfinder_window_execute_command (cmd, screen, window, NULL, &error);
+ result = xfce_appfinder_widget_execute_command (cmd, screen, widget, NULL, &error);
g_free (cmd);
}
}
}
else
{
- text = gtk_entry_get_text (GTK_ENTRY (window->entry));
+ text = gtk_entry_get_text (GTK_ENTRY (widget->entry));
save_cmd = TRUE;
- if (xfce_appfinder_window_execute_command (text, screen, window, &save_cmd, &error))
+ if (xfce_appfinder_widget_execute_command (text, screen, widget, &save_cmd, &error))
{
if (save_cmd)
- result = xfce_appfinder_model_save_command (window->model, text, &error);
+ result = xfce_appfinder_model_save_command (widget->model, text, &error);
else
result = TRUE;
}
}
- gtk_entry_set_icon_from_stock (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_PRIMARY,
+ gtk_entry_set_icon_from_stock (GTK_ENTRY (widget->entry), GTK_ENTRY_ICON_PRIMARY,
result ? NULL : GTK_STOCK_DIALOG_ERROR);
- gtk_entry_set_icon_tooltip_text (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_PRIMARY,
+ gtk_entry_set_icon_tooltip_text (GTK_ENTRY (widget->entry), GTK_ENTRY_ICON_PRIMARY,
error != NULL ? error->message : NULL);
if (error != NULL)
@@ -1515,70 +1475,39 @@ xfce_appfinder_window_execute (XfceAppfinderWindow *window)
}
if (result)
- gtk_widget_destroy (GTK_WIDGET (window));
+ gtk_widget_destroy (GTK_WIDGET (widget));
}
void
-xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window,
+xfce_appfinder_widget_set_expanded (XfceAppfinderWidget *widget,
gboolean expanded)
{
- GdkGeometry hints;
- gint width;
- GtkWidget *parent;
GtkEntryCompletion *completion;
APPFINDER_DEBUG ("set expand = %s", expanded ? "true" : "false");
- /* force window geomentry */
- if (expanded)
- {
- gtk_window_set_geometry_hints (GTK_WINDOW (window), NULL, NULL, 0);
- gtk_window_get_size (GTK_WINDOW (window), &width, NULL);
- gtk_window_resize (GTK_WINDOW (window), width, window->last_window_height);
- }
- else
- {
- if (gtk_widget_get_visible (GTK_WIDGET (window)))
- gtk_window_get_size (GTK_WINDOW (window), NULL, &window->last_window_height);
-
- hints.max_height = -1;
- hints.max_width = G_MAXINT;
- gtk_window_set_geometry_hints (GTK_WINDOW (window), NULL, &hints, GDK_HINT_MAX_SIZE);
- }
-
- /* repack the button box */
- g_object_ref (G_OBJECT (window->bbox));
- parent = gtk_widget_get_parent (window->bbox);
- if (parent != NULL)
- gtk_container_remove (GTK_CONTAINER (parent), window->bbox);
- if (expanded)
- gtk_container_add (GTK_CONTAINER (window->bin_expanded), window->bbox);
- else
- gtk_container_add (GTK_CONTAINER (window->bin_collapsed), window->bbox);
- gtk_widget_set_visible (window->bin_expanded, expanded);
- gtk_widget_set_visible (window->bin_collapsed, !expanded);
- gtk_widget_set_visible (window->button_preferences, expanded);
- g_object_unref (G_OBJECT (window->bbox));
+ gtk_widget_set_visible (widget->bin_expanded, expanded);
+ gtk_widget_set_visible (widget->bin_collapsed, !expanded);
/* show/hide pane with treeviews */
- gtk_widget_set_visible (window->paned, expanded);
+ gtk_widget_set_visible (widget->paned, expanded);
/* toggle icon */
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_SECONDARY,
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (widget->entry), GTK_ENTRY_ICON_SECONDARY,
expanded ? GTK_STOCK_GO_UP : GTK_STOCK_GO_DOWN);
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_PRIMARY, NULL);
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (widget->entry), GTK_ENTRY_ICON_PRIMARY, NULL);
/* update completion (remove completed text of restart completion) */
- completion = gtk_entry_get_completion (GTK_ENTRY (window->entry));
+ completion = gtk_entry_get_completion (GTK_ENTRY (widget->entry));
if (completion != NULL)
- gtk_editable_delete_selection (GTK_EDITABLE (window->entry));
- gtk_entry_set_completion (GTK_ENTRY (window->entry), expanded ? NULL : window->completion);
- if (!expanded && gtk_entry_get_text_length (GTK_ENTRY (window->entry)) > 0)
- gtk_entry_completion_insert_prefix (window->completion);
+ gtk_editable_delete_selection (GTK_EDITABLE (widget->entry));
+ gtk_entry_set_completion (GTK_ENTRY (widget->entry), expanded ? NULL : widget->completion);
+ if (!expanded && gtk_entry_get_text_length (GTK_ENTRY (widget->entry)) > 0)
+ gtk_entry_completion_insert_prefix (widget->completion);
/* update state */
- xfce_appfinder_window_entry_changed (window);
- xfce_appfinder_window_item_changed (window);
+ xfce_appfinder_widget_entry_changed (widget);
+ xfce_appfinder_widget_item_changed (widget);
}
diff --git a/src/appfinder-widget.h b/src/appfinder-widget.h
index 95b935d..2a16dad 100644
--- a/src/appfinder-widget.h
+++ b/src/appfinder-widget.h
@@ -16,29 +16,31 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef __XFCE_APPFINDER_WINDOW_H__
-#define __XFCE_APPFINDER_WINDOW_H__
+#ifndef __XFCE_APPFINDER_WIDGET_H__
+#define __XFCE_APPFINDER_WIDGET_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
-typedef struct _XfceAppfinderWindowClass XfceAppfinderWindowClass;
-typedef struct _XfceAppfinderWindow XfceAppfinderWindow;
+typedef struct _XfceAppfinderWidgetClass XfceAppfinderWidgetClass;
+typedef struct _XfceAppfinderWidget XfceAppfinderWidget;
-#define XFCE_TYPE_APPFINDER_WINDOW (xfce_appfinder_window_get_type ())
-#define XFCE_APPFINDER_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_APPFINDER_WINDOW, XfceAppfinderWindow))
-#define XFCE_APPFINDER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_APPFINDER_WINDOW, XfceAppfinderWindowClass))
-#define XFCE_IS_APPFINDER_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_APPFINDER_WINDOW))
-#define XFCE_IS_APPFINDER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_APPFINDER_WINDOW))
-#define XFCE_APPFINDER_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_APPFINDER_WINDOW, XfceAppfinderWindowClass))
+#define XFCE_TYPE_APPFINDER_WIDGET (xfce_appfinder_widget_get_type ())
+#define XFCE_APPFINDER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_APPFINDER_WIDGET, XfceAppfinderWidget))
+#define XFCE_APPFINDER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_APPFINDER_WIDGET, XfceAppfinderWidgetClass))
+#define XFCE_IS_APPFINDER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_APPFINDER_WIDGET))
+#define XFCE_IS_APPFINDER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_APPFINDER_WIDGET))
+#define XFCE_APPFINDER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_APPFINDER_WIDGET, XfceAppfinderWidgetClass))
-GType xfce_appfinder_window_get_type (void) G_GNUC_CONST;
+GType xfce_appfinder_widget_get_type (void) G_GNUC_CONST;
-void xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window,
+void xfce_appfinder_widget_set_expanded (XfceAppfinderWidget *appfinder_widget,
gboolean expanded);
+void xfce_appfinder_widget_execute (XfceAppfinderWidget *appfinder_widget);
+void xfce_appfinder_widget_save_settings (XfceAppfinderWidget *widget);
G_END_DECLS
-#endif /* !__XFCE_APPFINDER_WINDOW_H__ */
+#endif /* !__XFCE_APPFINDER_WIDGET_H__ */
diff --git a/src/appfinder-window.c b/src/appfinder-window.c
index a57786d..ea5a397 100644
--- a/src/appfinder-window.c
+++ b/src/appfinder-window.c
@@ -33,6 +33,7 @@
#include <xfconf/xfconf.h>
#include <glib/gstdio.h>
+#include <src/appfinder-widget.h>
#include <src/appfinder-window.h>
#include <src/appfinder-model.h>
#include <src/appfinder-category-model.h>
@@ -51,62 +52,18 @@
#define DEFAULT_WINDOW_WIDTH 400
#define DEFAULT_WINDOW_HEIGHT 400
-#define DEFAULT_PANED_POSITION 180
-
static void xfce_appfinder_window_finalize (GObject *object);
static void xfce_appfinder_window_unmap (GtkWidget *widget);
-static gboolean xfce_appfinder_window_key_press_event (GtkWidget *widget,
- GdkEventKey *event);
-static void xfce_appfinder_window_view (XfceAppfinderWindow *window);
-static gboolean xfce_appfinder_window_popup_menu (GtkWidget *view,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_set_padding (GtkWidget *entry,
- GtkWidget *align);
-static gboolean xfce_appfinder_window_completion_match_func (GtkEntryCompletion *completion,
- const gchar *key,
- GtkTreeIter *iter,
- gpointer data);
-static void xfce_appfinder_window_entry_changed (XfceAppfinderWindow *window);
-static void xfce_appfinder_window_entry_activate (GtkEditable *entry,
- XfceAppfinderWindow *window);
-static gboolean xfce_appfinder_window_entry_key_press_event (GtkWidget *entry,
- GdkEventKey *event,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_entry_icon_released (GtkEntry *entry,
- GtkEntryIconPosition icon_pos,
- GdkEvent *event,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_drag_begin (GtkWidget *widget,
- GdkDragContext *drag_context,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_drag_data_get (GtkWidget *widget,
- GdkDragContext *drag_context,
- GtkSelectionData *data,
- guint info,
- guint drag_time,
- XfceAppfinderWindow *window);
-static gboolean xfce_appfinder_window_treeview_key_press_event (GtkWidget *widget,
- GdkEventKey *event,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_category_changed (GtkTreeSelection *selection,
- XfceAppfinderWindow *window);
-static void xfce_appfinder_window_category_set_categories (XfceAppfinderModel *model,
- XfceAppfinderWindow *window);
static void xfce_appfinder_window_preferences (GtkWidget *button,
XfceAppfinderWindow *window);
-static void xfce_appfinder_window_property_changed (XfconfChannel *channel,
- const gchar *prop,
- const GValue *value,
- XfceAppfinderWindow *window);
-static gboolean xfce_appfinder_window_item_visible (GtkTreeModel *model,
- GtkTreeIter *iter,
+static void xfce_appfinder_window_expansion_changed (XfceAppfinderWidget *appfinder_widget,
+ gboolean expanded,
+ gpointer data);
+static void xfce_appfinder_window_selection_changed (XfceAppfinderWidget *appfinder_widget,
+ gboolean selected,
gpointer data);
-static void xfce_appfinder_window_item_changed (XfceAppfinderWindow *window);
-static void xfce_appfinder_window_row_activated (XfceAppfinderWindow *window);
-static void xfce_appfinder_window_icon_theme_changed (XfceAppfinderWindow *window);
-static void xfce_appfinder_window_execute (XfceAppfinderWindow *window);
@@ -119,24 +76,9 @@ struct _XfceAppfinderWindow
{
GtkWindow __parent__;
- XfceAppfinderModel *model;
-
- XfceAppfinderCategoryModel *category_model;
-
- XfceAppfinderActions *actions;
-
- GtkEntryCompletion *completion;
-
XfconfChannel *channel;
- GtkWidget *paned;
- GtkWidget *entry;
- GtkWidget *image;
- GtkWidget *view;
- GtkWidget *viewscroll;
- GtkWidget *sidepane;
-
- GdkPixbuf *icon_find;
+ GtkWidget *appfinder_widget;
GtkWidget *bbox;
GtkWidget *button_launch;
@@ -144,24 +86,10 @@ struct _XfceAppfinderWindow
GtkWidget *bin_collapsed;
GtkWidget *bin_expanded;
- GarconMenuDirectory *filter_category;
- gchar *filter_text;
-
- guint idle_entry_changed_id;
-
gint last_window_height;
-
- gulong property_watch_id;
- gulong categories_changed_id;
-};
-
-static const GtkTargetEntry target_list[] =
-{
- { "text/uri-list", 0, 0 }
+ gboolean expanded;
};
-
-
G_DEFINE_TYPE (XfceAppfinderWindow, xfce_appfinder_window, GTK_TYPE_WINDOW)
@@ -177,7 +105,6 @@ xfce_appfinder_window_class_init (XfceAppfinderWindowClass *klass)
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->unmap = xfce_appfinder_window_unmap;
- gtkwidget_class->key_press_event = xfce_appfinder_window_key_press_event;
}
@@ -185,34 +112,18 @@ xfce_appfinder_window_class_init (XfceAppfinderWindowClass *klass)
static void
xfce_appfinder_window_init (XfceAppfinderWindow *window)
{
- GtkWidget *vbox, *vbox2;
- GtkWidget *entry;
- GtkWidget *pane;
- GtkWidget *scroll;
- GtkWidget *sidepane;
+ GtkWidget *vbox;
GtkWidget *image;
GtkWidget *hbox;
- GtkWidget *align;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkTreeSelection *selection;
GtkWidget *bbox;
GtkWidget *button;
- GtkEntryCompletion *completion;
- GtkIconTheme *icon_theme;
gint integer;
+ window->expanded = TRUE;
+
window->channel = xfconf_channel_get ("xfce4-appfinder");
window->last_window_height = xfconf_channel_get_int (window->channel, "/last/window-height", DEFAULT_WINDOW_HEIGHT);
- window->category_model = xfce_appfinder_category_model_new ();
- xfconf_g_property_bind (window->channel, "/category-icon-size", G_TYPE_UINT,
- G_OBJECT (window->category_model), "icon-size");
-
- window->model = xfce_appfinder_model_get ();
- xfconf_g_property_bind (window->channel, "/item-icon-size", G_TYPE_UINT,
- G_OBJECT (window->model), "icon-size");
-
gtk_window_set_title (GTK_WINDOW (window), _("Application Finder"));
integer = xfconf_channel_get_int (window->channel, "/last/window-width", DEFAULT_WINDOW_WIDTH);
gtk_window_set_default_size (GTK_WINDOW (window), integer, -1);
@@ -221,128 +132,30 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
if (xfconf_channel_get_bool (window->channel, "/always-center", FALSE))
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
- vbox = gtk_vbox_new (FALSE, 6);
+ vbox = gtk_vbox_new (FALSE, 10);
gtk_container_add (GTK_CONTAINER (window), vbox);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 7);
gtk_widget_show (vbox);
- hbox = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
- gtk_widget_show (hbox);
+ window->appfinder_widget = g_object_new (XFCE_TYPE_APPFINDER_WIDGET,
+ NULL);
- align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
- gtk_box_pack_start (GTK_BOX (hbox), align, FALSE, FALSE, 0);
- gtk_widget_show (align);
-
- window->icon_find = xfce_appfinder_model_load_pixbuf (GTK_STOCK_FIND, XFCE_APPFINDER_ICON_SIZE_48);
- window->image = image = gtk_image_new_from_pixbuf (window->icon_find);
- gtk_container_add (GTK_CONTAINER (align), image);
- gtk_widget_show (image);
-
- vbox2 = gtk_vbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
- gtk_widget_show (vbox2);
-
- align = gtk_alignment_new (0.0, 0.0, 1.0, 0.0);
- gtk_box_pack_start (GTK_BOX (vbox2), align, TRUE, TRUE, 0);
- gtk_widget_show (align);
-
- window->entry = entry = gtk_entry_new ();
- gtk_container_add (GTK_CONTAINER (align), entry);
- g_signal_connect (G_OBJECT (entry), "icon-release",
- G_CALLBACK (xfce_appfinder_window_entry_icon_released), window);
- g_signal_connect (G_OBJECT (entry), "realize",
- G_CALLBACK (xfce_appfinder_window_set_padding), align);
- g_signal_connect_swapped (G_OBJECT (entry), "changed",
- G_CALLBACK (xfce_appfinder_window_entry_changed), window);
- g_signal_connect (G_OBJECT (entry), "activate",
- G_CALLBACK (xfce_appfinder_window_entry_activate), window);
- g_signal_connect (G_OBJECT (entry), "key-press-event",
- G_CALLBACK (xfce_appfinder_window_entry_key_press_event), window);
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
- GTK_ENTRY_ICON_SECONDARY,
- GTK_STOCK_GO_DOWN);
- gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
- GTK_ENTRY_ICON_SECONDARY,
- _("Toggle view mode"));
- gtk_widget_show (entry);
-
- window->completion = completion = gtk_entry_completion_new ();
- gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (window->model));
- gtk_entry_completion_set_match_func (completion, xfce_appfinder_window_completion_match_func, window, NULL);
- gtk_entry_completion_set_text_column (completion, XFCE_APPFINDER_MODEL_COLUMN_COMMAND);
- gtk_entry_completion_set_popup_completion (completion, TRUE);
- gtk_entry_completion_set_popup_single_match (completion, FALSE);
- gtk_entry_completion_set_inline_completion (completion, TRUE);
-
- window->bin_collapsed = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_box_pack_start (GTK_BOX (vbox2), window->bin_collapsed, FALSE, TRUE, 0);
- gtk_widget_show (window->bin_collapsed);
-
- window->paned = pane = gtk_hpaned_new ();
- gtk_box_pack_start (GTK_BOX (vbox), pane, TRUE, TRUE, 0);
- integer = xfconf_channel_get_int (window->channel, "/last/pane-position", DEFAULT_PANED_POSITION);
- gtk_paned_set_position (GTK_PANED (pane), integer);
- g_object_set (G_OBJECT (pane), "position-set", TRUE, NULL);
-
- scroll = gtk_scrolled_window_new (NULL, NULL);
- gtk_paned_add1 (GTK_PANED (pane), scroll);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
- gtk_widget_show (scroll);
-
- sidepane = window->sidepane = gtk_tree_view_new_with_model (GTK_TREE_MODEL (window->category_model));
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (sidepane), FALSE);
- gtk_tree_view_set_enable_search (GTK_TREE_VIEW (sidepane), FALSE);
- g_signal_connect_swapped (G_OBJECT (sidepane), "start-interactive-search",
- G_CALLBACK (gtk_widget_grab_focus), entry);
- g_signal_connect (G_OBJECT (sidepane), "key-press-event",
- G_CALLBACK (xfce_appfinder_window_treeview_key_press_event), window);
- gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (sidepane),
- xfce_appfinder_category_model_row_separator_func, NULL, NULL);
- gtk_container_add (GTK_CONTAINER (scroll), sidepane);
- gtk_widget_show (sidepane);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sidepane));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
- g_signal_connect (G_OBJECT (selection), "changed",
- G_CALLBACK (xfce_appfinder_window_category_changed), window);
-
- column = gtk_tree_view_column_new ();
- gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
- gtk_tree_view_append_column (GTK_TREE_VIEW (sidepane), GTK_TREE_VIEW_COLUMN (column));
-
- renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, FALSE);
- gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
- "pixbuf", XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_ICON, NULL);
-
- renderer = gtk_cell_renderer_text_new ();
- g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE);
- gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
- "text", XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_NAME, NULL);
-
- window->viewscroll = scroll = gtk_scrolled_window_new (NULL, NULL);
- gtk_paned_add2 (GTK_PANED (pane), scroll);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
- gtk_widget_show (scroll);
-
- /* set the icon or tree view */
- xfce_appfinder_window_view (window);
-
- window->bin_expanded = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_box_pack_start (GTK_BOX (vbox), window->bin_expanded, FALSE, TRUE, 0);
- gtk_widget_show (window->bin_expanded);
+ gtk_box_pack_start (GTK_BOX (vbox), window->appfinder_widget, TRUE, TRUE, 0);
+ gtk_widget_show (window->appfinder_widget);
+
+ g_signal_connect_swapped (G_OBJECT(window->appfinder_widget), "destroy",
+ G_CALLBACK(gtk_widget_destroy), window);
window->bbox = hbox = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
gtk_widget_show (hbox);
window->button_preferences = button = gtk_button_new_from_stock (GTK_STOCK_PREFERENCES);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (xfce_appfinder_window_preferences), window);
+ g_signal_connect (G_OBJECT(window->appfinder_widget), "expansion-changed",
+ G_CALLBACK(xfce_appfinder_window_expansion_changed), button);
bbox = gtk_hbutton_box_new ();
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
@@ -359,29 +172,15 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
window->button_launch = button = gtk_button_new_with_mnemonic ("La_unch");
gtk_container_add (GTK_CONTAINER (bbox), button);
g_signal_connect_swapped (G_OBJECT (button), "clicked",
- G_CALLBACK (xfce_appfinder_window_execute), window);
+ G_CALLBACK (xfce_appfinder_widget_execute), window->appfinder_widget);
gtk_widget_set_sensitive (button, FALSE);
gtk_widget_show (button);
+ g_signal_connect (G_OBJECT(window->appfinder_widget), "selection-changed",
+ G_CALLBACK(xfce_appfinder_window_selection_changed), button);
image = gtk_image_new_from_stock (GTK_STOCK_EXECUTE, GTK_ICON_SIZE_BUTTON);
gtk_button_set_image (GTK_BUTTON (button), image);
- icon_theme = gtk_icon_theme_get_for_screen (gtk_window_get_screen (GTK_WINDOW (window)));
- g_signal_connect_swapped (G_OBJECT (icon_theme), "changed",
- G_CALLBACK (xfce_appfinder_window_icon_theme_changed), window);
-
- /* load categories in the model */
- xfce_appfinder_window_category_set_categories (NULL, window);
- window->categories_changed_id =
- g_signal_connect (G_OBJECT (window->model), "categories-changed",
- G_CALLBACK (xfce_appfinder_window_category_set_categories),
- window);
-
- /* monitor xfconf property changes */
- window->property_watch_id =
- g_signal_connect (G_OBJECT (window->channel), "property-changed",
- G_CALLBACK (xfce_appfinder_window_property_changed), window);
-
APPFINDER_DEBUG ("constructed window");
}
@@ -390,26 +189,6 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
static void
xfce_appfinder_window_finalize (GObject *object)
{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (object);
-
- if (window->idle_entry_changed_id != 0)
- g_source_remove (window->idle_entry_changed_id);
-
- g_signal_handler_disconnect (window->channel, window->property_watch_id);
- g_signal_handler_disconnect (window->model, window->categories_changed_id);
-
- g_object_unref (G_OBJECT (window->model));
- g_object_unref (G_OBJECT (window->category_model));
- g_object_unref (G_OBJECT (window->completion));
- g_object_unref (G_OBJECT (window->icon_find));
-
- if (window->actions != NULL)
- g_object_unref (G_OBJECT (window->actions));
-
- if (window->filter_category != NULL)
- g_object_unref (G_OBJECT (window->filter_category));
- g_free (window->filter_text);
-
(*G_OBJECT_CLASS (xfce_appfinder_window_parent_class)->finalize) (object);
}
@@ -420,881 +199,19 @@ xfce_appfinder_window_unmap (GtkWidget *widget)
{
XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (widget);
gint width, height;
- gint position;
- position = gtk_paned_get_position (GTK_PANED (window->paned));
+ xfce_appfinder_widget_save_settings (XFCE_APPFINDER_WIDGET (window->appfinder_widget));
+
gtk_window_get_size (GTK_WINDOW (window), &width, &height);
- if (!gtk_widget_get_visible (window->paned))
+ if (!window->expanded)
height = window->last_window_height;
(*GTK_WIDGET_CLASS (xfce_appfinder_window_parent_class)->unmap) (widget);
xfconf_channel_set_int (window->channel, "/last/window-height", height);
xfconf_channel_set_int (window->channel, "/last/window-width", width);
- xfconf_channel_set_int (window->channel, "/last/pane-position", position);
-}
-
-
-
-static gboolean
-xfce_appfinder_window_key_press_event (GtkWidget *widget,
- GdkEventKey *event)
-{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (widget);
- GtkWidget *entry;
- XfceAppfinderIconSize icon_size = XFCE_APPFINDER_ICON_SIZE_DEFAULT_ITEM;
-
- if (event->keyval == GDK_Escape)
- {
- gtk_widget_destroy (widget);
- return TRUE;
- }
- else if ((event->state & GDK_CONTROL_MASK) != 0)
- {
- switch (event->keyval)
- {
- case GDK_l:
- entry = XFCE_APPFINDER_WINDOW (widget)->entry;
-
- gtk_widget_grab_focus (entry);
- gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
-
- return TRUE;
-
- case GDK_1:
- case GDK_2:
- /* toggle between icon and tree view */
- xfconf_channel_set_bool (window->channel, "/icon-view",
- event->keyval == GDK_1);
- return TRUE;
-
- case GDK_plus:
- case GDK_minus:
- case GDK_KP_Add:
- case GDK_KP_Subtract:
- g_object_get (G_OBJECT (window->model), "icon-size", &icon_size, NULL);
- if ((event->keyval == GDK_plus || event->keyval == GDK_KP_Add))
- {
- if (icon_size < XFCE_APPFINDER_ICON_SIZE_LARGEST)
- icon_size++;
- }
- else if (icon_size > XFCE_APPFINDER_ICON_SIZE_SMALLEST)
- {
- icon_size--;
- }
-
- case GDK_0:
- case GDK_KP_0:
- g_object_set (G_OBJECT (window->model), "icon-size", icon_size, NULL);
- return TRUE;
- }
- }
-
- return (*GTK_WIDGET_CLASS (xfce_appfinder_window_parent_class)->key_press_event) (widget, event);
-}
-
-
-
-static void
-xfce_appfinder_window_set_item_width (XfceAppfinderWindow *window)
-{
- gint width;
- XfceAppfinderIconSize icon_size;
- GtkOrientation item_orientation = GTK_ORIENTATION_VERTICAL;
- GList *renderers;
- GList *li;
-
- appfinder_return_if_fail (GTK_IS_ICON_VIEW (window->view));
-
- g_object_get (G_OBJECT (window->model), "icon-size", &icon_size, NULL);
-
- /* some hard-coded values for the cell size that seem to work fine */
- switch (icon_size)
- {
- case XFCE_APPFINDER_ICON_SIZE_SMALLEST:
- width = 16 * 3.75;
- break;
-
- case XFCE_APPFINDER_ICON_SIZE_SMALLER:
- width = 24 * 3;
- break;
-
- case XFCE_APPFINDER_ICON_SIZE_SMALL:
- width = 36 * 2.5;
- break;
-
- case XFCE_APPFINDER_ICON_SIZE_NORMAL:
- width = 48 * 2;
- break;
-
- case XFCE_APPFINDER_ICON_SIZE_LARGE:
- width = 64 * 1.5;
- break;
-
- case XFCE_APPFINDER_ICON_SIZE_LARGER:
- width = 96 * 1.75;
- break;
-
- case XFCE_APPFINDER_ICON_SIZE_LARGEST:
- width = 128 * 1.25;
- break;
- }
-
- if (xfconf_channel_get_bool (window->channel, "/text-beside-icons", FALSE))
- {
- item_orientation = GTK_ORIENTATION_HORIZONTAL;
- width *= 2;
- }
-
-#if GTK_CHECK_VERSION (2, 22, 0)
- gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (window->view), item_orientation);
-#else
- gtk_icon_view_set_orientation (GTK_ICON_VIEW (window->view), item_orientation);
-#endif
- gtk_icon_view_set_item_width (GTK_ICON_VIEW (window->view), width);
-
- if (item_orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- /* work around the yalign = 0.0 gtk uses */
- renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (window->view));
- for (li = renderers; li != NULL; li = li->next)
- g_object_set (li->data, "yalign", 0.5, NULL);
- g_list_free (renderers);
- }
-}
-
-
-
-static gboolean
-xfce_appfinder_window_view_button_press_event (GtkWidget *widget,
- GdkEventButton *event,
- XfceAppfinderWindow *window)
-{
- gint x, y;
- GtkTreePath *path;
- gboolean have_selection = FALSE;
-
- if (event->button == 3
- && event->type == GDK_BUTTON_PRESS)
- {
- if (GTK_IS_TREE_VIEW (widget))
- {
- gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW (widget),
- event->x, event->y, &x, &y);
-
- if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), x, y, &path, NULL, NULL, NULL))
- {
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (widget), path, NULL, FALSE);
- gtk_tree_path_free (path);
- have_selection = TRUE;
- }
- }
- else
- {
- path = gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (widget), event->x, event->y);
- if (path != NULL)
- {
- gtk_icon_view_select_path (GTK_ICON_VIEW (widget), path);
- gtk_icon_view_set_cursor (GTK_ICON_VIEW (widget), path, NULL, FALSE);
- gtk_tree_path_free (path);
- have_selection = TRUE;
- }
- }
-
- if (have_selection)
- return xfce_appfinder_window_popup_menu (widget, window);
- }
-
- return FALSE;
-}
-
-
-
-static void
-xfce_appfinder_window_view (XfceAppfinderWindow *window)
-{
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkTreeModel *filter_model;
- GtkTreeSelection *selection;
- GtkWidget *view;
- gboolean icon_view;
-
- icon_view = xfconf_channel_get_bool (window->channel, "/icon-view", FALSE);
- if (window->view != NULL)
- {
- if (icon_view && GTK_IS_ICON_VIEW (window->view))
- return;
- gtk_widget_destroy (window->view);
- }
-
- filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (window->model), NULL);
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model), xfce_appfinder_window_item_visible, window, NULL);
-
- if (icon_view)
- {
- window->view = view = gtk_icon_view_new_with_model (filter_model);
- gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (view), GTK_SELECTION_BROWSE);
- gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (view), XFCE_APPFINDER_MODEL_COLUMN_ICON);
- gtk_icon_view_set_text_column (GTK_ICON_VIEW (view), XFCE_APPFINDER_MODEL_COLUMN_TITLE);
- gtk_icon_view_set_tooltip_column (GTK_ICON_VIEW (view), XFCE_APPFINDER_MODEL_COLUMN_TOOLTIP);
- xfce_appfinder_window_set_item_width (window);
-
- g_signal_connect_swapped (G_OBJECT (view), "selection-changed",
- G_CALLBACK (xfce_appfinder_window_item_changed), window);
- g_signal_connect_swapped (G_OBJECT (view), "item-activated",
- G_CALLBACK (xfce_appfinder_window_row_activated), window);
- }
- else
- {
- window->view = view = gtk_tree_view_new_with_model (filter_model);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
- gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), FALSE);
- gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (view), XFCE_APPFINDER_MODEL_COLUMN_TOOLTIP);
- g_signal_connect_swapped (G_OBJECT (view), "row-activated",
- G_CALLBACK (xfce_appfinder_window_row_activated), window);
- g_signal_connect_swapped (G_OBJECT (view), "start-interactive-search",
- G_CALLBACK (gtk_widget_grab_focus), window->entry);
- g_signal_connect (G_OBJECT (view), "key-press-event",
- G_CALLBACK (xfce_appfinder_window_treeview_key_press_event), window);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
- g_signal_connect_swapped (G_OBJECT (selection), "changed",
- G_CALLBACK (xfce_appfinder_window_item_changed), window);
-
- column = gtk_tree_view_column_new ();
- gtk_tree_view_column_set_spacing (column, 2);
- gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), GTK_TREE_VIEW_COLUMN (column));
-
- renderer = gtk_cell_renderer_pixbuf_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, FALSE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
- "pixbuf", XFCE_APPFINDER_MODEL_COLUMN_ICON, NULL);
-
- renderer = gtk_cell_renderer_text_new ();
- g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
- "markup", XFCE_APPFINDER_MODEL_COLUMN_ABSTRACT, NULL);
- }
-
- gtk_drag_source_set (view, GDK_BUTTON1_MASK, target_list,
- G_N_ELEMENTS (target_list), GDK_ACTION_COPY);
- g_signal_connect (G_OBJECT (view), "drag-begin",
- G_CALLBACK (xfce_appfinder_window_drag_begin), window);
- g_signal_connect (G_OBJECT (view), "drag-data-get",
- G_CALLBACK (xfce_appfinder_window_drag_data_get), window);
- g_signal_connect (G_OBJECT (view), "popup-menu",
- G_CALLBACK (xfce_appfinder_window_popup_menu), window);
- g_signal_connect (G_OBJECT (view), "button-press-event",
- G_CALLBACK (xfce_appfinder_window_view_button_press_event), window);
- gtk_container_add (GTK_CONTAINER (window->viewscroll), view);
- gtk_widget_show (view);
-
- g_object_unref (G_OBJECT (filter_model));
-}
-
-
-
-static gboolean
-xfce_appfinder_window_view_get_selected (XfceAppfinderWindow *window,
- GtkTreeModel **model,
- GtkTreeIter *iter)
-{
- GtkTreeSelection *selection;
- gboolean have_iter;
- GList *items;
-
- appfinder_return_val_if_fail (XFCE_IS_APPFINDER_WINDOW (window), FALSE);
- appfinder_return_val_if_fail (model != NULL, FALSE);
- appfinder_return_val_if_fail (iter != NULL, FALSE);
-
- if (GTK_IS_TREE_VIEW (window->view))
- {
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (window->view));
- have_iter = gtk_tree_selection_get_selected (selection, model, iter);
- }
- else
- {
- items = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (window->view));
- appfinder_assert (g_list_length (items) <= 1);
- if (items != NULL)
- {
- *model = gtk_icon_view_get_model (GTK_ICON_VIEW (window->view));
- have_iter = gtk_tree_model_get_iter (*model, iter, items->data);
-
- gtk_tree_path_free (items->data);
- g_list_free (items);
- }
- else
- {
- have_iter = FALSE;
- }
- }
-
- return have_iter;
-}
-
-
-
-static void
-xfce_appfinder_window_popup_menu_edit (GtkWidget *mi,
- XfceAppfinderWindow *window)
-{
- GError *error = NULL;
- gchar *cmd;
- const gchar *uri;
- GtkWidget *menu = gtk_widget_get_parent (mi);
-
- appfinder_return_if_fail (GTK_IS_MENU (menu));
- appfinder_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window));
-
- uri = g_object_get_data (G_OBJECT (menu), "uri");
- if (G_LIKELY (uri != NULL))
- {
- cmd = g_strdup_printf ("exo-desktop-item-edit --xid=0x%x '%s'",
- APPFINDER_WIDGET_XID (window), uri);
- if (!g_spawn_command_line_async (cmd, &error))
- {
- xfce_dialog_show_error (GTK_WINDOW (window), error,
- _("Failed to launch desktop item editor"));
- g_error_free (error);
- }
- g_free (cmd);
- }
-}
-
-
-
-static void
-xfce_appfinder_window_popup_menu_revert (GtkWidget *mi,
- XfceAppfinderWindow *window)
-{
- const gchar *uri;
- const gchar *name;
- GError *error;
- GtkWidget *menu = gtk_widget_get_parent (mi);
-
- appfinder_return_if_fail (GTK_IS_MENU (menu));
- appfinder_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window));
-
- name = g_object_get_data (G_OBJECT (menu), "name");
- if (name == NULL)
- return;
-
- if (xfce_dialog_confirm (GTK_WINDOW (window), GTK_STOCK_REVERT_TO_SAVED, NULL,
- _("This will permanently remove the custom desktop file from your home directory."),
- _("Are you sure you want to revert \"%s\"?"), name))
- {
- uri = g_object_get_data (G_OBJECT (menu), "uri");
- if (uri != NULL)
- {
- if (g_unlink (uri + 7) == -1)
- {
- error = g_error_new (G_FILE_ERROR, g_file_error_from_errno (errno),
- "%s: %s", uri + 7, g_strerror (errno));
- xfce_dialog_show_error (GTK_WINDOW (window), error,
- _("Failed to remove desktop file"));
- g_error_free (error);
- }
- }
- }
-}
-
-
-
-static void
-xfce_appfinder_window_popup_menu_hide (GtkWidget *mi,
- XfceAppfinderWindow *window)
-{
- const gchar *uri;
- const gchar *name;
- GtkWidget *menu = gtk_widget_get_parent (mi);
- gchar *path;
- gchar *message;
- gchar **dirs;
- guint i;
- const gchar *relpath;
- XfceRc *rc;
-
- appfinder_return_if_fail (GTK_IS_MENU (menu));
- appfinder_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window));
-
- name = g_object_get_data (G_OBJECT (menu), "name");
- if (name == NULL)
- return;
-
- path = xfce_resource_save_location (XFCE_RESOURCE_DATA, "applications/", FALSE);
- /* I18N: the first %s will be replace with users' applications directory, the
- * second with Hidden=true */
- message = g_strdup_printf (_("To unhide the item you have to manually "
- "remove the desktop file from \"%s\" or "
- "open the file in the same directory and "
- "remove the line \"%s\"."), path, "Hidden=true");
-
- if (xfce_dialog_confirm (GTK_WINDOW (window), NULL, _("_Hide"), message,
- _("Are you sure you want to hide \"%s\"?"), name))
- {
- uri = g_object_get_data (G_OBJECT (menu), "uri");
- if (uri != NULL)
- {
- /* lookup the correct relative path */
- dirs = xfce_resource_lookup_all (XFCE_RESOURCE_DATA, "applications/");
- for (i = 0; dirs[i] != NULL; i++)
- {
- if (g_str_has_prefix (uri + 7, dirs[i]))
- {
- /* relative path to XFCE_RESOURCE_DATA */
- relpath = uri + 7 + strlen (dirs[i]) - 13;
-
- /* xfcerc can handle everything else */
- rc = xfce_rc_config_open (XFCE_RESOURCE_DATA, relpath, FALSE);
- xfce_rc_set_group (rc, G_KEY_FILE_DESKTOP_GROUP);
- xfce_rc_write_bool_entry (rc, G_KEY_FILE_DESKTOP_KEY_HIDDEN, TRUE);
- xfce_rc_close (rc);
-
- break;
- }
- }
- g_strfreev (dirs);
- }
- }
-
- g_free (path);
- g_free (message);
-}
-
-
-
-static gboolean
-xfce_appfinder_window_popup_menu (GtkWidget *view,
- XfceAppfinderWindow *window)
-{
- GtkWidget *menu;
- GtkTreeModel *model;
- GtkTreeIter iter;
- gchar *title;
- gchar *uri;
- GtkWidget *mi;
- gchar *path;
- gboolean uri_is_local;
-
- if (xfce_appfinder_window_view_get_selected (window, &model, &iter))
- {
- gtk_tree_model_get (model, &iter,
- XFCE_APPFINDER_MODEL_COLUMN_TITLE, &title,
- XFCE_APPFINDER_MODEL_COLUMN_URI, &uri, -1);
-
- uri_is_local = g_str_has_prefix (uri, "file://");
-
- menu = gtk_menu_new ();
- g_object_set_data_full (G_OBJECT (menu), "uri", uri, g_free);
- g_object_set_data_full (G_OBJECT (menu), "name", title, g_free);
- g_signal_connect (G_OBJECT (menu), "selection-done",
- G_CALLBACK (gtk_widget_destroy), NULL);
-
- mi = gtk_menu_item_new_with_label (title);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- gtk_widget_set_sensitive (mi, FALSE);
- gtk_widget_show (mi);
-
- mi = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- gtk_widget_show (mi);
-
- mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_EDIT, NULL);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- g_signal_connect (G_OBJECT (mi), "activate",
- G_CALLBACK (xfce_appfinder_window_popup_menu_edit), window);
- gtk_widget_show (mi);
-
- mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_REVERT_TO_SAVED, NULL);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- g_signal_connect (G_OBJECT (mi), "activate",
- G_CALLBACK (xfce_appfinder_window_popup_menu_revert), window);
- path = xfce_resource_save_location (XFCE_RESOURCE_DATA, "applications/", FALSE);
- gtk_widget_set_sensitive (mi, uri_is_local && g_str_has_prefix (uri + 7, path));
- gtk_widget_show (mi);
- g_free (path);
-
- mi = gtk_image_menu_item_new_with_mnemonic (_("_Hide"));
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- gtk_widget_set_sensitive (mi, uri_is_local);
- g_signal_connect (G_OBJECT (mi), "activate",
- G_CALLBACK (xfce_appfinder_window_popup_menu_hide), window);
- gtk_widget_show (mi);
-
- gtk_menu_popup (GTK_MENU (menu),
- NULL, NULL, NULL, NULL, 3,
- gtk_get_current_event_time ());
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-
-
-static void
-xfce_appfinder_window_update_image (XfceAppfinderWindow *window,
- GdkPixbuf *pixbuf)
-{
- if (pixbuf == NULL)
- pixbuf = window->icon_find;
-
- /* gtk doesn't check this */
- if (gtk_image_get_pixbuf (GTK_IMAGE (window->image)) != pixbuf)
- gtk_image_set_from_pixbuf (GTK_IMAGE (window->image), pixbuf);
-}
-
-
-
-static void
-xfce_appfinder_window_set_padding (GtkWidget *entry,
- GtkWidget *align)
-{
- gint padding;
-
- /* 48 is the icon size of XFCE_APPFINDER_ICON_SIZE_48 */
- padding = (48 - entry->allocation.height) / 2;
- gtk_alignment_set_padding (GTK_ALIGNMENT (align), MAX (0, padding), 0, 0, 0);
-}
-
-
-
-static gboolean
-xfce_appfinder_window_completion_match_func (GtkEntryCompletion *completion,
- const gchar *key,
- GtkTreeIter *iter,
- gpointer data)
-{
- const gchar *text;
-
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);
-
- appfinder_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
- appfinder_return_val_if_fail (XFCE_IS_APPFINDER_WINDOW (data), FALSE);
- appfinder_return_val_if_fail (GTK_TREE_MODEL (window->model)
- == gtk_entry_completion_get_model (completion), FALSE);
-
- /* don't use the casefolded key generated by gtk */
- text = gtk_entry_get_text (GTK_ENTRY (window->entry));
-
- return xfce_appfinder_model_get_visible_command (window->model, iter, text);
-}
-
-
-
-static gboolean
-xfce_appfinder_window_entry_changed_idle (gpointer data)
-{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);
- const gchar *text;
- GdkPixbuf *pixbuf;
- gchar *normalized;
- GtkTreeModel *model;
-
- GDK_THREADS_ENTER ();
-
- text = gtk_entry_get_text (GTK_ENTRY (window->entry));
-
- if (gtk_widget_get_visible (window->paned))
- {
- g_free (window->filter_text);
-
- if (IS_STRING (text))
- {
- normalized = g_utf8_normalize (text, -1, G_NORMALIZE_ALL);
- window->filter_text = g_utf8_casefold (normalized, -1);
- g_free (normalized);
- }
- else
- {
- window->filter_text = NULL;
- }
-
- APPFINDER_DEBUG ("refilter entry");
- if (GTK_IS_TREE_VIEW (window->view))
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (window->view));
- else
- model = gtk_icon_view_get_model (GTK_ICON_VIEW (window->view));
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
- }
- else
- {
- gtk_widget_set_sensitive (window->button_launch, IS_STRING (text));
-
- pixbuf = xfce_appfinder_model_get_icon_for_command (window->model, text);
- xfce_appfinder_window_update_image (window, pixbuf);
- if (pixbuf != NULL)
- g_object_unref (G_OBJECT (pixbuf));
- }
- GDK_THREADS_LEAVE ();
-
- return FALSE;
-}
-
-
-
-static void
-xfce_appfinder_window_entry_changed_idle_destroyed (gpointer data)
-{
- XFCE_APPFINDER_WINDOW (data)->idle_entry_changed_id = 0;
-}
-
-
-
-static void
-xfce_appfinder_window_entry_changed (XfceAppfinderWindow *window)
-{
- if (window->idle_entry_changed_id != 0)
- g_source_remove (window->idle_entry_changed_id);
-
- window->idle_entry_changed_id =
- g_idle_add_full (G_PRIORITY_DEFAULT, xfce_appfinder_window_entry_changed_idle,
- window, xfce_appfinder_window_entry_changed_idle_destroyed);
-}
-
-
-
-static void
-xfce_appfinder_window_entry_activate (GtkEditable *entry,
- XfceAppfinderWindow *window)
-{
- GtkTreePath *path;
-
- if (gtk_widget_get_visible (window->paned))
- {
- if (GTK_IS_TREE_VIEW (window->view))
- {
- if (gtk_tree_view_get_visible_range (GTK_TREE_VIEW (window->view), &path, NULL))
- {
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (window->view), path, NULL, FALSE);
- gtk_tree_path_free (path);
- }
- }
- else if (gtk_icon_view_get_visible_range (GTK_ICON_VIEW (window->view), &path, NULL))
- {
- gtk_icon_view_select_path (GTK_ICON_VIEW (window->view), path);
- gtk_icon_view_set_cursor (GTK_ICON_VIEW (window->view), path, NULL, FALSE);
- gtk_tree_path_free (path);
- }
-
- gtk_widget_grab_focus (window->view);
- }
- else if (gtk_widget_get_sensitive (window->button_launch))
- {
- gtk_button_clicked (GTK_BUTTON (window->button_launch));
- }
-}
-
-
-
-static gboolean
-xfce_appfinder_window_entry_key_press_event (GtkWidget *entry,
- GdkEventKey *event,
- XfceAppfinderWindow *window)
-{
- gboolean expand, is_expanded;
-
- if (event->keyval == GDK_Up || event->keyval == GDK_Down)
- {
- expand = (event->keyval == GDK_Down);
- is_expanded = gtk_widget_get_visible (window->paned);
- if (is_expanded != expand)
- {
- /* don't break entry completion navigation in collapsed mode */
- if (!is_expanded
- && gdk_pointer_is_grabbed ())
- return FALSE;
-
- xfce_appfinder_window_set_expanded (window, expand);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
-
-static void
-xfce_appfinder_window_drag_begin (GtkWidget *widget,
- GdkDragContext *drag_context,
- XfceAppfinderWindow *window)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
- GdkPixbuf *pixbuf;
-
- if (xfce_appfinder_window_view_get_selected (window, &model, &iter))
- {
- gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_ICON_LARGE, &pixbuf, -1);
- if (G_LIKELY (pixbuf != NULL))
- {
- gtk_drag_set_icon_pixbuf (drag_context, pixbuf, 0, 0);
- g_object_unref (G_OBJECT (pixbuf));
- }
- }
- else
- {
- gtk_drag_set_icon_stock (drag_context, GTK_STOCK_DIALOG_ERROR, 0, 0);
- }
-}
-
-
-
-static void
-xfce_appfinder_window_drag_data_get (GtkWidget *widget,
- GdkDragContext *drag_context,
- GtkSelectionData *data,
- guint info,
- guint drag_time,
- XfceAppfinderWindow *window)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
- gchar *uris[2];
-
- if (xfce_appfinder_window_view_get_selected (window, &model, &iter))
- {
- uris[1] = NULL;
- gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_URI, &uris[0], -1);
- gtk_selection_data_set_uris (data, uris);
- g_free (uris[0]);
- }
-}
-
-
-
-static gboolean
-xfce_appfinder_window_treeview_key_press_event (GtkWidget *widget,
- GdkEventKey *event,
- XfceAppfinderWindow *window)
-{
- if (widget == window->view)
- {
- if (event->keyval == GDK_Left)
- {
- gtk_widget_grab_focus (window->sidepane);
- return TRUE;
- }
- }
- else if (widget == window->sidepane)
- {
- if (event->keyval == GDK_Right)
- {
- gtk_widget_grab_focus (window->view);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
-
-static void
-xfce_appfinder_window_entry_icon_released (GtkEntry *entry,
- GtkEntryIconPosition icon_pos,
- GdkEvent *event,
- XfceAppfinderWindow *window)
-{
- if (icon_pos == GTK_ENTRY_ICON_SECONDARY)
- xfce_appfinder_window_set_expanded (window, !gtk_widget_get_visible (window->paned));
-}
-
-
-
-static void
-xfce_appfinder_window_category_changed (GtkTreeSelection *selection,
- XfceAppfinderWindow *window)
-{
- GtkTreeIter iter;
- GtkTreeModel *model;
- GarconMenuDirectory *category;
- gchar *name;
-
- if (gtk_tree_selection_get_selected (selection, &model, &iter))
- {
- gtk_tree_model_get (model, &iter,
- XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_DIRECTORY, &category,
- XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_NAME, &name, -1);
-
- if (window->filter_category != category)
- {
- if (window->filter_category != NULL)
- g_object_unref (G_OBJECT (window->filter_category));
-
- if (category == NULL)
- window->filter_category = NULL;
- else
- window->filter_category = g_object_ref (G_OBJECT (category));
-
- APPFINDER_DEBUG ("refilter category");
-
- /* update visible items */
- if (GTK_IS_TREE_VIEW (window->view))
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (window->view));
- else
- model = gtk_icon_view_get_model (GTK_ICON_VIEW (window->view));
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
-
- /* store last category */
- if (xfconf_channel_get_bool (window->channel, "/remember-category", FALSE))
- xfconf_channel_set_string (window->channel, "/last/category", name);
- }
-
- g_free (name);
- if (category != NULL)
- g_object_unref (G_OBJECT (category));
- }
-}
-
-
-
-static void
-xfce_appfinder_window_category_set_categories (XfceAppfinderModel *signal_from_model,
- XfceAppfinderWindow *window)
-{
- GSList *categories;
- GtkTreePath *path;
- gchar *name = NULL;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkTreeSelection *selection;
-
- appfinder_return_if_fail (GTK_IS_TREE_VIEW (window->sidepane));
-
- if (signal_from_model != NULL)
- {
- /* reload from the model, make sure we restore the selected category */
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (window->sidepane));
- if (gtk_tree_selection_get_selected (selection, &model, &iter))
- gtk_tree_model_get (model, &iter, XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_NAME, &name, -1);
- }
-
- /* update the categories */
- categories = xfce_appfinder_model_get_categories (window->model);
- if (categories != NULL)
- xfce_appfinder_category_model_set_categories (window->category_model, categories);
- g_slist_free (categories);
-
- if (name == NULL && xfconf_channel_get_bool (window->channel, "/remember-category", FALSE))
- name = xfconf_channel_get_string (window->channel, "/last/category", NULL);
-
- path = xfce_appfinder_category_model_find_category (window->category_model, name);
- if (path != NULL)
- {
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (window->sidepane), path, NULL, FALSE);
- gtk_tree_path_free (path);
- }
-
- g_free (name);
+ APPFINDER_DEBUG ("unmapped window");
}
@@ -1306,230 +223,19 @@ xfce_appfinder_window_preferences (GtkWidget *button,
appfinder_return_if_fail (GTK_IS_WIDGET (button));
/* preload the actions, to make sure there are default values */
- if (window->actions == NULL)
- window->actions = xfce_appfinder_actions_get ();
+ //if (window->actions == NULL)
+ // window->actions = xfce_appfinder_actions_get ();
xfce_appfinder_preferences_show (gtk_widget_get_screen (button));
}
-
static void
-xfce_appfinder_window_property_changed (XfconfChannel *channel,
- const gchar *prop,
- const GValue *value,
- XfceAppfinderWindow *window)
-{
- appfinder_return_if_fail (XFCE_IS_APPFINDER_WINDOW (window));
- appfinder_return_if_fail (window->channel == channel);
-
- if (g_strcmp0 (prop, "/icon-view") == 0)
- {
- xfce_appfinder_window_view (window);
- }
- else if (g_strcmp0 (prop, "/item-icon-size") == 0)
- {
- if (GTK_IS_ICON_VIEW (window->view))
- xfce_appfinder_window_set_item_width (window);
- }
- else if (g_strcmp0 (prop, "/text-beside-icons") == 0)
- {
- if (GTK_IS_ICON_VIEW (window->view))
- xfce_appfinder_window_set_item_width (window);
- }
-}
-
-
-
-static gboolean
-xfce_appfinder_window_item_visible (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);
-
- return xfce_appfinder_model_get_visible (XFCE_APPFINDER_MODEL (model), iter,
- window->filter_category, window->filter_text);
-}
-
-
-
-static void
-xfce_appfinder_window_item_changed (XfceAppfinderWindow *window)
-{
- GtkTreeIter iter;
- GtkTreeModel *model;
- gboolean can_launch;
- GdkPixbuf *pixbuf;
-
- if (gtk_widget_get_visible (window->paned))
- {
- can_launch = xfce_appfinder_window_view_get_selected (window, &model, &iter);
- gtk_widget_set_sensitive (window->button_launch, can_launch);
-
- if (can_launch)
- {
- gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_ICON_LARGE, &pixbuf, -1);
- if (G_LIKELY (pixbuf != NULL))
- {
- xfce_appfinder_window_update_image (window, pixbuf);
- g_object_unref (G_OBJECT (pixbuf));
- }
- }
- else
- {
- xfce_appfinder_window_update_image (window, NULL);
- }
- }
-}
-
-
-
-static void
-xfce_appfinder_window_row_activated (XfceAppfinderWindow *window)
-{
- if (gtk_widget_get_sensitive (window->button_launch))
- gtk_button_clicked (GTK_BUTTON (window->button_launch));
-}
-
-
-
-static void
-xfce_appfinder_window_icon_theme_changed (XfceAppfinderWindow *window)
-{
- if (window->icon_find != NULL)
- g_object_unref (G_OBJECT (window->icon_find));
- window->icon_find = xfce_appfinder_model_load_pixbuf (GTK_STOCK_FIND, XFCE_APPFINDER_ICON_SIZE_48);
-
- /* drop cached pixbufs */
- xfce_appfinder_model_icon_theme_changed (window->model);
- xfce_appfinder_category_model_icon_theme_changed (window->category_model);
-
- /* update state */
- xfce_appfinder_window_entry_changed (window);
- xfce_appfinder_window_item_changed (window);
-}
-
-
-
-static gboolean
-xfce_appfinder_window_execute_command (const gchar *text,
- GdkScreen *screen,
- XfceAppfinderWindow *window,
- gboolean *save_cmd,
- GError **error)
-{
- gboolean succeed = FALSE;
- gchar *action_cmd = NULL;
- gchar *expanded;
-
- appfinder_return_val_if_fail (error != NULL && *error == NULL, FALSE);
- appfinder_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
-
- if (!IS_STRING (text))
- return TRUE;
-
- if (window->actions == NULL)
- window->actions = xfce_appfinder_actions_get ();
-
- /* try to match a custom action */
- action_cmd = xfce_appfinder_actions_execute (window->actions, text, save_cmd, error);
- if (*error != NULL)
- return FALSE;
- else if (action_cmd != NULL)
- text = action_cmd;
-
- if (IS_STRING (text))
- {
- /* expand variables */
- expanded = xfce_expand_variables (text, NULL);
-
- /* spawn the command */
- APPFINDER_DEBUG ("spawn \"%s\"", expanded);
- succeed = xfce_spawn_command_line_on_screen (screen, expanded, FALSE, FALSE, error);
- g_free (expanded);
- }
-
- g_free (action_cmd);
-
- return succeed;
-}
-
-
-
-static void
-xfce_appfinder_window_execute (XfceAppfinderWindow *window)
-{
- GtkTreeModel *model;
- GtkTreeIter iter, orig;
- GError *error = NULL;
- gboolean result = FALSE;
- GdkScreen *screen;
- const gchar *text;
- gchar *cmd = NULL;
- gboolean regular_command = FALSE;
- gboolean save_cmd;
-
- if (!gtk_widget_get_sensitive (window->button_launch))
- return;
-
- screen = gtk_window_get_screen (GTK_WINDOW (window));
- if (gtk_widget_get_visible (window->paned))
- {
- if (xfce_appfinder_window_view_get_selected (window, &model, &iter))
- {
- gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &orig, &iter);
- result = xfce_appfinder_model_execute (window->model, &orig, screen, ®ular_command, &error);
-
- if (!result && regular_command)
- {
- gtk_tree_model_get (model, &iter, XFCE_APPFINDER_MODEL_COLUMN_COMMAND, &cmd, -1);
- result = xfce_appfinder_window_execute_command (cmd, screen, window, NULL, &error);
- g_free (cmd);
- }
- }
- }
- else
- {
- text = gtk_entry_get_text (GTK_ENTRY (window->entry));
- save_cmd = TRUE;
-
- if (xfce_appfinder_window_execute_command (text, screen, window, &save_cmd, &error))
- {
- if (save_cmd)
- result = xfce_appfinder_model_save_command (window->model, text, &error);
- else
- result = TRUE;
- }
- }
-
- gtk_entry_set_icon_from_stock (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_PRIMARY,
- result ? NULL : GTK_STOCK_DIALOG_ERROR);
- gtk_entry_set_icon_tooltip_text (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_PRIMARY,
- error != NULL ? error->message : NULL);
-
- if (error != NULL)
- {
- g_warning ("Failed to execute: %s", error->message);
- g_error_free (error);
- }
-
- if (result)
- gtk_widget_destroy (GTK_WIDGET (window));
-}
-
-
-
-void
-xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window,
- gboolean expanded)
+xfce_appfinder_window_update_size (XfceAppfinderWindow *window,
+ gboolean expanded)
{
GdkGeometry hints;
gint width;
- GtkWidget *parent;
- GtkEntryCompletion *completion;
-
- APPFINDER_DEBUG ("set expand = %s", expanded ? "true" : "false");
/* force window geomentry */
if (expanded)
@@ -1547,38 +253,38 @@ xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window,
hints.max_width = G_MAXINT;
gtk_window_set_geometry_hints (GTK_WINDOW (window), NULL, &hints, GDK_HINT_MAX_SIZE);
}
+}
- /* repack the button box */
- g_object_ref (G_OBJECT (window->bbox));
- parent = gtk_widget_get_parent (window->bbox);
- if (parent != NULL)
- gtk_container_remove (GTK_CONTAINER (parent), window->bbox);
- if (expanded)
- gtk_container_add (GTK_CONTAINER (window->bin_expanded), window->bbox);
- else
- gtk_container_add (GTK_CONTAINER (window->bin_collapsed), window->bbox);
- gtk_widget_set_visible (window->bin_expanded, expanded);
- gtk_widget_set_visible (window->bin_collapsed, !expanded);
+void
+xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window,
+ gboolean expanded)
+{
+ window->expanded = expanded;
+ xfce_appfinder_widget_set_expanded (XFCE_APPFINDER_WIDGET (window->appfinder_widget), expanded);
+ gtk_widget_set_visible (window->button_preferences, expanded);
+ xfce_appfinder_window_update_size (window, expanded);
+
+}
+
+static void
+xfce_appfinder_window_expansion_changed (XfceAppfinderWidget *appfinder_widget,
+ gboolean expanded,
+ gpointer data)
+{
+ XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);
+
+ window->expanded = expanded;
gtk_widget_set_visible (window->button_preferences, expanded);
- g_object_unref (G_OBJECT (window->bbox));
-
- /* show/hide pane with treeviews */
- gtk_widget_set_visible (window->paned, expanded);
-
- /* toggle icon */
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_SECONDARY,
- expanded ? GTK_STOCK_GO_UP : GTK_STOCK_GO_DOWN);
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_PRIMARY, NULL);
-
- /* update completion (remove completed text of restart completion) */
- completion = gtk_entry_get_completion (GTK_ENTRY (window->entry));
- if (completion != NULL)
- gtk_editable_delete_selection (GTK_EDITABLE (window->entry));
- gtk_entry_set_completion (GTK_ENTRY (window->entry), expanded ? NULL : window->completion);
- if (!expanded && gtk_entry_get_text_length (GTK_ENTRY (window->entry)) > 0)
- gtk_entry_completion_insert_prefix (window->completion);
-
- /* update state */
- xfce_appfinder_window_entry_changed (window);
- xfce_appfinder_window_item_changed (window);
+ xfce_appfinder_window_update_size (window, expanded);
+}
+
+
+static void
+xfce_appfinder_window_selection_changed (XfceAppfinderWidget *appfinder_widget,
+ gboolean selected,
+ gpointer data)
+{
+ GtkWidget *widget = GTK_WIDGET (data);
+
+ gtk_widget_set_sensitive (widget, selected);
}
More information about the Xfce4-commits
mailing list