]> www.fi.muni.cz Git - evince.git/blobdiff - cut-n-paste/recent-files/egg-recent-view-uimanager.c
Respect the screen when opening help (#437866).
[evince.git] / cut-n-paste / recent-files / egg-recent-view-uimanager.c
index 1ae6f3e485ae9534f81e09d63f58f668bf2a2113..b8e3d4de042640a344efbd8e081e499ed9ef2dd7 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
 /* -*- 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
  * 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 EGG_RECENT_ACTION "EggRecentFile"
 #define EGG_RECENT_SEPARATOR (NULL)
 
+#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;
 
 struct _EggRecentViewUIManager {
        GObject         parent_instance;
 
@@ -71,6 +80,8 @@ struct _EggRecentViewUIManager {
        EggRecentModel *model;
        GConfClient    *client;
        GtkIconSize     icon_size;
        EggRecentModel *model;
        GConfClient    *client;
        GtkIconSize     icon_size;
+
+       gint            label_width;
 };
 
 
 };
 
 
@@ -92,11 +103,29 @@ enum {
        PROP_UIMANAGER,
        PROP_PATH,
        PROP_SHOW_ICONS,
        PROP_UIMANAGER,
        PROP_PATH,
        PROP_SHOW_ICONS,
-       PROP_SHOW_NUMBERS
+       PROP_SHOW_NUMBERS,
+       PROP_LABEL_WIDTH
 };
 
 static guint view_signals[LAST_SIGNAL] = { 0 };
 
 };
 
 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)
 {
 static void
 egg_recent_view_uimanager_clear (EggRecentViewUIManager *view)
 {
@@ -131,7 +160,10 @@ egg_recent_view_uimanager_set_list (EggRecentViewUIManager *view, GList *list)
                gchar *group = g_strdup_printf ("EggRecentActions%u", 
                                                view->merge_id);
                view->action_group = gtk_action_group_new (group);
                gchar *group = g_strdup_printf ("EggRecentActions%u", 
                                                view->merge_id);
                view->action_group = gtk_action_group_new (group);
-               gtk_ui_manager_insert_action_group (view->uimanager, view->action_group, 0);
+               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);
        }
 
                g_free (group);
        }
 
@@ -155,7 +187,6 @@ egg_recent_view_uimanager_set_list (EggRecentViewUIManager *view, GList *list)
                gchar         *uri;
                gchar         *basename;
                gchar         *escaped;
                gchar         *uri;
                gchar         *basename;
                gchar         *escaped;
-               gchar         *ellipsized;
                gchar         *label;
                gchar         *tooltip = NULL;
 
                gchar         *label;
                gchar         *tooltip = NULL;
 
@@ -170,30 +201,26 @@ egg_recent_view_uimanager_set_list (EggRecentViewUIManager *view, GList *list)
                if (view->tooltip_func != NULL)
                        tooltip = (*view->tooltip_func) (item, view->tooltip_func_data);
 
                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);
                escaped = egg_recent_util_escape_underlines (basename);
                g_free (basename);
                g_free (uri);
-           
-               if (strlen (escaped) > 40) {
-                       ellipsized = g_strdup_printf ("%.40s...", escaped);
-                       g_free (escaped);
-               } else {        
-                       ellipsized = escaped;
-               }
 
                if (view->show_numbers) {
                        if (index >= 10)
                                label = g_strdup_printf ("%d.  %s", 
                                                         index, 
 
                if (view->show_numbers) {
                        if (index >= 10)
                                label = g_strdup_printf ("%d.  %s", 
                                                         index, 
-                                                        ellipsized);
+                                                        escaped);
                        else
                                label = g_strdup_printf ("_%d.  %s", 
                                                         index, 
                        else
                                label = g_strdup_printf ("_%d.  %s", 
                                                         index, 
-                                                        ellipsized);
-                       g_free (ellipsized);
+                                                        escaped);
+                       g_free (escaped);
                } else 
                } else 
-                       label = ellipsized;
+                       label = escaped;
 
                action = g_object_new (GTK_TYPE_ACTION,
                                       "name", name,
 
                action = g_object_new (GTK_TYPE_ACTION,
                                       "name", name,
@@ -246,6 +273,84 @@ egg_recent_view_uimanager_set_list (EggRecentViewUIManager *view, GList *list)
        }
 }
 
        }
 }
 
+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, 
 static void
 model_changed_cb (EggRecentModel         *model,  
                  GList                  *list, 
@@ -254,7 +359,8 @@ model_changed_cb (EggRecentModel         *model,
        if (list != NULL)
                egg_recent_view_uimanager_set_list (view, list);
        else
        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);
 }
 
        gtk_ui_manager_ensure_update (view->uimanager);
 }
 
@@ -336,6 +442,9 @@ egg_recent_view_uimanager_set_property (GObject      *object,
        case PROP_SHOW_NUMBERS:
                egg_recent_view_uimanager_show_numbers (view, g_value_get_boolean (value));
                break;
        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;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -363,6 +472,9 @@ egg_recent_view_uimanager_get_property (GObject    *object,
        case PROP_SHOW_NUMBERS:
                g_value_set_boolean (value, view->show_numbers);
                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;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -410,6 +522,8 @@ egg_recent_view_uimanager_finalize (GObject *object)
                g_object_unref (view->client);
                view->client = NULL;
        }
                g_object_unref (view->client);
                view->client = NULL;
        }
+
+       G_OBJECT_CLASS (egg_recent_view_uimanager_parent_class)->finalize (object);
 }
 
 static void
 }
 
 static void
@@ -461,6 +575,16 @@ egg_recent_view_uimanager_class_init (EggRecentViewUIManagerClass * klass)
                                                               "Whether or not to show numbers",
                                                               TRUE,
                                                               G_PARAM_READWRITE));
                                                               "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;
 }
 
        klass->activate = NULL;
 }
@@ -536,6 +660,7 @@ egg_recent_view_uimanager_init (EggRecentViewUIManager * view)
        view->tooltip_func_data = NULL;
 
        view->icon_size = GTK_ICON_SIZE_MENU;
        view->tooltip_func_data = NULL;
 
        view->icon_size = GTK_ICON_SIZE_MENU;
+       view->label_width = DEFAULT_LABEL_WIDTH_CHARS;
 }
 
 void
 }
 
 void
@@ -650,6 +775,21 @@ egg_recent_view_uimanager_get_path (EggRecentViewUIManager *view)
        return view->path;
 }
 
        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,
 void
 egg_recent_view_uimanager_set_action_func (EggRecentViewUIManager   *view,
                                           GCallback                 callback,
@@ -694,21 +834,13 @@ egg_recent_view_uimanager_new (GtkUIManager  *uimanager,
        return EGG_RECENT_VIEW_UIMANAGER (view);
 }
 
        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)
 {
        static GType egg_recent_view_uimanager_type = 0;
 
        if(!egg_recent_view_uimanager_type) {
 GType
 egg_recent_view_uimanager_get_type (void)
 {
        static GType egg_recent_view_uimanager_type = 0;
 
        if(!egg_recent_view_uimanager_type) {
-               static const GTypeInfo egg_recent_view_uimanager_info = {
+               const GTypeInfo egg_recent_view_uimanager_info = {
                        sizeof (EggRecentViewUIManagerClass),
                        NULL, /* base init */
                        NULL, /* base finalize */
                        sizeof (EggRecentViewUIManagerClass),
                        NULL, /* base init */
                        NULL, /* base finalize */
@@ -720,7 +852,7 @@ egg_recent_view_uimanager_get_type (void)
                        (GInstanceInitFunc) egg_recent_view_uimanager_init
                };
 
                        (GInstanceInitFunc) egg_recent_view_uimanager_init
                };
 
-               static const GInterfaceInfo view_info =
+               const GInterfaceInfo view_info =
                {
                        (GInterfaceInitFunc) egg_recent_view_init,
                        NULL,
                {
                        (GInterfaceInitFunc) egg_recent_view_init,
                        NULL,