[yelp/yelp-3-0] [yelp-window.c] Implement larger/smaller text menu items
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp/yelp-3-0] [yelp-window.c] Implement larger/smaller text menu items
- Date: Thu, 18 Mar 2010 01:52:34 +0000 (UTC)
commit a06002be19e3180893bad549682046a8c284e05c
Author: Shaun McCance <shaunm gnome org>
Date: Tue Mar 16 11:38:44 2010 -0500
[yelp-window.c] Implement larger/smaller text menu items
data/ui/yelp-ui.xml | 2 +
libyelp/yelp-settings.c | 7 +++--
src/yelp-window.c | 58 +++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 57 insertions(+), 10 deletions(-)
---
diff --git a/data/ui/yelp-ui.xml b/data/ui/yelp-ui.xml
index a7f3ab7..bde0506 100644
--- a/data/ui/yelp-ui.xml
+++ b/data/ui/yelp-ui.xml
@@ -5,6 +5,8 @@
<menuitem action="Close"/>
</menu>
<menu action="ViewMenu">
+ <menuitem action="LargerText"/>
+ <menuitem action="SmallerText"/>
</menu>
<menu action="GoMenu">
</menu>
diff --git a/libyelp/yelp-settings.c b/libyelp/yelp-settings.c
index c15599e..fe49bbb 100644
--- a/libyelp/yelp-settings.c
+++ b/libyelp/yelp-settings.c
@@ -157,8 +157,7 @@ yelp_settings_class_init (YelpSettingsClass *klass)
g_param_spec_int ("font-adjustment",
_("Font Adjustment"),
_("A size adjustment to add to font sizes"),
- -G_MAXINT, G_MAXINT,
- 0,
+ -3, 10, 0,
G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
@@ -510,7 +509,9 @@ yelp_settings_get_font_size (YelpSettings *settings,
done:
g_mutex_unlock (settings->priv->mutex);
- return ret + settings->priv->font_adjustment;
+ ret += settings->priv->font_adjustment;
+ ret = (ret < 5) ? 5 : ret;
+ return ret;
}
void
diff --git a/src/yelp-window.c b/src/yelp-window.c
index c1adb40..2b53adc 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -45,6 +45,8 @@ static void window_close (GtkAction *action,
YelpWindow *window);
static void window_open_location (GtkAction *action,
YelpWindow *window);
+static void window_font_adjustment (GtkAction *action,
+ YelpWindow *window);
static void entry_location_selected (YelpLocationEntry *entry,
YelpWindow *window);
@@ -102,6 +104,8 @@ typedef struct _YelpWindowPrivate YelpWindowPrivate;
struct _YelpWindowPrivate {
GtkListStore *history;
+ GtkActionGroup *action_group;
+
/* no refs on these, owned by containers */
YelpView *view;
GtkWidget *back_button;
@@ -130,17 +134,26 @@ static const GtkActionEntry entries[] = {
NULL,
G_CALLBACK (window_close) },
{ "OpenLocation", NULL,
- N_("Open _Location"),
+ N_("Open Location"),
"<Control>L",
NULL,
- G_CALLBACK (window_open_location) }
+ G_CALLBACK (window_open_location) },
+ { "LargerText", NULL,
+ N_("_Larger Text"),
+ "<Control>plus",
+ NULL,
+ G_CALLBACK (window_font_adjustment) },
+ { "SmallerText", NULL,
+ N_("_Smaller Text"),
+ "<Control>minus",
+ NULL,
+ G_CALLBACK (window_font_adjustment) }
};
static void
yelp_window_init (YelpWindow *window)
{
GtkWidget *vbox, *scroll;
- GtkActionGroup *action_group;
GtkUIManager *ui_manager;
GError *error = NULL;
YelpWindowPrivate *priv = GET_PRIV (window);
@@ -151,13 +164,13 @@ yelp_window_init (YelpWindow *window)
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
- action_group = gtk_action_group_new ("MenuActions");
- gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
- gtk_action_group_add_actions (action_group,
+ priv->action_group = gtk_action_group_new ("MenuActions");
+ gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE);
+ gtk_action_group_add_actions (priv->action_group,
entries, G_N_ELEMENTS (entries),
window);
ui_manager = gtk_ui_manager_new ();
- gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
+ gtk_ui_manager_insert_action_group (ui_manager, priv->action_group, 0);
gtk_window_add_accel_group (GTK_WINDOW (window),
gtk_ui_manager_get_accel_group (ui_manager));
if (!gtk_ui_manager_add_ui_from_file (ui_manager,
@@ -253,6 +266,11 @@ yelp_window_dispose (GObject *object)
priv->history = NULL;
}
+ if (priv->action_group) {
+ g_object_unref (priv->action_group);
+ priv->action_group = NULL;
+ }
+
if (priv->align_location) {
g_object_unref (priv->align_location);
priv->align_location = NULL;
@@ -351,6 +369,32 @@ window_open_location (GtkAction *action, YelpWindow *window)
}
static void
+window_font_adjustment (GtkAction *action,
+ YelpWindow *window)
+{
+ GtkAction *larger, *smaller;
+ YelpSettings *settings = yelp_settings_get_default ();
+ GParamSpec *spec = g_object_class_find_property (YELP_SETTINGS_GET_CLASS (settings),
+ "font-adjustment");
+ gint adjust = yelp_settings_get_font_adjustment (settings);
+ YelpWindowPrivate *priv = GET_PRIV (window);
+
+ if (!G_PARAM_SPEC_INT (spec)) {
+ g_warning ("Expcected integer param spec for font-adjustment");
+ return;
+ }
+
+ adjust += g_str_equal (gtk_action_get_name (action), "LargerText") ? 1 : -1;
+ yelp_settings_set_font_adjustment (settings, adjust);
+
+ larger = gtk_action_group_get_action (priv->action_group, "LargerText");
+ gtk_action_set_sensitive (larger, adjust < ((GParamSpecInt *) spec)->maximum);
+
+ smaller = gtk_action_group_get_action (priv->action_group, "SmallerText");
+ gtk_action_set_sensitive (smaller, adjust > ((GParamSpecInt *) spec)->minimum);
+}
+
+static void
entry_location_selected (YelpLocationEntry *entry,
YelpWindow *window)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]