private bool CanMoveDown(object obj) { if (SelectedTaskNode == null || dialog != null) { return(false); } if (SelectedTaskNode.ParentNode != null) { TreeNode parentNode = SelectedTaskNode.ParentNode; int index = parentNode.TreeNodes.IndexOf(SelectedTaskNode); if (index + 1 < parentNode.TreeNodes.Count) { return(true); } } else { int index = AllTreeRoots.IndexOf(SelectedTaskNode); if (index + 1 < AllTreeRoots.Count) { return(true); } } return(false); }
private void MoveDown(object obj) { int curI = (int)SelectedTaskNode.Task.IndexNumber; if (SelectedTaskNode.ParentNode != null) { TreeNode parentNode = SelectedTaskNode.ParentNode; int index = parentNode.TreeNodes.IndexOf(SelectedTaskNode); parentNode.TreeNodes[index].Task.IndexNumber = parentNode.TreeNodes[index + 1].Task.IndexNumber; parentNode.TreeNodes[index + 1].Task.IndexNumber = curI; DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(TaskCommandEnum.Edit, parentNode.TreeNodes[index].Task)); // todo было бы прикольно вызывать так: parentNode.TreeNodes[index].Task.EditCommand() DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(TaskCommandEnum.Edit, parentNode.TreeNodes[index + 1].Task)); parentNode.TreeNodes.Move(index, index + 1); ChangeSelection(parentNode.TreeNodes[index + 1]); } else { int index = AllTreeRoots.IndexOf(SelectedTaskNode); AllTreeRoots[index].Task.IndexNumber = AllTreeRoots[index + 1].Task.IndexNumber; AllTreeRoots[index + 1].Task.IndexNumber = curI; DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(TaskCommandEnum.Edit, AllTreeRoots[index].Task)); DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(TaskCommandEnum.Edit, AllTreeRoots[index + 1].Task)); AllTreeRoots.Move(index, index + 1); ChangeSelection(AllTreeRoots[index + 1]); } }
private void MoveUp(object obj) { int curI = (int)SelectedTaskNode.Task.IndexNumber; TreeNode newSeleted = SelectedTaskNode; if (SelectedTaskNode.ParentNode != null) { TreeNode parentNode = SelectedTaskNode.ParentNode; int index = parentNode.TreeNodes.IndexOf(SelectedTaskNode); parentNode.TreeNodes[index].Task.IndexNumber = parentNode.TreeNodes[index - 1].Task.IndexNumber; parentNode.TreeNodes[index - 1].Task.IndexNumber = curI; DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(TaskCommandEnum.Edit, parentNode.TreeNodes[index].Task)); DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(TaskCommandEnum.Edit, parentNode.TreeNodes[index - 1].Task)); parentNode.TreeNodes.Move(index, index - 1); ChangeSelection(parentNode.TreeNodes[index - 1]); } else { int index = AllTreeRoots.IndexOf(SelectedTaskNode); AllTreeRoots[index].Task.IndexNumber = AllTreeRoots[index - 1].Task.IndexNumber; AllTreeRoots[index - 1].Task.IndexNumber = curI; DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(TaskCommandEnum.Edit, AllTreeRoots[index].Task)); DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(TaskCommandEnum.Edit, AllTreeRoots[index - 1].Task)); AllTreeRoots.Move(index, index - 1); ChangeSelection(AllTreeRoots[index - 1]); } }
//private void _doTaskCommand(KeyValuePair<TaskCommandEnum, Task> pair) public void DoTaskCommand(KeyValuePair <TaskCommandEnum, Task> pair) { TaskCommandEnum command = pair.Key; Task task = pair.Value; switch (command) { case TaskCommandEnum.Add: TasksVM.Add(task); TreeNode newNode = TasksVM.DictionaryFull[task.ID]; if (newNode.ParentNode == null) { AddRootNode(newNode); } ChangeSelection(newNode); if (newNode.ParentNode != null) { newNode.ParentNode.IsExpanded = true; } break; case TaskCommandEnum.Edit: TreeNode oldNode = TasksVM.DictionaryFull[task.ID]; int index = -1; if (oldNode.ParentNode == null) { index = AllTreeRoots.IndexOf(oldNode); } TasksVM.Edit(task, true); newNode = TasksVM.DictionaryFull[task.ID]; if (index != -1 && newNode.ParentNode == null) { UpdateRootNode(index, newNode); } else if (newNode.ParentNode == null) { AddRootNode(newNode); } else { DeleteRootNode(oldNode); } if (oldNode.ParentNode != newNode.ParentNode) { Context.procedureWork.RepareUserFave(task.ID); TasksVM.Init_tracker = false; TasksVM.InitFave(); } TaskFaveVM.DoTaskCommand(new KeyValuePair <FaveTaskCommandEnum, Task>(FaveTaskCommandEnum.Edit, task)); // MessengerInstance.Send<KeyValuePair<FaveTaskCommandEnum, Task>>( //new KeyValuePair<FaveTaskCommandEnum, Task>(FaveTaskCommandEnum.Edit, task)); //todo Настя сделать ссылки на task из общего словаря, чтобы не пришлось пробрасывать изменения в избранное break; } }