private void Command_RemoveTask(object sender, ExecutedRoutedEventArgs e) { TasksGroupControl selectedGroup = groups.FirstOrDefault(x => x.SelectedTask != null); if (selectedGroup != null) { Task selectedTask = selectedGroup.SelectedTask; selectedTask.State = TaskState.Removed; selectedGroup.RemoveTask(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.TaskRemoved); NotificationHelper.Notify(NotificationType.TaskRemoved, selectedTask.Name); } }
private void Command_EditTask(object sender, ExecutedRoutedEventArgs e) { deselect = false; TasksGroupControl selectedGroup = groups.FirstOrDefault(x => x.SelectedTask != null); if (selectedGroup != null && (selectedGroup.SelectedTask.State == TaskState.Open || selectedGroup.SelectedTask.State == TaskState.Postponed)) { EditTaskWindow window = new EditTaskWindow(this, selectedGroup.SelectedTask); if (window.ShowDialog() ?? false) { selectedGroup.UpdateTask(window.EditedTask); using (IRepository <Task, long> repository = PersistentFactory.GetContext().GetRepository <Task, long>()) repository.Update(window.EditedTask); NotificationHelper.Notify(NotificationType.TaskUpdated, window.EditedTask.Name); } } }
public void Select(TasksGroupControl control, StackPanel panel) { DateTime today = DateTime.Today; int warning = 0, critical = 0; foreach (Task task in control.Tasks) { if (task.Deadline < today) { critical++; } else if (task.Deadline == today) { warning++; } } panel.Children.Remove(tbCritical); panel.Children.Remove(imgCritical); panel.Children.Remove(tbWarning); panel.Children.Remove(imgWarning); if (critical > 0) { tbCritical.Text = critical.ToString(); panel.Children.Add(tbCritical); panel.Children.Add(imgCritical); } if (warning > 0) { tbWarning.Text = warning.ToString(); panel.Children.Add(tbWarning); panel.Children.Add(imgWarning); } }
public TaskArchivingAction(TasksGroupControl closedTasksGroup) : base(600) { this.closedTasksGroup = closedTasksGroup; }
public DeadlineIconsAction(TasksGroupControl groupControl) : base(60) { GroupControl = groupControl; }
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); }