[gbrainy] Confirm delete of game session history
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Confirm delete of game session history
- Date: Sun, 6 Jun 2010 17:04:50 +0000 (UTC)
commit 22959b10833b617877bda99f5b0cccbedf8c0b03
Author: Jordi Mas <jmas softcatala org>
Date: Sun Jun 6 19:05:36 2010 +0200
Confirm delete of game session history
src/Clients/Classical/Dialogs/HigMessageDialog.cs | 218 ++++++++++++++++++++
src/Clients/Classical/Dialogs/PreferencesDialog.cs | 17 ++-
.../Classical/Dialogs/ui/PlayerHistoryDialog.ui | 2 +-
.../Classical/Dialogs/ui/PreferencesDialog.ui | 8 +-
src/Clients/Classical/Makefile.am | 1 +
src/Clients/Classical/gbrainy.ui | 2 +-
6 files changed, 238 insertions(+), 10 deletions(-)
---
diff --git a/src/Clients/Classical/Dialogs/HigMessageDialog.cs b/src/Clients/Classical/Dialogs/HigMessageDialog.cs
new file mode 100644
index 0000000..64b9548
--- /dev/null
+++ b/src/Clients/Classical/Dialogs/HigMessageDialog.cs
@@ -0,0 +1,218 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ *
+ * Based largely on code Tomboy project source code
+ *
+ */
+
+using System;
+using Gtk;
+
+namespace gbrainy.Clients.Classical
+{
+ public class HigMessageDialog : Gtk.Dialog
+ {
+ Gtk.AccelGroup accel_group;
+ Gtk.VBox extra_widget_vbox;
+ Gtk.Widget extra_widget;
+ Gtk.Image image;
+
+ public HigMessageDialog (Gtk.Window parent,
+ Gtk.DialogFlags flags,
+ Gtk.MessageType type,
+ Gtk.ButtonsType buttons,
+ string header,
+ string msg) : base ()
+ {
+ HasSeparator = false;
+ BorderWidth = 5;
+ Resizable = false;
+ Title = string.Empty;
+
+ VBox.Spacing = 12;
+ ActionArea.Layout = Gtk.ButtonBoxStyle.End;
+
+ accel_group = new Gtk.AccelGroup ();
+ AddAccelGroup (accel_group);
+
+ Gtk.HBox hbox = new Gtk.HBox (false, 12);
+ hbox.BorderWidth = 5;
+ hbox.Show ();
+ VBox.PackStart (hbox, false, false, 0);
+
+ switch (type) {
+ case Gtk.MessageType.Error:
+ image = new Gtk.Image (Gtk.Stock.DialogError,
+ Gtk.IconSize.Dialog);
+ break;
+ case Gtk.MessageType.Question:
+ image = new Gtk.Image (Gtk.Stock.DialogQuestion,
+ Gtk.IconSize.Dialog);
+ break;
+ case Gtk.MessageType.Info:
+ image = new Gtk.Image (Gtk.Stock.DialogInfo,
+ Gtk.IconSize.Dialog);
+ break;
+ case Gtk.MessageType.Warning:
+ image = new Gtk.Image (Gtk.Stock.DialogWarning,
+ Gtk.IconSize.Dialog);
+ break;
+ default:
+ image = new Gtk.Image ();
+ break;
+ }
+
+ if (image != null) {
+ image.Show ();
+ image.Yalign = 0;
+ hbox.PackStart (image, false, false, 0);
+ }
+
+ Gtk.VBox label_vbox = new Gtk.VBox (false, 0);
+ label_vbox.Show ();
+ hbox.PackStart (label_vbox, true, true, 0);
+
+ string title = String.Format ("<span weight='bold' size='larger'>{0}" +
+ "</span>\n",
+ header);
+
+ Gtk.Label label;
+
+ label = new Gtk.Label (title);
+ label.UseMarkup = true;
+ label.UseUnderline = false;
+ label.Justify = Gtk.Justification.Left;
+ label.LineWrap = true;
+ label.SetAlignment (0.0f, 0.5f);
+ label.Show ();
+ label_vbox.PackStart (label, false, false, 0);
+
+ label = new Gtk.Label (msg);
+ label.UseMarkup = true;
+ label.UseUnderline = false;
+ label.Justify = Gtk.Justification.Left;
+ label.LineWrap = true;
+ label.SetAlignment (0.0f, 0.5f);
+ label.Show ();
+ label_vbox.PackStart (label, false, false, 0);
+
+ extra_widget_vbox = new Gtk.VBox (false, 0);
+ extra_widget_vbox.Show();
+ label_vbox.PackStart (extra_widget_vbox, true, true, 12);
+
+ switch (buttons) {
+ case Gtk.ButtonsType.None:
+ break;
+ case Gtk.ButtonsType.Ok:
+ AddButton (Gtk.Stock.Ok, Gtk.ResponseType.Ok, true);
+ break;
+ case Gtk.ButtonsType.Close:
+ AddButton (Gtk.Stock.Close, Gtk.ResponseType.Close, true);
+ break;
+ case Gtk.ButtonsType.Cancel:
+ AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, true);
+ break;
+ case Gtk.ButtonsType.YesNo:
+ AddButton (Gtk.Stock.No, Gtk.ResponseType.No, false);
+ AddButton (Gtk.Stock.Yes, Gtk.ResponseType.Yes, true);
+ break;
+ case Gtk.ButtonsType.OkCancel:
+ AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, false);
+ AddButton (Gtk.Stock.Ok, Gtk.ResponseType.Ok, true);
+ break;
+ }
+
+ if (parent != null)
+ TransientFor = parent;
+
+ if ((int) (flags & Gtk.DialogFlags.Modal) != 0)
+ Modal = true;
+
+ if ((int) (flags & Gtk.DialogFlags.DestroyWithParent) != 0)
+ DestroyWithParent = true;
+ }
+
+ // constructor for a HIG confirmation alert with two buttons
+ public HigMessageDialog (Gtk.Window parent,
+ Gtk.DialogFlags flags,
+ Gtk.MessageType type,
+ string header,
+ string msg,
+ string ok_caption)
+ : this (parent, flags, type, Gtk.ButtonsType.Cancel, header, msg)
+ {
+ AddButton (ok_caption, Gtk.ResponseType.Ok, false);
+ }
+
+ protected void AddButton (string stock_id, Gtk.ResponseType response, bool is_default)
+ {
+ Gtk.Button button = new Gtk.Button (stock_id);
+ button.CanDefault = true;
+
+ AddButton (button, response, is_default);
+ }
+
+ protected void AddButton (Gdk.Pixbuf pixbuf, string label_text, Gtk.ResponseType response, bool is_default)
+ {
+ Gtk.Button button = new Gtk.Button ();
+ Gtk.Image image = new Gtk.Image (pixbuf);
+ // NOTE: This property is new to GTK+ 2.10, but we don't
+ // really need the line because we're just setting
+ // it to the default value anyway.
+ //button.ImagePosition = Gtk.PositionType.Left;
+ button.Image = image;
+ button.Label = label_text;
+ button.UseUnderline = true;
+ button.CanDefault = true;
+
+ AddButton (button, response, is_default);
+ }
+
+ private void AddButton (Gtk.Button button, Gtk.ResponseType response, bool is_default)
+ {
+ button.Show ();
+
+ AddActionWidget (button, response);
+
+ if (is_default) {
+ DefaultResponse = response;
+ button.AddAccelerator ("activate",
+ accel_group,
+ (uint) Gdk.Key.Escape,
+ 0,
+ Gtk.AccelFlags.Visible);
+ }
+ }
+
+ //Run and destroy a standard confirmation dialog
+ public static Gtk.ResponseType RunHigConfirmation(Gtk.Window parent,
+ Gtk.DialogFlags flags,
+ Gtk.MessageType type,
+ string header,
+ string msg,
+ string ok_caption)
+ {
+ HigMessageDialog hmd = new HigMessageDialog(parent, flags, type, header, msg, ok_caption);
+ try {
+ return (Gtk.ResponseType)hmd.Run();
+ } finally {
+ hmd.Destroy();
+ }
+ }
+
+ }
+}
diff --git a/src/Clients/Classical/Dialogs/PreferencesDialog.cs b/src/Clients/Classical/Dialogs/PreferencesDialog.cs
index 375e144..d774237 100644
--- a/src/Clients/Classical/Dialogs/PreferencesDialog.cs
+++ b/src/Clients/Classical/Dialogs/PreferencesDialog.cs
@@ -47,11 +47,11 @@ namespace gbrainy.Clients.Classical
maxstoredspinbutton.Value = Preferences.GetIntValue (Preferences.MaxStoredGamesKey);
minplayedspinbutton.Value = Preferences.GetIntValue (Preferences.MinPlayedGamesKey);
colorblindcheckbutton.Active = Preferences.GetBoolValue (Preferences.ColorBlindKey);
-
+
switch ((Game.Difficulty) Preferences.GetIntValue (Preferences.DifficultyKey)) {
case Game.Difficulty.Easy:
rb_easy.Active = rb_easy.HasFocus = true;
- break;
+ break;
case Game.Difficulty.Medium:
rb_medium.Active = rb_medium.HasFocus = true;
break;
@@ -69,13 +69,22 @@ namespace gbrainy.Clients.Classical
if (rb_master.Active)
return Game.Difficulty.Master;
- return Game.Difficulty.Medium;
+ return Game.Difficulty.Medium;
}
}
private void OnCleanHistory (object sender, EventArgs args)
{
- history.Clean ();
+ if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation (
+ this,
+ Gtk.DialogFlags.DestroyWithParent,
+ Gtk.MessageType.Warning,
+ Catalog.GetString ("You are about to delete the player's game session history."),
+ Catalog.GetString ("If you proceed, you will lose the history of the previous game sessions. Do you want to continue?"),
+ Catalog.GetString ("_Delete")))
+ {
+ history.Clean ();
+ }
}
private void OnOK (object sender, EventArgs args)
diff --git a/src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui b/src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui
index 2b1ba1c..e590dd9 100644
--- a/src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui
+++ b/src/Clients/Classical/Dialogs/ui/PlayerHistoryDialog.ui
@@ -5,7 +5,7 @@
<object class="GtkDialog" id="playerhistory">
<property name="visible">True</property>
<property name="border_width">7</property>
- <property name="title" translatable="yes">Player's Game History</property>
+ <property name="title" translatable="yes">Player's Game Session History</property>
<property name="default_width">450</property>
<property name="default_height">450</property>
<property name="type_hint">dialog</property>
diff --git a/src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui b/src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui
index 8a456b4..5cbd762 100644
--- a/src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui
+++ b/src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui
@@ -214,7 +214,7 @@
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="ypad">5</property>
- <property name="label" translatable="yes"><b>Player's Game History</b></property>
+ <property name="label" translatable="yes"><b>Player's Game Session History</b></property>
<property name="use_markup">True</property>
</object>
<packing>
@@ -236,7 +236,7 @@
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="xpad">5</property>
- <property name="label" translatable="yes">Minimum number of played puzzles to store the game:</property>
+ <property name="label" translatable="yes">Minimum number of played games to store the game session:</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
@@ -248,7 +248,7 @@
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="xpad">5</property>
- <property name="label" translatable="yes">Maximum number of stored games in the player's game history:</property>
+ <property name="label" translatable="yes">Maximum number of records in the player's game session history:</property>
</object>
<packing>
<property name="top_attach">1</property>
@@ -306,7 +306,7 @@
<property name="layout_style">start</property>
<child>
<object class="GtkButton" id="clear_button">
- <property name="label" translatable="yes">Clear Player's Game History</property>
+ <property name="label" translatable="yes">Delete Player's Game Session History</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
diff --git a/src/Clients/Classical/Makefile.am b/src/Clients/Classical/Makefile.am
index 88a4b9b..6ff1d7c 100644
--- a/src/Clients/Classical/Makefile.am
+++ b/src/Clients/Classical/Makefile.am
@@ -14,6 +14,7 @@ GBRAINY_CSDISTFILES = \
$(srcdir)/Dialogs/AboutDialog.cs \
$(srcdir)/Dialogs/CustomGameDialog.cs \
$(srcdir)/Dialogs/BuilderDialog.cs \
+ $(srcdir)/Dialogs/HigMessageDialog.cs \
$(srcdir)/Dialogs/PlayerHistoryDialog.cs \
$(srcdir)/Dialogs/PreferencesDialog.cs
diff --git a/src/Clients/Classical/gbrainy.ui b/src/Clients/Classical/gbrainy.ui
index 0586a0f..acb30f4 100644
--- a/src/Clients/Classical/gbrainy.ui
+++ b/src/Clients/Classical/gbrainy.ui
@@ -153,7 +153,7 @@
</child>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem6">
- <property name="label" translatable="yes" >Player's Game History</property>
+ <property name="label" translatable="yes" >Player's Game Session History</property>
<property name="visible">True</property>
<property name="use_stock">False</property>
<signal name="activate" handler="OnHistory"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]