Esempio n. 1
0
        public void DeleteTask()
        {
            if (!IsTaskSelected())
            {
                return;
            }
            var res = MessageBox.Show("Permanently delete the selected task?",
                                      "Confirm Delete",
                                      MessageBoxButton.YesNo,
                                      MessageBoxImage.Warning);

            if (res == MessageBoxResult.Yes)
            {
                try
                {
                    _taskList.Delete((Task)_window.lbTasks.SelectedItem);
                }
                catch (Exception ex)
                {
                    ex.Handle("Error deleting task");
                }

                UpdateDisplayedTasks();
            }
        }
Esempio n. 2
0
        public void Delete_InFile()
        {
            var fileContents = File.ReadAllLines(Data.TestDataPath).ToList();
            var task         = new Task(fileContents.Last());

            fileContents.Remove(fileContents.Last());

            var tl = new TaskList(Data.TestDataPath);

            tl.Delete(task);

            var newFileContents = File.ReadAllLines(Data.TestDataPath);

            CollectionAssert.AreEquivalent(fileContents, newFileContents);
        }
Esempio n. 3
0
        public void Delete_InCollection()
        {
            var task = new Task("(B) Delete_InCollection +test @task");
            var tl   = new TaskList(_testDataPath);

            tl.Add(task);

            List <Task> tasks = tl.ToList();

            tasks.Remove(tasks.Last());

            tl.Delete(task);

            List <Task> newTasks = tl.ToList();

            Assert.AreEqual(tasks.Count, newTasks.Count);

            for (int i = 0; i < tasks.Count; i++)
            {
                Assert.AreEqual(tasks[i].ToString(), newTasks[i].ToString());
            }
        }
Esempio n. 4
0
        public void Delete_InFile()
        {
            string tempTasksFile = CreateTempTasksFile();

            try
            {
                string[]      fileLines    = File.ReadAllLines(tempTasksFile);
                List <string> fileContents = fileLines.ToList();
                var           task         = new Task(fileContents.Last());
                fileContents.Remove(fileContents.Last());

                var tl = new TaskList(tempTasksFile);
                tl.Delete(task);
                tl.SaveTasks(tempTasksFile);

                string[] newFileContents = File.ReadAllLines(tempTasksFile);
                CollectionAssert.AreEquivalent(fileContents, newFileContents);
            }
            finally
            {
                File.Delete(tempTasksFile);
            }
        }
Esempio n. 5
0
        public void Delete_InCollection()
        {
            var task = new Task("(B) Delete_InCollection +test @task");
            var tl   = new TaskList(Data.TestDataPath);

            tl.Add(task);

            var tasks = new List <Task>(tl.Tasks);

            tasks.Remove(tasks.Where(x => x.Raw == task.Raw).First());


            tl.Delete(task);

            var newTasks = tl.Tasks.ToList();

            Assert.AreEqual(tasks.Count, newTasks.Count);

            for (int i = 0; i < tasks.Count; i++)
            {
                Assert.AreEqual(tasks[i].ToString(), newTasks[i].ToString());
            }
        }
        private void RemoveSelectedTasks()
        {
            if (_selectedTasks.Count == 0)
            {
                return;
            }

            _workingWithSelectedTasks = true;

            foreach (var task in _selectedTasks)
            {
                if (task != null)
                {
                    TaskList.Delete(task);
                }
            }

            _selectedTasks.Clear();

            _taskFileService.SaveTasks();

            _workingWithSelectedTasks = false;
        }
Esempio n. 7
0
        public void Delete_InCollection()
        {
            var task = new Task("(B) Delete_InCollection +test @task");
            var tl   = new TaskList(TestDataPath);

            tl.Add(task);

            var tasks = new List <Task>(tl.Tasks);

            Console.WriteLine($"{ReferenceEquals(task, tasks.First())}");
            Console.WriteLine($"{task == tasks.First()}");
            tasks.Remove(tasks.First(x => x == task));

            tl.Delete(task);

            var newTasks = tl.Tasks.ToList();

            Assert.AreEqual(tasks.Count, newTasks.Count);

            for (int i = 0; i < tasks.Count; i++)
            {
                Assert.AreEqual(tasks[i].ToString(), newTasks[i].ToString());
            }
        }
