[Goodies-commits] r6586 - in xfce4-clipman-plugin/branches/xfce-4-6: . panel-plugin tests

Mike Massonnet mmassonnet at xfce.org
Wed Jan 28 16:05:53 CET 2009


Author: mmassonnet
Date: 2009-01-28 15:05:53 +0000 (Wed, 28 Jan 2009)
New Revision: 6586

Modified:
   xfce4-clipman-plugin/branches/xfce-4-6/ChangeLog
   xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/actions.c
   xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/actions.h
   xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/panel-plugin.c
   xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/settings-dialog.glade
   xfce4-clipman-plugin/branches/xfce-4-6/tests/test_actions.c
Log:
Actions are configurable through the settings dialog.

Modified: xfce4-clipman-plugin/branches/xfce-4-6/ChangeLog
===================================================================
--- xfce4-clipman-plugin/branches/xfce-4-6/ChangeLog	2009-01-28 00:28:28 UTC (rev 6585)
+++ xfce4-clipman-plugin/branches/xfce-4-6/ChangeLog	2009-01-28 15:05:53 UTC (rev 6586)
@@ -1,4 +1,24 @@
 2009-01-26	Mike Massonnet
+Actions are configurable through the settings dialog.
+
+	- panel-plugin/actions.c:
+		Fix a crasher in clipman_actions_load() when reading the XML
+		file from the user config directory.  Add debug messages when
+		loading and saving the XML file.
+	- panel-plugin/actions.c(clipman_actions_get_entries):
+		New method to retrieve the list of every acion.
+	- panel-plugin/actions.c(clipman_actions_remove_command):
+		Renamed the method clipman_actions_remove() to
+		clipman_actions_remove_command() and re-implement
+		clipman_actions_remove() to remove an entry entirely.
+	- panel-plugin/settings-dialog.glade:
+		Rename some widgets and add signal handlers.
+	- panel-plugin/panel-plugin.c:
+		Set up the actions dialog in panel_plugin_configure() and a
+		add a load of new callbacks and functions specific to the
+		settings dialog to add/edit/delete actions.
+
+2009-01-26	Mike Massonnet
 Small tweak in the GRegex.
 
 	- panel-plugin/actions.c(clipman_actions_add):

Modified: xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/actions.c
===================================================================
--- xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/actions.c	2009-01-28 00:28:28 UTC (rev 6585)
+++ xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/actions.c	2009-01-28 15:05:53 UTC (rev 6586)
@@ -448,6 +448,38 @@
  * clipman_actions_remove:
  * @actions:        a #ClipmanActions
  * @action_name:    the human readable name for the regex
+ *
+ * Removes a #ClipmanActionsEntry from the list of actions.
+ *
+ * Returns: FALSE if no action could be removed
+ */
+gboolean
+clipman_actions_remove (ClipmanActions *actions,
+                        const gchar *action_name)
+{
+  ClipmanActionsEntry *entry;
+  GSList *l;
+
+  l = g_slist_find_custom (actions->priv->entries, action_name, (GCompareFunc)__clipman_actions_entry_compare_name);
+  if (l == NULL)
+    {
+      g_warning ("No corresponding entry `%s'", action_name);
+      return FALSE;
+    }
+
+  DBG ("Drop the entry `%s'", action_name);
+
+  entry = l->data;
+  __clipman_actions_entry_free (entry);
+  actions->priv->entries = g_slist_delete_link (actions->priv->entries, l);
+
+  return TRUE;
+}
+
+/**
+ * clipman_actions_remove_command:
+ * @actions:        a #ClipmanActions
+ * @action_name:    the human readable name for the regex
  * @command_name:   the command to remove
  *
  * Removes a command from the list of actions.  If the command is the last
@@ -457,9 +489,9 @@
  * Returns: FALSE if no command could be removed
  */
 gboolean
