[yelp/yelp-3-0] Added ability to show text cursor with F7 or View menu



commit 90d229b9544f29087abab8caf77bd857233afbe2
Author: Shaun McCance <shaunm gnome org>
Date:   Fri Mar 26 16:13:17 2010 -0500

    Added ability to show text cursor with F7 or View menu

 data/ui/yelp-ui.xml     |    2 ++
 libyelp/yelp-settings.c |   34 +++++++++++++++++++++++++++++++++-
 libyelp/yelp-settings.h |    4 ++++
 libyelp/yelp-view.c     |   17 ++++++++++++++++-
 src/yelp-application.c  |   39 +++++++++++++++++++++++++++++++++++++++
 src/yelp-application.h  |   12 +++++++-----
 src/yelp-window.c       |   21 +++++++++++++++++++++
 7 files changed, 122 insertions(+), 7 deletions(-)
---
diff --git a/data/ui/yelp-ui.xml b/data/ui/yelp-ui.xml
index bde0506..35c95d2 100644
--- a/data/ui/yelp-ui.xml
+++ b/data/ui/yelp-ui.xml
@@ -7,6 +7,8 @@
     <menu action="ViewMenu">
       <menuitem action="LargerText"/>
       <menuitem action="SmallerText"/>
+      <separator/>
+      <menuitem action="ShowTextCursor"/>
     </menu>
     <menu action="GoMenu">
     </menu>
diff --git a/libyelp/yelp-settings.c b/libyelp/yelp-settings.c
index 15e7c6b..26034e1 100644
--- a/libyelp/yelp-settings.c
+++ b/libyelp/yelp-settings.c
@@ -45,6 +45,8 @@ struct _YelpSettingsPriv {
     gulong        gtk_font_changed;
     gulong        icon_theme_changed;
 
+    gboolean      show_text_cursor;
+
     gboolean      editor_mode;
 };
 
@@ -60,7 +62,8 @@ enum {
   PROP_0,
   PROP_GTK_SETTINGS,
   PROP_GTK_ICON_THEME,
-  PROP_FONT_ADJUSTMENT
+  PROP_FONT_ADJUSTMENT,
+  PROP_SHOW_TEXT_CURSOR
 };
 
 gchar *icon_names[YELP_SETTINGS_NUM_ICONS];
@@ -163,6 +166,16 @@ yelp_settings_class_init (YelpSettingsClass *klass)
                                                        G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
                                                        G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
