Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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("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.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:
            case Key.F2:
                _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:
                _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;
            }
        }