aboutsummaryrefslogtreecommitdiffstats
path: root/src/ephy-encoding-menu.c
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-10-12 01:36:32 +0800
committerChristian Persch <chpe@src.gnome.org>2003-10-12 01:36:32 +0800
commit0b5f13ef5a9f6a28812cfa959ad9f5b786312ad2 (patch)
tree0ea5527c72c09963efef6ae55938c3b36969ad04 /src/ephy-encoding-menu.c
parent6c4b99d210e3391080ce18502a507dc38869189c (diff)
downloadgsoc2013-epiphany-0b5f13ef5a9f6a28812cfa959ad9f5b786312ad2.tar
gsoc2013-epiphany-0b5f13ef5a9f6a28812cfa959ad9f5b786312ad2.tar.gz
gsoc2013-epiphany-0b5f13ef5a9f6a28812cfa959ad9f5b786312ad2.tar.bz2
gsoc2013-epiphany-0b5f13ef5a9f6a28812cfa959ad9f5b786312ad2.tar.lz
gsoc2013-epiphany-0b5f13ef5a9f6a28812cfa959ad9f5b786312ad2.tar.xz
gsoc2013-epiphany-0b5f13ef5a9f6a28812cfa959ad9f5b786312ad2.tar.zst
gsoc2013-epiphany-0b5f13ef5a9f6a28812cfa959ad9f5b786312ad2.zip
Encoding menu improvements, part 2: Implement ephy_embed_get_encoding, and
2003-10-11 Christian Persch <chpe@cvs.gnome.org> * embed/ephy-embed.c: (ephy_embed_get_encoding): * embed/ephy-embed.h: * embed/mozilla/EphyWrapper.cpp: * embed/mozilla/EphyWrapper.h: * embed/mozilla/mozilla-embed.cpp: * src/ephy-encoding-menu.c: (ephy_encoding_menu_verb_cb), (update_encoding_menu_cb), (ephy_encoding_menu_set_window): Encoding menu improvements, part 2: Implement ephy_embed_get_encoding, and use it in the menu to indicate the encoding of the loaded page.
Diffstat (limited to 'src/ephy-encoding-menu.c')
-rw-r--r--src/ephy-encoding-menu.c69
1 files changed, 65 insertions, 4 deletions
diff --git a/src/ephy-encoding-menu.c b/src/ephy-encoding-menu.c
index 741e4226e..2f3596c23 100644
--- a/src/ephy-encoding-menu.c
+++ b/src/ephy-encoding-menu.c
@@ -31,6 +31,8 @@
#include <bonobo/bonobo-i18n.h>
#include <gtk/gtkaction.h>
+#include <gtk/gtktoggleaction.h>
+#include <gtk/gtkradioaction.h>
#include <gtk/gtkuimanager.h>
#include <string.h>
@@ -96,7 +98,15 @@ ephy_encoding_menu_verb_cb (GtkAction *action,
const char *encoding;
const char *action_name;
-
+ /* do nothing if this action was _de_activated, or if we're updating
+ * the menu, i.e. setting the active encoding from the document
+ */
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) == FALSE
+ || menu->priv->update_tag)
+ {
+ return;
+ }
+
embed = ephy_window_get_active_embed (menu->priv->window);
g_return_if_fail (embed != NULL);
@@ -123,11 +133,52 @@ ephy_encoding_menu_init (EphyEncodingMenu *menu)
}
static void
+update_encoding_menu_cb (GtkAction *dummy, EphyEncodingMenu *menu)
+{
+ EphyEmbed *embed;
+ GtkAction *action = NULL;
+ char *encoding;
+
+ embed = ephy_window_get_active_embed (menu->priv->window);
+ g_return_if_fail (embed != NULL);
+
+ ephy_embed_get_encoding (embed, &encoding);
+
+ if (encoding != NULL)
+ {
+ char name[32];
+
+ g_snprintf (name, 32, "Encoding%s", encoding);
+ action = gtk_action_group_get_action (menu->priv->action_group,
+ name);
+ }
+
+ if (action != NULL)
+ {
+ /* FIXME: block the "activate" signal instead; needs to wait
+ * until g_signal_handlers_block_matched supports blocking
+ * by signal id alone.
+ */
+ menu->priv->update_tag = TRUE;
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
+ menu->priv->update_tag = FALSE;
+ }
+ else
+ {
+ g_warning ("Could not find action for encoding '%s'!\n", encoding);
+ }
+
+ g_free (encoding);
+}
+
+static void
ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
{
EphyEmbedSingle *single;
GtkActionGroup *action_group;
+ GtkAction *action;
GList *encodings, *groups, *l;
+ GSList *radio_group = NULL;
g_return_if_fail (EPHY_IS_WINDOW (window));
@@ -145,15 +196,17 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
for (l = encodings; l != NULL; l = l->next)
{
const EncodingInfo *info = (EncodingInfo *) l->data;
- GtkAction *action;
char name[32];
g_snprintf (name, 32, "Encoding%s", info->encoding);
- action = g_object_new (GTK_TYPE_ACTION,
+ action = g_object_new (GTK_TYPE_RADIO_ACTION,
"name", name,
"label", info->title,
NULL);
+ gtk_radio_action_set_group (GTK_RADIO_ACTION (action), radio_group);
+ radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
+
g_signal_connect (action, "activate",
G_CALLBACK (ephy_encoding_menu_verb_cb),
menu);
@@ -170,7 +223,6 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
for (l = groups; l != NULL; l = l->next)
{
const LanguageGroupInfo *info = (LanguageGroupInfo *) l->data;
- GtkAction *action;
char name[32];
g_snprintf (name, 32, "EncodingGroup%d", info->group);
@@ -190,6 +242,15 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
action_group, 0);
g_object_unref (action_group);
+ action = gtk_ui_manager_get_action (menu->priv->manager,
+ "/menubar/ViewMenu");
+ if (action != NULL)
+ {
+ g_signal_connect_object (action, "activate",
+ G_CALLBACK (update_encoding_menu_cb),
+ menu, 0);
+ }
+
ephy_encoding_menu_rebuild (menu);
}