+    g_object_class_install_property (object_class,
+                                     PROP_SHOW_TEXT_CURSOR,
+                                     g_param_spec_boolean ("show-text-cursor",
+                                                           _("Show Text Cursor"),
+                                                           _("Show the text cursor or caret for accessibile navigation"),
+                                                           FALSE,
+                                                           G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
+                                                           G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+                                                           
+
     settings_signals[COLORS_CHANGED] =
 	g_signal_new ("colors-changed",
 		      G_OBJECT_CLASS_TYPE (klass),
@@ -243,6 +256,9 @@ yelp_settings_get_property (GObject    *object,
     case PROP_FONT_ADJUSTMENT:
         g_value_set_int (value, settings->priv->font_adjustment);
         break;
+    case PROP_SHOW_TEXT_CURSOR:
+        g_value_set_boolean (value, settings->priv->show_text_cursor);
+        break;
     default:
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 	break;
@@ -325,6 +341,9 @@ yelp_settings_set_property (GObject      *object,
         settings->priv->font_adjustment = g_value_get_int (value);
         gtk_font_changed (settings->priv->gtk_settings, NULL, settings);
         break;
+    case PROP_SHOW_TEXT_CURSOR:
+        settings->priv->show_text_cursor = g_value_get_boolean (value);
+        break;
     default:
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 	break;
@@ -628,6 +647,19 @@ yelp_settings_get_icon_param (YelpSettingsIcon icon)
 
 /******************************************************************************/
 
+gboolean
+yelp_settings_get_show_text_cursor (YelpSettings *settings)
+{
+    return settings->priv->show_text_cursor;
+}
+
+void
+yelp_settings_set_show_text_cursor (YelpSettings *settings,
+                                    gboolean      show)
+{
+    g_object_set (settings, "show-text-cursor", show, NULL);
+}
+
 void
 yelp_settings_set_editor_mode (YelpSettings *settings,
                                gboolean      editor_mode)
diff --git a/libyelp/yelp-settings.h b/libyelp/yelp-settings.h
index 511af87..6a23044 100644
--- a/libyelp/yelp-settings.h
+++ b/libyelp/yelp-settings.h
@@ -118,6 +118,10 @@ gchar **            yelp_settings_get_all_params       (YelpSettings       *sett
                                                         gint                extra,
                                                         gint               *end);
 
+gboolean            yelp_settings_get_show_text_cursor (YelpSettings       *settings);
+void                yelp_settings_set_show_text_cursor (YelpSettings       *settings,
+                                                        gboolean            show);
+
 void                yelp_settings_set_editor_mode      (YelpSettings       *settings,
                                                         gboolean            editor_mode);
 
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index 365d4b6..725bafd 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -71,6 +71,7 @@ static void        view_show_error_page           (YelpView           *view,
                                                    GError             *error);
 
 static void        settings_set_fonts             (YelpSettings       *settings);
+static void        settings_show_text_cursor      (YelpSettings       *settings);
 
 static void        uri_resolved                   (YelpUri            *uri,
                                                    YelpView           *view);
@@ -188,9 +189,14 @@ yelp_view_class_init (YelpViewClass *klass)
     websettings = webkit_web_settings_new ();
     g_signal_connect (settings,
                       "fonts-changed",
-                      settings_set_fonts,
+                      G_CALLBACK (settings_set_fonts),
                       NULL);
     settings_set_fonts (settings);
+    g_signal_connect (settings,
+                      "notify::show-text-cursor",
+                      G_CALLBACK (settings_show_text_cursor),
+                      NULL);
+    settings_show_text_cursor (settings);
 
     object_class->dispose = yelp_view_dispose;
     object_class->finalize = yelp_view_finalize;
@@ -608,6 +614,15 @@ settings_set_fonts (YelpSettings *settings)
     g_free (family);
 }
 
+static void
+settings_show_text_cursor (YelpSettings *settings)
+{
+    g_object_set (websettings,
+                  "enable-caret-browsing",
+                  yelp_settings_get_show_text_cursor (settings),
+                  NULL);
+}
+
 /******************************************************************************/
 
 static void
diff --git a/src/yelp-application.c b/src/yelp-application.c
index cd0a430..f428b48 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -71,6 +71,9 @@ struct _YelpApplicationPrivate {
     GSList *windows;
 
     GHashTable *windows_by_document;
+
+    gboolean show_text_cursor;
+    gboolean map_show_text_cursor;
 };
 
 static void
@@ -156,6 +159,32 @@ yelp_application_adjust_font (YelpApplication  *app,
     }
 }
 
+void
+yelp_application_set_show_text_cursor (YelpApplication  *app,
+                                       gboolean          show)
+{
+    GSList *cur;
+    YelpSettings *settings = yelp_settings_get_default ();
+    YelpApplicationPrivate *priv = GET_PRIV (app);
+
+    /* We get callbacks in the loop. Ignore them. */
+    if (priv->map_show_text_cursor)
+        return;
+
+    priv->show_text_cursor = show;
+    yelp_settings_set_show_text_cursor (settings, show);
+    priv->map_show_text_cursor = TRUE;
+    for (cur = priv->windows; cur != NULL; cur = cur->next) {
+        YelpWindow *win = (YelpWindow *) cur->data;
+        GtkActionGroup *group = yelp_window_get_action_group (win);
+        GtkAction *action;
+
+        action = gtk_action_group_get_action (group, "ShowTextCursor");
+        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show);
+    }
+    priv->map_show_text_cursor = FALSE;
+}
+
 /******************************************************************************/
 
 YelpApplication *
@@ -301,8 +330,18 @@ application_uri_resolved (YelpUri             *uri,
     window = g_hash_table_lookup (priv->windows_by_document, doc_uri);
 
     if (window == NULL) {
+        GtkActionGroup *group;
+        GtkAction *action;
         window = yelp_window_new (data->app);
         priv->windows = g_slist_prepend (priv->windows, window);
+
+        group = yelp_window_get_action_group (window);
+        action = gtk_action_group_get_action (group, "ShowTextCursor");
+        priv->map_show_text_cursor = TRUE;
+        gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
+                                      priv->show_text_cursor);
+        priv->map_show_text_cursor = FALSE;
+
         g_hash_table_insert (priv->windows_by_document, doc_uri, window);
         g_object_set_data (G_OBJECT (window), "doc_uri", doc_uri);
         g_signal_connect (window, "delete-event",
diff --git a/src/yelp-application.h b/src/yelp-application.h
index 49542d4..a6ebc0d 100644
--- a/src/yelp-application.h
+++ b/src/yelp-application.h
@@ -54,11 +54,13 @@ gboolean          yelp_application_load_uri    (YelpApplication  *app,
                                                 guint             timestamp,
                                                 GError          **error);
 
-void              yelp_application_adjust_font     (YelpApplication  *app,
-                                                    gint              adjust);
+void              yelp_application_adjust_font          (YelpApplication  *app,
+                                                         gint              adjust);
 
-void              yelp_application_install_package (YelpApplication  *app,
-                                                    const gchar      *pkg,
-                                                    const gchar      *alt);
+void              yelp_application_set_show_text_cursor (YelpApplication  *app,
+                                                         gboolean          show);
+void              yelp_application_install_package      (YelpApplication   *app,
+                                                         const gchar       *pkg,
+                                                         const gchar       *alt);
 
 #endif /* __YELP_APPLICATION_H__ */
diff --git a/src/yelp-window.c b/src/yelp-window.c
index 444b8db..1fd0008 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -55,6 +55,8 @@ static void          window_open_location         (GtkAction          *action,
                                                    YelpWindow         *window);
 static void          window_font_adjustment       (GtkAction          *action,
                                                    YelpWindow         *window);
+static void          window_show_text_cursor      (GtkToggleAction    *action,
+                                                   YelpWindow         *window);
 
 static void          entry_location_selected      (YelpLocationEntry  *entry,
                                                    YelpWindow         *window);
@@ -184,6 +186,7 @@ yelp_window_init (YelpWindow *window)
 {
     GtkWidget *vbox, *scroll;
     GtkUIManager *ui_manager;
+    GtkAction *action;
     GError *error = NULL;
     YelpWindowPrivate *priv = GET_PRIV (window);
 
@@ -198,6 +201,14 @@ yelp_window_init (YelpWindow *window)
     gtk_action_group_add_actions (priv->action_group,
 				  entries, G_N_ELEMENTS (entries),
 				  window);
+    action = gtk_toggle_action_new ("ShowTextCursor",
+                                    _("Show Text _Cursor"),
+                                    NULL, NULL);
+    g_signal_connect (action, "activate",
+                      G_CALLBACK (window_show_text_cursor), window);
+    gtk_action_group_add_action_with_accel (priv->action_group,
+                                            action, "F7");
+
     ui_manager = gtk_ui_manager_new ();
     gtk_ui_manager_insert_action_group (ui_manager, priv->action_group, 0);
     gtk_window_add_accel_group (GTK_WINDOW (window),
@@ -482,6 +493,16 @@ window_font_adjustment (GtkAction  *action,
 }
 
 static void
+window_show_text_cursor (GtkToggleAction *action,
+                         YelpWindow *window)
+{
+    YelpWindowPrivate *priv = GET_PRIV (window);
+
+    yelp_application_set_show_text_cursor (priv->application,
+                                           gtk_toggle_action_get_active (action));
+}
+
+static void
 entry_location_selected (YelpLocationEntry  *entry,
                          YelpWindow         *window)
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]