=?utf-8?q?=5Bhitori=5D_Bug_676602_=E2=80=94_Port_to_GMenu?=



commit e40104c541facd63a5cb21c1e4572ad0ef1aa209
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Sep 29 02:39:46 2012 +0100

    Bug 676602 â Port to GMenu
    
    Split the menu up into an application and a window menu, and port them both
    to GMenu/GAction.
    
    The new menu layout is:
     â Application:
      - New Game
      - About Hitori
      - Help
      - Quit
     â Window:
      - Board Size (with submenu)
      - Hint
      - Undo
      - Redo
    
    This was chosen because the actions in the window menu all perform some
    operation specifically on the contents of the main window. Itâs arguable
    that âNew Gameâ should also be there, but that could be considered to open
    a new main window, sort of, so itâs in the application menu.
    
    Closes: https://bugzilla.gnome.org/show_bug.cgi?id=676602

 data/hitori.ui  |  258 +++++++++++++++++++------------------------------------
 src/interface.c |  192 ++++++++++++++++++++++++++---------------
 src/main.c      |   16 ++--
 src/main.h      |    6 +-
 4 files changed, 221 insertions(+), 251 deletions(-)
---
diff --git a/data/hitori.ui b/data/hitori.ui
index 00a7ee0..12dfc1a 100644
--- a/data/hitori.ui
+++ b/data/hitori.ui
@@ -1,183 +1,99 @@
 <?xml version="1.0"?>
 <!--*- mode: xml -*-->
 <interface>
