Пример #1
0
        //this is just for j and k - the nav keys. Using KeyDown allows for holding the key to navigate
        private void lbTasks_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt) && lbTasks.HasItems)
            {
                var selected = lbTasks.SelectedItem as Task;
                var updated  = new Task(selected.Raw);

                switch (e.SystemKey)
                {
                case Key.Up:
                    updated.IncPriority();
                    _taskList.Update(selected, updated);
                    Reload();
                    FilterAndSort(_currentSort);
                    break;

                case Key.Down:
                    updated.DecPriority();
                    _taskList.Update(selected, updated);
                    FilterAndSort(_currentSort);
                    Reload();
                    break;

                case Key.Left:
                case Key.Right:
                    updated.SetPriority(' ');
                    _taskList.Update(selected, updated);
                    FilterAndSort(_currentSort);
                    Reload();
                    break;
                }

                return;
            }

            switch (e.Key)
            {
            case Key.J:
                if (lbTasks.SelectedIndex < lbTasks.Items.Count - 1)
                {
                    lbTasks.ScrollIntoView(lbTasks.Items[lbTasks.SelectedIndex + 1]);
                    lbTasks.SelectedIndex = lbTasks.SelectedIndex + 1;
                }
                break;

            case Key.K:
                if (lbTasks.SelectedIndex > 0)
                {
                    lbTasks.ScrollIntoView(lbTasks.Items[lbTasks.SelectedIndex - 1]);
                    lbTasks.SelectedIndex = lbTasks.SelectedIndex - 1;
                }
                break;

            default:
                break;
            }
        }
Пример #2
0
        public void IncreasePriority()
        {
            Task selectedTask = (Task)_window.lbTasks.SelectedItem;

            if (selectedTask == null)
            {
                return;
            }

            try
            {
                Task newTask = new Task(selectedTask.Raw);
                newTask.IncPriority();
                _taskList.Update(selectedTask, newTask);
            }
            catch (Exception ex)
            {
                ex.Handle("Error while changing priority.");
            }
            finally
            {
                ReloadFile();
            }
        }
Пример #3
0
        public void TaskListPreviewKeyDown(KeyEventArgs e)
        {
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt) && _window.lbTasks.HasItems)
            {
                var selected = _window.lbTasks.SelectedItem as Task;
                if (selected == null)
                {
                    return;
                }

                var updated = new Task(selected.Raw);

                switch (e.SystemKey)
                {
                case Key.Up:
                    updated.IncPriority();
                    try
                    {
                        _taskList.Update(selected, updated);
                    }
                    catch (Exception ex)
                    {
                        ex.Handle("Error while changing priority");
                    }

                    Refresh();

                    break;

                case Key.Down:
                    updated.DecPriority();
                    try
                    {
                        _taskList.Update(selected, updated);
                    }
                    catch (Exception ex)
                    {
                        ex.Handle("Error while changing priority");
                    }

                    Refresh();
                    break;

                case Key.Left:
                case Key.Right:
                    updated.SetPriority(' ');
                    try
                    {
                        _taskList.Update(selected, updated);
                    }
                    catch (Exception ex)
                    {
                        ex.Handle("Error while changing priority");
                    }
                    Refresh();
                    break;
                }
                _window.lbTasks.Focus();
                return;
            }

            switch (e.Key)
            {
            case Key.J:
            case Key.Down:
                if (_window.lbTasks.SelectedIndex < _window.lbTasks.Items.Count - 1)
                {
                    _window.lbTasks.SelectedIndex++;
                    _window.lbTasks.ScrollIntoView(_window.lbTasks.Items[_window.lbTasks.SelectedIndex]);
                }
                e.Handled = true;
                break;

            case Key.K:
            case Key.Up:
                if (_window.lbTasks.SelectedIndex > 0)
                {
                    _window.lbTasks.ScrollIntoView(_window.lbTasks.Items[_window.lbTasks.SelectedIndex - 1]);
                    _window.lbTasks.SelectedIndex = _window.lbTasks.SelectedIndex - 1;
                }
                e.Handled = true;
                break;

            default:
                break;
            }
        }