private void Command_NewTask(object sender, ExecutedRoutedEventArgs e) { EditTaskWindow window = new EditTaskWindow(this); if (window.ShowDialog() ?? false) { groupOpen.AddTask(window.EditedTask); using (IRepository <Task, long> repository = PersistentFactory.GetContext().GetRepository <Task, long>()) repository.Add(window.EditedTask); StatsHelper.Update(StatsData.TaskCreated); NotificationHelper.Notify(NotificationType.TaskCreated, window.EditedTask.Name); ActionsCollection.Instance.Add(new TaskDeadlineAction(window.EditedTask)); } }
private void Command_PostponeTask(object sender, ExecutedRoutedEventArgs e) { if (groupOpen.SelectedTask != null) { Task selectedTask = groupOpen.SelectedTask; selectedTask.State = TaskState.Postponed; selectedTask.Updated = DateTime.Now; groupOpen.RemoveTask(selectedTask); groupPostponed.AddTask(selectedTask); using (IRepository <Task, long> repository = PersistentFactory.GetContext().GetRepository <Task, long>()) repository.Update(selectedTask); NotificationHelper.Notify(NotificationType.TaskDeferred, selectedTask.Name); } }
private void Command_CloseTask(object sender, ExecutedRoutedEventArgs e) { TasksGroupControl selectedGroup = groups.FirstOrDefault(x => x.SelectedTask != null); if (selectedGroup != null && (selectedGroup.SelectedTask.State == TaskState.Open || selectedGroup.SelectedTask.State == TaskState.Postponed)) { Task selectedTask = selectedGroup.SelectedTask; selectedTask.Close(); selectedGroup.RemoveTask(selectedTask); groupClosed.AddTask(selectedTask); ActionsCollection.Instance.Remove(ActionsCollection.Instance.Actions.OfType <TaskDeadlineAction>().FirstOrDefault(x => x.Task == selectedTask)); using (IRepository <Task, long> repository = PersistentFactory.GetContext().GetRepository <Task, long>()) repository.Update(selectedTask); StatsHelper.Update(StatsData.TaskClosed); StatsHelper.Update(StatsHelper.PriorityUpdate(selectedTask.Priority)); NotificationHelper.Notify(NotificationType.TaskClosed, selectedTask.Name); } }
public MainWindow() { InitializeComponent(); NotificationManager.Instance.Targets.Add(this); Closing += (sender, e) => NotificationManager.Instance.Targets.Remove(this); groupOpen = new TasksGroupControl("Open tasks"); groupPostponed = new TasksGroupControl("Postponed tasks"); groupClosed = new TasksGroupControl("Closed tasks"); groups.Add(groupOpen); groups.Add(groupPostponed); groups.Add(groupClosed); foreach (TasksGroupControl group in groups) { pnlGroups.Children.Add(group); group.OnTaskSelect += OnTaskSelect; group.OnTaskSelected += OnTaskSelected; } groupOpen.BackgroundSelector = new OpenTaskBackgroundSelector(); groupPostponed.BackgroundSelector = new OpenTaskBackgroundSelector(); groupClosed.BackgroundSelector = new TaskBackgroundSelector(); groupOpen.DateSelector = new DeadlineSelector(); groupPostponed.DateSelector = new DeadlineSelector(); groupClosed.DateSelector = new ClosedSelector(); groupOpen.ActivityVisibilitySelector = new SimpleBoolSelector(true); groupPostponed.ActivityVisibilitySelector = new SimpleBoolSelector(false); groupClosed.ActivityVisibilitySelector = new SimpleBoolSelector(false); groupOpen.GroupIconsSelector = new DeadlineIconsSelector(); groupPostponed.GroupIconsSelector = new DeadlineIconsSelector(); groupOpen.TaskDoubleClick += t => Command_EditTask(null, null); groupPostponed.TaskDoubleClick += t => Command_EditTask(null, null); groupClosed.TaskDoubleClick += t => Command_ShowTask(null, null); groupOpen.AddOrderSelector(x => x.Task.Deadline, false).AddOrderSelector(x => x.Task.Priority, true); groupPostponed.AddOrderSelector(x => x.Task.Deadline, false).AddOrderSelector(x => x.Task.Priority, true); groupClosed.AddOrderSelector(x => x.Task.Closed, true); groupOpen.OnTaskControlCreated += t => ActionsCollection.Instance.Add(new TaskControlAction(t)); groupPostponed.OnTaskControlCreated += t => ActionsCollection.Instance.Add(new TaskControlAction(t)); groupOpen.OnTaskControlRemove += t => ActionsCollection.Instance.Remove(ActionsCollection.Instance.Actions.OfType <TaskControlAction>().FirstOrDefault(x => x.TaskControl == t)); groupPostponed.OnTaskControlRemove += t => ActionsCollection.Instance.Remove(ActionsCollection.Instance.Actions.OfType <TaskControlAction>().FirstOrDefault(x => x.TaskControl == t)); groupOpen.Collapse(false); ActionsCollection.Instance.Add(new DeadlineIconsAction(groupOpen)); ActionsCollection.Instance.Add(new DeadlineIconsAction(groupPostponed)); ActionsCollection.Instance.Add(new TaskArchivingAction(groupClosed)); using (IRepository <Task, long> repository = PersistentFactory.GetContext().GetRepository <Task, long>()) { foreach (Task task in repository.GetAll()) { switch (task.State) { case TaskState.Open: groupOpen.AddTask(task); ActionsCollection.Instance.Add(new TaskDeadlineAction(task)); break; case TaskState.Postponed: groupPostponed.AddTask(task); ActionsCollection.Instance.Add(new TaskDeadlineAction(task)); break; case TaskState.Closed: groupClosed.AddTask(task); break; } } } TemplatesAction templatesAction = new TemplatesAction(); templatesAction.TaskCreated += task => { if (task != null) { groupOpen.Dispatcher.Invoke(() => groupOpen.AddTask(task)); using (IRepository <Task, long> repository = PersistentFactory.GetContext().GetRepository <Task, long>()) repository.Add(task); StatsHelper.Update(StatsData.TaskCreated); StatsHelper.Update(StatsData.TaskCreatedFromTemplate); NotificationHelper.Notify(NotificationType.TaskCreatedFromTemplate, task.Name); ActionsCollection.Instance.Add(new TaskDeadlineAction(task)); } }; ActionsCollection.Instance.Add(templatesAction); ActionsCollection.Instance.Add(new LastRunAction()); backgroundThread.Start(); RefreshMenu(); Log.Debug($"{groups.Sum(x => x.Count)} tasks loaded", this); Log.Info("Main window opened", this); }