[gnome-sudoku/arnaudb/improve-code: 2/5] Use Gtk namespace.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku/arnaudb/improve-code: 2/5] Use Gtk namespace.
- Date: Mon, 13 Apr 2020 13:01:33 +0000 (UTC)
commit 0903baeb7a74541ad11ff337e07b3310aeca3ca3
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Apr 13 13:19:24 2020 +0200
Use Gtk namespace.
src/gnome-sudoku.vala | 34 +++++++++++++++---------------
src/number-picker.vala | 2 +-
src/print-dialog.vala | 55 ++++++++++++++++++++++---------------------------
src/sudoku-printer.vala | 25 +++++++++++-----------
4 files changed, 55 insertions(+), 61 deletions(-)
---
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 9fd5ea4..5c15b45 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -28,11 +28,11 @@ public class Sudoku : Gtk.Application
private bool is_tiled;
private int window_width;
private int window_height;
- private Gtk.Button play_custom_game_button;
- private Gtk.Button play_pause_button;
- private Gtk.Label play_pause_label;
- private Gtk.Label clock_label;
- private Gtk.Image clock_image;
+ private Button play_custom_game_button;
+ private Button play_pause_button;
+ private Label play_pause_label;
+ private Label clock_label;
+ private Image clock_image;
private ApplicationWindow window;
@@ -164,11 +164,11 @@ public class Sudoku : Gtk.Application
game_box = (Box) builder.get_object ("game_box");
undo_redo_box = (Box) builder.get_object ("undo_redo_box");
back_button = (Button) builder.get_object ("back_button");
- clock_label = (Gtk.Label) builder.get_object ("clock_label");
- clock_image = (Gtk.Image) builder.get_object ("clock_image");
- play_custom_game_button = (Gtk.Button) builder.get_object ("play_custom_game_button");
- play_pause_button = (Gtk.Button) builder.get_object ("play_pause_button");
- play_pause_label = (Gtk.Label) builder.get_object ("play_pause_label");
+ clock_label = (Label) builder.get_object ("clock_label");
+ clock_image = (Image) builder.get_object ("clock_image");
+ play_custom_game_button = (Button) builder.get_object ("play_custom_game_button");
+ play_pause_button = (Button) builder.get_object ("play_pause_button");
+ play_pause_label = (Label) builder.get_object ("play_pause_label");
undo_action = (SimpleAction) lookup_action ("undo");
redo_action = (SimpleAction) lookup_action ("redo");
@@ -289,11 +289,11 @@ public class Sudoku : Gtk.Application
// Warning dialog shown when starting a custom game that has multiple solutions.
var warning_str = "%s\n%s".printf(_("The puzzle you have entered has multiple solutions."),
_("Valid Sudoku puzzles have exactly one solution."));
var dialog = new MessageDialog (window, DialogFlags.MODAL, MessageType.WARNING,
ButtonsType.NONE, warning_str);
- dialog.add_button (_("_Back"), Gtk.ResponseType.REJECT);
- dialog.add_button (_("Play _Anyway"), Gtk.ResponseType.ACCEPT);
+ dialog.add_button (_("_Back"), ResponseType.REJECT);
+ dialog.add_button (_("Play _Anyway"), ResponseType.ACCEPT);
dialog.response.connect ((response_id) => {
- if (response_id == Gtk.ResponseType.ACCEPT)
+ if (response_id == ResponseType.ACCEPT)
start_custom_game (game.board);
dialog.destroy ();
@@ -401,13 +401,13 @@ public class Sudoku : Gtk.Application
minutes).printf (minutes);
var dialog = new MessageDialog (window, DialogFlags.DESTROY_WITH_PARENT, MessageType.INFO,
ButtonsType.NONE, time_str);
- dialog.add_button (_("_Quit"), Gtk.ResponseType.REJECT);
- dialog.add_button (_("Play _Again"), Gtk.ResponseType.ACCEPT);
+ dialog.add_button (_("_Quit"), ResponseType.REJECT);
+ dialog.add_button (_("Play _Again"), ResponseType.ACCEPT);
dialog.response.connect ((response_id) => {
- if (response_id == Gtk.ResponseType.ACCEPT)
+ if (response_id == ResponseType.ACCEPT)
show_new_game_screen ();
- else if (response_id == Gtk.ResponseType.REJECT)
+ else if (response_id == ResponseType.REJECT)
quit ();
dialog.destroy ();
});
diff --git a/src/number-picker.vala b/src/number-picker.vala
index eaececf..75c7744 100644
--- a/src/number-picker.vala
+++ b/src/number-picker.vala
@@ -21,7 +21,7 @@
using Gtk;
-private class NumberPicker : Gtk.Grid
+private class NumberPicker : Grid
{
private SudokuBoard board;
diff --git a/src/print-dialog.vala b/src/print-dialog.vala
index a11debb..b7c13c0 100644
--- a/src/print-dialog.vala
+++ b/src/print-dialog.vala
@@ -19,35 +19,30 @@
* along with GNOME Sudoku. If not, see <http://www.gnu.org/licenses/>.
*/
+using Gtk;
+
[GtkTemplate (ui = "/org/gnome/Sudoku/ui/print-dialog.ui")]
-public class PrintDialog : Gtk.Dialog
+public class PrintDialog : Dialog
{
private SudokuSaver saver;
- 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;
- [GtkChild]
- private Gtk.RadioButton medium_radio_button;
- [GtkChild]
- private Gtk.RadioButton hard_radio_button;
- [GtkChild]
- private Gtk.RadioButton very_hard_radio_button;
-
- private Gtk.Revealer revealer;
- private Gtk.Spinner spinner;
+ private GLib.Settings settings;
+
+ [GtkChild] private Button print_button;
+ [GtkChild] private Box print_box;
+ [GtkChild] private SpinButton n_sudokus_button;
+ [GtkChild] private RadioButton easy_radio_button;
+ [GtkChild] private RadioButton medium_radio_button;
+ [GtkChild] private RadioButton hard_radio_button;
+ [GtkChild] private RadioButton very_hard_radio_button;
+
+ private Revealer revealer;
+ private Spinner spinner;
private Cancellable cancellable;
private const string DIFFICULTY_KEY_NAME = "print-multiple-sudoku-difficulty";
- public PrintDialog (SudokuSaver saver, Gtk.Window window)
+ public PrintDialog (SudokuSaver saver, Window window)
{
Object (use_header_bar: 1);
@@ -55,17 +50,17 @@ public class PrintDialog : Gtk.Dialog
settings = new GLib.Settings ("org.gnome.Sudoku");
this.response.connect ((response_id) => {
- if (response_id == Gtk.ResponseType.CANCEL || response_id == Gtk.ResponseType.DELETE_EVENT)
+ if (response_id == ResponseType.CANCEL || response_id == ResponseType.DELETE_EVENT)
cancellable.cancel ();
});
set_transient_for (window);
- spinner = new Gtk.Spinner ();
- revealer = new Gtk.Revealer ();
+ spinner = new Spinner ();
+ revealer = new Revealer ();
revealer.add (spinner);
- revealer.valign = Gtk.Align.CENTER;
- ((Gtk.HeaderBar) get_header_bar ()).pack_end (revealer);
+ revealer.valign = Align.CENTER;
+ ((HeaderBar) get_header_bar ()).pack_end (revealer);
var saved_difficulty = (DifficultyCategory) settings.get_enum (DIFFICULTY_KEY_NAME);
if (saved_difficulty == DifficultyCategory.EASY)
@@ -82,7 +77,7 @@ public class PrintDialog : Gtk.Dialog
wrap_adjustment ("print-multiple-sudokus-to-print", n_sudokus_button.get_adjustment ());
}
- private void wrap_adjustment (string key_name, Gtk.Adjustment action)
+ private void wrap_adjustment (string key_name, Adjustment action)
{
action.set_value (settings.get_int (key_name));
action.value_changed.connect (() => settings.set_int (key_name, (int) action.get_value ()));
@@ -90,7 +85,7 @@ public class PrintDialog : Gtk.Dialog
public bool start_spinner_cb ()
{
- revealer.set_transition_type (Gtk.RevealerTransitionType.SLIDE_LEFT);
+ revealer.set_transition_type (RevealerTransitionType.SLIDE_LEFT);
revealer.show_all ();
spinner.start ();
revealer.set_reveal_child (true);
@@ -99,7 +94,7 @@ public class PrintDialog : Gtk.Dialog
public override void response (int response)
{
- if (response != Gtk.ResponseType.OK)
+ if (response != ResponseType.OK)
{
destroy ();
return;
@@ -136,7 +131,7 @@ public class PrintDialog : Gtk.Dialog
revealer.hide ();
var printer = new SudokuPrinter (boards, this);
- if (printer.print_sudoku () == Gtk.PrintOperationResult.APPLY)
+ if (printer.print_sudoku () == PrintOperationResult.APPLY)
{
foreach (SudokuBoard board in boards)
saver.add_game_to_finished (new SudokuGame (board));
diff --git a/src/sudoku-printer.vala b/src/sudoku-printer.vala
index 90934fe..f708f25 100644
--- a/src/sudoku-printer.vala
+++ b/src/sudoku-printer.vala
@@ -20,12 +20,11 @@
*/
using Gtk;
-using Gdk;
public class SudokuPrinter : GLib.Object {
private Gee.List<SudokuBoard> boards;
- private Gtk.Window window;
+ private Window window;
private int margin;
private int n_sudokus;
@@ -37,33 +36,33 @@ public class SudokuPrinter : GLib.Object {
{
try
{
- var result = print_op.run (Gtk.PrintOperationAction.PRINT_DIALOG, window);
+ var result = print_op.run (PrintOperationAction.PRINT_DIALOG, window);
return result;
}
catch (GLib.Error e)
{
- new Gtk.MessageDialog (window, Gtk.DialogFlags.MODAL,
- Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE,
- /* Error message if printing fails */
- "%s\n%s".printf (_("Error printing file:"), e.message)).run ();
+ new MessageDialog (window, DialogFlags.MODAL,
+ MessageType.ERROR, ButtonsType.CLOSE,
+ /* Error message if printing fails */
+ "%s\n%s".printf (_("Error printing file:"), e.message)).run ();
}
- return Gtk.PrintOperationResult.ERROR;
+ return PrintOperationResult.ERROR;
}
- public SudokuPrinter (Gee.List<SudokuBoard> boards, Gtk.Window window)
+ public SudokuPrinter (Gee.List<SudokuBoard> boards, Window window)
{
this.boards = boards;
this.window = window;
this.margin = 25;
this.n_sudokus = boards.size;
- this.print_op = new Gtk.PrintOperation ();
+ this.print_op = new PrintOperation ();
print_op.begin_print.connect (begin_print_cb);
print_op.draw_page.connect (draw_page_cb);
}
- private void begin_print_cb (Gtk.PrintOperation operation, Gtk.PrintContext context)
+ private void begin_print_cb (PrintOperation operation, PrintContext context)
{
int pages = n_sudokus / SUDOKUS_PER_PAGE;
while (pages * SUDOKUS_PER_PAGE < n_sudokus)
@@ -72,7 +71,7 @@ public class SudokuPrinter : GLib.Object {
operation.set_n_pages (pages);
}
- private void draw_page_cb (Gtk.PrintOperation operation, Gtk.PrintContext context, int page_nr)
+ private void draw_page_cb (PrintOperation operation, PrintContext context, int page_nr)
{
Cairo.Context cr = context.get_cairo_context ();
var width = context.get_width ();
@@ -204,7 +203,7 @@ public class SudokuPrinter : GLib.Object {
Cairo.TextExtents extents;
var sudoku = sudoku_board.get_cells ();
- var invert = Gtk.Widget.get_default_direction () == Gtk.TextDirection.RTL;
+ var invert = Widget.get_default_direction () == TextDirection.RTL;
for (var x = 0; x < SUDOKU_SIZE; x++)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]