-clipman_actions_remove (ClipmanActions *actions,
-                        const gchar *action_name,
-                        const gchar *command_name)
+clipman_actions_remove_command (ClipmanActions *actions,
+                                const gchar *action_name,
+                                const gchar *command_name)
 {
   ClipmanActionsEntry *entry;
   GSList *l;
@@ -467,7 +499,10 @@
 
   l = g_slist_find_custom (actions->priv->entries, action_name, (GCompareFunc)__clipman_actions_entry_compare_name);
   if (l == NULL)
-    return FALSE;
+    {
+      g_warning ("No corresponding entry `%s'", action_name);
+      return FALSE;
+    }
 
   entry = l->data;
   found = g_hash_table_remove (entry->commands, command_name);
@@ -489,6 +524,18 @@
 }
 
 /**
+ * clipman_actions_get_entries:
+ * @actions:    a #ClipmanActions
+ *
+ * Returns: a #const #GSList owned by #ClipmanActions
+ */
+const GSList *
+clipman_actions_get_entries (ClipmanActions *actions)
+{
+  return actions->priv->entries;
+}
+
+/**
  * clipman_actions_match:
  * @actions:    a #ClipmanActions
  * @text:       the text to match against the existing regex's
@@ -610,7 +657,7 @@
   EntryParser *parser;
 
   filename = g_strdup_printf ("%s/xfce4/panel/xfce4-clipman-actions.xml", g_get_user_config_dir ());
-  load = g_file_get_contents (filename, &data, NULL, NULL);
+  load = g_file_get_contents (filename, &data, &size, NULL);
 
   if (!load)
     {
@@ -622,6 +669,8 @@
   if (!load)
     g_warning ("Unable to load actions from an XML file");
 
+  DBG ("Load actions from file %s", filename);
+
   if (load)
     {
       parser = g_slice_new0 (EntryParser);
@@ -653,6 +702,7 @@
   gchar *tmp;
   GSList *l;
 
+  /* Generate the XML output format */
   output = g_string_new ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                          "<actions>\n");
 
@@ -706,6 +756,7 @@
 
   /* And now write output to the xml file */
   filename = g_strdup_printf ("%s/xfce4/panel/xfce4-clipman-actions.xml", g_get_user_config_dir ());
+  DBG ("Save actions to file %s", filename);
   data = g_string_free (output, FALSE);
   if (!g_file_set_contents (filename, data, -1, NULL))
     g_warning ("Unable to write the actions to the XML file %s", filename);

Modified: xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/actions.h
===================================================================
--- xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/actions.h	2009-01-28 00:28:28 UTC (rev 6585)
+++ xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/actions.h	2009-01-28 15:05:53 UTC (rev 6586)
@@ -74,8 +74,11 @@
                                                                 const gchar *command_name,
                                                                 const gchar *command);
 gboolean                clipman_actions_remove                 (ClipmanActions *actions,
+                                                                const gchar *action_name);
+gboolean                clipman_actions_remove_command         (ClipmanActions *actions,
                                                                 const gchar *action_name,
-                                                                const gchar *command);
+                                                                const gchar *command_name);
+const GSList *          clipman_actions_get_entries            (ClipmanActions *actions);
 GSList *                clipman_actions_match                  (ClipmanActions *actions,
                                                                 const gchar *match);
 void                    clipman_actions_match_with_menu        (ClipmanActions *actions,

Modified: xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/panel-plugin.c	2009-01-28 00:28:28 UTC (rev 6585)
+++ xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/panel-plugin.c	2009-01-28 15:05:53 UTC (rev 6586)
@@ -50,6 +50,7 @@
   ClipmanActions       *actions;
   ClipmanCollector     *collector;
   ClipmanHistory       *history;
+  GladeXML             *gxml;
   GtkWidget            *button;
   GtkWidget            *image;
   GtkWidget            *menu;
@@ -87,8 +88,41 @@
                                                          gboolean *push_in,
                                                          MyPlugin *plugin);
 
+/*
+ * Settings Dialog functions declarations
+ */
 
