[Goodies-commits] r7663 - in xfce4-clipman-plugin/trunk: . panel-plugin
Mike Massonnet
mmassonnet at xfce.org
Sat Jul 4 07:23:28 CEST 2009
Author: mmassonnet
Date: 2009-07-04 05:23:28 +0000 (Sat, 04 Jul 2009)
New Revision: 7663
Modified:
xfce4-clipman-plugin/trunk/ChangeLog
xfce4-clipman-plugin/trunk/panel-plugin/actions.c
xfce4-clipman-plugin/trunk/panel-plugin/actions.h
xfce4-clipman-plugin/trunk/panel-plugin/collector.c
xfce4-clipman-plugin/trunk/panel-plugin/common.h
xfce4-clipman-plugin/trunk/panel-plugin/settings-dialog.glade
xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c
Log:
Add groups to ClipmanActions
Modified: xfce4-clipman-plugin/trunk/ChangeLog
===================================================================
--- xfce4-clipman-plugin/trunk/ChangeLog 2009-07-03 20:07:43 UTC (rev 7662)
+++ xfce4-clipman-plugin/trunk/ChangeLog 2009-07-04 05:23:28 UTC (rev 7663)
@@ -1,3 +1,18 @@
+2009-07-04 Mike Massonnet
+Add groups to ClipmanActions
+
+ - panel-plugin/actions.c:
+ New function clipman_actions_set_group to change a group of a
+ given action identified by its human readable name.
+ On action match check for the group (-1 means all the groups).
+ Save/load the group to/from the xml file.
+ - panel-plugin/collector.c:
+ On default clipboard change, get a match from actions with
+ group "manual".
+ - panel-plugin/xfce4-clipman-settings.c,
+ panel-plugin/settings-dialog.glade:
+ Show the toggle button "only on manual copy".
+
2009-07-02 Mike Massonnet
Add a real good daemon
Modified: xfce4-clipman-plugin/trunk/panel-plugin/actions.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/actions.c 2009-07-03 20:07:43 UTC (rev 7662)
+++ xfce4-clipman-plugin/trunk/panel-plugin/actions.c 2009-07-04 05:23:28 UTC (rev 7663)
@@ -131,6 +131,7 @@
ACTION,
ACTION_NAME,
REGEX,
+ GROUP,
COMMANDS,
COMMAND,
COMMAND_NAME,
@@ -149,6 +150,7 @@
gchar *action_name;
gchar *regex;
+ gint group;
gchar *command_name;
gchar *command;
};
@@ -224,6 +226,8 @@
}
else if (!g_ascii_strcasecmp (element_name, "regex"))
parser->state = REGEX;
+ else if (!g_ascii_strcasecmp (element_name, "group"))
+ parser->state = GROUP;
else if (!g_ascii_strcasecmp (element_name, "commands"))
parser->state = COMMANDS;
else if (!g_ascii_strcasecmp (element_name, "exec"))
@@ -250,22 +254,29 @@
g_free (parser->regex);
parser->action_name = NULL;
parser->regex = NULL;
+ parser->group = 0;
parser->state = ACTIONS;
break;
case ACTION_NAME:
case REGEX:
+ case GROUP:
case COMMANDS:
parser->state = ACTION;
break;
case COMMAND:
if (parser->action_name == NULL || parser->regex == NULL)
- g_warning ("Closing a command but no action name nor regex set");
+ {
+ g_warning ("Closing a command but no action name nor regex set");
+ }
else
- clipman_actions_add (parser->actions, parser->action_name, parser->regex,
- parser->command_name, parser->command);
+ {
+ clipman_actions_add (parser->actions, parser->action_name, parser->regex,
+ parser->command_name, parser->command);
+ clipman_actions_set_group (parser->actions, parser->action_name, parser->group);
+ }
g_free (parser->command_name);
g_free (parser->command);
@@ -308,6 +319,9 @@
parser->regex = g_strdup (text);
break;
+ case GROUP:
+ parser->group = (gint)g_strtod (text, NULL);
+
case COMMAND_NAME:
if (parser->name_use)
{
@@ -483,6 +497,9 @@
* The command can contain the parameter '%s' that will be replaced by the
* matching regex text.
*
+ * The action is created with the default group 0. To change it use the
+ * function clipman_actions_set_group().
+ *
* Returns: FALSE if the regex was invalid
*/
gboolean
@@ -515,6 +532,7 @@
entry = g_slice_new0 (ClipmanActionsEntry);
entry->action_name = g_strdup (action_name);
entry->regex = _regex;
+ entry->group = 0;
entry->commands = g_hash_table_new_full ((GHashFunc)g_str_hash, (GEqualFunc)g_str_equal,
(GDestroyNotify)g_free, (GDestroyNotify)g_free);
g_hash_table_insert (entry->commands, g_strdup (command_name), g_strdup (command));
@@ -611,6 +629,33 @@
}
/**
+ * clipman_actions_set_group:
+ * @actions: a #ClipmanActions
+ * @action_name: the human readable name for the regex
+ * @group: the group identifier
+ *
+ * Changes the group of @action_name to @group.
+ */
+void
+clipman_actions_set_group (ClipmanActions *actions,
+ const gchar *action_name,
+ gint group)
+{
+ 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;
+ }
+
+ entry = l->data;
+ entry->group = group;
+}
+
+/**
* clipman_actions_get_entries:
* @actions: a #ClipmanActions
*
@@ -625,6 +670,7 @@
/**
* clipman_actions_match:
* @actions: a #ClipmanActions
+ * @group: the group identifier
* @text: the text to match against the existing regex's
*
* Searches a regex match for @text and returns a newly allocated #GSList which
@@ -632,11 +678,13 @@
* #ClipmanActionsEntry for each matched action.
* Note that the data inside the list is owned by #ClipmanActions and must not
* be modified.
+ * The @group identifier can be -1 to get a match from all groups.
*
* Returns: a newly allocated #GSList
*/
GSList *
clipman_actions_match (ClipmanActions *actions,
+ gint group,
const gchar *text)
{
ClipmanActionsEntry *entry;
@@ -646,8 +694,11 @@
for (l = actions->priv->entries; l != NULL; l = l->next)
{
entry = l->data;
- if (g_regex_match (entry->regex, text, 0, NULL))
- entries = g_slist_prepend (entries, entry);
+ if (group == -1 || group == entry->group)
+ {
+ if (g_regex_match (entry->regex, text, 0, NULL))
+ entries = g_slist_prepend (entries, entry);
+ }
}
return entries;
@@ -656,6 +707,7 @@
/**
* clipman_actions_match_with_menu:
* @actions: a #ClipmanActions
+ * @group: the group identifier
* @text: the text to match against the existing regex's
*
* Builds and displays a menu with matching actions for @text.
@@ -664,13 +716,14 @@
*/
void
clipman_actions_match_with_menu (ClipmanActions *actions,
+ gint group,
const gchar *text)
{
ClipmanActionsEntry *entry;
GtkWidget *mi;
GSList *l, *entries;
- entries = clipman_actions_match (actions, text);
+ entries = clipman_actions_match (actions, group, text);
if (entries == NULL)
return;
@@ -805,6 +858,8 @@
g_string_append_printf (output, "\t\t<regex>%s</regex>\n", tmp);
g_free (tmp);
+ g_string_append_printf (output, "\t\t<group>%d</group>\n", entry->group);
+
g_string_append (output, "\t\t<commands>\n");
#if GLIB_CHECK_VERSION (2,16,0)
Modified: xfce4-clipman-plugin/trunk/panel-plugin/actions.h
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/actions.h 2009-07-03 20:07:43 UTC (rev 7662)
+++ xfce4-clipman-plugin/trunk/panel-plugin/actions.h 2009-07-04 05:23:28 UTC (rev 7663)
@@ -30,6 +30,7 @@
{
gchar *action_name;
GRegex *regex;
+ gint group;
GHashTable *commands;
};
@@ -77,10 +78,15 @@
gboolean clipman_actions_remove_command (ClipmanActions *actions,
const gchar *action_name,
const gchar *command_name);
+void clipman_actions_set_group (ClipmanActions *actions,
+ const gchar *action_name,
+ gint group);
const GSList * clipman_actions_get_entries (ClipmanActions *actions);
GSList * clipman_actions_match (ClipmanActions *actions,
+ gint group,
const gchar *match);
void clipman_actions_match_with_menu (ClipmanActions *actions,
+ gint group,
const gchar *match);
void clipman_actions_load (ClipmanActions *actions);
void clipman_actions_save (ClipmanActions *actions);
Modified: xfce4-clipman-plugin/trunk/panel-plugin/collector.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/collector.c 2009-07-03 20:07:43 UTC (rev 7662)
+++ xfce4-clipman-plugin/trunk/panel-plugin/collector.c 2009-07-04 05:23:28 UTC (rev 7663)
@@ -111,6 +111,8 @@
text = gtk_clipboard_wait_for_text (collector->priv->default_clipboard);
if (text != NULL && text[0] != '\0')
clipman_history_add_text (collector->priv->history, text);
+ if (collector->priv->enable_actions)
+ clipman_actions_match_with_menu (collector->priv->actions, ACTION_GROUP_MANUAL, text);
g_free (text);
}
else if (has_image)
@@ -163,7 +165,7 @@
/* Match for actions */
if (collector->priv->enable_actions)
- clipman_actions_match_with_menu (collector->priv->actions, text);
+ clipman_actions_match_with_menu (collector->priv->actions, ACTION_GROUP_SELECTION, text);
}
g_free (text);
}
Modified: xfce4-clipman-plugin/trunk/panel-plugin/common.h
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/common.h 2009-07-03 20:07:43 UTC (rev 7662)
+++ xfce4-clipman-plugin/trunk/panel-plugin/common.h 2009-07-04 05:23:28 UTC (rev 7663)
@@ -39,3 +39,9 @@
#define XFCE_CLIPMAN_SELECTION "XFCE_CLIPMAN_SELECTION"
#define XFCE_CLIPMAN_MESSAGE "MENU"
+/*
+ * Action Groups
+ */
+
+#define ACTION_GROUP_SELECTION 0
+#define ACTION_GROUP_MANUAL 1
Modified: xfce4-clipman-plugin/trunk/panel-plugin/settings-dialog.glade
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/settings-dialog.glade 2009-07-03 20:07:43 UTC (rev 7662)
+++ xfce4-clipman-plugin/trunk/panel-plugin/settings-dialog.glade 2009-07-04 05:23:28 UTC (rev 7663)
@@ -271,7 +271,7 @@
<widget class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="stock">gtk-add</property>
- <property name="icon-size">4</property>
+ <property name="icon-size">1</property>
</widget>
</child>
</widget>
@@ -541,8 +541,9 @@
</packing>
</child>
<child>
- <widget class="GtkCheckButton" id="checkbutton1">
- <property name="label" translatable="yes">Activate only on default clipboard</property>
+ <widget class="GtkCheckButton" id="manual">
+ <property name="label" translatable="yes">Activate only on manual copy</property>
+ <property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip" translatable="yes">By default the action is triggerred by a selection, check this option to trigger the action only when you make a manual copy</property>
Modified: xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c 2009-07-03 20:07:43 UTC (rev 7662)
+++ xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c 2009-07-04 05:23:28 UTC (rev 7663)
@@ -267,11 +267,13 @@
GtkTreeIter iter;
const gchar *action_name;
const gchar *regex;
+ gint group;
gchar *command_name;
gchar *command;
action_name = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (gxml, "action-name")));
regex = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (gxml, "regex")));
+ group = (gint)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "manual")));
treeview = glade_xml_get_widget (gxml, "commands");
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
@@ -287,6 +289,7 @@
{
gtk_tree_model_get (model, &iter, 1, &command_name, 2, &command, -1);
clipman_actions_add (actions, action_name, regex, command_name, command);
+ clipman_actions_set_group (actions, action_name, group);
g_free (command_name);
g_free (command);
}
@@ -387,6 +390,7 @@
gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "action-name")), entry->action_name);
gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "regex")), g_regex_get_pattern (entry->regex));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "manual")), entry->group);
res = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide (dialog);
@@ -451,6 +455,7 @@
gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "action-name")), "");
gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "regex")), "");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "manual")), FALSE);
model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (gxml, "commands")));
gtk_list_store_clear (GTK_LIST_STORE (model));
More information about the Goodies-commits
mailing list