diff --git a/src/SmartCommander/ViewModels/FilesPaneViewModel.cs b/src/SmartCommander/ViewModels/FilesPaneViewModel.cs index c0d5b8b..efe011e 100644 --- a/src/SmartCommander/ViewModels/FilesPaneViewModel.cs +++ b/src/SmartCommander/ViewModels/FilesPaneViewModel.cs @@ -15,7 +15,6 @@ using System.Reactive.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; -using System.Windows.Input; using Path = System.IO.Path; namespace SmartCommander.ViewModels @@ -37,8 +36,7 @@ public class FilesPaneViewModel : ViewModelBase private bool _isSelected; private SortingBy _sorting = SortingBy.SortingByName; - private bool _ascending = true; - public event EventHandler? FocusChanged; + private bool _ascending = true; public string CurrentDirectory { @@ -96,12 +94,7 @@ public bool IsSelected set { _isSelected = value; - this.RaisePropertyChanged(nameof(GridBorderBrush)); - - if (value) - { - FocusChanged?.Invoke(this, EventArgs.Empty); - } + this.RaisePropertyChanged(nameof(GridBorderBrush)); } } @@ -124,7 +117,7 @@ public FilesPaneViewModel() ShowViewerDialog = new Interaction<ViewerViewModel, ViewerViewModel?>(); } - public FilesPaneViewModel(MainWindowViewModel mainVM, EventHandler focusHandler) + public FilesPaneViewModel(MainWindowViewModel mainVM) { CurrentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); ViewCommand = ReactiveCommand.Create(View); @@ -132,8 +125,7 @@ public FilesPaneViewModel(MainWindowViewModel mainVM, EventHandler focusHandler) ZipCommand = ReactiveCommand.Create(Zip); UnzipCommand = ReactiveCommand.Create(Unzip); ShowViewerDialog = new Interaction<ViewerViewModel, ViewerViewModel?>(); - _mainVM = mainVM; - FocusChanged += focusHandler; + _mainVM = mainVM; } public event Action<object, object>? ScrollToItemRequested; @@ -151,12 +143,12 @@ public void RequestScroll(object item, object? column) public void CellPointerPressed(object sender, object parameter) { - _mainVM.SelectedPane = this; + IsSelected = true; } public void SortingStarted(object sender, object parameter) { - _mainVM.SelectedPane = this; + IsSelected = true; DataGridColumnEventArgs? args = parameter as DataGridColumnEventArgs; if (args != null) @@ -248,7 +240,7 @@ public void SelectionChanged(object sender, object parameter) public void Tapped(object sender, object parameter) { - _mainVM.SelectedPane = this; + IsSelected = true; } public void DoubleTapped(object sender, object parameter) diff --git a/src/SmartCommander/ViewModels/MainWindowViewModel.cs b/src/SmartCommander/ViewModels/MainWindowViewModel.cs index c24c30c..34aea86 100644 --- a/src/SmartCommander/ViewModels/MainWindowViewModel.cs +++ b/src/SmartCommander/ViewModels/MainWindowViewModel.cs @@ -2,6 +2,7 @@ using Avalonia.Styling; using MsBox.Avalonia.Enums; using ReactiveUI; +using Serilog; using SmartCommander.Assets; using SmartCommander.Models; using System; @@ -43,9 +44,9 @@ public MainWindowViewModel() OptionsCommand = ReactiveCommand.CreateFromTask(ShowOptions); - LeftFileViewModel = new FilesPaneViewModel(this, OnFocusChanged); - RightFileViewModel = new FilesPaneViewModel(this, OnFocusChanged); - SelectedPane = RightFileViewModel; + LeftFileViewModel = new FilesPaneViewModel(this); + RightFileViewModel = new FilesPaneViewModel(this); + LeftFileViewModel.IsSelected = true; if (!string.IsNullOrEmpty(OptionsModel.Instance.LeftPanePath)) { @@ -66,15 +67,7 @@ private void SetLanguage() var culture = new CultureInfo(cultureName); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; - } - - private void OnFocusChanged(object? sender, EventArgs e) - { - if (sender is FilesPaneViewModel) - { - SelectedPane = (FilesPaneViewModel)sender; - } - } + } public ReactiveCommand<Unit, Unit> ExitCommand { get; } @@ -186,7 +179,26 @@ public FilesPaneViewModel SecondPane } } - public FilesPaneViewModel SelectedPane { get; set; } + public FilesPaneViewModel SelectedPane + { + get + { + if (LeftFileViewModel.IsSelected) + { + return LeftFileViewModel; + } + else if (RightFileViewModel.IsSelected) + { + return RightFileViewModel; + } + else + { + Log.Error("No pane is selected"); + } + return LeftFileViewModel; + } + } + public void Execute() { diff --git a/src/SmartCommander/Views/FilesPane.axaml b/src/SmartCommander/Views/FilesPane.axaml index 0e949ab..d50cba1 100644 --- a/src/SmartCommander/Views/FilesPane.axaml +++ b/src/SmartCommander/Views/FilesPane.axaml @@ -42,8 +42,7 @@ </Grid> <DataGrid Name="PaneDataGrid" Loaded="OnLoaded" IsFocused="{Binding IsSelected, Mode=OneWayToSource}" - - Margin="5" Grid.Row="1" IsTabStop="True" + Margin="5" Grid.Row="1" IsTabStop="True" ItemsSource="{Binding FoldersFilesList}" AutoGenerateColumns="False" CanUserResizeColumns="True"