Esempio n. 8
0
        public void TaskListKeyUp(Key key, ModifierKeys modifierKeys = ModifierKeys.None)
        {
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) && Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) && key == Key.C)
            {
                var currentTask = _window.lbTasks.SelectedItem as Task;
                if (currentTask != null)
                {
                    _window.taskText.Text = currentTask.Raw;
                    _window.taskText.Select(_window.taskText.Text.Length, 0);         //puts cursor at the end
                    _window.taskText.Focus();
                }
                return;
            }
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) && key == Key.C)
            {
                var currentTask = _window.lbTasks.SelectedItem as Task;
                if (currentTask != null)
                {
                    Clipboard.SetText(currentTask.Raw);
                }

                return;
            }

            // create and open can be used when there's no list loaded
            switch (key)
            {
            case Key.C:
                _window.File_New(null, null);
                return;

            case Key.O:
                _window.File_Open(null, null);
                return;
            }

            if (_taskList == null)
            {
                return;
            }

            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
            {
                return;
            }

            switch (key)
            {
            case Key.N:
                // create one-line string of all filter but not ones beginning with a minus, and use as the starting text for a new task
                string filters = "";
                foreach (var filter in User.Default.FilterText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (filter.Substring(0, 1) != "-")
                    {
                        if (filter.Contains("due:active"))
                        {
                            filters = filters + " " + "due:today";     // If the current filter is "active", replace it here with "today"
                        }
                        else
                        {
                            filters = filters + " " + filter;
                        }
                    }
                }

                _window.taskText.Text = filters;
                _window.taskText.Focus();
                break;

            case Key.OemQuestion:
                _window.Help(null, null);
                break;

            case Key.F:
                ShowFilterDialog();
                break;

            case Key.RightShift:
                // Add Calendar to the titlebar
                AddCalendarToTitle();
                break;

            // Filter Presets
            case Key.NumPad0:
            case Key.D0:
                User.Default.FilterText = "";
                UpdateDisplayedTasks();
                User.Default.Save();
                break;

            case Key.NumPad1:
            case Key.D1:
                User.Default.FilterText = User.Default.FilterTextPreset1;
                UpdateDisplayedTasks();
                User.Default.Save();
                break;

            case Key.NumPad2:
            case Key.D2:
                User.Default.FilterText = User.Default.FilterTextPreset2;
                UpdateDisplayedTasks();
                User.Default.Save();
                break;

            case Key.NumPad3:
            case Key.D3:
                User.Default.FilterText = User.Default.FilterTextPreset3;
                UpdateDisplayedTasks();
                User.Default.Save();
                break;

            case Key.X:
                if (!IsTaskSelected())
                {
                    break;
                }
                ToggleComplete((Task)_window.lbTasks.SelectedItem);
                UpdateDisplayedTasks();
                break;

            case Key.D:
                if (!IsTaskSelected())
                {
                    break;
                }
                if (modifierKeys != ModifierKeys.Windows)
                {
                    var res = MessageBox.Show("Permanently delete the selected task?",
                                              "Confirm Delete",
                                              MessageBoxButton.YesNo,
                                              MessageBoxImage.Warning);

                    if (res == MessageBoxResult.Yes)
                    {
                        try
                        {
                            _taskList.Delete((Task)_window.lbTasks.SelectedItem);
                        }
                        catch (Exception ex)
                        {
                            ex.Handle("Error deleting task");
                        }

                        UpdateDisplayedTasks();
                    }
                }
                break;

            case Key.U:
            case Key.F2:
                if (!IsTaskSelected())
                {
                    break;
                }
                _updating             = (Task)_window.lbTasks.SelectedItem;
                _window.taskText.Text = _updating.ToString();
                _window.taskText.Select(_window.taskText.Text.Length, 0);     //puts cursor at the end
                _window.taskText.Focus();
                break;

            case Key.P:
                if (!IsTaskSelected())
                {
                    break;
                }
                PostponeTask((Task)_window.lbTasks.SelectedItem, ShowPostponeDialog());
                UpdateDisplayedTasks();
                break;

            default:
                break;
            }
        }
