[gnome-sudoku] Keep the Cancel button sensitive after clicking Print
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku] Keep the Cancel button sensitive after clicking Print
- Date: Tue, 17 Mar 2015 13:32:24 +0000 (UTC)
commit 5c73b73d3b4bc1ffbdb9ff1e5e3b5cb0f8d96370
Author: Iulian Radu <iulian radu67 gmail com>
Date: Tue Mar 17 11:15:36 2015 +0200
Keep the Cancel button sensitive after clicking Print
If the user clicks Print, the Cancel button should remain sensitive.
Pressing Cancel should stop the Print operation
https://bugzilla.gnome.org/show_bug.cgi?id=736773
lib/sudoku-generator.vala | 3 ++-
src/gnome-sudoku.vala | 6 +++---
src/print-dialog.vala | 28 ++++++++++++++++++++++++----
3 files changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/lib/sudoku-generator.vala b/lib/sudoku-generator.vala
index 0ae7c1e..fc2fcb3 100644
--- a/lib/sudoku-generator.vala
+++ b/lib/sudoku-generator.vala
@@ -80,7 +80,7 @@ public class SudokuGenerator : Object
return board;
}
- public async static Gee.List<SudokuBoard> generate_boards_async (int nboards, DifficultyCategory
category) throws ThreadError
+ public async static Gee.List<SudokuBoard> generate_boards_async (int nboards, DifficultyCategory
category, Cancellable? cancellable) throws ThreadError, IOError
{
var boards = new ArrayList<SudokuBoard> ();
var pool = new ThreadPool<Worker>.with_owned_data ((worker) => {
@@ -93,6 +93,7 @@ public class SudokuGenerator : Object
}
yield;
+ cancellable.set_error_if_cancelled ();
return boards;
}
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 555cdfa..789aed8 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -405,13 +405,13 @@ public class Sudoku : Gtk.Application
back_button.sensitive = false;
- SudokuGenerator.generate_boards_async.begin (1, selected_difficulty, (obj, res) => {
+ SudokuGenerator.generate_boards_async.begin (1, selected_difficulty, null, (obj, res) => {
try {
var gen_boards = SudokuGenerator.generate_boards_async.end (res);
back_button.sensitive = true;
start_game (gen_boards[0]);
- } catch (ThreadError e) {
- error ("Thread error: %s", e.message);
+ } catch (Error e) {
+ error ("Error: %s", e.message);
}
});
}
diff --git a/src/print-dialog.vala b/src/print-dialog.vala
index a96278b..1be7ef5 100644
--- a/src/print-dialog.vala
+++ b/src/print-dialog.vala
@@ -26,6 +26,10 @@ public class PrintDialog : Gtk.Dialog
private Settings settings;
[GtkChild]
+ private Gtk.Button print_button;
+ [GtkChild]
+ private Gtk.Box print_box;
+ [GtkChild]
private Gtk.SpinButton n_sudokus_button;
[GtkChild]
private Gtk.RadioButton easy_radio_button;
@@ -39,12 +43,14 @@ public class PrintDialog : Gtk.Dialog
private Gtk.Revealer revealer;
private Gtk.Spinner spinner;
- private const string DIFFICULTY_KEY_NAME = "print-multiple-sudoku-difficulty";
+ private Cancellable cancellable;
/* After emitting our response, we continue to asynchronously generate puzzles
in the background. This signal indicates when we are really finished. */
public signal void finished ();
+ private const string DIFFICULTY_KEY_NAME = "print-multiple-sudoku-difficulty";
+
public PrintDialog (SudokuSaver saver, Gtk.Window window)
{
Object (use_header_bar: Gtk.Settings.get_default ().gtk_dialogs_use_header ? 1 : 0);
@@ -52,6 +58,12 @@ public class PrintDialog : Gtk.Dialog
this.saver = saver;
settings = new GLib.Settings ("org.gnome.sudoku");
+ this.response.connect ((response_id) => {
+ if (response_id == Gtk.ResponseType.CANCEL || response_id == Gtk.ResponseType.DELETE_EVENT) {
+ cancellable.cancel ();
+ }
+ });
+
set_transient_for (window);
spinner = new Gtk.Spinner ();
@@ -128,16 +140,17 @@ public class PrintDialog : Gtk.Dialog
Timeout.add_seconds (3, (SourceFunc) start_spinner_cb);
- sensitive = false;
+ print_button.sensitive = false;
+ print_box.sensitive = false;
- SudokuGenerator.generate_boards_async.begin (nsudokus, level, (obj, res) => {
+ cancellable = new Cancellable ();
+ SudokuGenerator.generate_boards_async.begin (nsudokus, level, cancellable, (obj, res) => {
try
{
var boards = SudokuGenerator.generate_boards_async.end (res);
spinner.stop ();
revealer.hide ();
- sensitive = true;
var printer = new SudokuPrinter (boards, this);
if (printer.print_sudoku () == Gtk.PrintOperationResult.APPLY)
@@ -150,6 +163,13 @@ public class PrintDialog : Gtk.Dialog
{
error ("Thread error: %s\n", e.message);
}
+ catch (IOError e)
+ {
+ if (!(e is IOError.CANCELLED))
+ {
+ warning ("Error: %s\n", e.message);
+ }
+ }
finished ();
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]