-	<object class="GtkUIManager" id="hitori_ui_manager">
-		<child>
-			<object class="GtkActionGroup" id="hitori_action_group">
-				<child>
-					<object class="GtkAction" id="game_menu">
-						<property name="name">game_menu</property>
-						<property name="label" translatable="yes">_Game</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkAction" id="new_game_menu">
-						<property name="stock-id">gtk-new</property>
-						<property name="name">new_game_menu</property>
-						<signal name="activate" handler="hitori_new_game_cb"/>
-					</object>
-				</child>
-				<child>
-					<object class="GtkAction" id="board_size_menu">
-						<property name="label" translatable="yes">Board _Size</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkRadioAction" id="board_size_5">
-						<property name="label" translatable="yes">5Ã5</property>
-						<property name="value">5</property>
-						<property name="current-value">5</property>
-						<signal name="changed" handler="hitori_board_size_cb"/>
-					</object>
-				</child>
-				<child>
-					<object class="GtkRadioAction" id="board_size_6">
-						<property name="label" translatable="yes">6Ã6</property>
-						<property name="value">6</property>
-						<property name="group">board_size_5</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkRadioAction" id="board_size_7">
-						<property name="label" translatable="yes">7Ã7</property>
-						<property name="value">7</property>
-						<property name="group">board_size_5</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkRadioAction" id="board_size_8">
-						<property name="label" translatable="yes">8Ã8</property>
-						<property name="value">8</property>
-						<property name="group">board_size_5</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkRadioAction" id="board_size_9">
-						<property name="label" translatable="yes">9Ã9</property>
-						<property name="value">9</property>
-						<property name="group">board_size_5</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkRadioAction" id="board_size_10">
-						<property name="label" translatable="yes">10Ã10</property>
-						<property name="value">10</property>
-						<property name="group">board_size_5</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkAction" id="hint_menu">
-						<property name="stock-id">gtk-info</property>
-						<property name="name">hint_menu</property>
-						<property name="label" translatable="yes">_Hint</property>
-						<signal name="activate" handler="hitori_hint_cb"/>
-					</object>
-					<accelerator key="H" modifiers="GDK_CONTROL_MASK"/>
-				</child>
-				<child>
-					<object class="GtkAction" id="undo_menu">
-						<property name="stock-id">gtk-undo</property>
-						<property name="name">undo_menu</property>
-						<property name="sensitive">False</property>
-						<signal name="activate" handler="hitori_undo_cb"/>
-					</object>
-					<accelerator key="Z" modifiers="GDK_CONTROL_MASK"/>
-				</child>
-				<child>
-					<object class="GtkAction" id="redo_menu">
-						<property name="stock-id">gtk-redo</property>
-						<property name="name">redo_menu</property>
-						<property name="sensitive">False</property>
-						<signal name="activate" handler="hitori_redo_cb"/>
-					</object>
-					<accelerator key="Z" modifiers="GDK_CONTROL_MASK|GDK_SHIFT_MASK"/>
-				</child>
-				<child>
-					<object class="GtkAction" id="quit_menu">
-						<property name="stock-id">gtk-quit</property>
-						<property name="name">quit_menu</property>
-						<signal name="activate" handler="hitori_quit_cb"/>
-					</object>
-				</child>
-				<!--<child>
-					<object class="GtkAction" id="settings_menu">
-						<property name="name">settings_menu</property>
-						<property name="label" translatable="yes">_Settings</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkAction" id="preferences_menu">
-						<property name="stock-id">gtk-preferences</property>
-						<property name="name">preferences_menu</property>
-					</object>
-				</child>-->
-				<child>
-					<object class="GtkAction" id="help_menu">
-						<property name="name">help_menu</property>
-						<property name="label" translatable="yes">_Help</property>
-					</object>
-				</child>
-				<child>
-					<object class="GtkAction" id="contents_menu">
-						<property name="stock-id">gtk-help</property>
-						<property name="name">contents_menu</property>
-						<signal name="activate" handler="hitori_contents_cb"/>
-					</object>
-					<accelerator key="F1"/>
-				</child>
-				<child>
-					<object class="GtkAction" id="about_menu">
-						<property name="stock-id">gtk-about</property>
-						<property name="name">about_menu</property>
-						<signal name="activate" handler="hitori_about_cb"/>
-					</object>
-				</child>
-			</object>
-		</child>
-		<ui>
-			<menubar name="hitori_menu_bar">
-				<menu action="game_menu">
-					<menuitem action="new_game_menu"/>
-					<separator/>
-					<menuitem action="hint_menu"/>
-					<separator/>
-					<menu name="board_size" action="board_size_menu">
-						<menuitem name="board_size_5" action="board_size_5"/>
-						<menuitem name="board_size_6" action="board_size_6"/>
-						<menuitem name="board_size_7" action="board_size_7"/>
-						<menuitem name="board_size_8" action="board_size_8"/>
-						<menuitem name="board_size_9" action="board_size_9"/>
-						<menuitem name="board_size_10" action="board_size_10"/>
-					</menu>
-					<separator/>
-					<menuitem action="undo_menu"/>
-					<menuitem action="redo_menu"/>
-					<separator/>
-					<menuitem action="quit_menu"/>
-				</menu>
-				<!--<menu action="settings_menu">
-					<menuitem action="preferences_menu"/>
-				</menu>-->
-				<menu action="help_menu">
-					<menuitem action="contents_menu"/>
-					<menuitem action="about_menu"/>
-				</menu>
-			</menubar>
-		</ui>
-	</object>
-	<object class="GtkWindow" id="hitori_main_window">
+	<menu id="app_menu">
+		<section>
+			<item>
+				<attribute name="action">app.new-game</attribute>
+				<attribute name="label" translatable="yes">_New Game</attribute>
+				<attribute name="accel">&lt;Primary&gt;n</attribute>
+			</item>
+		</section>
+		<section>
+			<item>
+				<attribute name="action">app.about</attribute>
+				<attribute name="label" translatable="yes">_About Hitori</attribute>
+			</item>
+			<item>
+				<attribute name="action">app.help</attribute>
+				<attribute name="label" translatable="yes">_Help</attribute>
+				<attribute name="accel">F1</attribute>
+			</item>
+			<item>
+				<attribute name="action">app.quit</attribute>
+				<attribute name="label" translatable="yes">_Quit</attribute>
+				<attribute name="accel">&lt;Primary&gt;q</attribute>
+			</item>
+		</section>
+	</menu>
+
+	<menu id="win_menu">
+		<submenu>
+			<attribute name="label" translatable="yes">_Game</attribute>
+			<submenu id="board_size_menu">
+				<attribute name="label" translatable="yes">Board _Size</attribute>
+				<section>
+					<item>
+						<attribute name="action">win.board-size</attribute>
+						<attribute name="label" translatable="yes">5Ã5</attribute>
+						<attribute name="target">5</attribute>
+					</item>
+					<item>
+						<attribute name="action">win.board-size</attribute>
+						<attribute name="label" translatable="yes">6Ã6</attribute>
+						<attribute name="target">6</attribute>
+					</item>
+					<item>
+						<attribute name="action">win.board-size</attribute>
+						<attribute name="label" translatable="yes">7Ã7</attribute>
+						<attribute name="target">7</attribute>
+					</item>
+					<item>
+						<attribute name="action">win.board-size</attribute>
+						<attribute name="label" translatable="yes">8Ã8</attribute>
+						<attribute name="target">8</attribute>
+					</item>
+					<item>
+						<attribute name="action">win.board-size</attribute>
+						<attribute name="label" translatable="yes">9Ã9</attribute>
+						<attribute name="target">9</attribute>
+					</item>
+					<item>
+						<attribute name="action">win.board-size</attribute>
+						<attribute name="label" translatable="yes">10Ã10</attribute>
+						<attribute name="target">10</attribute>
+					</item>
+				</section>
+			</submenu>
+			<section>
+				<item>
+					<attribute name="action">win.hint</attribute>
+					<attribute name="label" translatable="yes">_Hint</attribute>
+					<attribute name="accel">&lt;Primary&gt;h</attribute>
+				</item>
+			</section>
+			<section>
+				<item>
+					<attribute name="action">win.undo</attribute>
+					<attribute name="label" translatable="yes">_Undo</attribute>
+					<attribute name="accel">&lt;Primary&gt;z</attribute>
+				</item>
+				<item>
+					<attribute name="action">win.redo</attribute>
+					<attribute name="label" translatable="yes">_Redo</attribute>
+					<attribute name="accel">&lt;Primary&gt;&lt;Shift&gt;z</attribute>
+				</item>
+			</section>
+		</submenu>
+	</menu>
+
+	<object class="GtkApplicationWindow" id="hitori_main_window">
 		<property name="title" translatable="yes">Hitori</property>
 		<signal name="destroy" handler="hitori_destroy_cb"/>
 		<signal name="window-state-event" handler="hitori_window_state_event_cb"/>
 		<child>
 			<object class="GtkVBox" id="vbox1">
 				<child>
