]> Pileus Git - ~andy/gtk/commitdiff
bloatpad: add left/centre/right toolbar buttons
authorRyan Lortie <desrt@desrt.ca>
Fri, 6 Jan 2012 17:51:10 +0000 (12:51 -0500)
committerRyan Lortie <desrt@desrt.ca>
Mon, 9 Jan 2012 14:02:08 +0000 (15:02 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=667394

examples/bloatpad.c

index 1f2a913c74e9e195e2265e48aff302db7c0639ad..30dd77342f136c831a6e0f11c1c62a0d541c446f 100644 (file)
@@ -13,6 +13,14 @@ activate_toggle (GSimpleAction *action,
   g_variant_unref (state);
 }
 
+static void
+activate_radio (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  g_action_change_state (G_ACTION (action), parameter);
+}
+
 static void
 change_fullscreen_state (GSimpleAction *action,
                          GVariant      *state,
@@ -26,6 +34,29 @@ change_fullscreen_state (GSimpleAction *action,
   g_simple_action_set_state (action, state);
 }
 
+static void
+change_justify_state (GSimpleAction *action,
+                      GVariant      *state,
+                      gpointer       user_data)
+{
+  GtkTextView *text = g_object_get_data (user_data, "bloatpad-text");
+  const gchar *str;
+
+  str = g_variant_get_string (state, NULL);
+
+  if (g_str_equal (str, "left"))
+    gtk_text_view_set_justification (text, GTK_JUSTIFY_LEFT);
+  else if (g_str_equal (str, "center"))
+    gtk_text_view_set_justification (text, GTK_JUSTIFY_CENTER);
+  else if (g_str_equal (str, "right"))
+    gtk_text_view_set_justification (text, GTK_JUSTIFY_RIGHT);
+  else
+    /* ignore this attempted change */
+    return;
+
+  g_simple_action_set_state (action, state);
+}
+
 static GtkClipboard *
 get_clipboard (GtkWidget *widget)
 {
@@ -62,7 +93,8 @@ window_paste (GSimpleAction *action,
 static GActionEntry win_entries[] = {
   { "copy", window_copy, NULL, NULL, NULL },
   { "paste", window_paste, NULL, NULL, NULL },
-  { "fullscreen", activate_toggle, NULL, "false", change_fullscreen_state }
+  { "fullscreen", activate_toggle, NULL, "false", change_fullscreen_state },
+  { "justify", activate_radio, "s", "'left'", change_justify_state }
 };
 
 static void
@@ -70,6 +102,8 @@ new_window (GApplication *app,
             GFile        *file)
 {
   GtkWidget *window, *grid, *scrolled, *view;
+  GtkWidget *toolbar;
+  GtkToolItem *button;
 
   window = gtk_application_window_new (GTK_APPLICATION (app));
   gtk_window_set_default_size ((GtkWindow*)window, 640, 480);
@@ -79,6 +113,21 @@ new_window (GApplication *app,
   grid = gtk_grid_new ();
   gtk_container_add (GTK_CONTAINER (window), grid);
 
+  toolbar = gtk_toolbar_new ();
+  button = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_JUSTIFY_LEFT);
+  gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button), "win.justify::left");
+  gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (button));
+
+  button = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_JUSTIFY_CENTER);
+  gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button), "win.justify::center");
+  gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (button));
+
+  button = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_JUSTIFY_RIGHT);
+  gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button), "win.justify::right");
+  gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (button));
+
+  gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 1, 1);
+
   scrolled = gtk_scrolled_window_new (NULL, NULL);
   gtk_widget_set_hexpand (scrolled, TRUE);
   gtk_widget_set_vexpand (scrolled, TRUE);
@@ -88,7 +137,7 @@ new_window (GApplication *app,
 
   gtk_container_add (GTK_CONTAINER (scrolled), view);
 
-  gtk_grid_attach (GTK_GRID (grid), scrolled, 0, 0, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), scrolled, 0, 1, 1, 1);
 
   if (file != NULL)
     {