Clone in a terminal:
Commit 392ed85
Johan Mattsson - 2015-10-08T13:42:47+00:00
392ed8596948722b664934427d69f0e719480710johan.mattsson.m@gmail.com

Make all tasks cancelable

Changed files (2)

Diff

diff --git a/libbirdfont/StrokeTask.vala b/libbirdfont/StrokeTask.valaindex 44462bd..dc92412 100644--- a/libbirdfont/StrokeTask.vala+++ b/libbirdfont/StrokeTask.vala@@ -15,7 +15,6 @@ namespace BirdFont { 	 public class StrokeTask : Task {-	bool cancelled = false; 	Path original; // path in gui thread 	Path background_path; // path in background thread 	@@ -30,22 +29,6 @@ public class StrokeTask : Task { 		original = new Path (); 		background_path = new Path (); 	}-	-	public void cancel () {-		lock (cancelled) {	-			cancelled = true;-		}-	}--	public bool is_cancelled () {-		bool c;-		-		lock (cancelled) {	-			c = cancelled;-		}-		-		return c;-	} 		 	public override void run () { 		PathList stroke;@@ -56,13 +39,10 @@ public class StrokeTask : Task { 		stroke = tool.get_stroke (background_path, w);  		IdleSource idle = new IdleSource (); -		idle.set_callback (() => {-			-			lock (cancelled) {			-				if (!cancelled) {-					original.full_stroke = stroke;-					GlyphCanvas.redraw ();-				}+		idle.set_callback (() => {	+			if (!is_cancelled ()) {+				original.full_stroke = stroke;+				GlyphCanvas.redraw (); 			}  			return false;diff --git a/libbirdfont/Task.vala b/libbirdfont/Task.valaindex ce7088f..2f88de8 100644--- a/libbirdfont/Task.vala+++ b/libbirdfont/Task.vala@@ -1,5 +1,5 @@ /*-    Copyright (C) 2014 Johan Mattsson+    Copyright (C) 2014 2015 Johan Mattsson      This library is free software; you can redistribute it and/or modify      it under the terms of the GNU Lesser General Public License as @@ -18,13 +18,30 @@ public class Task : GLib.Object { 	 	public delegate void Runnable (); 	Runnable task;+	bool cancelled = false; 	 	public Task (owned Runnable? r) { 		if (r != null) { 			task = (!) ((owned) r); 		} 	}-	++	public void cancel () {+		lock (cancelled) {	+			cancelled = true;+		}+	}++	public bool is_cancelled () {+		bool c;+		+		lock (cancelled) {	+			c = cancelled;+		}+		+		return c;+	}+		 	public virtual void run () { 		if (task == null) { 			warning ("No task set.");

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112