-					<object class="GtkMenuBar" constructor="hitori_ui_manager" id="hitori_menu_bar"/>
-					<packing>
-						<property name="expand">False</property>
-					</packing>
-				</child>
-				<child>
 					<object class="GtkDrawingArea" id="hitori_drawing_area">
 						<property name="width-request">400</property>
 						<property name="height-request">400</property>
diff --git a/src/interface.c b/src/interface.c
index 6f81c49..a9128a2 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -44,14 +44,29 @@ gboolean hitori_draw_cb (GtkWidget *drawing_area, cairo_t *cr, Hitori *hitori);
 gboolean hitori_button_release_cb (GtkWidget *drawing_area, GdkEventButton *event, Hitori *hitori);
 void hitori_destroy_cb (GtkWindow *window, Hitori *hitori);
 void hitori_window_state_event_cb (GtkWindow *window, GdkEventWindowState *event, Hitori *hitori);
-void hitori_new_game_cb (GtkAction *action, Hitori *hitori);
-void hitori_hint_cb (GtkAction *action, Hitori *hitori);
-void hitori_undo_cb (GtkAction *action, Hitori *hitori);
-void hitori_redo_cb (GtkAction *action, Hitori *hitori);
-void hitori_quit_cb (GtkAction *action, Hitori *hitori);
-void hitori_contents_cb (GtkAction *action, Hitori *hitori);
-void hitori_about_cb (GtkAction *action, Hitori *hitori);
-void hitori_board_size_cb (GtkRadioAction *action, GtkRadioAction *current, Hitori *hitori);
+static void new_game_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void hint_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void undo_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void redo_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void quit_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void help_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void about_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void board_size_activate_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void board_size_change_cb (GSimpleAction *action, GVariant *state, gpointer user_data);
+
+static GActionEntry app_entries[] = {
+	{ "new-game", new_game_cb, NULL, NULL, NULL },
+	{ "about", about_cb, NULL, NULL, NULL },
+	{ "help", help_cb, NULL, NULL, NULL },
+	{ "quit", quit_cb, NULL, NULL, NULL },
+};
+
+static GActionEntry win_entries[] = {
+	{ "board-size", board_size_activate_cb, "s", "'5'", board_size_change_cb },
+	{ "hint", hint_cb, NULL, NULL, NULL },
+	{ "undo", undo_cb, NULL, NULL, NULL },
+	{ "redo", redo_cb, NULL, NULL, NULL },
+};
 
 GtkWidget *
 hitori_create_interface (Hitori *hitori)