Esempio n. 9
0
		public void Delete_InFile()
		{
			string tempTasksFile = CreateTempTasksFile();
			try
			{
				string[] fileLines = File.ReadAllLines(tempTasksFile);
				List<string> fileContents = fileLines.ToList();
				var task = new Task(fileContents.Last());
				fileContents.Remove(fileContents.Last());

				var tl = new TaskList(tempTasksFile);
				tl.Delete(task);
				tl.SaveTasks(tempTasksFile);

				string[] newFileContents = File.ReadAllLines(tempTasksFile);
				CollectionAssert.AreEquivalent(fileContents, newFileContents);
			}
			finally
			{
				File.Delete(tempTasksFile);
			}
		}
Esempio n. 10
0
		public void Delete_InCollection()
		{
			var task = new Task("(B) Delete_InCollection +test @task");
			var tl = new TaskList(_testDataPath);
			tl.Add(task);

			List<Task> tasks = tl.ToList();
			tasks.Remove(tasks.Last());

			tl.Delete(task);

			List<Task> newTasks = tl.ToList();

			Assert.AreEqual(tasks.Count, newTasks.Count);

			for (int i = 0; i < tasks.Count; i++)
				Assert.AreEqual(tasks[i].ToString(), newTasks[i].ToString());
		}
Esempio n. 11
0
        private void KeyboardShortcut(Key key, ModifierKeys modifierKeys = ModifierKeys.None)
        {
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) && key == Key.C)
            {
                var currentTask = lbTasks.SelectedItem as Task;
                if (currentTask != null)
                {
                    Clipboard.SetText(currentTask.Raw);
                }

                return;
            }

            // create and open can be used when there's no list loaded
            switch (key)
            {
            case Key.C:
                File_New(null, null);
                return;

            case Key.O:
                File_Open(null, null);
                return;
            }

            if (_taskList == null)
            {
                return;
            }

            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
            {
                return;
            }

            switch (key)
            {
            case Key.N:
                // create one-line string of all filter but not ones beginning with a minus, and use as the starting text for a new task
                string filters = "";
                foreach (var filter in User.Default.FilterText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (filter.Substring(0, 1) != "-")
                    {
                        if (filter.Contains("active"))
                        {
                            // If the current filter is "active", replace it here with "today"
                            filters = filters + " " + "due:today";
                        }
                        else
                        {
                            filters = filters + " " + filter;
                        }
                    }
                }
                taskText.Text = filters;
                taskText.Focus();
                break;

            case Key.OemQuestion:
                Help(null, null);
                break;

            case Key.F:
                Filter(null, null);
                break;

            case Key.RightShift:
                // Add Calendar to the titlebar
                AddCalendarToTitle();
                break;

            // Filter Presets
            case Key.NumPad0:
            case Key.D0:
                User.Default.FilterText = "";
                FilterAndSort(_currentSort);
                User.Default.Save();
                break;

            case Key.NumPad1:
            case Key.D1:
                User.Default.FilterText = User.Default.FilterTextPreset1;
                FilterAndSort(_currentSort);
                User.Default.Save();
                break;

            case Key.NumPad2:
            case Key.D2:
                User.Default.FilterText = User.Default.FilterTextPreset2;
                FilterAndSort(_currentSort);
                User.Default.Save();
                break;

            case Key.NumPad3:
            case Key.D3:
                User.Default.FilterText = User.Default.FilterTextPreset3;
                FilterAndSort(_currentSort);
                User.Default.Save();
                break;

            case Key.OemPeriod:
                Reload();
                FilterAndSort(_currentSort);
                break;

            case Key.X:
                ToggleComplete((Task)lbTasks.SelectedItem);
                FilterAndSort(_currentSort);
                break;

            case Key.D:
                if (modifierKeys != ModifierKeys.Windows)
                {
                    var res = MessageBox.Show("Permanently delete the selected task?",
                                              "Confirm Delete",
                                              MessageBoxButton.YesNo,
                                              MessageBoxImage.Warning);

                    if (res == MessageBoxResult.Yes)
                    {
                        Try(() => _taskList.Delete((Task)lbTasks.SelectedItem), "Error deleting task");
                        FilterAndSort(_currentSort);
                    }
                }
                break;

            case Key.U:
                _updating     = (Task)lbTasks.SelectedItem;
                taskText.Text = _updating.ToString();
                taskText.Focus();
                break;

            case Key.P:
                _updating = (Task)lbTasks.SelectedItem;

                int iPostponeCount = Postpone(null, null);
                if (iPostponeCount <= 0)
                {
                    // User canceled, or entered a non-positive number or garbage
                    break;
                }

                // Get the current DueDate from the item being updated
                DateTime dtNewDueDate;
                string   postponedString;
                if (_updating.DueDate.Length > 0)
                {
                    dtNewDueDate = Convert.ToDateTime(_updating.DueDate);
                }
                else
                {
                    // Current item doesn't have a due date.  Use today as the due date
                    dtNewDueDate = Convert.ToDateTime(DateTime.Now.ToString());
                }

                // Add days to that date
                dtNewDueDate = dtNewDueDate.AddDays(iPostponeCount);

                // Build a dummy string which we'll display so the rest of the system thinks we edited the current item.
                // Otherwise we end up with 2 items which differ only by due date
                if (_updating.DueDate.Length > 0)
                {
                    // The item has a due date, so exchange the current with the new
                    postponedString = _updating.Raw.Replace(_updating.DueDate, dtNewDueDate.ToString("yyyy-MM-dd"));
                }
                else
                {
                    // The item doesn't have a due date, so just append the new due date to the task
                    postponedString = _updating.Raw.ToString() + " due:" + dtNewDueDate.ToString("yyyy-MM-dd");
                }

                // Display our "dummy" string.  If they cancel, no changes are committed.
                taskText.Text = postponedString;
                taskText.Focus();
                break;

            default:
                break;
            }
        }