+static void             setup_actions_treeview          (GtkTreeView *treeview,
+                                                         MyPlugin *plugin);
+static void             refresh_actions_treeview        (GtkTreeView *treeview,
+                                                         MyPlugin *plugin);
+static void             apply_action                    (const gchar *original_action_name,
+                                                         MyPlugin *plugin);
+static void             cb_actions_selection_changed    (GtkTreeSelection *selection,
+                                                         MyPlugin *plugin);
+static void             cb_add_action                   (GtkButton *button,
+                                                         MyPlugin *plugin);
+static void             cb_edit_action                  (GtkButton *button,
+                                                         MyPlugin *plugin);
+static void             cb_actions_row_activated        (GtkTreeView *treeview,
+                                                         GtkTreePath *path,
+                                                         GtkTreeViewColumn *column,
+                                                         MyPlugin *plugin);
+static void             cb_delete_action                (GtkButton *button,
+                                                         MyPlugin *plugin);
+static void             setup_commands_treeview         (GtkTreeView *treeview,
+                                                         MyPlugin *plugin);
+static void             entry_dialog_cleanup            (GtkDialog *dialog,
+                                                         MyPlugin *plugin);
+static void             cb_commands_selection_changed   (GtkTreeSelection *selection,
+                                                         MyPlugin *plugin);
+static void             cb_add_command                  (GtkButton *button,
+                                                         MyPlugin *plugin);
+static void             cb_delete_command               (GtkButton *button,
+                                                         MyPlugin *plugin);
 
+
+
 /*
  * Panel Plugin functions
  */
@@ -188,44 +222,66 @@
 panel_plugin_configure (XfcePanelPlugin *panel_plugin,
                         MyPlugin *plugin)
 {
-  GladeXML *gxml;
   GtkWidget *dialog;
 
-  /* Get GladeXML and the dialog */
-  gxml = glade_xml_new_from_buffer (settings_dialog_glade, settings_dialog_glade_length, NULL, NULL);
-  dialog = glade_xml_get_widget (gxml, "settings-dialog");
+  /* GladeXML */
+  plugin->gxml = glade_xml_new_from_buffer (settings_dialog_glade, settings_dialog_glade_length, NULL, NULL);
+
+  /* Settings dialog */
+  dialog = glade_xml_get_widget (plugin->gxml, "settings-dialog");
   /* FIXME Doing this with Glade makes the panel button unclickable... but
    * still we need to destroy the dialog when the panel quits, so keep it. */
+  /* FIXME Now with the actions this bit is getting nastier... when the menu
+   * with actions should popup it is "hidden" while this dialog is shown. */
   gtk_window_set_transient_for (GTK_WINDOW (dialog),
                                 GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel_plugin))));
 
-  /* Set default values */
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "save-on-quit")),
+  /* General settings */
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "save-on-quit")),
                                 DEFAULT_SAVE_ON_QUIT);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "add-selections")),
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "add-selections")),
                                 DEFAULT_ADD_PRIMARY_CLIPBOARD);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "store-an-image")),
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "store-an-image")),
                                 (gboolean)DEFAULT_MAX_IMAGES_IN_HISTORY);
-  gtk_spin_button_set_value (GTK_SPIN_BUTTON (glade_xml_get_widget (gxml, "max-texts-in-history")),
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (glade_xml_get_widget (plugin->gxml, "max-texts-in-history")),
                              (gdouble)DEFAULT_MAX_TEXTS_IN_HISTORY);
 
-  /* Bind the Xfconf properties to the widgets */
   xfconf_g_property_bind (plugin->channel, "/settings/save-on-quit", G_TYPE_BOOLEAN,
-                          G_OBJECT (glade_xml_get_widget (gxml, "save-on-quit")), "active");
+                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "save-on-quit")), "active");
   xfconf_g_property_bind (plugin->channel, "/settings/add-primary-clipboard", G_TYPE_BOOLEAN,
-                          G_OBJECT (glade_xml_get_widget (gxml, "add-selections")), "active");
+                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "add-selections")), "active");
   xfconf_g_property_bind (plugin->channel, "/settings/max-images-in-history", G_TYPE_UINT,
-                          G_OBJECT (glade_xml_get_widget (gxml, "store-an-image")), "active");
+                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "store-an-image")), "active");
   xfconf_g_property_bind (plugin->channel, "/settings/max-texts-in-history", G_TYPE_UINT,
-                          G_OBJECT (glade_xml_get_widget (gxml, "max-texts-in-history")), "value");
+                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "max-texts-in-history")), "value");
 
