Example #1
0
        private static void ExecutedUpdateTaskCommand(object sender, ExecutedRoutedEventArgs e)
        {
            object[] args        = e.Parameter as object[];
            UserTask task        = args[0] as UserTask;
            bool     dateChanged = (bool)args[1];

            string           id      = task.ID;
            TasksPeekContent _sender = sender as TasksPeekContent;

            foreach (TreeViewItem each in _sender.tasksTreeView.Items)
            {
                foreach (TreeViewItem t in each.Items)
                {
                    if ((t.Header as UserTask).ID == id)
                    {
                        if (dateChanged)
                        {
                            // Delete the task from the tree
                            TreeViewItem parent = t.Parent as TreeViewItem;
                            parent.Items.Remove(t);

                            if (!parent.HasItems)
                            {
                                _sender.tasksTreeView.Items.Remove(parent);
                            }

                            // Re-add the task to the tree
                            string header = "No Date";

                            if (task.DueDate.HasValue)
                            {
                                header = TasksView.GetFriendlyName(task.DueDate.Value);
                            }

                            TreeViewItem group = new TreeViewItem();
                            group.Header = header;
                            _sender.AddTask(task, group);
                        }
                        else
                        {
                            t.Header = new UserTask(false);
                            t.Header = task;
                        }

                        return;
                    }
                }
            }
        }
Example #2
0
        private static void ExecutedDeleteTaskCommand(object sender, ExecutedRoutedEventArgs e)
        {
            UserTask         task    = e.Parameter as UserTask;
            string           id      = task.ID;
            TasksPeekContent _sender = sender as TasksPeekContent;

            foreach (TreeViewItem each in _sender.tasksTreeView.Items)
            {
                foreach (TreeViewItem t in each.Items)
                {
                    if ((t.Header as UserTask).ID == id)
                    {
                        _sender.deleteTask(t, false);
                        break;
                    }
                }
            }
        }
Example #3
0
        private static void ExecutedTaskReorderCommand(object sender, ExecutedRoutedEventArgs e)
        {
            ItemReorderEventArgs args      = (ItemReorderEventArgs)e.Parameter;
            TasksPeekContent     _sender   = (TasksPeekContent)sender;
            UserTask             _peekTask = (UserTask)args.Item.Header;
            TreeViewItem         tvItem    = null;

            foreach (TreeViewItem parent in _sender.tasksTreeView.Items)
            {
                foreach (TreeViewItem child in parent.Items)
                {
                    if (((DatabaseObject)child.Header).ID == _peekTask.ID)
                    {
                        tvItem = child;
                        break;
                    }
                }

                if (tvItem != null)
                {
                    break;
                }
            }

            if (tvItem == null)
            {
                UserTask task = (UserTask)args.Item.Header;

                int newIndex = ((ItemsControl)args.Item.Parent).Items.IndexOf(args.Item);

                string header = "No Date";

                if (task.DueDate != null)
                {
                    header = TasksView.GetFriendlyName(task.DueDate.Value);
                }

                TreeViewItem group = new TreeViewItem()
                {
                    Header = header
                };

                _sender.AddTask(new UserTask(task), group, true, newIndex);
            }
            else
            {
                UserTask task = (UserTask)tvItem.Header;
                task.DueDate   = _peekTask.DueDate;
                task.StartDate = _peekTask.StartDate;

                string header = "No Date";

                if (task.DueDate != null)
                {
                    header = TasksView.GetFriendlyName(task.DueDate.Value);
                }

                TreeViewItem group = new TreeViewItem();
                group.Header = header;

                int origIndex = ((ItemsControl)tvItem.Parent).Items.IndexOf(tvItem);
                int newIndex  = ((ItemsControl)args.Item.Parent).Items.IndexOf(args.Item);

                if (origIndex < newIndex && args.NewParent == args.OldParent && Settings.AnimationsEnabled)
                {
                    newIndex++;
                }

                _sender.deleteTask(tvItem, false);
                _sender.AddTask(task, group, true, newIndex);

                if (task.IsOverdue && task.Status != UserTask.StatusPhase.Completed)
                {
                    tvItem.Foreground = new SolidColorBrush(Color.FromArgb(255, 218, 17, 17));
                }
                else
                {
                    tvItem.Foreground = Brushes.Black;
                }
            }
        }