From 83d942948f8e46ce3f8e100ab3cfb746608af0df Mon Sep 17 00:00:00 2001 From: Andre Miranda Date: Thu, 12 Oct 2017 16:30:27 -0300 Subject: [PATCH] Add single window option --- src/appfinder-preferences.c | 65 ++++++++++++++++++++++++++--------------- src/appfinder-preferences.glade | 18 ++++++++++++ src/main.c | 11 ++++++- 3 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/appfinder-preferences.c b/src/appfinder-preferences.c index e3cd0c6..2ccdf65 100644 --- a/src/appfinder-preferences.c +++ b/src/appfinder-preferences.c @@ -36,22 +36,24 @@ -static void xfce_appfinder_preferences_response (GtkWidget *window, - gint response_id, - XfceAppfinderPreferences *preferences); -static void xfce_appfinder_preferences_beside_sensitive (GtkWidget *show_icons, - GtkWidget *text_beside_icon); -static void xfce_appfinder_preferences_clear_history (XfceAppfinderPreferences *preferences); -static void xfce_appfinder_preferences_action_add (XfceAppfinderPreferences *preferences); -static void xfce_appfinder_preferences_action_remove (GtkWidget *button, - XfceAppfinderPreferences *preferences); -static void xfce_appfinder_preferences_action_changed (XfconfChannel *channel, - const gchar *prop_name, - const GValue *value, - XfceAppfinderPreferences *preferences); -static void xfce_appfinder_preferences_action_populate (XfceAppfinderPreferences *preferences); -static void xfce_appfinder_preferences_selection_changed (GtkTreeSelection *selection, - XfceAppfinderPreferences *preferences); +static void xfce_appfinder_preferences_response (GtkWidget *window, + gint response_id, + XfceAppfinderPreferences *preferences); +static void xfce_appfinder_preferences_beside_sensitive (GtkWidget *show_icons, + GtkWidget *text_beside_icon); +static void xfce_appfinder_preferences_single_window_sensitive (GtkWidget *keep_running, + GtkWidget *single_window); +static void xfce_appfinder_preferences_clear_history (XfceAppfinderPreferences *preferences); +static void xfce_appfinder_preferences_action_add (XfceAppfinderPreferences *preferences); +static void xfce_appfinder_preferences_action_remove (GtkWidget *button, + XfceAppfinderPreferences *preferences); +static void xfce_appfinder_preferences_action_changed (XfconfChannel *channel, + const gchar *prop_name, + const GValue *value, + XfceAppfinderPreferences *preferences); +static void xfce_appfinder_preferences_action_populate (XfceAppfinderPreferences *preferences); +static void xfce_appfinder_preferences_selection_changed (GtkTreeSelection *selection, + XfceAppfinderPreferences *preferences); @@ -96,9 +98,8 @@ xfce_appfinder_preferences_class_init (XfceAppfinderPreferencesClass *klass) static void xfce_appfinder_preferences_init (XfceAppfinderPreferences *preferences) { - GObject *object; + GObject *object, *previous; GtkTreePath *path; - GObject *icons; preferences->channel = xfconf_channel_get ("xfce4-appfinder"); @@ -119,21 +120,29 @@ xfce_appfinder_preferences_init (XfceAppfinderPreferences *preferences) xfconf_g_property_bind (preferences->channel, "/always-center", G_TYPE_BOOLEAN, G_OBJECT (object), "active"); - object = gtk_builder_get_object (GTK_BUILDER (preferences), "enable-service"); + previous = gtk_builder_get_object (GTK_BUILDER (preferences), "enable-service"); xfconf_g_property_bind (preferences->channel, "/enable-service", G_TYPE_BOOLEAN, + G_OBJECT (previous), "active"); + + object = gtk_builder_get_object (GTK_BUILDER (preferences), "single-window"); + xfconf_g_property_bind (preferences->channel, "/single-window", G_TYPE_BOOLEAN, G_OBJECT (object), "active"); - icons = gtk_builder_get_object (GTK_BUILDER (preferences), "icon-view"); + g_signal_connect (G_OBJECT (previous), "toggled", + G_CALLBACK (xfce_appfinder_preferences_single_window_sensitive), object); + xfce_appfinder_preferences_single_window_sensitive (GTK_WIDGET (previous), GTK_WIDGET (object)); + + previous = gtk_builder_get_object (GTK_BUILDER (preferences), "icon-view"); xfconf_g_property_bind (preferences->channel, "/icon-view", G_TYPE_BOOLEAN, - G_OBJECT (icons), "active"); + G_OBJECT (previous), "active"); object = gtk_builder_get_object (GTK_BUILDER (preferences), "text-beside-icons"); xfconf_g_property_bind (preferences->channel, "/text-beside-icons", G_TYPE_BOOLEAN, G_OBJECT (object), "active"); - g_signal_connect (G_OBJECT (icons), "toggled", + g_signal_connect (G_OBJECT (previous), "toggled", G_CALLBACK (xfce_appfinder_preferences_beside_sensitive), object); - xfce_appfinder_preferences_beside_sensitive (GTK_WIDGET (icons), GTK_WIDGET (object)); + xfce_appfinder_preferences_beside_sensitive (GTK_WIDGET (previous), GTK_WIDGET (object)); object = gtk_builder_get_object (GTK_BUILDER (preferences), "item-icon-size"); gtk_combo_box_set_active (GTK_COMBO_BOX (object), XFCE_APPFINDER_ICON_SIZE_DEFAULT_ITEM); @@ -209,6 +218,16 @@ xfce_appfinder_preferences_beside_sensitive (GtkWidget *show_icons, +static void +xfce_appfinder_preferences_single_window_sensitive (GtkWidget *keep_running, + GtkWidget *single_window) +{ + gtk_widget_set_sensitive (single_window, + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (keep_running))); +} + + + static void xfce_appfinder_preferences_clear_history (XfceAppfinderPreferences *preferences) { diff --git a/src/appfinder-preferences.glade b/src/appfinder-preferences.glade index 3f27320..cee55c1 100644 --- a/src/appfinder-preferences.glade +++ b/src/appfinder-preferences.glade @@ -194,6 +194,24 @@ 2 + + + Single window + False + True + True + False + When an instance is running in the background, only open one window at a time. + True + True + True + + + True + True + 3 + + diff --git a/src/main.c b/src/main.c index 1cd76f3..d81d233 100644 --- a/src/main.c +++ b/src/main.c @@ -178,6 +178,15 @@ appfinder_window_new (const gchar *startup_id, gboolean expanded) { GtkWidget *window; + XfconfChannel *channel; + + if (g_slist_length (windows) > 0) + { + channel = xfconf_channel_get ("xfce4-appfinder"); + if (xfconf_channel_get_bool (channel, "/single-window", FALSE)) + gtk_window_present (GTK_WINDOW (g_slist_nth_data (windows, 0))); + return; + } window = g_object_new (XFCE_TYPE_APPFINDER_WINDOW, "startup-id", IS_STRING (startup_id) ? startup_id : NULL, @@ -247,7 +256,7 @@ main (gint argc, gchar **argv) if (!opt_collapsed && strcmp (*argv, "xfrun4") == 0) opt_collapsed = TRUE; - /* become the serivce owner or ask the current + /* become the service owner or ask the current * owner to spawn an instance */ if (G_LIKELY (!opt_disable_server)) { -- 2.14.2