public FindDialogViewModel(Window dialog, MainViewModel mainViewModel) : base(dialog) { _mainViewModel = mainViewModel; SearchCommand = new DelegateCommand(() => { byte[] bytes; if (IsBytesSearch) { bytes = HexEdit.GetBytes(0, (int)HexEdit.Size); } else { Encoding encoding; if (IsAscii) { encoding = Encoding.ASCII; } else if (IsUTF8) { encoding = Encoding.UTF8; } else { encoding = Encoding.Unicode; } bytes = encoding.GetBytes(SearchString); } // initiate search var files = IsSearchFile ? Enumerable.Range(0, 1).Select(_ => _mainViewModel.SelectedFile) : _mainViewModel.OpenFiles; _finder = new ByteFinder(files, bytes, ByteFinderOptions.FromStart); RaisePropertyChanged(nameof(FindResults)); }, () => IsStringSearch && !string.IsNullOrEmpty(SearchString) || IsBytesSearch && HexEdit?.Size > 0) .ObservesProperty(() => IsStringSearch).ObservesProperty(() => IsBytesSearch).ObservesProperty(() => SearchString); GoToFindLocationCommand = new DelegateCommand <FindResultViewModel>(result => { _mainViewModel.SelectedFile = result.OpenFile; result.Editor.CaretOffset = result.Offset; }, result => result != null); }
protected override void OnClose(bool?result) { _data = HexEdit.GetBytes(0, (int)HexEdit.Size); }