void SetCellRendererCallbacks(CellRendererText renderer, EditedHandler handler) { // The user is going to "edit" or "cancel", timer can't continue. renderer.EditingStarted += CellRenderer_EditingStarted; // Canceled: timer can continue. renderer.EditingCanceled += (o, args) => { if (toggled && taskBeingEdited != null) { taskBeingEdited.Inactivate(); InactivateTimer.ToggleTimer(taskBeingEdited); taskBeingEdited = null; toggled = false; } }; // Edited: after calling the delegate the timer can continue. renderer.Edited += (o, args) => { if (handler != null) { handler(o, args); } if (toggled && taskBeingEdited != null) { taskBeingEdited.Inactivate(); InactivateTimer.ToggleTimer(taskBeingEdited); taskBeingEdited = null; toggled = false; } }; }
public static void CancelTimer(ITask task) { Logger.Debug("Timeout Canceled for task: " + task.Name); InactivateTimer timer = null; uint timerId = task.TimerID; if (timerId != 0) { if (timers.ContainsKey(timerId)) { timer = timers [timerId]; timers.Remove(timerId); } GLib.Source.Remove(timerId); GLib.Source.Remove(timer.pulseTimeoutId); timer.pulseTimeoutId = 0; task.TimerID = 0; } if (timer != null) { GLib.Source.Remove(timer.pulseTimeoutId); timer.pulseTimeoutId = 0; GLib.Source.Remove(timer.secondTimerId); timer.secondTimerId = 0; timer.Paused = false; } }
public static void ToggleTimer(ITask task) { InactivateTimer timer = null; if (timers.TryGetValue(task.TimerID, out timer)) { timer.Paused = !timer.Paused; } }
void OnTaskToggled(object sender, Gtk.ToggledArgs args) { Logger.Debug("OnTaskToggled"); Gtk.TreeIter iter; Gtk.TreePath path = new Gtk.TreePath(args.Path); if (!Model.GetIter(out iter, path)) { return; // Do nothing } ITask task = Model.GetValue(iter, 0) as ITask; if (task == null) { return; } // remove any timer set up on this task InactivateTimer.CancelTimer(task); if (task.State == TaskState.Active) { bool showCompletedTasks = Application.Preferences.GetBool( Preferences.ShowCompletedTasksKey); // When showCompletedTasks is true, complete the tasks right // away. Otherwise, set a timer and show the timer animation // before marking the task completed. if (showCompletedTasks) { task.Complete(); ShowCompletedTaskStatus(); } else { task.Inactivate(); // Read the inactivate timeout from a preference int timeout = Application.Preferences.GetInt(Preferences.InactivateTimeoutKey); Logger.Debug("Read timeout from prefs: {0}", timeout); InactivateTimer timer = new InactivateTimer(this, iter, task, (uint)timeout); timer.StartTimer(); toggled = true; } } else { status = Catalog.GetString("Action Canceled"); TaskWindow.ShowStatus(status); task.Activate(); } }
void CellRenderer_EditingStarted(object o, EditingStartedArgs args) { if (!toggled) { return; } Gtk.TreeIter iter; Gtk.TreePath path = new Gtk.TreePath(args.Path); if (!Model.GetIter(out iter, path)) { return; } ITask task = Model.GetValue(iter, 0) as ITask; if (task == null) { return; } taskBeingEdited = task; InactivateTimer.ToggleTimer(taskBeingEdited); }