add 'Re-edit' to the message context menu in the Drafts folder
[claws.git] / src / gtk / menu.c
index 0684b6fa753a0dc028d45c42bbb680c301ef9f8a..558869d543dd4fb16d65c98c07a97aa5965faa47 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
  *
  * 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
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
-#if !GTK_CHECK_VERSION(3, 0, 0)
 #include "gtkcmoptionmenu.h"
-#endif
 #include "menu.h"
 #include "utils.h"
 #include "gtkutils.h"
-
-#ifdef MAEMO
-#ifdef CHINOOK
-#include <hildon/hildon-program.h>
-#else
-#include <hildon-widgets/hildon-program.h>
-#endif
-#endif
+#include "defs.h"
 
 GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries,
                                            gint num_entries, gpointer data)
@@ -88,7 +79,7 @@ void cm_toggle_menu_set_active(gchar *menu, gboolean active)
        g_free(path);
 }
 
-void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, gchar *menu, gboolean sensitive)
+void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, const gchar *menu, gboolean sensitive)
 {
        GtkWidget *widget;
        gchar *path = g_strdup_printf("/%s/", menu);
@@ -103,6 +94,10 @@ void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, gchar *menu, gboolean
        }
 
        gtk_widget_set_sensitive(widget, sensitive);
+
+       if (strcmp(menu, "Menus/SummaryViewPopup/Reedit") == 0)
+               (sensitive)? gtk_widget_show(widget) : gtk_widget_hide(widget);
+
        g_free(path);
 }
 
@@ -133,6 +128,25 @@ gchar *cm_menu_item_get_shortcut(GtkUIManager *gui_manager, gchar *menu)
 
 }
 
+GtkWidget *cm_menu_item_new_label_from_url(gchar *url)
+{
+       gint len = strlen(url);
+       if (len > MAX_MENU_LABEL_LENGTH) {
+               g_message("Refusing a %d bytes string as menu label\n", len);
+               url[64] = '\0', url[63] = url[62] = url[61] = '.', url[60] = ' ';
+               GtkWidget *newlabel = gtk_menu_item_new_with_label(url);
+               gtk_widget_set_tooltip_markup(GTK_WIDGET(newlabel),
+                       g_strconcat("<span><b>", _("Warning:"), "</b>",
+                       _("This URL was too long for displaying and\n"
+                       "has been truncated for safety. This message could be\n"
+                       "corrupted, malformed or part of some DoS attempt."),
+                       "</span>", NULL));
+               return newlabel;
+       }
+       
+       return gtk_menu_item_new_with_label(url);
+}
+
 void cm_toggle_menu_set_active_full(GtkUIManager *gui_manager, gchar *menu, gboolean active)
 {
        GtkWidget *widget;
@@ -199,7 +213,6 @@ void menu_button_position(GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
                *y -= mreq.height;
 }
 
-#if !GTK_CHECK_VERSION(3, 0, 0)
 gint menu_find_option_menu_index(GtkCMOptionMenu *optmenu, gpointer data,
                                 GCompareFunc func)
 {
@@ -208,7 +221,7 @@ gint menu_find_option_menu_index(GtkCMOptionMenu *optmenu, gpointer data,
        gpointer menu_data;
        GList *children;
        GList *cur;
-       gint n;
+       gint n, found = -1;
 
        menu = gtk_cmoption_menu_get_menu(optmenu);
        children = gtk_container_get_children(GTK_CONTAINER(GTK_MENU_SHELL(menu)));
@@ -219,14 +232,17 @@ gint menu_find_option_menu_index(GtkCMOptionMenu *optmenu, gpointer data,
                menu_data = g_object_get_data(G_OBJECT(menuitem),
                                              MENU_VAL_ID);
                if (func) {
-                       if (func(menu_data, data) == 0)
-                               return n;
-               } else if (menu_data == data)
-                       return n;
+                       if (func(menu_data, data) == 0) {
+                               found = n;
+                               break;
+                       }
+               } else if (menu_data == data) {
+                       found = n;
+                       break;
+               }
        }
 
        g_list_free(children);
 
-       return -1;
+       return found;
 }
-#endif