Esempio n. 12
0
 public void onDelete()
 {
     taskList.Delete(task, task.duration / MINUTES_PER_TOKEN);
 }
Esempio n. 13
0
        private void KeyboardShortcut(Key key)
        {
            // create and open can be used when there's no list loaded
            switch (key)
            {
            case Key.C:
                File_New(null, null);
                return;

            case Key.O:
                File_Open(null, null);
                return;
            }

            if (_taskList == null)
            {
                return;
            }

            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
            {
                return;
            }

            switch (key)
            {
            case Key.N:
                // create one-line string of all filter but not ones beginning with a minus, and use as the starting text for a new task
                string filters = "";
                foreach (var filter in User.Default.FilterText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (filter.Substring(0, 1) != "-")
                    {
                        filters = filters + " " + filter;
                    }
                }
                taskText.Text = filters;
                taskText.Focus();
                break;

            case Key.OemQuestion:
                Help(null, null);
                break;

            case Key.F:
                Filter(null, null);
                break;

            case Key.OemPeriod:
                Reload();
                FilterAndSort(_currentSort);
                break;

            case Key.X:
                ToggleComplete((Task)lbTasks.SelectedItem);
                FilterAndSort(_currentSort);
                break;

            case Key.D:
                var res = MessageBox.Show("Permanently delete the selected task?",
                                          "Confirm Delete",
                                          MessageBoxButton.YesNo,
                                          MessageBoxImage.Warning);

                if (res == MessageBoxResult.Yes)
                {
                    _taskList.Delete((Task)lbTasks.SelectedItem);
                    FilterAndSort(_currentSort);
                }
                break;

            case Key.U:
                _updating     = (Task)lbTasks.SelectedItem;
                taskText.Text = _updating.ToString();
                taskText.Focus();
                break;

            default:
                break;
            }
        }