public FileExplorerViewModel(string initialDirectory) : base(initialDirectory)
        {
            RootPath = new NotifyingProperty <string>(
                (oldS, newS) => { if (newS.Trim() != oldS)
                                  {
                                      SetPath(newS);
                                  }
                },
                initialDirectory
                );
            DragDropRootPath = new DragAndDropHandler(x => true, SetRootPathAndCaretIndex);
            SelectedItem     = new NotifyingProperty <FileSystemEntityViewModel>(x => {
                SelectedIndex = x == null ? -1 : GetItems(this).Select((e, i) => new { I = i, E = e }).First(z => z.E == x).I;
            });

            _refreshTimer.Interval = TimeSpan.FromMilliseconds(100);
            _refreshTimer.Tick    += _refreshTimer_Tick;

            InteractCommand = new ChainCommand(
                InteractCommand,
                x => {
                if (IsExpanded.Value)
                {
                    _refreshTimer.Start();
                }
                else
                {
                    _refreshTimer.Stop();
                }
            }
                );

            KeyPressHandler         = new KeyPressHandler(KeyPressed);
            PathBoxLostFocusCommand = new RelayCommand(x => PathBoxHasFocus.Value = false);

            PathBoxGotFocusCommand = new RelayCommand(x => {
                DeselectItem();
                PathBoxHasFocus.Value = true;
                if (_updatePathBoxCaretIndex)
                {
                    var arg = (RoutedEventArgs)x;
                    SetCaretIndex((TextBox)arg.Source);
                }
                _updatePathBoxCaretIndex = false;
            });

            PathBoxTextChangedCommand = new RelayCommand(
                x => {
                var arg = (TextChangedEventArgs)x;
                SetCaretIndex((TextBox)arg.Source);
            },
                x => _updatePathBoxCaretIndex
                );

            FavoriteSelectedCommand = new RelayCommand(
                x => SetRootPathAndCaretIndex((string)x)
                );
        }
        public FileExplorerViewModel(string initialDirectory) : base(initialDirectory) {
            RootPath = new NotifyingProperty<string>(
                (oldS, newS) => { if(newS.Trim() != oldS) SetPath(newS); },
                initialDirectory
            );
            DragDropRootPath = new DragAndDropHandler(x => true, SetRootPathAndCaretIndex);
            SelectedItem = new NotifyingProperty<FileSystemEntityViewModel>(x => {
                SelectedIndex = x == null ? -1 : GetItems(this).Select((e, i) => new { I = i, E = e }).First(z => z.E == x).I;
            });

            _refreshTimer.Interval = TimeSpan.FromMilliseconds(100);
            _refreshTimer.Tick += _refreshTimer_Tick;

            InteractCommand = new ChainCommand(
                InteractCommand,
                x => {
                    if(IsExpanded.Value) _refreshTimer.Start();
                    else _refreshTimer.Stop();
                }
            );

            KeyPressHandler = new KeyPressHandler(KeyPressed);
            PathBoxLostFocusCommand = new RelayCommand(x => PathBoxHasFocus.Value = false);

            PathBoxGotFocusCommand = new RelayCommand(x => {
                DeselectItem();
                PathBoxHasFocus.Value = true;
                if(_updatePathBoxCaretIndex) {
                    var arg = (RoutedEventArgs)x;
                    SetCaretIndex((TextBox)arg.Source);
                }
                _updatePathBoxCaretIndex = false;
            });

            PathBoxTextChangedCommand = new RelayCommand(
                x => {
                    var arg = (TextChangedEventArgs)x;
                    SetCaretIndex((TextBox)arg.Source);
                },
                x => _updatePathBoxCaretIndex
            );

            FavoriteSelectedCommand = new RelayCommand(
                x => SetRootPathAndCaretIndex((string)x)
            );
        }
