[Xfce4-commits] <xfce4-panel:devel> * Make some more stuff work in the launcher dialogs.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:26:36 CEST 2009
Updating branch refs/heads/devel
to 029076f97cfa5ad498d025d6c2f787fe08263ea3 (commit)
from 706b00e6bb67ab6687252118aa492997af41d36a (commit)
commit 029076f97cfa5ad498d025d6c2f787fe08263ea3
Author: Nick Schermer <nick at xfce.org>
Date: Thu Jan 1 20:14:31 2009 +0100
* Make some more stuff work in the launcher dialogs.
configure.in.in | 9 +-
plugins/launcher/Makefile.am | 2 +
plugins/launcher/launcher-dialog.c | 206 ++++++++++++++++++++++++++++++--
plugins/launcher/launcher-dialog.glade | 50 +++++---
plugins/launcher/launcher-dialog.h | 4 +-
plugins/launcher/launcher.c | 3 +
6 files changed, 240 insertions(+), 34 deletions(-)
diff --git a/configure.in.in b/configure.in.in
index 7253310..66874b7 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -96,17 +96,18 @@ XDT_CHECK_LIBX11_REQUIRE()
dnl ***********************************
dnl *** Check for required packages ***
dnl ***********************************
-XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.5.90])
+XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.5.92])
+XDT_CHECK_PACKAGE([LIBXFCE4MENU], [libxfce4menu-0.1], [4.5.92])
+XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.5.0])
+XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.5.92])
+XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.90])
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.12.0])
XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.14.0])
XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.14.0])
XDT_CHECK_PACKAGE([GMODULE], [gmodule-2.0], [2.14.0])
-XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.5.0])
-XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.90])
XDT_CHECK_PACKAGE([DBUS], [dbus-glib-1], [0.34])
XDT_CHECK_PACKAGE([CAIRO], [cairo], [1.0.0])
XDT_CHECK_PACKAGE([LIBWNCK], [libwnck-1.0], [2.12])
-XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.5.91])
dnl ***********************************
dnl *** Check for optional packages ***
diff --git a/plugins/launcher/Makefile.am b/plugins/launcher/Makefile.am
index c420ecf..5feff27 100644
--- a/plugins/launcher/Makefile.am
+++ b/plugins/launcher/Makefile.am
@@ -29,6 +29,7 @@ liblauncher_la_CFLAGS = \
$(GTK_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
+ $(LIBXFCE4MENU_CFLAGS) \
$(EXO_CFLAGS) \
$(XFCONF_CFLAGS) \
$(LIBSTARTUP_NOTIFICATION_CFLAGS) \
@@ -45,6 +46,7 @@ liblauncher_la_LIBADD = \
$(GTK_LIBS) \
$(LIBXFCE4UTIL_LIBS) \
$(LIBXFCE4UI_LIBS) \
+ $(LIBXFCE4MENU_LIBS) \
$(EXO_LIBS) \
$(XFCONF_LIBS) \
$(LIBSTARTUP_NOTIFICATION_LIBS)
diff --git a/plugins/launcher/launcher-dialog.c b/plugins/launcher/launcher-dialog.c
index c358fef..0f8b384 100644
--- a/plugins/launcher/launcher-dialog.c
+++ b/plugins/launcher/launcher-dialog.c
@@ -19,8 +19,14 @@
#include <config.h>
#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
#include <exo/exo.h>
#include <libxfce4ui/libxfce4ui.h>
+#include <libxfce4menu/libxfce4menu.h>
+#include <common/panel-private.h>
#include "launcher.h"
#include "launcher-dialog.h"
@@ -28,6 +34,146 @@
+static gboolean
+launcher_dialog_add_visible_function (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ gchar *name;
+ gboolean visible = FALSE;
+ const gchar *text;
+ gchar *normalized;
+ gchar *text_casefolded;
+ gchar *name_casefolded;
+
+ /* get the search string from the entry */
+ text = gtk_entry_get_text (GTK_ENTRY (user_data));
+ if (G_UNLIKELY (!IS_STRING (text)))
+ return TRUE;
+
+ /* casefold the search text */
+ normalized = g_utf8_normalize (text, -1, G_NORMALIZE_ALL);
+ text_casefolded = g_utf8_casefold (normalized, -1);
+ g_free (normalized);
+
+ gtk_tree_model_get (model, iter, 0, &name, -1);
+ if (G_LIKELY (name != NULL))
+ {
+ /* casefold the name */
+ normalized = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
+ name_casefolded = g_utf8_casefold (normalized, -1);
+ g_free (normalized);
+
+ /* search */
+ visible = (strstr (name_casefolded, text_casefolded) != NULL);
+
+ /* cleanup */
+ g_free (name);
+ g_free (name_casefolded);
+ }
+
+ /* cleanup */
+ g_free (text_casefolded);
+
+ return visible;
+}
+
+
+
+static void
+launcher_dialog_add_store_append (GtkListStore *store,
+ XfceMenu *menu)
+{
+ GSList *items, *lp;
+ guint i;
+
+ if (G_UNLIKELY (xfce_menu_has_layout (menu)))
+ {
+ items = xfce_menu_get_layout_elements (menu);
+ }
+ else
+ {
+ items = xfce_menu_get_menus (menu);
+ items = g_slist_concat (items, xfce_menu_get_items (menu));
+ }
+
+ for (lp = items, i = 0; lp != NULL; lp = g_slist_next (lp))
+ {
+ if (XFCE_IS_MENU_ITEM (lp->data))
+ {
+ /* insert the item */
+ gtk_list_store_insert_with_values (store, NULL, i++, 0, xfce_menu_item_get_name (lp->data), -1);
+ }
+ else if (XFCE_IS_MENU (lp->data))
+ {
+ /* append the sub items in the store */
+ launcher_dialog_add_store_append (store, XFCE_MENU (lp->data));
+ }
+ }
+
+ /* free the list */
+ g_slist_free (items);
+}
+
+
+
+static gboolean
+launcher_dialog_add_populate_model_idle (gpointer user_data)
+{
+ GtkListStore *store = GTK_LIST_STORE (user_data);
+ XfceMenu *root;
+ GError *error = NULL;
+
+ panel_return_val_if_fail (GTK_IS_LIST_STORE (store), FALSE);
+
+ /* initialize the menu library */
+ /* TODO */
+ xfce_menu_init (NULL);
+
+ GDK_THREADS_ENTER ();
+
+ /* get the root menu */
+ root = xfce_menu_get_root (&error);
+ if (G_LIKELY (root != NULL))
+ {
+ /* start appending items in the store */
+ launcher_dialog_add_store_append (store, root);
+
+ /* release the root menu */
+ g_object_unref (G_OBJECT (root));
+ }
+ else
+ {
+ /* TODO make this a warning dialog or something */
+ g_message ("Failed to load the root menu: %s", error->message);
+ g_error_free (error);
+ }
+
+ GDK_THREADS_LEAVE ();
+
+ return FALSE;
+}
+
+
+
+static void
+launcher_dialog_add_populate_model (GtkBuilder *builder)
+{
+ GObject *store;
+
+ panel_return_if_fail (GTK_IS_BUILDER (builder));
+
+ /* get the store and make sure it's empty */
+ store = gtk_builder_get_object (builder, "add-store");
+ gtk_list_store_clear (GTK_LIST_STORE (store));
+
+ /* fire an idle menu system load */
+ /* TODO finish this */
+ g_idle_add (launcher_dialog_add_populate_model_idle, store);
+}
+
+
+
static void
launcher_dialog_tree_selection_changed (GtkTreeSelection *selection,
GtkBuilder *builder)
@@ -61,9 +207,9 @@ launcher_dialog_tree_selection_changed (GtkTreeSelection *selection,
object = gtk_builder_get_object (builder, "entry-move-down");
gtk_widget_set_sensitive (GTK_WIDGET (object), n_children > position);
-
+
object = gtk_builder_get_object (builder, "entry-edit");
- gtk_widget_set_sensitive (GTK_WIDGET (object), position >= 0);
+ gtk_widget_set_sensitive (GTK_WIDGET (object), position >= 0 /* TODO custom only */);
}
@@ -73,7 +219,8 @@ launcher_dialog_entry_button_clicked (GtkWidget *button,
GtkBuilder *builder)
{
const gchar *name;
- GObject *dialog;
+ GObject *object;
+ GtkWidget *dialog;
panel_return_if_fail (GTK_IS_BUILDABLE (button));
panel_return_if_fail (GTK_IS_BUILDER (builder));
@@ -83,12 +230,29 @@ launcher_dialog_entry_button_clicked (GtkWidget *button,
if (exo_str_is_equal (name, "entry-add"))
{
- dialog = gtk_builder_get_object (builder, "dialog-add");
- gtk_widget_show (GTK_WIDGET (dialog));
+ object = gtk_builder_get_object (builder, "dialog-add");
+ launcher_dialog_add_populate_model (builder);
+ gtk_widget_show (GTK_WIDGET (object));
}
else if (exo_str_is_equal (name, "entry-remove"))
{
+ /* create question dialog */
+ dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (button)),
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
+ GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
+ _("Are you sure you want to remove \"%s\"?"), "TODO");
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+
+ /* run the dialog */
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+
+ }
+ /* destroy */
+ gtk_widget_destroy (dialog);
}
else if (exo_str_is_equal (name, "entry-move-up"))
{
@@ -100,8 +264,8 @@ launcher_dialog_entry_button_clicked (GtkWidget *button,
}
else /* entry-edit */
{
- dialog = gtk_builder_get_object (builder, "dialog-editor");
- gtk_widget_show (GTK_WIDGET (dialog));
+ object = gtk_builder_get_object (builder, "dialog-editor");
+ gtk_widget_show (GTK_WIDGET (object));
}
}
@@ -127,6 +291,7 @@ launcher_dialog_response (GtkWidget *dialog,
}
+
static void
launcher_dialog_editor_response (GtkWidget *dialog,
gint response_id,
@@ -135,6 +300,7 @@ launcher_dialog_editor_response (GtkWidget *dialog,
panel_return_if_fail (GTK_IS_DIALOG (dialog));
panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
+ /* hide the dialog, since it's owned by gtkbuilder */
gtk_widget_hide (dialog);
}
@@ -148,6 +314,7 @@ launcher_dialog_add_response (GtkWidget *dialog,
panel_return_if_fail (GTK_IS_DIALOG (dialog));
panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
+ /* hide the dialog, since it's owned by gtkbuilder */
gtk_widget_hide (dialog);
}
@@ -158,7 +325,7 @@ launcher_dialog_show (LauncherPlugin *plugin)
{
GtkBuilder *builder;
GObject *dialog;
- GObject *object;
+ GObject *object, *entry;
guint i;
GtkTreeSelection *selection;
const gchar *entry_names[] = { "entry-add", "entry-remove", "entry-move-up", "entry-move-down", "entry-edit" };
@@ -204,16 +371,25 @@ launcher_dialog_show (LauncherPlugin *plugin)
object = gtk_builder_get_object (builder, "arrow-position");
xfconf_g_property_bind (plugin->channel, "/arrow-position", G_TYPE_UINT, object, "active");
-
+
/* setup responses for the other dialogs */
object = gtk_builder_get_object (builder, "dialog-editor");
g_signal_connect (G_OBJECT (object), "response", G_CALLBACK (launcher_dialog_editor_response), plugin);
g_signal_connect (G_OBJECT (object), "delete-event", G_CALLBACK (exo_noop_true), NULL);
-
+
object = gtk_builder_get_object (builder, "dialog-add");
g_signal_connect (G_OBJECT (object), "response", G_CALLBACK (launcher_dialog_add_response), plugin);
g_signal_connect (G_OBJECT (object), "delete-event", G_CALLBACK (exo_noop_true), NULL);
+ object = gtk_builder_get_object (builder, "add-store");
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (object), 0, GTK_SORT_ASCENDING);
+
+ /* setup search filter in the add dialog */
+ object = gtk_builder_get_object (builder, "add-store-filter");
+ entry = gtk_builder_get_object (builder, "add-search");
+ gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (object), launcher_dialog_add_visible_function, entry, NULL);
+ g_signal_connect_swapped (G_OBJECT (entry), "changed", G_CALLBACK (gtk_tree_model_filter_refilter), object);
+
/* show the dialog */
gtk_widget_show (GTK_WIDGET (dialog));
}
@@ -224,3 +400,13 @@ launcher_dialog_show (LauncherPlugin *plugin)
panel_assert_not_reached ();
}
}
+
+
+
+void
+launcher_dialog_menu_shutdown (void)
+{
+ /* decrease counter and unload library */
+ /* TODO */
+ //xfce_menu_shutdown ();
+}
diff --git a/plugins/launcher/launcher-dialog.glade b/plugins/launcher/launcher-dialog.glade
index 374f6d3..0740111 100644
--- a/plugins/launcher/launcher-dialog.glade
+++ b/plugins/launcher/launcher-dialog.glade
@@ -29,6 +29,15 @@
</row>
</data>
</object>
+ <object class="GtkListStore" id="add-store">
+ <columns>
+ <!-- column-name name -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
+ <object class="GtkTreeModelFilter" id="add-store-filter">
+ <property name="child_model">add-store</property>
+ </object>
<object class="XfceTitledDialog" id="dialog">
<property name="title" translatable="yes">Launcher Properties</property>
<property name="default_width">350</property>
@@ -249,7 +258,6 @@
<property name="visible">True</property>
<property name="label" translatable="yes">_Arrow button position:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">arrow-position</property>
</object>
<packing>
<property name="expand">False</property>
@@ -259,7 +267,6 @@
<child>
<object class="GtkComboBox" id="arrow-position">
<property name="visible">True</property>
- <property name="model">arrow-position-store</property>
<property name="button_sensitivity">on</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
@@ -349,7 +356,6 @@
<property name="destroy_with_parent">True</property>
<property name="icon_name">applications-other</property>
<property name="type_hint">normal</property>
- <property name="transient_for">dialog</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox3">
@@ -369,7 +375,6 @@
<property name="xalign">0</property>
<property name="label" translatable="yes">_Name:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">entry-name</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
@@ -382,7 +387,6 @@
<property name="xalign">0</property>
<property name="label" translatable="yes">C_omment:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">entry-description</property>
</object>
<packing>
<property name="top_attach">1</property>
@@ -397,7 +401,6 @@
<property name="xalign">0</property>
<property name="label" translatable="yes">_Working Directory:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">entry-working-directory</property>
</object>
<packing>
<property name="top_attach">4</property>
@@ -445,7 +448,7 @@
<object class="GtkFileChooserButton" id="entry-working-directory">
<property name="visible">True</property>
<property name="action">select-folder</property>
- <property name="title" translatable="yes">Select A Working Directory</property>
+ <property name="title" translatable="yes">Select a Working Directory</property>
</object>
<packing>
<property name="left_attach">1</property>
@@ -641,7 +644,6 @@
<property name="destroy_with_parent">True</property>
<property name="icon_name">gtk-add</property>
<property name="type_hint">normal</property>
- <property name="transient_for">dialog</property>
<property name="has_separator">False</property>
<property name="subtitle" translatable="yes">Add a new or custom launcher entry</property>
<child internal-child="vbox">
@@ -663,7 +665,6 @@
<property name="xalign">1</property>
<property name="label" translatable="yes">_Search:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">add-search</property>
</object>
<packing>
<property name="position">0</property>
@@ -696,6 +697,21 @@
<object class="GtkTreeView" id="add-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="model">add-store-filter</property>
+ <property name="headers_visible">False</property>
+ <property name="rules_hint">True</property>
+ <property name="enable_search">False</property>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <property name="title">Icon</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
@@ -713,7 +729,7 @@
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="button5">
+ <object class="GtkButton" id="button-add">
<property name="label" translatable="yes">gtk-add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -725,12 +741,14 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="button6">
+ <object class="GtkButton" id="button-custom">
<property name="label" translatable="yes">C_ustom</property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">image1</property>
+ <property name="use_underline">True</property>
</object>
<packing>
<property name="position">1</property>
@@ -758,8 +776,8 @@
</object>
</child>
<action-widgets>
- <action-widget response="2">button5</action-widget>
- <action-widget response="3">button6</action-widget>
+ <action-widget response="2">button-add</action-widget>
+ <action-widget response="3">button-custom</action-widget>
<action-widget response="0">button7</action-widget>
</action-widgets>
</object>
@@ -768,10 +786,4 @@
<property name="stock">gtk-new</property>
<property name="icon-size">4</property>
</object>
- <object class="GtkSizeGroup" id="sizegroup1">
- <property name="mode">both</property>
- <widgets>
- <widget name="entry-iconn"/>
- </widgets>
- </object>
</interface>
diff --git a/plugins/launcher/launcher-dialog.h b/plugins/launcher/launcher-dialog.h
index f5bef00..90d7b67 100644
--- a/plugins/launcher/launcher-dialog.h
+++ b/plugins/launcher/launcher-dialog.h
@@ -20,6 +20,8 @@
#include "launcher.h"
-void launcher_dialog_show (LauncherPlugin *plugin);
+void launcher_dialog_show (LauncherPlugin *plugin);
+
+void launcher_dialog_menu_shutdown (void);
#endif /* !__XFCE_LAUNCHER_DIALOG_H__ */
diff --git a/plugins/launcher/launcher.c b/plugins/launcher/launcher.c
index 1b94842..0ea44fd 100644
--- a/plugins/launcher/launcher.c
+++ b/plugins/launcher/launcher.c
@@ -321,6 +321,9 @@ launcher_plugin_free_data (XfcePanelPlugin *panel_plugin)
/* shutdown xfconf */
xfconf_shutdown ();
+
+ /* shutdown the menu if needed */
+ launcher_dialog_menu_shutdown ();
/* stop popup timeout */
if (G_UNLIKELY (plugin->popup_timeout_id))
More information about the Xfce4-commits
mailing list