<commit_before>//
// FSpot.Bling.Animation,cs
//
// Author(s):
//	<NAME>  <<EMAIL>>
//
// This is free software. See COPYING for details
//

//TODO: send the progresschanged event

using System;
using System.ComponentModel;
using GLibBeans;

namespace FSpot.Bling
{
	public abstract class Animation<T>
	{
		enum AnimationState {
			NotRunning = 0,
			Running,
			Paused,
		}

		TimeSpan duration;
		TimeSpan pausedafter;

		DateTimeOffset starttime;
		T from;
		T to;
		Action<T> action;
		AnimationState state;
		GLib.Priority priority = GLib.Priority.DefaultIdle;

		public Animation ()
		{
			from = default (T);
			to = default (T);
			duration = TimeSpan.Zero;
			action = null;
			state = AnimationState.NotRunning;
		}

		public Animation (T from, T to, TimeSpan duration, Action<T> action) : this (from, to, duration, action, GLib.Priority.DefaultIdle)
		{
		}

		public Animation (T from, T to, TimeSpan duration, Action<T> action, GLib.Priority priority)
		{
			this.from = from;
			this.to = to;
			this.duration = duration;
			this.action = action;
			this.priority = priority;
			state = AnimationState.NotRunning;
		}

		public void Pause ()
		{
			if (state == AnimationState.Paused)
				return;
			if (state != AnimationState.NotRunning)
				throw new InvalidOperationException ("Can't Pause () a non running animation.");
			GLib.Idle.Remove (Handler);
			pausedafter = DateTimeOffset.Now - starttime;
			state = AnimationState.Paused;
		}

		public void Resume ()
		{
			if (state == AnimationState.Running)
				return;
			if (state != AnimationState.Paused)
				throw new InvalidOperationException ("Can't Resume () a non running animation.");
			starttime = DateTimeOffset.Now - pausedafter;
			state = AnimationState.Running;
			Sources.SetPriority (GLib.Timeout.Add (40, Handler), GLib.Priority.DefaultIdle);
		}

		public void Start ()
		{
			if (state != AnimationState.NotRunning)
				throw new InvalidOperationException ("Can't Start () a running or paused animation.");
			starttime = DateTimeOffset.Now;
			state = AnimationState.Running;
			Sources.SetPriority (GLib.Timeout.Add (40, Handler), GLib.Priority.DefaultIdle);
		}<commit_msg>Fix animation prioritization.<commit_after>//
// FSpot.Bling.Animation,cs
//
// Author(s):
//	<NAME>  <<EMAIL>>
//
// This is free software. See COPYING for details
//

//TODO: send the progresschanged event

using System;
using System.ComponentModel;
using GLibBeans;

namespace FSpot.Bling
{
	public abstract class Animation<T>
	{
		enum AnimationState {
			NotRunning = 0,
			Running,
			Paused,
		}

		TimeSpan duration;
		TimeSpan pausedafter;

		DateTimeOffset starttime;
		T from;
		T to;
		Action<T> action;
		AnimationState state;
		GLib.Priority priority = GLib.Priority.DefaultIdle;

		public Animation ()
		{
			from = default (T);
			to = default (T);
			duration = TimeSpan.Zero;
			action = null;
			state = AnimationState.NotRunning;
		}

		public Animation (T from, T to, TimeSpan duration, Action<T> action) : this (from, to, duration, action, GLib.Priority.DefaultIdle)
		{
		}

		public Animation (T from, T to, TimeSpan duration, Action<T> action, GLib.Priority priority)
		{
			this.from = from;
			this.to = to;
			this.duration = duration;
			this.action = action;
			this.priority = priority;
			state = AnimationState.NotRunning;
		}

		public void Pause ()
		{
			if (state == AnimationState.Paused)
				return;
			if (state != AnimationState.NotRunning)
				throw new InvalidOperationException ("Can't Pause () a non running animation.");
			GLib.Idle.Remove (Handler);
			pausedafter = DateTimeOffset.Now - starttime;
			state = AnimationState.Paused;
		}

		public void Resume ()
		{
			if (state == AnimationState.Running)
				return;
			if (state != AnimationState.Paused)
				throw new InvalidOperationException ("Can't Resume () a non running animation.");
			starttime = DateTimeOffset.Now - pausedafter;
			state = AnimationState.Running;
			Sources.SetPriority (GLib.Timeout.Add (40, Handler), priority);
		}

		public void Start ()
		{
			if (state != AnimationState.NotRunning)
				throw new InvalidOperationException ("Can't Start () a running or paused animation.");
			starttime = DateTimeOffset.Now;
			state = AnimationState.Running;
			Sources.SetPriority (GLib.Timeout.Add (40, Handler), priority);
		}
{'fraction_non_alphanumeric': 0.1133518776077886, 'fraction_numerical': 0.0023180343069077423, 'mean_word_length': 3.4761410788381744, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2935494', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1318, 'n_words': 376}