Esempio n. 3
0
        public KeyBindingViewModel(KeyBinding binding, Action<KeyBinding, KeyBinding> bindingChangedCallback, Action<KeyBindingViewModel> deleteBindingCallback)
        {
            _currentBinding = binding;
            _bindingChangedCallback = bindingChangedCallback;
            KeyPressHandler = new KeyPressHandler(
                KeyPressed,
                keyDownCanExecute: x => IsEditingBinding.Value,
                keyUpCanExecute: x => IsEditingBinding.Value
            );
            Keys = new NotifyingProperty<HashSet<Key>>(_currentBinding.Keys);
            PathOrLiteral = new NotifyingProperty<string>(x => CommitChanges(), (binding as LuaKeyBinding)?.PathOrLiteral);
            ExecuteOnKeyUp = new NotifyingProperty<bool>(
                x => {
                    if(IsEditingBinding.Value) EndEditBinding();
                    else CommitChanges();
                },
                _currentBinding.ExecuteOnKeyUp
            );
            ExecuteOnKeyDown = new NotifyingProperty<bool>(
                x => {
                    if(!x) RepeatOnKeyDown.Value = x;
                    else if(IsEditingBinding.Value) EndEditBinding();
                    else CommitChanges();
                },
                _currentBinding.ExecuteOnKeyDown
            );
            RepeatOnKeyDown = new NotifyingProperty<bool>(
                x => {
                    if (x) ExecuteOnKeyDown.Value = x;
                    else if(IsEditingBinding.Value) EndEditBinding();
                    else CommitChanges();
                },
                _currentBinding.RepeatOnKeyDown
            );
            IsEditingBinding = new NotifyingProperty<bool>();
            StartEditingCommand = new RelayCommand(x => StartEditBinding());
            EndEditingCommand = new RelayCommand(x => EndEditBinding());
            if (deleteBindingCallback != null) DeleteBindingCommand = new RelayCommand(x => deleteBindingCallback(this));

            PathOrLiteralGotFocusCommand = new RelayCommand(x => PathOrLiteralIsFocused.Value = true);
            PathOrLiteralLostFocusCommand = new RelayCommand(x => PathOrLiteralIsFocused.Value = false);
            DragDrop = new DragAndDropHandler(AllowDrop, Drop);
            LostKeyboardFocusCommand = new RelayCommand(x => KeyPressHandler.ClearPressedKeys());
        }
Esempio n. 4
0
        private bool KeyPressed(IReadOnlyList <Key> arg)
        {
            if (arg.Count == 1)
            {
                switch (arg[0])
                {
                case Key.Escape:
                    KeyPressHandler.ClearPressedKeys();
                    Keys.Value = _currentBinding.Keys;
                    EndEditBinding();
                    return(true);

                case Key.Enter:
                    KeyPressHandler.ClearPressedKeys();
                    EndEditBinding();
                    return(true);
                }
            }

            Keys.Value = new HashSet <Key>(arg);
            return(true);
        }
Esempio n. 5
0
        public KeyBindingViewModel(KeyBinding binding, Action <KeyBinding, KeyBinding> bindingChangedCallback, Action <KeyBindingViewModel> deleteBindingCallback)
        {
            _currentBinding         = binding;
            _bindingChangedCallback = bindingChangedCallback;
            KeyPressHandler         = new KeyPressHandler(
                KeyPressed,
                keyDownCanExecute: x => IsEditingBinding.Value,
                keyUpCanExecute: x => IsEditingBinding.Value
                );
            Keys           = new NotifyingProperty <HashSet <Key> >(_currentBinding.Keys);
            PathOrLiteral  = new NotifyingProperty <string>(x => CommitChanges(), (binding as LuaKeyBinding)?.PathOrLiteral);
            ExecuteOnKeyUp = new NotifyingProperty <bool>(
                x => {
                if (IsEditingBinding.Value)
                {
                    EndEditBinding();
                }
                else
                {
                    CommitChanges();
                }
            },
                _currentBinding.ExecuteOnKeyUp
                );
            ExecuteOnKeyDown = new NotifyingProperty <bool>(
                x => {
                if (!x)
                {
                    RepeatOnKeyDown.Value = x;
                }
                else if (IsEditingBinding.Value)
                {
                    EndEditBinding();
                }
                else
                {
                    CommitChanges();
                }
            },
                _currentBinding.ExecuteOnKeyDown
                );
            RepeatOnKeyDown = new NotifyingProperty <bool>(
                x => {
                if (x)
                {
                    ExecuteOnKeyDown.Value = x;
                }
                else if (IsEditingBinding.Value)
                {
                    EndEditBinding();
                }
                else
                {
                    CommitChanges();
                }
            },
                _currentBinding.RepeatOnKeyDown
                );
            IsEditingBinding    = new NotifyingProperty <bool>();
            StartEditingCommand = new RelayCommand(x => StartEditBinding());
            EndEditingCommand   = new RelayCommand(x => EndEditBinding());
            if (deleteBindingCallback != null)
            {
                DeleteBindingCommand = new RelayCommand(x => deleteBindingCallback(this));
            }

            PathOrLiteralGotFocusCommand  = new RelayCommand(x => PathOrLiteralIsFocused.Value = true);
            PathOrLiteralLostFocusCommand = new RelayCommand(x => PathOrLiteralIsFocused.Value = false);
            DragDrop = new DragAndDropHandler(AllowDrop, Drop);
            LostKeyboardFocusCommand = new RelayCommand(x => KeyPressHandler.ClearPressedKeys());
        }