@@ -87,11 +102,19 @@ hitori_create_interface (Hitori *hitori)
 	/* Setup the main window */
 	hitori->window = GTK_WIDGET (gtk_builder_get_object (builder, "hitori_main_window"));
 	hitori->drawing_area = GTK_WIDGET (gtk_builder_get_object (builder, "hitori_drawing_area"));
-	hitori->undo_action = GTK_ACTION (gtk_builder_get_object (builder, "undo_menu"));
-	hitori->redo_action = GTK_ACTION (gtk_builder_get_object (builder, "redo_menu"));
-	hitori->hint_action = GTK_ACTION (gtk_builder_get_object (builder, "hint_menu"));
 	hitori->timer_label = GTK_LABEL (gtk_builder_get_object (builder, "hitori_timer"));
 
+	/* Set up the menus (application and window). */
+	g_action_map_add_action_entries (G_ACTION_MAP (hitori), app_entries, G_N_ELEMENTS (app_entries), hitori);
+	gtk_application_set_app_menu (GTK_APPLICATION (hitori), G_MENU_MODEL (gtk_builder_get_object (builder, "app_menu")));
+
+	g_action_map_add_action_entries (G_ACTION_MAP (hitori->window), win_entries, G_N_ELEMENTS (win_entries), hitori);
+	gtk_application_set_menubar (GTK_APPLICATION (hitori), G_MENU_MODEL (gtk_builder_get_object (builder, "win_menu")));
+
+	hitori->undo_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), "undo"));
+	hitori->redo_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), "redo"));
+	hitori->hint_action = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), "hint"));
+
 	g_object_unref (builder);
 
 	/* Set up font descriptions for the drawing area */
@@ -102,6 +125,13 @@ hitori_create_interface (Hitori *hitori)
 	/* Reset the timer */
 	hitori_reset_timer (hitori);
 
+	/* Disable undo/redo until a cell has been clicked. */
+	g_simple_action_set_enabled (hitori->undo_action, FALSE);
+	g_simple_action_set_enabled (hitori->redo_action, FALSE);
+
+	/* Set the initial board size. */
+	g_simple_action_set_state (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (hitori->window), "board-size")), g_variant_new_string ("5"));
+
 	return hitori->window;
 }
 
@@ -327,7 +357,7 @@ hitori_button_release_cb (GtkWidget *drawing_area, GdkEventButton *event, Hitori
 	if (hitori->undo_stack != NULL)
 		hitori->undo_stack->redo = undo;
 	hitori->undo_stack = undo;
-	gtk_action_set_sensitive (hitori->undo_action, TRUE);
+	g_simple_action_set_enabled (hitori->undo_action, TRUE);
 
 	/* Stop any current hints */
 	hitori_cancel_hinting (hitori);
@@ -365,10 +395,11 @@ hitori_window_state_event_cb (GtkWindow *window, GdkEventWindowState *event, Hit
 	}
 }
 
