#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
+#include <sys/stat.h>
#include <time.h>
#include <gtk/gtk.h>
#include <libgnomevfs/gnome-vfs.h>
#define EGG_RECENT_MODEL_MAX_ITEMS 500
#define EGG_RECENT_MODEL_DEFAULT_LIMIT 10
#define EGG_RECENT_MODEL_TIMEOUT_LENGTH 200
+#define EGG_RECENT_MODEL_POLL_TIME 3
+
+/* needed for Darwin */
+#if !HAVE_DECL_LOCKF
+int lockf (int filedes, int function, off_t size);
+#endif
#define EGG_RECENT_MODEL_KEY_DIR "/desktop/gnome/recent_files"
#define EGG_RECENT_MODEL_DEFAULT_LIMIT_KEY EGG_RECENT_MODEL_KEY_DIR "/default_limit"
guint expiration_change_notify_id;
guint changed_timeout;
+ guint poll_timeout;
+ time_t last_mtime;
};
/* signals */
GSList *states;
GList *items;
EggRecentItem *current_item;
-}ParseInfo;
+} ParseInfo;
typedef enum {
STATE_START,
STATE_GROUP
} ParseState;
-typedef struct _ChangedData {
+typedef struct {
EggRecentModel *model;
GList *list;
-}ChangedData;
+} ChangedData;
#define TAG_RECENT_FILES "RecentFiles"
#define TAG_RECENT_ITEM "RecentItem"
NULL,
error_handler};
+static GObjectClass *parent_class;
+
+static void egg_recent_model_clear_mime_filter (EggRecentModel *model);
+static void egg_recent_model_clear_group_filter (EggRecentModel *model);
+static void egg_recent_model_clear_scheme_filter (EggRecentModel *model);
+
+static GObjectClass *parent_class;
+
static gboolean
egg_recent_model_string_match (const GSList *list, const gchar *str)
{
-static void
-parse_info_init (ParseInfo *info)
+static ParseInfo *
+parse_info_init (void)
{
- info->states = g_slist_prepend (NULL, STATE_START);
- info->items = NULL;
+ ParseInfo *retval;
+
+ retval = g_new0 (ParseInfo, 1);
+ retval->states = g_slist_prepend (NULL, STATE_START);
+ retval->items = NULL;
+
+ return retval;
}
static void
parse_info_free (ParseInfo *info)
{
g_slist_free (info->states);
+ g_free (info);
}
static void
#define ELEMENT_IS(name) (strcmp (element_name, (name)) == 0)
+static gboolean
+valid_element (ParseInfo *info,
+ int valid_parent_state,
+ const gchar *element_name,
+ const gchar *valid_element,
+ GError **error)
+{
+ if (peek_state (info) != valid_parent_state) {
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ "Unexpected tag '%s', tag '%s' expected",
+ element_name, valid_element);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void
start_element_handler (GMarkupParseContext *context,
const gchar *element_name,
if (ELEMENT_IS (TAG_RECENT_FILES))
push_state (info, STATE_RECENT_FILES);
else if (ELEMENT_IS (TAG_RECENT_ITEM)) {
- info->current_item = egg_recent_item_new ();
- push_state (info, STATE_RECENT_ITEM);
- } else if (ELEMENT_IS (TAG_URI))
- push_state (info, STATE_URI);
- else if (ELEMENT_IS (TAG_MIME_TYPE))
- push_state (info, STATE_MIME_TYPE);
- else if (ELEMENT_IS (TAG_TIMESTAMP))
- push_state (info, STATE_TIMESTAMP);
- else if (ELEMENT_IS (TAG_PRIVATE)) {
- push_state (info, STATE_PRIVATE);
- egg_recent_item_set_private (info->current_item, TRUE);
- } else if (ELEMENT_IS (TAG_GROUPS))
- push_state (info, STATE_GROUPS);
- else if (ELEMENT_IS (TAG_GROUP))
- push_state (info, STATE_GROUP);
+ if (valid_element (info, STATE_RECENT_FILES,
+ TAG_RECENT_ITEM, TAG_RECENT_FILES, error)) {
+ info->current_item = egg_recent_item_new ();
+ push_state (info, STATE_RECENT_ITEM);
+ }
+ } else if (ELEMENT_IS (TAG_URI)) {
+ if (valid_element (info, STATE_RECENT_ITEM,
+ TAG_URI, TAG_RECENT_ITEM, error)) {
+ push_state (info, STATE_URI);
+ }
+ } else if (ELEMENT_IS (TAG_MIME_TYPE)) {
+ if (valid_element (info, STATE_RECENT_ITEM,
+ TAG_MIME_TYPE, TAG_RECENT_ITEM, error)) {
+ push_state (info, STATE_MIME_TYPE);
+ }
+ } else if (ELEMENT_IS (TAG_TIMESTAMP)) {
+ if (valid_element (info, STATE_RECENT_ITEM,
+ TAG_TIMESTAMP, TAG_RECENT_ITEM, error)) {
+ push_state (info, STATE_TIMESTAMP);
+ }
+ } else if (ELEMENT_IS (TAG_PRIVATE)) {
+ if (valid_element (info, STATE_RECENT_ITEM,
+ TAG_PRIVATE, TAG_RECENT_ITEM, error)) {
+ push_state (info, STATE_PRIVATE);
+ egg_recent_item_set_private (info->current_item, TRUE);
+ }
+ } else if (ELEMENT_IS (TAG_GROUPS)) {
+ if (valid_element (info, STATE_RECENT_ITEM,
+ TAG_GROUPS, TAG_RECENT_ITEM, error)) {
+ push_state (info, STATE_GROUPS);
+ }
+ } else if (ELEMENT_IS (TAG_GROUP)) {
+ if (valid_element (info, STATE_GROUPS,
+ TAG_GROUP, TAG_GROUPS, error)) {
+ push_state (info, STATE_GROUP);
+ }
+ }
}
static gint
switch (peek_state (info)) {
case STATE_RECENT_ITEM:
- info->items = g_list_append (info->items,
- info->current_item);
- if (info->current_item->uri == NULL ||
- strlen (info->current_item->uri) == 0)
- g_warning ("URI NOT LOADED");
- break;
+ if (!info->current_item) {
+ g_warning ("No recent item found\n");
+ break;
+ }
+
+ if (!info->current_item->uri) {
+ g_warning ("Invalid item found\n");
+ break;
+ }
+
+ info->items = g_list_prepend (info->items,
+ info->current_item);
+ info->current_item = NULL;
+ break;
default:
- break;
+ break;
}
pop_state (info);
GError **error)
{
ParseInfo *info = (ParseInfo *)user_data;
+ gchar *value;
+
+ value = g_strndup (text, text_len);
switch (peek_state (info)) {
case STATE_START:
case STATE_GROUPS:
break;
case STATE_URI:
- egg_recent_item_set_uri (info->current_item, text);
+ egg_recent_item_set_uri (info->current_item, value);
break;
case STATE_MIME_TYPE:
- egg_recent_item_set_mime_type (info->current_item,
- text);
+ egg_recent_item_set_mime_type (info->current_item, value);
break;
case STATE_TIMESTAMP:
egg_recent_item_set_timestamp (info->current_item,
- (time_t)atoi (text));
+ (time_t)atoi (value));
break;
case STATE_GROUP:
egg_recent_item_add_group (info->current_item,
text);
break;
}
-
+
+ g_free (value);
}
static void
}
static GList *
-egg_recent_model_filter (EggRecentModel *model,
- GList *list)
+egg_recent_model_filter (EggRecentModel *model, GList *list)
{
- EggRecentItem *item;
GList *newlist = NULL;
+ GList *l;
gchar *mime_type;
gchar *uri;
g_return_val_if_fail (list != NULL, NULL);
- while (list) {
+ for (l = list; l != NULL ; l = l->next) {
+ EggRecentItem *item = (EggRecentItem *) l->data;
gboolean pass_mime_test = FALSE;
gboolean pass_group_test = FALSE;
gboolean pass_scheme_test = FALSE;
- item = (EggRecentItem *)list->data;
- list = list->next;
+ g_assert (item != NULL);
+
uri = egg_recent_item_get_uri (item);
/* filter by mime type */
if (pass_mime_test && pass_group_test && pass_scheme_test)
newlist = g_list_prepend (newlist, item);
+ else
+ egg_recent_item_unref (item);
g_free (uri);
}
- if (newlist) {
- newlist = g_list_reverse (newlist);
- g_list_free (list);
- }
+ g_list_free (list);
-
- return newlist;
+ return g_list_reverse (newlist);
}
g_return_if_fail (EGG_IS_RECENT_MODEL (user_data));
model = EGG_RECENT_MODEL (user_data);
- if (event_type == GNOME_VFS_MONITOR_EVENT_CHANGED) {
+ if (event_type == GNOME_VFS_MONITOR_EVENT_CHANGED ||
+ event_type == GNOME_VFS_MONITOR_EVENT_CREATED ||
+ event_type == GNOME_VFS_MONITOR_EVENT_DELETED) {
if (model->priv->changed_timeout > 0) {
g_source_remove (model->priv->changed_timeout);
}
}
}
+static gboolean
+egg_recent_model_poll_timeout (gpointer user_data)
+{
+ EggRecentModel *model;
+ struct stat stat_buf;
+ int stat_res;
+
+ model = EGG_RECENT_MODEL (user_data);
+ stat_res = stat (model->priv->path, &stat_buf);
+
+ if (!stat_res && stat_buf.st_mtime &&
+ stat_buf.st_mtime != model->priv->last_mtime) {
+ model->priv->last_mtime = stat_buf.st_mtime;
+
+ if (model->priv->changed_timeout > 0)
+ g_source_remove (model->priv->changed_timeout);
+
+ model->priv->changed_timeout = g_timeout_add (
+ EGG_RECENT_MODEL_TIMEOUT_LENGTH,
+ (GSourceFunc)egg_recent_model_changed_timeout,
+ model);
+ }
+ return TRUE;
+}
+
static void
egg_recent_model_monitor (EggRecentModel *model, gboolean should_monitor)
{
if (should_monitor && model->priv->monitor == NULL) {
char *uri;
+ GnomeVFSResult result;
uri = gnome_vfs_get_uri_from_local_path (model->priv->path);
- gnome_vfs_monitor_add (&model->priv->monitor,
- uri,
- GNOME_VFS_MONITOR_FILE,
- egg_recent_model_monitor_cb,
- model);
+ result = gnome_vfs_monitor_add (&model->priv->monitor,
+ uri,
+ GNOME_VFS_MONITOR_FILE,
+ egg_recent_model_monitor_cb,
+ model);
g_free (uri);
/* if the above fails, don't worry about it.
* local notifications will still happen
*/
+ if (result == GNOME_VFS_ERROR_NOT_SUPPORTED) {
+ if (model->priv->poll_timeout > 0)
+ g_source_remove (model->priv->poll_timeout);
+
+ model->priv->poll_timeout = g_timeout_add (
+ EGG_RECENT_MODEL_POLL_TIME * 1000,
+ egg_recent_model_poll_timeout,
+ model);
+ }
} else if (!should_monitor && model->priv->monitor != NULL) {
gnome_vfs_monitor_cancel (model->priv->monitor);
GList *list=NULL;
gchar *content;
GMarkupParseContext *ctx;
- ParseInfo info;
+ ParseInfo *info;
GError *error;
content = egg_recent_model_read_raw (model, file);
return NULL;
}
- parse_info_init (&info);
+ info = parse_info_init ();
- ctx = g_markup_parse_context_new (&parser, 0, &info, NULL);
+ ctx = g_markup_parse_context_new (&parser, 0, info, NULL);
error = NULL;
- if (!g_markup_parse_context_parse (ctx, content, strlen (content),
- &error)) {
- g_warning (error->message);
+ if (!g_markup_parse_context_parse (ctx, content, strlen (content), &error)) {
+ g_warning ("Error while parsing the .recently-used file: %s\n",
+ error->message);
+
g_error_free (error);
- error = NULL;
- goto out;
+ parse_info_free (info);
+
+ return NULL;
}
error = NULL;
- if (!g_markup_parse_context_end_parse (ctx, &error))
- goto out;
-
- g_markup_parse_context_free (ctx);
-out:
- list = info.items;
+ if (!g_markup_parse_context_end_parse (ctx, &error)) {
+ g_warning ("Unable to complete parsing of the .recently-used file: %s\n",
+ error->message);
+
+ g_error_free (error);
+ g_markup_parse_context_free (ctx);
+ parse_info_free (info);
- parse_info_free (&info);
+ return NULL;
+ }
+
+ list = g_list_reverse (info->items);
+ g_markup_parse_context_free (ctx);
+ parse_info_free (info);
g_free (content);
- /*
- g_print ("Total items: %d\n", g_list_length (list));
- */
-
return list;
}
}
static FILE *
-egg_recent_model_open_file (EggRecentModel *model)
+egg_recent_model_open_file (EggRecentModel *model,
+ gboolean for_writing)
{
FILE *file;
mode_t prev_umask;
file = fopen (model->priv->path, "r+");
- if (file == NULL) {
+ if (file == NULL && for_writing) {
/* be paranoid */
prev_umask = umask (077);
static gboolean
egg_recent_model_lock_file (FILE *file)
{
-#ifdef F_TLOCK
+#ifdef HAVE_LOCKF
int fd;
gint try = 5;
return FALSE;
#else
return TRUE;
-#endif
+#endif /* HAVE_LOCKF */
}
static gboolean
egg_recent_model_unlock_file (FILE *file)
{
-#ifdef F_TLOCK
+#ifdef HAVE_LOCKF
int fd;
rewind (file);
return (lockf (fd, F_ULOCK, 0) == 0) ? TRUE : FALSE;
#else
return TRUE;
-#endif
+#endif /* HAVE_LOCKF */
}
static void
g_hash_table_destroy (model->priv->monitors);
model->priv->monitors = NULL;
+ if (model->priv->poll_timeout > 0)
+ g_source_remove (model->priv->poll_timeout);
+ model->priv->poll_timeout =0;
g_free (model->priv);
+
+ parent_class->finalize (object);
}
static void
switch (prop_id)
{
case PROP_MIME_FILTERS:
+ if (model->priv->mime_filter_values != NULL)
+ egg_recent_model_clear_mime_filter (model);
+
model->priv->mime_filter_values =
(GSList *)g_value_get_pointer (value);
break;
case PROP_GROUP_FILTERS:
+ if (model->priv->group_filter_values != NULL)
+ egg_recent_model_clear_group_filter (model);
+
model->priv->group_filter_values =
(GSList *)g_value_get_pointer (value);
break;
case PROP_SCHEME_FILTERS:
+ if (model->priv->scheme_filter_values != NULL)
+ egg_recent_model_clear_scheme_filter (model);
+
model->priv->scheme_filter_values =
(GSList *)g_value_get_pointer (value);
break;
{
GObjectClass *object_class;
+ parent_class = g_type_class_peek_parent (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
object_class = G_OBJECT_CLASS (klass);
object_class->set_property = egg_recent_model_set_property;
object_class->get_property = egg_recent_model_get_property;
(GDestroyNotify) gnome_vfs_monitor_cancel);
model->priv->monitor = NULL;
+ model->priv->poll_timeout = 0;
+ model->priv->last_mtime = 0;
egg_recent_model_monitor (model, TRUE);
}
g_free (uri);
}
- file = egg_recent_model_open_file (model);
+ file = egg_recent_model_open_file (model, TRUE);
g_return_val_if_fail (file != NULL, FALSE);
time (&t);
g_return_val_if_fail (EGG_IS_RECENT_MODEL (model), FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
- file = egg_recent_model_open_file (model);
+ file = egg_recent_model_open_file (model, TRUE);
g_return_val_if_fail (file != NULL, FALSE);
if (egg_recent_model_lock_file (file)) {
egg_recent_model_get_list (EggRecentModel *model)
{
FILE *file;
- GList *list=NULL;
+ GList *list = NULL;
- file = egg_recent_model_open_file (model);
- g_return_val_if_fail (file != NULL, NULL);
+ file = egg_recent_model_open_file (model, FALSE);
+ if (file == NULL)
+ return NULL;
- if (egg_recent_model_lock_file (file)) {
+ if (egg_recent_model_lock_file (file))
list = egg_recent_model_read (model, file);
-
- } else {
+ else {
g_warning ("Failed to lock: %s", strerror (errno));
fclose (file);
return NULL;
FILE *file;
int fd;
- file = egg_recent_model_open_file (model);
+ file = egg_recent_model_open_file (model, TRUE);
g_return_if_fail (file != NULL);
fd = fileno (file);
g_warning ("Failed to unlock: %s", strerror (errno));
fclose (file);
+
+ if (model->priv->monitor == NULL) {
+ /* since monitoring isn't working, at least give a
+ * local notification
+ */
+ egg_recent_model_changed (model);
+ }
}
+static void
+egg_recent_model_clear_mime_filter (EggRecentModel *model)
+{
+ g_return_if_fail (model != NULL);
+
+ if (model->priv->mime_filter_values != NULL) {
+ g_slist_foreach (model->priv->mime_filter_values,
+ (GFunc) g_pattern_spec_free, NULL);
+ g_slist_free (model->priv->mime_filter_values);
+ model->priv->mime_filter_values = NULL;
+ }
+}
/**
* egg_recent_model_set_filter_mime_types:
g_return_if_fail (model != NULL);
- if (model->priv->mime_filter_values != NULL) {
- g_slist_foreach (model->priv->mime_filter_values,
- (GFunc) g_pattern_spec_free, NULL);
- g_slist_free (model->priv->mime_filter_values);
- model->priv->mime_filter_values = NULL;
- }
+ egg_recent_model_clear_mime_filter (model);
va_start (valist, model);
model->priv->mime_filter_values = list;
}
+static void
+egg_recent_model_clear_group_filter (EggRecentModel *model)
+{
+ g_return_if_fail (model != NULL);
+
+ if (model->priv->group_filter_values != NULL) {
+ g_slist_foreach (model->priv->group_filter_values, (GFunc)g_free, NULL);
+ g_slist_free (model->priv->group_filter_values);
+ model->priv->group_filter_values = NULL;
+ }
+}
+
/**
* egg_recent_model_set_filter_groups:
* @model: A EggRecentModel object.
g_return_if_fail (model != NULL);
- if (model->priv->group_filter_values != NULL) {
- g_slist_foreach (model->priv->group_filter_values, (GFunc)g_free, NULL);
- g_slist_free (model->priv->group_filter_values);
- model->priv->group_filter_values = NULL;
- }
-
+ egg_recent_model_clear_group_filter (model);
+
va_start (valist, model);
str = va_arg (valist, gchar*);
model->priv->group_filter_values = list;
}
+static void
+egg_recent_model_clear_scheme_filter (EggRecentModel *model)
+{
+ g_return_if_fail (model != NULL);
+
+ if (model->priv->scheme_filter_values != NULL) {
+ g_slist_foreach (model->priv->scheme_filter_values,
+ (GFunc) g_pattern_spec_free, NULL);
+ g_slist_free (model->priv->scheme_filter_values);
+ model->priv->scheme_filter_values = NULL;
+ }
+}
+
/**
* egg_recent_model_set_filter_uri_schemes:
* @model: A EggRecentModel object.
g_return_if_fail (model != NULL);
- if (model->priv->scheme_filter_values != NULL) {
- g_slist_foreach (model->priv->scheme_filter_values,
- (GFunc) g_pattern_spec_free, NULL);
- g_slist_free (model->priv->scheme_filter_values);
- model->priv->scheme_filter_values = NULL;
- }
-
+ egg_recent_model_clear_scheme_filter (model);
+
va_start (valist, model);
str = va_arg (valist, gchar*);
g_return_if_fail (model != NULL);
- file = egg_recent_model_open_file (model);
- g_return_if_fail (file != NULL);
+ file = egg_recent_model_open_file (model, FALSE);
+ if (file == NULL)
+ return;
if (egg_recent_model_lock_file (file)) {
list = egg_recent_model_read (model, file);
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/**
+/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
#define EGG_RECENT_ACTION "EggRecentFile"
#define EGG_RECENT_SEPARATOR (NULL)
-#define LABEL_WIDTH_CHARS 32
+#ifndef EGG_COMPILATION
+#include <glib/gi18n.h>
+#else
+#define _(x) (x)
+#define N_(x) (x)
+#endif
+
+#define DEFAULT_LABEL_WIDTH_CHARS 30
struct _EggRecentViewUIManager {
GObject parent_instance;
EggRecentModel *model;
GConfClient *client;
GtkIconSize icon_size;
+
+ gint label_width;
};
PROP_UIMANAGER,
PROP_PATH,
PROP_SHOW_ICONS,
- PROP_SHOW_NUMBERS
+ PROP_SHOW_NUMBERS,
+ PROP_LABEL_WIDTH
};
static guint view_signals[LAST_SIGNAL] = { 0 };
+static void
+connect_proxy_cb (GtkActionGroup *action_group,
+ GtkAction *action,
+ GtkWidget *proxy,
+ EggRecentViewUIManager *view)
+{
+ if (GTK_IS_MENU_ITEM (proxy))
+ {
+ GtkWidget *label;
+
+ label = GTK_BIN (proxy)->child;
+
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_label_set_max_width_chars (GTK_LABEL (label), view->label_width);
+ }
+}
+
static void
egg_recent_view_uimanager_clear (EggRecentViewUIManager *view)
{
gtk_ui_manager_ensure_update (view->uimanager);
}
-static void
-connect_proxy_cb (GtkActionGroup *action_group,
- GtkAction *action,
- GtkWidget *proxy)
-{
- if (GTK_IS_MENU_ITEM (proxy))
- {
- GtkLabel *label;
-
- label = (GtkLabel *) ((GtkBin *) proxy)->child;
-
- gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (label, LABEL_WIDTH_CHARS);
- }
-}
-
-
static void
egg_recent_view_uimanager_set_list (EggRecentViewUIManager *view, GList *list)
{
view->action_group = gtk_action_group_new (group);
g_signal_connect (view->action_group, "connect-proxy",
G_CALLBACK (connect_proxy_cb), view);
- gtk_ui_manager_insert_action_group (view->uimanager, view->action_group, -1);
+ gtk_ui_manager_insert_action_group (view->uimanager,
+ view->action_group, -1);
g_free (group);
}
if (view->tooltip_func != NULL)
tooltip = (*view->tooltip_func) (item, view->tooltip_func_data);
- basename = g_path_get_basename (uri);
+ if (!tooltip)
+ tooltip = g_strdup_printf (_("Open '%s'"), uri);
+
+ basename = egg_recent_item_get_short_name (item);
escaped = egg_recent_util_escape_underlines (basename);
g_free (basename);
g_free (uri);
}
}
+static void
+egg_recent_view_uimanager_set_empty_list (EggRecentViewUIManager *view)
+{
+ gboolean is_embedded;
+
+ g_return_if_fail (view);
+
+ egg_recent_view_uimanager_clear (view);
+
+ if (view->merge_id == 0)
+ view->merge_id = gtk_ui_manager_new_merge_id (view->uimanager);
+
+ if (view->action_group == NULL) {
+ gchar *group = g_strdup_printf ("EggRecentActions%u",
+ view->merge_id);
+ view->action_group = gtk_action_group_new (group);
+ g_signal_connect (view->action_group, "connect-proxy",
+ G_CALLBACK (connect_proxy_cb), view);
+ gtk_ui_manager_insert_action_group (view->uimanager,
+ view->action_group, -1);
+ g_free (group);
+ }
+
+ if (view->leading_sep) {
+ gchar *sep_action = g_strdup_printf ("EggRecentLeadingSeparator%u",
+ view->merge_id);
+ gtk_ui_manager_add_ui (view->uimanager,
+ view->merge_id,
+ view->path,
+ sep_action,
+ EGG_RECENT_SEPARATOR,
+ GTK_UI_MANAGER_AUTO,
+ FALSE);
+ g_free (sep_action);
+ }
+
+ is_embedded = (view->leading_sep && view->trailing_sep);
+
+ if (is_embedded) {
+ GtkAction *action;
+ gchar *name;
+
+ name = g_strdup_printf (EGG_RECENT_NAME_PREFIX "%u-0", view->merge_id);
+
+ action = g_object_new (GTK_TYPE_ACTION,
+ "name", name,
+ "label", _("Empty"),
+ "sensitive", FALSE,
+ NULL);
+
+ gtk_action_group_add_action (view->action_group, action);
+ g_object_unref (action);
+
+ gtk_ui_manager_add_ui (view->uimanager,
+ view->merge_id,
+ view->path,
+ name,
+ name,
+ GTK_UI_MANAGER_AUTO,
+ FALSE);
+
+ g_free (name);
+ }
+
+ if (view->trailing_sep) {
+ gchar *sep_action = g_strdup_printf ("EggRecentTrailingSeparator%u",
+ view->merge_id);
+ gtk_ui_manager_add_ui (view->uimanager,
+ view->merge_id,
+ view->path,
+ sep_action,
+ EGG_RECENT_SEPARATOR,
+ GTK_UI_MANAGER_AUTO,
+ FALSE);
+ g_free (sep_action);
+ }
+}
+
static void
model_changed_cb (EggRecentModel *model,
GList *list,
if (list != NULL)
egg_recent_view_uimanager_set_list (view, list);
else
- egg_recent_view_uimanager_clear (view);
+ egg_recent_view_uimanager_set_empty_list (view);
+
gtk_ui_manager_ensure_update (view->uimanager);
}
case PROP_SHOW_NUMBERS:
egg_recent_view_uimanager_show_numbers (view, g_value_get_boolean (value));
break;
+ case PROP_LABEL_WIDTH:
+ egg_recent_view_uimanager_set_label_width (view, g_value_get_int (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_SHOW_NUMBERS:
g_value_set_boolean (value, view->show_numbers);
break;
+ case PROP_LABEL_WIDTH:
+ g_value_set_int (value, view->label_width);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
"Whether or not to show numbers",
TRUE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_LABEL_WIDTH,
+ g_param_spec_int ("label-width",
+ "Label Width",
+ "The desired width of the menu label, in characters",
+ -1,
+ G_MAXINT,
+ DEFAULT_LABEL_WIDTH_CHARS,
+ G_PARAM_READWRITE));
+
klass->activate = NULL;
}
view->tooltip_func_data = NULL;
view->icon_size = GTK_ICON_SIZE_MENU;
+ view->label_width = DEFAULT_LABEL_WIDTH_CHARS;
}
void
return view->path;
}
+void
+egg_recent_view_uimanager_set_label_width (EggRecentViewUIManager *view,
+ gint chars)
+{
+ g_return_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view));
+ view->label_width = chars;
+}
+
+gint
+egg_recent_view_uimanager_get_label_width (EggRecentViewUIManager *view)
+{
+ g_return_val_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view), DEFAULT_LABEL_WIDTH_CHARS);
+ return view->label_width;
+}
+
void
egg_recent_view_uimanager_set_action_func (EggRecentViewUIManager *view,
GCallback callback,
return EGG_RECENT_VIEW_UIMANAGER (view);
}
-/**
- * egg_recent_view_uimanager_get_type:
- * @:
- *
- * This returns a GType representing a EggRecentViewUIManager object.
- *
- * Returns: a GType
- */
GType
egg_recent_view_uimanager_get_type (void)
{