+  /* Actions */
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "enable-actions")),
+                                DEFAULT_ENABLE_ACTIONS);
+  xfconf_g_property_bind (plugin->channel, "/settings/enable-actions", G_TYPE_BOOLEAN,
+                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "enable-actions")), "active");
+
+  glade_xml_signal_connect_data (plugin->gxml, "cb_add_action", G_CALLBACK (cb_add_action), plugin);
+  glade_xml_signal_connect_data (plugin->gxml, "cb_edit_action", G_CALLBACK (cb_edit_action), plugin);
+  glade_xml_signal_connect_data (plugin->gxml, "cb_delete_action", G_CALLBACK (cb_delete_action), plugin);
+  glade_xml_signal_connect_data (plugin->gxml, "cb_actions_row_activated", G_CALLBACK (cb_actions_row_activated), plugin);
+  glade_xml_signal_connect_data (plugin->gxml, "cb_add_command", G_CALLBACK (cb_add_command), plugin);
+  glade_xml_signal_connect_data (plugin->gxml, "cb_delete_command", G_CALLBACK (cb_delete_command), plugin);
+
+  setup_actions_treeview (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "actions")), plugin);
+  setup_commands_treeview (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")), plugin);
+
   /* Run the dialog */
   xfce_panel_plugin_block_menu (panel_plugin);
   gtk_dialog_run (GTK_DIALOG (dialog));
   xfce_panel_plugin_unblock_menu (panel_plugin);
 
   gtk_widget_destroy (dialog);
-  g_object_unref (gxml);
+  g_object_unref (plugin->gxml);
+  plugin->gxml = NULL;
+
+  /* Save the actions */
+  clipman_actions_save (plugin->actions);
 }
 
 static void
@@ -436,3 +492,332 @@
     }
 }
 
+/*
+ * Settings Dialog functions
+ */
+
+/* Actions */
+static void
+setup_actions_treeview (GtkTreeView *treeview,
+                        MyPlugin *plugin)
+{
+  GtkTreeSelection *selection;
+  GtkListStore *model;
+  GtkCellRenderer *cell;
+
+  /* Define the model */
+  model = gtk_list_store_new (3, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
+  gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
+  g_object_unref (model);
+
+  /* Define the columns */
+  cell = gtk_cell_renderer_pixbuf_new ();
+  /* TODO Drop the comment once the icon is supported */
+  //g_object_set (cell, "width", 32, "height", 32, NULL);
+  gtk_tree_view_insert_column_with_attributes (treeview, -1, "Icon", cell, "icon-name", 1, NULL);
+
+  cell = gtk_cell_renderer_text_new ();
+  g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  gtk_tree_view_insert_column_with_attributes (treeview, -1, "Action", cell, "markup", 2, NULL);
+
+  refresh_actions_treeview (treeview, plugin);
+
+  selection = gtk_tree_view_get_selection (treeview);
+  g_signal_connect (selection, "changed", G_CALLBACK (cb_actions_selection_changed), plugin);
+}
+
+static void
+refresh_actions_treeview (GtkTreeView *treeview,
+                          MyPlugin *plugin)
+{
+  ClipmanActionsEntry *entry;
+  const GSList *entries;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gchar *title;
+
+  model = gtk_tree_view_get_model (treeview);
+  gtk_list_store_clear (GTK_LIST_STORE (model));
+
+  entries = clipman_actions_get_entries (plugin->actions);
+  for (; entries != NULL; entries = entries->next)
+    {
+      entry = entries->data;
+
+      title = g_strdup_printf ("<b>%s</b>\n<small>%s</small>", entry->action_name, g_regex_get_pattern (entry->regex));
+      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+      gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, entry, 1, entry->icon_name, 2, title, -1);
+      g_free (title);
+    }
+}
+
+static void
+apply_action (const gchar *original_action_name,
+              MyPlugin *plugin)
+{
+  GtkWidget *treeview;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  const gchar *action_name;
+  const gchar *regex;
+  gchar *command_name;
+  gchar *command;
+
+  action_name = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "action-name")));
+  regex = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "regex")));
+
+  treeview = glade_xml_get_widget (plugin->gxml, "commands");
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_model_get_iter_first (model, &iter))
+    return;
+
+  /* Remove the old actions */
+  if (original_action_name != NULL)
+    clipman_actions_remove (plugin->actions, original_action_name);
+
+  /* Add the new actions */
+  do
+    {
+      gtk_tree_model_get (model, &iter, 1, &command_name, 2, &command, -1);
+      clipman_actions_add (plugin->actions, action_name, regex, command_name, command);
+      g_free (command_name);
+      g_free (command);
+    }
+  while (gtk_tree_model_iter_next (model, &iter));
+
+  /* Refresh the actions treeview */
+  treeview = glade_xml_get_widget (plugin->gxml, "actions");
+  refresh_actions_treeview (GTK_TREE_VIEW (treeview), plugin);
+}
+
+static void
+cb_actions_selection_changed (GtkTreeSelection *selection,
+                              MyPlugin *plugin)
+{
+  GtkTreeModel *model;
+  gboolean sensitive;
+
+  sensitive = gtk_tree_selection_get_selected (selection, &model, NULL);
+
+  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "button-edit-action"), sensitive);
+  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "button-delete-action"), sensitive);
+}
+
+static void
+cb_add_action (GtkButton *button,
+               MyPlugin *plugin)
+{
+  GtkWidget *dialog;
+  gint res;
+
+  dialog = glade_xml_get_widget (plugin->gxml, "entry-dialog");
+  entry_dialog_cleanup (GTK_DIALOG (dialog), plugin);
+
+  res = gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_hide (dialog);
+
+  if (res == 1)
+    apply_action (NULL, plugin);
+}
+
+static void
+cb_edit_action (GtkButton *button,
+                MyPlugin *plugin)
+{
+  GtkWidget *treeview;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkTreePath *path;
+  GtkTreeViewColumn *column;
+
+  treeview = glade_xml_get_widget (plugin->gxml, "actions");
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      g_critical ("Trying to edit an action but got no selection");
+      return;
+    }
+
+  path = gtk_tree_model_get_path (model, &iter);
+  column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), 1);
+  gtk_tree_view_row_activated (GTK_TREE_VIEW (treeview), path, column);
+  gtk_tree_path_free (path);
+}
+
+static void
+cb_actions_row_activated (GtkTreeView *treeview,
+                          GtkTreePath *path,
+                          GtkTreeViewColumn *column,
+                          MyPlugin *plugin)
+{
+  ClipmanActionsEntry *entry;
+  GtkTreeModel *actions_model, *commands_model;
+  GtkTreeIter iter;
+  GtkWidget *dialog;
+  gchar *title;
+  gint res;
+
+  dialog = glade_xml_get_widget (plugin->gxml, "entry-dialog");
+  entry_dialog_cleanup (GTK_DIALOG (dialog), plugin);
+
+  actions_model = gtk_tree_view_get_model (treeview);
+  gtk_tree_model_get_iter (actions_model, &iter, path);
+  gtk_tree_model_get (actions_model, &iter, 0, &entry, -1);
+
+  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "action-name")), entry->action_name);
+  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "regex")), g_regex_get_pattern (entry->regex));
+
+  commands_model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")));
+#if GLIB_CHECK_VERSION (2,16,0)
+  GHashTableIter hiter;
+  gpointer key, value;
+  g_hash_table_iter_init (&hiter, entry->commands);
+  while (g_hash_table_iter_next (&hiter, &key, &value))
+    {
+      title = g_strdup_printf ("<b>%s</b>\n<small>%s</small>", (gchar *)key, (gchar *)value);
+      gtk_list_store_append (GTK_LIST_STORE (commands_model), &iter);
+      gtk_list_store_set (GTK_LIST_STORE (commands_model), &iter, 0, title, 1, key, 2, value, -1);
+      g_free (title);
+    }
+#endif
+
+  res = gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_hide (dialog);
+
+  if (res == 1)
+    apply_action (entry->action_name, plugin);
+}
+
+static void
+cb_delete_action (GtkButton *button,
+                  MyPlugin *plugin)
+{
+  ClipmanActionsEntry *entry;
+  GtkWidget *treeview;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  treeview = glade_xml_get_widget (plugin->gxml, "actions");
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      g_critical ("Trying to remove an action but got no selection");
+      return;
+    }
+
+  gtk_tree_model_get (model, &iter, 0, &entry, -1);
+  clipman_actions_remove (plugin->actions, entry->action_name);
+  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+}
+
+/* Entry Dialog */
+static void
+setup_commands_treeview (GtkTreeView *treeview,
+                         MyPlugin *plugin)
+{
+  GtkTreeSelection *selection;
+  GtkListStore *model;
+  GtkCellRenderer *cell;
+
+  /* Define the model */
+  model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+  gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
+  g_object_unref (model);
+
+  /* Define the columns */
+  cell = gtk_cell_renderer_text_new ();
+  g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  gtk_tree_view_insert_column_with_attributes (treeview, -1, "Command", cell, "markup", 0, NULL);
+
+  selection = gtk_tree_view_get_selection (treeview);
+  g_signal_connect (selection, "changed", G_CALLBACK (cb_commands_selection_changed), plugin);
+}
+
+static void
+entry_dialog_cleanup (GtkDialog *dialog,
+                      MyPlugin *plugin)
+{
+  GtkTreeModel *model;
+
+  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "action-name")), "");
+  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "regex")), "");
+
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")));
+  gtk_list_store_clear (GTK_LIST_STORE (model));
+}
+
+static void
+cb_commands_selection_changed (GtkTreeSelection *selection,
+                               MyPlugin *plugin)
+{
+  GtkTreeModel *model;
+  gboolean sensitive;
+
+  sensitive = gtk_tree_selection_get_selected (selection, &model, NULL);
+
+  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "button-delete-command"), sensitive);
+}
+
+static void
+cb_add_command (GtkButton *button,
+                MyPlugin *plugin)
+{
+  GtkWidget *dialog;
+  GtkWidget *command_name;
+  GtkWidget *command;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gchar *title;
+  gint res;
+
+  dialog = glade_xml_get_widget (plugin->gxml, "command-dialog");
+  command_name = glade_xml_get_widget (plugin->gxml, "command-name");
+  command = glade_xml_get_widget (plugin->gxml, "command");
+
+  res = gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_hide (dialog);
+
+  /* TODO remove the get_text checks once the sensitivity of ok button is handled */
+  if (res == 1 && gtk_entry_get_text (GTK_ENTRY (command_name))[0] != '\0'
+      && gtk_entry_get_text (GTK_ENTRY (command))[0] != '\0')
+    {
+      model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")));
+      title = g_strdup_printf ("<b>%s</b>\n<small>%s</small>",
+                               gtk_entry_get_text (GTK_ENTRY (command_name)),
+                               gtk_entry_get_text (GTK_ENTRY (command)));
+      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+      gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, title,
+                          1, gtk_entry_get_text (GTK_ENTRY (command_name)),
+                          2, gtk_entry_get_text (GTK_ENTRY (command)), -1);
+      g_free (title);
+    }
+
+  gtk_entry_set_text (GTK_ENTRY (command_name), "");
+  gtk_entry_set_text (GTK_ENTRY (command), "");
+}
+
+static void
+cb_delete_command (GtkButton *button,
+                   MyPlugin *plugin)
+{
+  GtkWidget *treeview;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  treeview = glade_xml_get_widget (plugin->gxml, "commands");
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      g_critical ("Trying to delete a command but got no selection");
+      return;
+    }
+
+  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+}
+

Modified: xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/settings-dialog.glade
===================================================================
--- xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/settings-dialog.glade	2009-01-28 00:28:28 UTC (rev 6585)
+++ xfce4-clipman-plugin/branches/xfce-4-6/panel-plugin/settings-dialog.glade	2009-01-28 15:05:53 UTC (rev 6586)
@@ -155,7 +155,6 @@
             <child>
               <widget class="GtkVBox" id="vbox3">
                 <property name="visible">True</property>
-                <property name="sensitive">False</property>
                 <property name="border_width">6</property>
                 <property name="spacing">6</property>
                 <child>
@@ -191,6 +190,7 @@
                             <property name="can_focus">True</property>
                             <property name="headers_visible">False</property>
                             <property name="rules_hint">True</property>
+                            <signal name="row_activated" handler="cb_actions_row_activated"/>
                           </widget>
                         </child>
                       </widget>
@@ -203,10 +203,11 @@
                         <property name="visible">True</property>
                         <property name="spacing">6</property>
                         <child>
-                          <widget class="GtkButton" id="add-action2">
+                          <widget class="GtkButton" id="button-add-action">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
+                            <signal name="clicked" handler="cb_add_action"/>
                             <child>
                               <widget class="GtkImage" id="image1">
                                 <property name="visible">True</property>
@@ -222,10 +223,12 @@
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkButton" id="button3">
+                          <widget class="GtkButton" id="button-edit-action">
                             <property name="visible">True</property>
+                            <property name="sensitive">False</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
+                            <signal name="clicked" handler="cb_edit_action"/>
                             <child>
                               <widget class="GtkImage" id="image2">
                                 <property name="visible">True</property>
@@ -241,10 +244,12 @@
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkButton" id="remove-action2">
+                          <widget class="GtkButton" id="button-delete-action">
                             <property name="visible">True</property>
+                            <property name="sensitive">False</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
+                            <signal name="clicked" handler="cb_delete_action"/>
                             <child>
                               <widget class="GtkImage" id="image3">
                                 <property name="visible">True</property>
@@ -331,11 +336,17 @@
       </widget>
     </child>
   </widget>
-  <widget class="GtkDialog" id="action-entry-dialog">
-    <property name="border_width">5</property>
+  <widget class="GtkDialog" id="entry-dialog">
     <property name="title" translatable="yes">Edit Action</property>
+    <property name="modal">True</property>
     <property name="window_position">center-on-parent</property>
+    <property name="default_width">300</property>
+    <property name="default_height">380</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="icon_name">system-run</property>
     <property name="type_hint">normal</property>
+    <property name="skip_taskbar_hint">True</property>
+    <property name="transient_for">settings-dialog</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
       <widget class="GtkVBox" id="dialog-vbox2">
@@ -357,7 +368,6 @@
                     <property name="visible">True</property>
                     <property name="n_rows">2</property>
                     <property name="n_columns">2</property>
-                    <property name="column_spacing">6</property>
                     <property name="row_spacing">6</property>
                     <child>
                       <widget class="GtkEntry" id="regex">
@@ -394,7 +404,7 @@
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkEntry" id="action-nam">
+                      <widget class="GtkEntry" id="action-name">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                       </widget>
@@ -450,6 +460,8 @@
                           <widget class="GtkTreeView" id="commands">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
+                            <property name="headers_visible">False</property>
+                            <property name="rules_hint">True</property>
                           </widget>
                         </child>
                       </widget>
@@ -462,10 +474,11 @@
                         <property name="visible">True</property>
                         <property name="spacing">6</property>
                         <child>
-                          <widget class="GtkButton" id="add-command">
+                          <widget class="GtkButton" id="button-add-command">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
+                            <signal name="clicked" handler="cb_add_command"/>
                             <child>
                               <widget class="GtkImage" id="image1">
                                 <property name="visible">True</property>
@@ -481,10 +494,12 @@
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkButton" id="remove-command">
+                          <widget class="GtkButton" id="button-delete-command">
                             <property name="visible">True</property>
+                            <property name="sensitive">False</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">True</property>
+                            <signal name="clicked" handler="cb_delete_command"/>
                             <child>
                               <widget class="GtkImage" id="image3">
                                 <property name="visible">True</property>
@@ -530,7 +545,7 @@
             <property name="visible">True</property>
             <property name="layout_style">end</property>
             <child>
-              <widget class="GtkButton" id="button1">
+              <widget class="GtkButton" id="button2">
                 <property name="label" translatable="yes">gtk-cancel</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -542,8 +557,9 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkButton" id="button2">
-                <property name="label" translatable="yes">gtk-ok</property>
+              <widget class="GtkButton" id="entry-dialogbutton-ok1">
+                <property name="label" translatable="yes">gtk-apply</property>
+                <property name="response_id">1</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
@@ -568,8 +584,10 @@
     <property name="title" translatable="yes">Edit Command</property>
     <property name="resizable">False</property>
     <property name="window_position">center-on-parent</property>
+    <property name="destroy_with_parent">True</property>
     <property name="icon_name">system-run</property>
     <property name="type_hint">normal</property>
+    <property name="transient_for">entry-dialog</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
       <widget class="GtkVBox" id="dialog-vbox3">
@@ -595,7 +613,7 @@
               <widget class="GtkLabel" id="label3">
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
-                <property name="label" translatable="yes">You can use the matching regex parameters "\1", "\2", and so on in the command to replace it against the matched sub-texts. The parameter "\0" represents the complete text.</property>
+                <property name="label" translatable="yes">You can use the matching regex parameters "\1", "\2" and so on in the command to replace it against the matched sub-texts. The parameter "\0" represents the complete text.</property>
                 <property name="wrap">True</property>
               </widget>
               <packing>
@@ -613,7 +631,6 @@
             <property name="border_width">6</property>
             <property name="n_rows">2</property>
             <property name="n_columns">2</property>
-            <property name="column_spacing">6</property>
             <property name="row_spacing">6</property>
             <child>
               <widget class="GtkLabel" id="label1">
@@ -640,7 +657,7 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkEntry" id="entry1">
+              <widget class="GtkEntry" id="command-name">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
               </widget>
@@ -651,7 +668,7 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkEntry" id="entry2">
+              <widget class="GtkEntry" id="command">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
               </widget>
@@ -687,6 +704,7 @@
             <child>
               <widget class="GtkButton" id="button2">
                 <property name="label" translatable="yes">gtk-ok</property>
+                <property name="response_id">1</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>

Modified: xfce4-clipman-plugin/branches/xfce-4-6/tests/test_actions.c
===================================================================
--- xfce4-clipman-plugin/branches/xfce-4-6/tests/test_actions.c	2009-01-28 00:28:28 UTC (rev 6585)
+++ xfce4-clipman-plugin/branches/xfce-4-6/tests/test_actions.c	2009-01-28 15:05:53 UTC (rev 6586)
@@ -21,11 +21,11 @@
 
   gtk_main ();
 
-  clipman_actions_remove (actions, "Image", "GPicView");
-  clipman_actions_remove (actions, "Image", "GPicView");
-  clipman_actions_remove (actions, "Image", "view");
-  clipman_actions_remove (actions, "Image", "Ristretto");
-  clipman_actions_remove (actions, "Text", "Mousepad");
+  clipman_actions_remove_command (actions, "Image", "GPicView");
+  clipman_actions_remove_command (actions, "Image", "GPicView");
+  clipman_actions_remove_command (actions, "Image", "view");
+  clipman_actions_remove_command (actions, "Image", "Ristretto");
+  clipman_actions_remove_command (actions, "Text", "Mousepad");
 
   return 0;
 }




More information about the Goodies-commits mailing list