-void
-hitori_new_game_cb (GtkAction *action, Hitori *hitori)
+static void
+new_game_cb (GSimpleAction *action, GVariant *parameters, gpointer user_data)
 {
-	hitori_new_game (hitori, hitori->board_size);
+	HitoriApplication *self = HITORI_APPLICATION (user_data);
+	hitori_new_game (self, self->board_size);
 }
 
 static void
@@ -429,30 +460,31 @@ hitori_update_hint (Hitori *hitori)
 	return TRUE;
 }
 
-void
-hitori_hint_cb (GtkAction *action, Hitori *hitori)
+static void
+hint_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
 {
+	HitoriApplication *self = HITORI_APPLICATION (user_data);
 	HitoriVector iter;
 
 	/* Bail if we're already hinting */
-	if (hitori->hint_status != HINT_DISABLED)
+	if (self->hint_status != HINT_DISABLED)
 		return;
 
 	/* Find the first cell which should be painted, but isn't (or vice-versa) */
-	for (iter.x = 0; iter.x < hitori->board_size; iter.x++) {
-		for (iter.y = 0; iter.y < hitori->board_size; iter.y++) {
-			guchar status = hitori->board[iter.x][iter.y].status & (CELL_PAINTED | CELL_SHOULD_BE_PAINTED);
+	for (iter.x = 0; iter.x < self->board_size; iter.x++) {
+		for (iter.y = 0; iter.y < self->board_size; iter.y++) {
+			guchar status = self->board[iter.x][iter.y].status & (CELL_PAINTED | CELL_SHOULD_BE_PAINTED);
 
 			if (status <= MAX (CELL_SHOULD_BE_PAINTED, CELL_PAINTED) &&
 			    status > 0) {
-				if (hitori->debug)
+				if (self->debug)
 					g_debug ("Beginning hinting in cell (%u,%u).", iter.x, iter.y);
 
 				/* Set up the cell for hinting */
-				hitori->hint_status = HINT_FLASHES;
-				hitori->hint_position = iter;
-				hitori->hint_timeout_id = g_timeout_add (HINT_INTERVAL, (GSourceFunc) hitori_update_hint, hitori);
-				hitori_update_hint ((gpointer) hitori);
+				self->hint_status = HINT_FLASHES;
+				self->hint_position = iter;
+				self->hint_timeout_id = g_timeout_add (HINT_INTERVAL, (GSourceFunc) hitori_update_hint, self);
+				hitori_update_hint ((gpointer) self);
 
 				return;
 			}
@@ -460,25 +492,27 @@ hitori_hint_cb (GtkAction *action, Hitori *hitori)
 	}
 }
 
-void
-hitori_undo_cb (GtkAction *action, Hitori *hitori)
+static void
+undo_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
 {
-	if (hitori->undo_stack->undo == NULL)
+	HitoriApplication *self = HITORI_APPLICATION (user_data);
+
+	if (self->undo_stack->undo == NULL)
 		return;
 
-	switch (hitori->undo_stack->type) {
+	switch (self->undo_stack->type) {
 		case UNDO_PAINT:
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_PAINTED;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_PAINTED;
 			break;
 		case UNDO_TAG1:
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_TAG1;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_TAG1;
 			break;
 		case UNDO_TAG2:
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_TAG2;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_TAG2;
 			break;
 		case UNDO_TAGS:
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_TAG1;
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_TAG2;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_TAG1;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_TAG2;
 			break;
 		case UNDO_NEW_GAME:
 		default:
@@ -487,40 +521,42 @@ hitori_undo_cb (GtkAction *action, Hitori *hitori)
 			break;
 	}
 
-	hitori->undo_stack = hitori->undo_stack->undo;
+	self->undo_stack = self->undo_stack->undo;
 
-	gtk_action_set_sensitive (hitori->redo_action, TRUE);
-	if (hitori->undo_stack->undo == NULL || hitori->undo_stack->type == UNDO_NEW_GAME)
-		gtk_action_set_sensitive (hitori->undo_action, FALSE);
+	g_simple_action_set_enabled (self->redo_action, TRUE);
+	if (self->undo_stack->undo == NULL || self->undo_stack->type == UNDO_NEW_GAME)
+		g_simple_action_set_enabled (self->undo_action, FALSE);
 
 	/* The player can't possibly have won, but we need to update the error highlighting */
-	hitori_check_win (hitori);
+	hitori_check_win (self);
 
 	/* Redraw */
-	gtk_widget_queue_draw (hitori->drawing_area);
+	gtk_widget_queue_draw (self->drawing_area);
 }
 
-void
-hitori_redo_cb (GtkAction *action, Hitori *hitori)
+static void
+redo_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
 {
-	if (hitori->undo_stack->redo == NULL)
+	HitoriApplication *self = HITORI_APPLICATION (user_data);
+
+	if (self->undo_stack->redo == NULL)
 		return;
 
-	hitori->undo_stack = hitori->undo_stack->redo;
+	self->undo_stack = self->undo_stack->redo;
 
-	switch (hitori->undo_stack->type) {
+	switch (self->undo_stack->type) {
 		case UNDO_PAINT:
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_PAINTED;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_PAINTED;
 			break;
 		case UNDO_TAG1:
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_TAG1;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_TAG1;
 			break;
 		case UNDO_TAG2:
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_TAG2;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_TAG2;
 			break;
 		case UNDO_TAGS:
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_TAG1;
-			hitori->board[hitori->undo_stack->cell.x][hitori->undo_stack->cell.y].status ^= CELL_TAG2;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_TAG1;
+			self->board[self->undo_stack->cell.x][self->undo_stack->cell.y].status ^= CELL_TAG2;
 			break;
 		case UNDO_NEW_GAME:
 		default:
@@ -529,30 +565,32 @@ hitori_redo_cb (GtkAction *action, Hitori *hitori)
 			break;
 	}
 
-	gtk_action_set_sensitive (hitori->undo_action, TRUE);
-	if (hitori->undo_stack->redo == NULL)
-		gtk_action_set_sensitive (hitori->redo_action, FALSE);
+	g_simple_action_set_enabled (self->undo_action, TRUE);
+	if (self->undo_stack->redo == NULL)
+		g_simple_action_set_enabled (self->redo_action, FALSE);
 
 	/* The player can't possibly have won, but we need to update the error highlighting */
-	hitori_check_win (hitori);
+	hitori_check_win (self);
 
 	/* Redraw */
-	gtk_widget_queue_draw (hitori->drawing_area);
+	gtk_widget_queue_draw (self->drawing_area);
 }
 
-void
-hitori_quit_cb (GtkAction *action, Hitori *hitori)
+static void
+quit_cb (GSimpleAction *action, GVariant *parameters, gpointer user_data)
 {
-	hitori_quit (hitori);
+	HitoriApplication *self = HITORI_APPLICATION (user_data);
+	hitori_quit (self);
 }
 
-void
-hitori_contents_cb (GtkAction *action, Hitori *hitori)
+static void
+help_cb (GSimpleAction *action, GVariant *parameters, gpointer user_data)
 {
+	HitoriApplication *self = HITORI_APPLICATION (user_data);
 	GError *error = NULL;
 
-	if (gtk_show_uri (gtk_widget_get_screen (hitori->window), "help:hitori", gtk_get_current_event_time (), &error) == FALSE) {
-		GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (hitori->window),
+	if (gtk_show_uri (gtk_widget_get_screen (self->window), "help:hitori", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (self->window),
 							    GTK_DIALOG_MODAL,
 							    GTK_MESSAGE_ERROR,
 							    GTK_BUTTONS_OK,
@@ -566,10 +604,12 @@ hitori_contents_cb (GtkAction *action, Hitori *hitori)
 	}
 }
 
-void
-hitori_about_cb (GtkAction *action, Hitori *hitori)
+static void
+about_cb (GSimpleAction *action, GVariant *parameters, gpointer user_data)
 {
+	HitoriApplication *self = HITORI_APPLICATION (user_data);
 	gchar *license;
+
 	const gchar *authors[] =
 	{
 		"Philip Withnall <philip tecnocode co uk>",
@@ -595,7 +635,7 @@ hitori_about_cb (GtkAction *action, Hitori *hitori)
 			  _(license_parts[2]),
 			  NULL);
 
-	gtk_show_about_dialog (GTK_WINDOW (hitori->window),
+	gtk_show_about_dialog (GTK_WINDOW (self->window),
 				"version", VERSION,
 				"copyright", _("Copyright \xc2\xa9 2007\342\200\2232010 Philip Withnall"),
 				"comments", _("A logic puzzle designed by Nikoli."),
@@ -611,8 +651,22 @@ hitori_about_cb (GtkAction *action, Hitori *hitori)
 	g_free (license);
 }
 
-void
-hitori_board_size_cb (GtkRadioAction *action, GtkRadioAction *current, Hitori *hitori)
+static void
+board_size_activate_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+	g_action_change_state (G_ACTION (action), parameter);
+}
+
+static void
+board_size_change_cb (GSimpleAction *action, GVariant *state, gpointer user_data)
 {
-	hitori_set_board_size (hitori, gtk_radio_action_get_current_value (current));
+	HitoriApplication *self = HITORI_APPLICATION (user_data);
+	const gchar *size_str;
+	guint64 size;
+
+	size_str = g_variant_get_string (state, NULL);
+	size = g_ascii_strtoull (size_str, NULL, 10);
+	hitori_set_board_size (self, size);
+
+	g_simple_action_set_state (action, state);
 }
diff --git a/src/main.c b/src/main.c
index 5244734..45d2804 100644
--- a/src/main.c
+++ b/src/main.c
@@ -281,8 +281,8 @@ hitori_clear_undo_stack (Hitori *hitori)
 	hitori->undo_stack->undo = NULL;
 	hitori->undo_stack->redo = NULL;
 
-	gtk_action_set_sensitive (hitori->undo_action, FALSE);
-	gtk_action_set_sensitive (hitori->redo_action, FALSE);
+	g_simple_action_set_enabled (hitori->undo_action, FALSE);
+	g_simple_action_set_enabled (hitori->redo_action, FALSE);
 }
 
 void
@@ -344,10 +344,10 @@ hitori_enable_events (Hitori *hitori)
 	hitori->processing_events = TRUE;
 
 	if (hitori->undo_stack->redo != NULL)
-		gtk_action_set_sensitive (hitori->redo_action, TRUE);
+		g_simple_action_set_enabled (hitori->redo_action, TRUE);
 	if (hitori->undo_stack->undo != NULL)
-		gtk_action_set_sensitive (hitori->redo_action, TRUE);
-	gtk_action_set_sensitive (hitori->hint_action, TRUE);
+		g_simple_action_set_enabled (hitori->redo_action, TRUE);
+	g_simple_action_set_enabled (hitori->hint_action, TRUE);
 
 	hitori_start_timer (hitori);
 }
@@ -356,9 +356,9 @@ void
 hitori_disable_events (Hitori *hitori)
 {
 	hitori->processing_events = FALSE;
-	gtk_action_set_sensitive (hitori->redo_action, FALSE);
-	gtk_action_set_sensitive (hitori->undo_action, FALSE);
-	gtk_action_set_sensitive (hitori->hint_action, FALSE);
+	g_simple_action_set_enabled (hitori->redo_action, FALSE);
+	g_simple_action_set_enabled (hitori->undo_action, FALSE);
+	g_simple_action_set_enabled (hitori->hint_action, FALSE);
 
 	hitori_pause_timer (hitori);
 }
diff --git a/src/main.h b/src/main.h
index 64a0f89..95357a6 100644
--- a/src/main.h
+++ b/src/main.h
@@ -77,9 +77,9 @@ typedef struct {
 	/* FIXME: This should all be merged into priv. */
 	GtkWidget *window;
 	GtkWidget *drawing_area;
-	GtkAction *undo_action;
-	GtkAction *redo_action;
-	GtkAction *hint_action;
+	GSimpleAction *undo_action;
+	GSimpleAction *redo_action;
+	GSimpleAction *hint_action;
 
 	gdouble drawing_area_width;
 	gdouble drawing_area_height;



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