The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Make all tasks cancelable

These changes was commited to the Birdfont repository Thu, 08 Oct 2015 13:42:47 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 08 Oct 2015 13:42:47 +0000 (15:42 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 08 Oct 2015 13:42:47 +0000 (15:42 +0200)
commit 392ed8596948722b664934427d69f0e719480710
tree 7409eda4bc01bf54751979ef02b7b99a52446758
parent f2550a618031f99c984997827f52c24198fb6887
Make all tasks cancelable

libbirdfont/StrokeTask.vala
libbirdfont/Task.vala
--- 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 @@ -29,22 +28,6 @@ base (null); 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 () { @@ -56,13 +39,10 @@ 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;
--- 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 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.");