protected FileSystemEntityViewModel() { IsExpanded = new NotifyingProperty<bool>( x => InteractCommand?.Execute(null) ); ErrorMessage = new NotifyingProperty<string>( x => Focusable.Value = string.IsNullOrEmpty(x) ); DragItem = new DragAndDropHandler( () => string.IsNullOrEmpty(ErrorMessage.Value), () => new DataObject(DataFormats.FileDrop, new string[] { EntityPath.Value }) ); FavoriteCommand = new RelayCommand( x => ArgsAndSettings.FavoritedLocations.Add(EntityPath.Value), x => !ArgsAndSettings.FavoritedLocations.Contains(EntityPath.Value) ); UnfavoriteCommand = new RelayCommand( x => ArgsAndSettings.FavoritedLocations.Remove(EntityPath.Value), x => ArgsAndSettings.FavoritedLocations.Contains(EntityPath.Value) ); }
public DirectoryViewModel(string path) { Items.Value = new ObservableCollection<FileSystemEntityViewModel>(new FileSystemEntityViewModel[] { null }); InteractCommand = new RelayCommand(async arg => { await UpdateState_Async(); }); SetPath(path); }
public DragAndDropHandler(Func<string, bool> allowDrop, Action<string> drop, Func<bool> allowDrag, Func<DataObject> makeDragObject) { _allowDrop = allowDrop; _allowDrag = allowDrag; _drop = drop; _makeDragObject = makeDragObject; DropCommand = new RelayCommand(x => Drop((DragEventArgs)x)); DragOverCommand = new RelayCommand(x => DragOver((DragEventArgs)x)); MouseLeftButtonDownCommand = new RelayCommand(x => _draggingStarted = true, x => _allowDrag()); MouseMoveCommand = new RelayCommand(x => HandleDrag((MouseEventArgs)x), x => _draggingStarted); }
public KeyPressHandler(Func<IReadOnlyList<Key>, bool> keyPressedCallback = null, Func<IReadOnlyList<Key>, IReadOnlyList<Key>, bool> keyReleasedCallback = null, Func<object, bool> keyDownCanExecute = null, Func<object, bool> keyUpCanExecute = null) { _keyPressedCallback = keyPressedCallback ?? new Func<IReadOnlyList<Key>, bool>(x => false); _keyReleasedCallback = keyReleasedCallback ?? new Func<IReadOnlyList<Key>, IReadOnlyList<Key>, bool>((x, y) => false); keyDownCanExecute = keyDownCanExecute ?? new Func<object, bool>(x => true); keyUpCanExecute = keyUpCanExecute ?? new Func<object, bool>(x => true); KeyDownCommand = new RelayCommand(x => KeyDown((KeyEventArgs)x), keyDownCanExecute); KeyUpCommand = new RelayCommand(x => KeyUp((KeyEventArgs)x), keyUpCanExecute); }
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 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()); }
public SelectableButtonViewModel(string text, ICommand command) { Text.Value = text; bool _ignoreSelectedChanged = false; IsSelected = new NotifyingProperty<bool>(isSelected => { if (_ignoreSelectedChanged || !isSelected) return; Command.Execute(null); }); Command = new RelayCommand( x => { _ignoreSelectedChanged = true; IsSelected.Value = true; command.Execute(x); _ignoreSelectedChanged = false; }, command.CanExecute ); }
public ToggleButtonViewModel(string text, ICommand command) { Text.Value = text; Command = new RelayCommand(x => { IsSelected.Value = !IsSelected.Value; command.Execute(x); }, command.CanExecute); }
public RenameViewModel(Func<string, string> validate, string currentName, Action requestClose) { Name = new NotifyingProperty<string>(x => ValidationError.Value = validate(x), currentName); OkCommand = new RelayCommand(x => { DialogResult = true; requestClose(); }); CancelCommand = new RelayCommand(x => { DialogResult = false; requestClose(); }); }
public FileViewModel(string path) { InteractCommand = new RelayCommand(x => ApplicationState.OpenDocument(path)); SetPath(path); IconImage.Value = Resources.Document_Generic.ToBitmapImage(); }