Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed FocusChanged and get back to old logic for SelectedPane #105

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/SmartCommander/ViewModels/FilesPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -124,16 +117,15 @@ 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);
EditCommand = ReactiveCommand.Create(Edit);
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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 25 additions & 13 deletions src/SmartCommander/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia.Styling;
using MsBox.Avalonia.Enums;
using ReactiveUI;
using Serilog;
using SmartCommander.Assets;
using SmartCommander.Models;
using System;
Expand Down Expand Up @@ -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))
{
Expand All @@ -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; }

Expand Down Expand Up @@ -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()
{
Expand Down
3 changes: 1 addition & 2 deletions src/SmartCommander/Views/FilesPane.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading