Commit d99e85d6 authored by Jannis Pohlmann's avatar Jannis Pohlmann

Generate persistent unique IDs and names for custom actions.

This adds an optional <unique-id> element to the <action> element in
uca.xml. When loading the UCA model from uca.xml, we check for this
element in the parser. If it is not given, we generate a new ID with the
following signature:

  <current_time.tv_sec>.<current_time.tv_usec>-<static counter value>

After parsing we check if we have generated new IDs and, if so,
immediately save the model back to the uca.xml file. This part is a bit
of a hack but it will be a no-brainer once we've switched to xfconf, I
think.

The ThunarUcaEditor is extended so that it generates a unique ID for new
items with the same signature as above. It does not overwrite IDs of
existing custom actions.

Together this allows for a persistent association of custom actions with
keyboard shortcuts.
parent 0edbd00a
/* $Id$ */
/*-
* Copyright (c) 2005-2007 Benedikt Meurer <benny@xfce.org>
* Copyright (c) 2011 Jannis Pohlmann <jannis@xfce.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -41,6 +42,9 @@ static void thunar_uca_editor_set_icon_name (ThunarUcaEditor
static ThunarUcaTypes thunar_uca_editor_get_types (const ThunarUcaEditor *uca_editor);
static void thunar_uca_editor_set_types (ThunarUcaEditor *uca_editor,
ThunarUcaTypes types);
static const gchar *thunar_uca_editor_get_unique_id (const ThunarUcaEditor *uca_editor);
static void thunar_uca_editor_set_unique_id (ThunarUcaEditor *uca_editor,
const gchar *unique_id);
static void thunar_uca_editor_command_clicked (ThunarUcaEditor *uca_editor);
static void thunar_uca_editor_icon_clicked (ThunarUcaEditor *uca_editor);
......@@ -101,6 +105,7 @@ thunar_uca_editor_init (ThunarUcaEditor *uca_editor)
GtkWidget *table;
GtkWidget *hbox;
GtkWidget *vbox;
gchar *unique_id;
/* configure the dialog properties */
gtk_dialog_add_button (GTK_DIALOG (uca_editor), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
......@@ -454,6 +459,11 @@ thunar_uca_editor_init (ThunarUcaEditor *uca_editor)
gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.0f);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
/* set a unique ID for new items. this will be overridden by existing items */
unique_id = thunar_uca_model_get_unique_id ();
thunar_uca_editor_set_unique_id (uca_editor, unique_id);
g_free (unique_id);
}
......@@ -751,6 +761,30 @@ thunar_uca_editor_set_types (ThunarUcaEditor *uca_editor,
static const gchar*
thunar_uca_editor_get_unique_id (const ThunarUcaEditor *uca_editor)
{
g_return_val_if_fail (THUNAR_UCA_IS_EDITOR (uca_editor), NULL);
return g_object_get_data (G_OBJECT (uca_editor->icon_button), "thunar-uca-unique-id");
}
static void
thunar_uca_editor_set_unique_id (ThunarUcaEditor *uca_editor,
const gchar *unique_id)
{
g_return_if_fail (THUNAR_UCA_IS_EDITOR (uca_editor));
/* remember the unique ID for the item */
g_object_set_data_full (G_OBJECT (uca_editor->icon_button),
"thunar-uca-unique-id",
g_strdup (unique_id),
g_free);
}
/**
* thunar_uca_editor_load:
* @uca_editor : a #ThunarUcaEditor.
......@@ -771,6 +805,7 @@ thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
gchar *command;
gchar *icon;
gchar *name;
gchar *unique_id;
gboolean startup_notify;
g_return_if_fail (THUNAR_UCA_IS_EDITOR (uca_editor));
......@@ -785,6 +820,7 @@ thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
THUNAR_UCA_MODEL_COLUMN_TYPES, &types,
THUNAR_UCA_MODEL_COLUMN_ICON, &icon,
THUNAR_UCA_MODEL_COLUMN_NAME, &name,
THUNAR_UCA_MODEL_COLUMN_UNIQUE_ID, &unique_id,
THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY, &startup_notify,
-1);
......@@ -794,6 +830,9 @@ thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
/* setup the new icon */
thunar_uca_editor_set_icon_name (uca_editor, icon);
/* setup the unique ID */
thunar_uca_editor_set_unique_id (uca_editor, unique_id);
/* apply the new values */
gtk_entry_set_text (GTK_ENTRY (uca_editor->description_entry), (description != NULL) ? description : "");
gtk_entry_set_text (GTK_ENTRY (uca_editor->patterns_entry), (patterns != NULL) ? patterns : "");
......@@ -806,6 +845,7 @@ thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
g_free (patterns);
g_free (command);
g_free (icon);
g_free (unique_id);
g_free (name);
}
......@@ -831,6 +871,7 @@ thunar_uca_editor_save (ThunarUcaEditor *uca_editor,
thunar_uca_model_update (uca_model, iter,
gtk_entry_get_text (GTK_ENTRY (uca_editor->name_entry)),
thunar_uca_editor_get_unique_id (uca_editor),
gtk_entry_get_text (GTK_ENTRY (uca_editor->description_entry)),
thunar_uca_editor_get_icon_name (uca_editor),
gtk_entry_get_text (GTK_ENTRY (uca_editor->command_entry)),
......
This diff is collapsed.
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
* Copyright (c) 2011 Jannis Pohlmann <jannis@xfce.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -38,6 +39,7 @@ typedef struct _ThunarUcaModel ThunarUcaModel;
typedef enum
{
THUNAR_UCA_MODEL_COLUMN_NAME,
THUNAR_UCA_MODEL_COLUMN_UNIQUE_ID,
THUNAR_UCA_MODEL_COLUMN_DESCRIPTION,
THUNAR_UCA_MODEL_COLUMN_ICON,
THUNAR_UCA_MODEL_COLUMN_COMMAND,
......@@ -88,6 +90,7 @@ void thunar_uca_model_remove (ThunarUcaModel *uca_mod
void thunar_uca_model_update (ThunarUcaModel *uca_model,
GtkTreeIter *iter,
const gchar *name,
const gchar *unique_id,
const gchar *description,
const gchar *icon,
const gchar *command,
......@@ -105,6 +108,8 @@ gboolean thunar_uca_model_parse_argv (ThunarUcaModel *uca_mod
gchar ***argvp,
GError **error);
gchar *thunar_uca_model_get_unique_id (void) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
G_END_DECLS;
#endif /* !__THUNAR_UCA_MODEL_H__ */
/* $Id$ */
/*-
* Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
* Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org>
* Copyright (c) 2009-2011 Jannis Pohlmann <jannis@xfce.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -28,6 +28,8 @@
#include <libxfce4util/libxfce4util.h>
#include <libxfce4ui/libxfce4ui.h>
#include <exo/exo.h>
#include <thunar-uca/thunar-uca-chooser.h>
#include <thunar-uca/thunar-uca-context.h>
#include <thunar-uca/thunar-uca-model.h>
......@@ -201,6 +203,7 @@ thunar_uca_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
gchar *tooltip;
gchar *label;
gchar *name;
gchar *unique_id;
paths = thunar_uca_model_match (uca_provider->model, files);
for (lp = g_list_last (paths); lp != NULL; lp = lp->prev)
......@@ -211,13 +214,13 @@ thunar_uca_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
/* determine the label, tooltip and stock-id for the item */
gtk_tree_model_get (GTK_TREE_MODEL (uca_provider->model), &iter,
THUNAR_UCA_MODEL_COLUMN_NAME, &label,
THUNAR_UCA_MODEL_COLUMN_UNIQUE_ID, &unique_id,
THUNAR_UCA_MODEL_COLUMN_ICON, &icon_name,
THUNAR_UCA_MODEL_COLUMN_DESCRIPTION, &tooltip,
-1);
/* generate a unique action name */
/* FIXME this name is persistent only if actions are not re-ordered in the GUI */
name = g_strdup_printf ("ThunarUca::action-%d", ++uca_provider->last_action_id);
name = g_strdup_printf ("ThunarUca::action-%s", unique_id);
/* create the new action with the given parameters */
action = gtk_action_new (name, label, tooltip, NULL);
......@@ -251,6 +254,7 @@ thunar_uca_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
g_free (icon_name);
g_free (tooltip);
g_free (label);
g_free (unique_id);
g_free (name);
}
......
......@@ -2,7 +2,7 @@
<!DOCTYPE actions [
<!ELEMENT actions (action)+>
<!ELEMENT action (icon|patterns|name|command|description|directories|audio-files|image-files|other-files|text-files|video-files)*>
<!ELEMENT action (icon|patterns|name|unique-id?|command|description|directories|audio-files|image-files|other-files|text-files|video-files)*>
<!ELEMENT icon (#PCDATA)>
<!ELEMENT command (#PCDATA)>
......@@ -11,6 +11,8 @@
<!ELEMENT name (#PCDATA)>
<!ATTLIST name xml:lang CDATA #IMPLIED>
<!ELEMENT unique-id (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ATTLIST description xml:lang CDATA #IMPLIED>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment