Example #1
0
        public void Update(Task currentTask, Task newTask)
        {
            try
            {
                Log.Debug("Updating task '{0}' to '{1}'", currentTask.ToString(), newTask.ToString());

                ReloadTasks();
                var currentIndex = _tasks.IndexOf(_tasks.First(t => t.Raw == currentTask.Raw));

                _tasks[currentIndex] = newTask;

                File.WriteAllLines(_filePath, _tasks.Select(t => t.ToString()));

                Log.Debug("Task '{0}' updated", currentTask.ToString());

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to update your task int the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #2
0
        public void Delete(Task task)
        {
            try
            {
                Log.Debug("Deleting task '{0}'", task.ToString());

                ReloadTasks();                 // make sure we're working on the latest file

                if (Tasks.Remove(Tasks.First(t => t.Raw == task.Raw)))
                {
                    WriteAllTasksToFile();
                }

                Log.Debug("Task '{0}' deleted", task.ToString());

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to remove your task from the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #3
0
        public void Delete(Task task)
        {
            try
            {
                Log.Debug("Deleting task '{0}'", task.ToString());

                if (Tasks.Remove(Tasks.First(t => t.Raw == task.Raw)))
                {
                    WriteAllTasksToFile();
                }

                Log.Debug("Task '{0}' deleted", task.ToString());
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to remove your task from the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
            finally
            {
                UpdateTaskListMetaData();
            }
        }
Example #4
0
        /// <summary>
        /// This method updates one task in the file. It works by replacing the "current task" with the "new task".
        /// </summary>
        /// <param name="currentTask">The task to replace.</param>
        /// <param name="newTask">The replacement task.</param>
        /// <param name="reloadTasksPriorToUpdate">Optionally reload task file prior to the update. Default is TRUE.</param>
        /// <param name="writeTasks">Optionally write task file after the update. Default is TRUE.</param>
        /// <param name="reloadTasksAfterUpdate">Optionally reload task file after the update. Default is TRUE.</param>
        public void Update(Task currentTask, Task newTask, bool writeTasks = true)
        {
            Log.Debug("Updating task '{0}' to '{1}'", currentTask.ToString(), newTask.ToString());

            try
            {
                // ensure that the task list still contains the current task...
                if (!Tasks.Any(t => t.Raw == currentTask.Raw))
                {
                    throw new Exception("That task no longer exists in to todo.txt file.");
                }

                var currentIndex = Tasks.IndexOf(Tasks.First(t => t.Raw == currentTask.Raw));
                Tasks[currentIndex] = newTask;

                Log.Debug("Task '{0}' updated", currentTask.ToString());

                if (writeTasks)
                {
                    WriteAllTasksToFile();
                }
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to update your task in the task list file.";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #5
0
        public void Delete(Task task)
        {
            try
            {
                Log.Debug("Deleting task {0}: {1}", task.Id.ToString(), task.ToString());

                ReloadTasks(); // make sure we're working on the latest file

                if (_tasks.Remove(_tasks.First(t => t == task)))
                {
                    File.WriteAllLines(_filePath, _tasks.Select(t => t.ToString()));
                }

                Log.Debug("Task {0} deleted", task.Id.ToString());
                Console.WriteLine("Task {0} deleted", task.Id.ToString());

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to remove your task from the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #6
0
        public void Add(Task task)
        {
            try
            {
                var output = task.ToString();

                Log.Debug("Adding task '{0}'", output);

                var text = File.ReadAllText(_filePath);
                if (text.Length > 0 && !text.EndsWith(_preferredLineEnding))
                {
                    output = _preferredLineEnding + output;
                }

                File.AppendAllLines(_filePath, new string[] { output });

                Log.Debug("Task '{0}' added", output);

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to add your task to the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #7
0
        public void Add(Task task)
        {
            try
            {
                var output = task.ToString();

                Log.Debug("Adding task '{0}'", output);

                var text = File.ReadAllText(_filePath);
                if (text.Length > 0 && !text.EndsWith(Environment.NewLine))
                    output = Environment.NewLine + output;

                File.AppendAllLines(_filePath, new string[] { output });

                Log.Debug("Task '{0}' added", output);

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to add your task to the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }

        }
Example #8
0
        public void Update(Task currentTask, Task newTask)
        {
            try
            {
                Log.Debug("Updating task '{0}' to '{1}'", currentTask.ToString(), newTask.ToString());

                ReloadTasks();

                // ensure that the task list still contains the current task...
                if (!Tasks.Any(t => t.Raw == currentTask.Raw))
                {
                    throw new Exception("That task no longer exists in to todo.txt file");
                }

                var currentIndex = Tasks.IndexOf(Tasks.First(t => t.Raw == currentTask.Raw));

                Tasks[currentIndex] = newTask;

                File.WriteAllLines(_filePath, Tasks.Select(t => t.ToString()));

                Log.Debug("Task '{0}' updated", currentTask.ToString());

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to update your task int the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #9
0
        public void Add(Task task)
        {
            try
            {
                var output = task.ToString();

                var text = File.ReadAllText(_filePath);
                if (text.Length > 0 && !text.EndsWith(Environment.NewLine))
                    output = Environment.NewLine + output;

                File.AppendAllLines(_filePath, new string[] { output });

                ReloadTasks();
            }
            catch (IOException ex)
            {
                throw new TaskException("An error occurred while trying to add your task to the task list file", ex);
            }

        }
Example #10
0
		public void Add(Task task)
		{
			try
			{
				var output = task.ToString();

				Log.Debug("Adding task '{0}'", output);

				var text = File.ReadAllText(_filePath);
                if (text.Length > 0 && !text.EndsWith(_preferredLineEnding))
                {
                    output = _preferredLineEnding + output;
                }

				File.AppendAllLines(_filePath, new string[] { output });

                Tasks.Add(task);

				Log.Debug("Task '{0}' added", output);
			}
			catch (IOException ex)
			{
				var msg = "An error occurred while trying to add your task to the task list file";
				Log.Error(msg, ex);
				throw new TaskException(msg, ex);
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
				throw;
			}
            finally
            {
                UpdateTaskListMetaData();
            }
		}
Example #11
0
		public void Update(Task currentTask, Task newTask)
		{
			try
			{
				Log.Debug("Updating task '{0}' to '{1}'", currentTask.ToString(), newTask.ToString());

				ReloadTasks();

				// ensure that the task list still contains the current task...
				if (!Tasks.Any(t => t.Raw == currentTask.Raw))
					throw new Exception("That task no longer exists in to todo.txt file");

				var currentIndex = Tasks.IndexOf(Tasks.First(t => t.Raw == currentTask.Raw));

				Tasks[currentIndex] = newTask;

				WriteAllTasksToFile();

				Log.Debug("Task '{0}' updated", currentTask.ToString());

				ReloadTasks();
			}
			catch (IOException ex)
			{
				var msg = "An error occurred while trying to update your task int the task list file";
				Log.Error(msg, ex);
				throw new TaskException(msg, ex);
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
				throw;
			}
		}
Example #12
0
 public void ToString_From_Parameters()
 {
     var task = new Task("(A)", _projects, _contexts, "This is a test task");
     Assert.AreEqual("(A) This is a test task +test @work", task.ToString());
 }
		private void KeyboardShortcut(Key key)
		{
			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.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:
					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;
				default:
					break;
			}
		}
Example #14
0
        public void Delete(Task task)
		{
			try
			{
				Log.Debug("Deleting task '{0}'", task.ToString());

				if (Tasks.Remove(Tasks.First(t => t.Raw == task.Raw)))
				{
					WriteAllTasksToFile();
				}

				Log.Debug("Task '{0}' deleted", task.ToString());
			}
			catch (IOException ex)
			{
				var msg = "An error occurred while trying to remove your task from the task list file";
				Log.Error(msg, ex);
				throw new TaskException(msg, ex);
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
				throw;
			}
            finally
            {
                UpdateTaskListMetaData();
            }
		}
Example #15
0
 public void ToString_From_Raw()
 {
     var task = new Task("(A) @work +test This is a test task");
     Assert.AreEqual("(A) @work +test This is a test task", task.ToString());
 }
Example #16
0
 public void UpdateTask()
 {
     // Abort if no task, or more than one task, is selected.
     if (!IsTaskSelected())
     {
         return;
     }
     _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();
 }
Example #17
0
        /// <summary>
        /// This method updates one task in the file. It works by replacing the "current task" with the "new task".
        /// </summary>
        /// <param name="currentTask">The task to replace.</param>
        /// <param name="newTask">The replacement task.</param>
        /// <param name="reloadTasksPriorToUpdate">Optionally reload task file prior to the update. Default is TRUE.</param>
        /// <param name="writeTasks">Optionally write task file after the update. Default is TRUE.</param>
        /// <param name="reloadTasksAfterUpdate">Optionally reload task file after the update. Default is TRUE.</param>
        public void Update(Task currentTask, Task newTask, bool writeTasks = true)
		{
            Log.Debug("Updating task '{0}' to '{1}'", currentTask.ToString(), newTask.ToString());

			try
			{

				// ensure that the task list still contains the current task...
				if (!Tasks.Any(t => t.Raw == currentTask.Raw))
                { 
					throw new Exception("That task no longer exists in to todo.txt file.");
                }

                var currentIndex = Tasks.IndexOf(Tasks.First(t => t.Raw == currentTask.Raw));
                Tasks[currentIndex] = newTask;

                Log.Debug("Task '{0}' updated", currentTask.ToString());

                if (writeTasks)
                {
                    WriteAllTasksToFile();
                }
			}
			catch (IOException ex)
			{
				var msg = "An error occurred while trying to update your task in the task list file.";
				Log.Error(msg, ex);
				throw new TaskException(msg, ex);
			}
			catch (Exception ex)
			{
				Log.Error(ex.ToString());
				throw;
			}
            finally
            {
                UpdateTaskListMetaData();
            }
		}
Example #18
0
		private void KeyboardShortcut(Key key)
		{
			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:
					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 = Convert.ToDateTime(_updating.DueDate);

                    // 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
                    string postponedString = _updating.Raw.Replace(_updating.DueDate, dtNewDueDate.ToString("yyyy-MM-dd"));

                    // Display our "dummy" string.  If they cancel, no changes are committed.  
                    taskText.Text = postponedString;
                    taskText.Focus();
                    break;
				default:
					break;
			}
		}
Example #19
0
        public void Delete(Task task)
        {
            try
            {
                Log.Debug("Deleting task '{0}'", task.ToString());

                ReloadTasks(); // make sure we're working on the latest file
                
                if (_tasks.Remove(_tasks.First(t => t.Raw == task.Raw)))
                    File.WriteAllLines(_filePath, _tasks.Select(t => t.ToString()));
                
                Log.Debug("Task '{0}' deleted", task.ToString());

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to remove your task from the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #20
0
        public void Update(Task currentTask, Task newTask)
        {
            try
            {
                Log.Debug("Updating task '{0}' to '{1}'", currentTask.ToString(), newTask.ToString());

                ReloadTasks();
                var currentIndex = _tasks.IndexOf(_tasks.First(t => t.Raw == currentTask.Raw));

                _tasks[currentIndex] = newTask;

                File.WriteAllLines(_filePath, _tasks.Select(t => t.ToString()));

                Log.Debug("Task '{0}' updated", currentTask.ToString());

                ReloadTasks();
            }
            catch (IOException ex)
            {
                var msg = "An error occurred while trying to update your task int the task list file";
                Log.Error(msg, ex);
                throw new TaskException(msg, ex);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }
Example #21
0
 private Task SetTaskCompletion(Task task, dynamic parameter = null)
 {
     task.Completed = !task.Completed;
     var newTask = new Task(task.ToString());
     return newTask;
 }
Example #22
0
        private Task SetTaskPriority(Task task, dynamic newPriority)
        {
            Regex rgx = new Regex(@"^\((?<priority>[A-Z])\)\s"); // matches priority strings such as "(A) " (including trailing space)

            string oldTaskRawText = task.ToString();
            string oldPriorityRaw = rgx.Match(oldTaskRawText).ToString(); // Priority letter plus parentheses and trailing space
            string oldPriority = rgx.Match(oldTaskRawText).Groups["priority"].Value.Trim(); // Priority letter 

            string newPriorityRaw = "(" + newPriority + ") ";
            string newTaskRawText = (String.IsNullOrEmpty(oldPriority)) ?
                newPriorityRaw + oldTaskRawText :            // prepend new priority
                rgx.Replace(oldTaskRawText, newPriorityRaw); // replace old priority (regex) with new priority (formatted)

            return new Task(newTaskRawText);
        }
Example #23
0
		public void TaskListKeyUp(Key key, ModifierKeys modifierKeys = ModifierKeys.None)
		{
			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("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.OemPeriod:
					Reload();
					UpdateDisplayedTasks();
					break;
				case Key.X:
					ToggleComplete((Task)_window.lbTasks.SelectedItem);
					UpdateDisplayedTasks();
					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)_window.lbTasks.SelectedItem);
							}
							catch (Exception ex)
							{
								ex.Handle("Error deleting task");
							}

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

					int iPostponeCount = ShowPostponeDialog();
					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.  
					_window.taskText.Text = postponedString;
					_window.taskText.Focus();
					break;
				default:
					break;
			}
		}
        private void KeyboardShortcut(Key key)
        {
            switch (key)
            {
                case Key.C:
                    File_New(null, null);
                    break;
                case Key.O:
                    File_Open(null, null);
                    break;
                case Key.N:
                    taskText.Text = User.Default.FilterText;
                    taskText.Focus();
                    break;
                case Key.OemQuestion:
                    Help(null, null);
                    break;
                case Key.F:
                    Filter(null, null);
                    break;
                case Key.OemPeriod:
                    _taskList.ReloadTasks();
                    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);

                    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;
            }
        }
Example #25
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);

					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;
			}
		}
 public void UpdateTask()
 {
     if (!IsTaskSelected()) return;
     _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();
 }