[gnome-mines] Remove the preferences dialog



commit fb559ade42a4f8e30f52d781dbc786d81bacd95b
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Apr 17 10:30:35 2014 -0500

    Remove the preferences dialog
    
    We only have two user-visible settings. They can more comfortably live
    in the app menu.

 src/gnome-mines.vala    |  102 +++++++++--------------------------------------
 src/minefield-view.vala |   47 ++++++++++++----------
 2 files changed, 45 insertions(+), 104 deletions(-)
---
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index bfc08d5..8bb2429 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -20,9 +20,11 @@ public class Mines : Gtk.Application
     private const int YSIZE_MAX = 100;
     private const string KEY_NMINES = "nmines";
     private const string KEY_MODE = "mode";
-    private const string KEY_USE_QUESTION_MARKS = "use-question-marks";
-    private const string KEY_USE_OVERMINE_WARNING = "use-overmine-warning";
-    private const string KEY_USE_AUTOFLAG = "use-autoflag";
+
+    /* Keys shared with MinefieldView */
+    public static const string KEY_USE_QUESTION_MARKS = "use-question-marks";
+    public static const string KEY_USE_OVERMINE_WARNING = "use-overmine-warning";
+    public static const string KEY_USE_AUTOFLAG = "use-autoflag";
 
     private Gtk.Box buttons_box;
     private Gtk.Button play_pause_button;
@@ -58,7 +60,6 @@ public class Mines : Gtk.Application
     /* Game status */
     private Gtk.Label flag_label;
 
-    private Gtk.Dialog? pref_dialog = null;
     private Gtk.SpinButton mines_spin;
     private SimpleAction new_game_action;
     private SimpleAction repeat_size_action;
@@ -69,14 +70,13 @@ public class Mines : Gtk.Application
 
     private const GLib.ActionEntry[] action_entries =
     {
-        { "new-game",      new_game_cb                                            },
-        { "repeat-size",   repeat_size_cb                                         },
-        { "pause",         toggle_pause_cb                                        },
-        { "scores",        scores_cb                                              },
-        { "preferences",   preferences_cb                                         },
-        { "quit",          quit_cb                                                },
-        { "help",          help_cb                                                },
-        { "about",         about_cb                                               }
+        { "new-game",           new_game_cb                                   },
+        { "repeat-size",        repeat_size_cb                                },
+        { "pause",              toggle_pause_cb                               },
+        { "scores",             scores_cb                                     },
+        { "quit",               quit_cb                                       },
+        { "help",               help_cb                                       },
+        { "about",              about_cb                                      }
     };
 
     public Mines ()
@@ -102,15 +102,20 @@ public class Mines : Gtk.Application
         repeat_size_action.set_enabled (false);
         pause_action = lookup_action ("pause") as SimpleAction;
         pause_action.set_enabled (false);
+        add_action (settings.create_action (KEY_USE_OVERMINE_WARNING));
+        add_action (settings.create_action (KEY_USE_QUESTION_MARKS));
 
         var menu = new Menu ();
         app_main_menu = new Menu ();
         menu.append_section (null, app_main_menu);
         app_main_menu.append (_("_New Game"), "app.new-game");
         app_main_menu.append (_("_Scores"), "app.scores");
-        app_main_menu.append (_("_Preferences"), "app.preferences");
         var section = new Menu ();
         menu.append_section (null, section);
+        section.append (_("_Show Warnings"), "app.%s".printf (KEY_USE_OVERMINE_WARNING));
+        section.append (_("_Use Question Flags"), "app.%s".printf (KEY_USE_QUESTION_MARKS));
+        section = new Menu ();
+        menu.append_section (null, section);
         section.append (_("_Help"), "app.help");
         section.append (_("_About"), "app.about");
         section.append (_("_Quit"), "app.quit");
@@ -153,10 +158,7 @@ public class Mines : Gtk.Application
         view_box.show ();
         main_vbox.pack_start (view_box, true, true, 0);
 
-        minefield_view = new MinefieldView ();
-        minefield_view.set_use_question_marks (settings.get_boolean (KEY_USE_QUESTION_MARKS));
-        minefield_view.set_use_overmine_warning (settings.get_boolean (KEY_USE_OVERMINE_WARNING));
-        minefield_view.set_use_autoflag (settings.get_boolean (KEY_USE_AUTOFLAG));
+        minefield_view = new MinefieldView (settings);
         minefield_view.button_press_event.connect (view_button_press_event);
         view_box.pack_start (minefield_view, true, true, 0);
 
@@ -754,54 +756,6 @@ public class Mines : Gtk.Application
         settings.set_int (KEY_NMINES,
                           (int) Math.round (spin.get_value () * (settings.get_int (KEY_XSIZE) * 
settings.get_int (KEY_YSIZE)) / 100.0f));
     }
-
-    private void use_question_toggle_cb (Gtk.ToggleButton button)
-    {
-        var use_question_marks = button.get_active ();
-        settings.set_boolean (KEY_USE_QUESTION_MARKS, use_question_marks);
-        minefield_view.set_use_question_marks (use_question_marks);
-    }
-
-    private void use_overmine_toggle_cb (Gtk.ToggleButton button)
-    {
-        var use_overmine_warning = button.get_active ();
-        settings.set_boolean (KEY_USE_OVERMINE_WARNING, use_overmine_warning);
-        minefield_view.set_use_overmine_warning (use_overmine_warning);
-    }
-
-    private Gtk.Dialog create_preferences ()
-    {
-        var dialog = new Gtk.Dialog.with_buttons (_("Mines Preferences"),
-                                                  window,
-                                                  Gtk.DialogFlags.USE_HEADER_BAR,
-                                                  null);
-        dialog.response.connect (pref_response_cb);
-        dialog.delete_event.connect (pref_delete_event_cb);
-        dialog.set_border_width (5);
-        dialog.set_resizable (false);
-        var box = (Gtk.Box) dialog.get_content_area ();
-
-        var grid = new Gtk.Grid ();
-        grid.show ();
-        grid.border_width = 6;
-        grid.set_row_spacing (6);
-        grid.set_column_spacing (18);
-        box.add (grid);
-
-        var question_toggle = new Gtk.CheckButton.with_mnemonic (_("_Use \"I'm not sure\" flags"));
-        question_toggle.show ();
-        question_toggle.toggled.connect (use_question_toggle_cb);
-        question_toggle.set_active (settings.get_boolean (KEY_USE_QUESTION_MARKS));
-        grid.attach (question_toggle, 0, 0, 1, 1);
-
-        var overmine_toggle = new Gtk.CheckButton.with_mnemonic (_("_Warn if too many flags are placed next 
to a number"));
-        overmine_toggle.show ();
-        overmine_toggle.toggled.connect (use_overmine_toggle_cb);
-        overmine_toggle.set_active (settings.get_boolean (KEY_USE_OVERMINE_WARNING));
-        grid.attach (overmine_toggle, 0, 1, 1, 1);
-
-        return dialog;
-    }
     
     private void set_mode (int mode)
     {
@@ -830,24 +784,6 @@ public class Mines : Gtk.Application
     {
         set_mode (3);
     }
-    
-    private void pref_response_cb (Gtk.Dialog dialog, int response_id)
-    {
-        pref_dialog.hide ();
-    }
-
-    private bool pref_delete_event_cb (Gtk.Widget widget, Gdk.EventAny event)
-    {
-        pref_dialog.hide ();
-        return true;
-    }
-
-    private void preferences_cb ()
-    {
-        if (pref_dialog == null)
-            pref_dialog = create_preferences ();
-        pref_dialog.present ();
-    }
 
     private void help_cb ()
     {
diff --git a/src/minefield-view.vala b/src/minefield-view.vala
index d9ae119..555ae38 100644
--- a/src/minefield-view.vala
+++ b/src/minefield-view.vala
@@ -92,14 +92,34 @@ private class Position : Object
 
 public class MinefieldView : Gtk.DrawingArea
 {
+    private Settings settings;
+
     /* true if allowed to mark locations with question marks */
-    private bool use_question_marks;
+    private bool use_question_marks
+    {
+        get
+        {
+            return settings.get_boolean (Mines.KEY_USE_QUESTION_MARKS);
+        }
+    }
 
     /* true if should warn when too many flags set */
-    private bool use_overmine_warning;
+    private bool use_overmine_warning
+    {
+        get
+        {
+            return settings.get_boolean (Mines.KEY_USE_OVERMINE_WARNING);
+        }
+    }
 
-    /* true if automatically set flags on middle click */
-    private bool use_autoflag;
+    /* true if automatically set flags on middle click... for debugging */
+    private bool use_autoflag
+    {
+        get
+        {
+            return settings.get_boolean (Mines.KEY_USE_AUTOFLAG);
+        }
+    }
 
     /* Position of keyboard cursor and selected squares */
     private Position keyboard_cursor;
@@ -154,8 +174,9 @@ public class MinefieldView : Gtk.DrawingArea
     public signal void look ();
     public signal void unlook ();
 
-    public MinefieldView ()
+    public MinefieldView (Settings settings)
     {
+        this.settings = settings;
         set_events (Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | 
Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.KEY_PRESS_MASK | 
Gdk.EventMask.KEY_RELEASE_MASK);
         can_focus = true;
         selected = new Position ();
@@ -195,22 +216,6 @@ public class MinefieldView : Gtk.DrawingArea
         }
     }
 
-    public void set_use_question_marks (bool use_question_marks)
-    {
-        this.use_question_marks = use_question_marks;
-    }
-
-    public void set_use_overmine_warning (bool use_overmine_warning)
-    {
-        this.use_overmine_warning = use_overmine_warning;
-        queue_draw ();
-    }
-
-    public void set_use_autoflag (bool use_autoflag)
-    {
-        this.use_autoflag = use_autoflag;
-    }
-
     private void explode_cb (Minefield minefield)
     {
         /* Show the mines that we missed or the flags that were wrong */


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