Skip to content

Commit

Permalink
Merge branch 'main' into dev/Enter_and_BackSpace_in_Filepanel
Browse files Browse the repository at this point in the history
  • Loading branch information
Diaskhan authored Sep 13, 2024
2 parents 58e2394 + f4ad480 commit e01ad10
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 52 deletions.
14 changes: 11 additions & 3 deletions src/SmartCommander/ViewModels/FilesPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class FilesPaneViewModel : ViewModelBase

private bool _isSelected;
private SortingBy _sorting = SortingBy.SortingByName;
private bool _ascending = true;
private bool _ascending = true;
public event EventHandler FocusChanged;

public string CurrentDirectory
{
get => _currentDirectory;
Expand Down Expand Up @@ -88,8 +90,12 @@ public bool IsSelected
set
{
_isSelected = value;
this.RaisePropertyChanged("IsSelected");
this.RaisePropertyChanged("GridBorderBrush");

if (value)
{
FocusChanged?.Invoke(this, EventArgs.Empty);
}
}
}

Expand All @@ -100,7 +106,9 @@ public bool IsCurrentDirectoryDisplayed
}


public Brush GridBorderBrush => IsSelected ? new SolidColorBrush(Colors.LightSkyBlue) : new SolidColorBrush(Colors.Transparent);
public static Brush SelectedBrush = new SolidColorBrush(Colors.LightSkyBlue);
public static Brush NotSelectedBrush = new SolidColorBrush(Colors.Transparent);
public Brush GridBorderBrush => IsSelected ? SelectedBrush : NotSelectedBrush;

public ObservableCollection<FileViewModel> FoldersFilesList { get; set; } = new ObservableCollection<FileViewModel>();

Expand Down
61 changes: 15 additions & 46 deletions src/SmartCommander/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public MainWindowViewModel()
F6Command = ReactiveCommand.CreateFromTask(Move);
F7Command = ReactiveCommand.Create(CreateNewFolder);
F8Command = ReactiveCommand.Create(Delete);
TabCommand = ReactiveCommand.Create(ChangeSelectedPane);
OptionsCommand = ReactiveCommand.CreateFromTask(ShowOptions);

LeftFileViewModel = new FilesPaneViewModel(this) { IsSelected = true };
LeftFileViewModel = new FilesPaneViewModel(this);
LeftFileViewModel.FocusChanged += OnFocusChanged;

RightFileViewModel = new FilesPaneViewModel(this);
RightFileViewModel.FocusChanged += OnFocusChanged;

if (!string.IsNullOrEmpty(OptionsModel.Instance.LeftPanePath))
{
Expand All @@ -53,6 +55,13 @@ public MainWindowViewModel()
SetTheme();
_progress = new Progress<int>(v => Progress_Show(v));
}
private void OnFocusChanged(object? sender, EventArgs e)
{
if (sender is FilesPaneViewModel)
{
SelectedPane = (FilesPaneViewModel)sender;
}
}

public ReactiveCommand<Unit, Unit> ExitCommand { get; }

Expand Down Expand Up @@ -136,63 +145,23 @@ public void SortDate()
SelectedPane.Ascending = true;
}

public void ChangeSelectedPane()
{
if (LeftFileViewModel.IsSelected)
{
SelectedPane = RightFileViewModel;
}
else if (RightFileViewModel.IsSelected)
{
SelectedPane = LeftFileViewModel;
}
}

public FilesPaneViewModel SecondPane
{
get
{
if (LeftFileViewModel.IsSelected)
{
return RightFileViewModel;
}
else if (RightFileViewModel.IsSelected)
if (SelectedPane == RightFileViewModel)
{
return LeftFileViewModel;
}
throw new Exception(Resources.ErrorNoPane);
}
}

public FilesPaneViewModel SelectedPane
{
get
{
if (LeftFileViewModel.IsSelected)
{
return LeftFileViewModel;
}
else if (RightFileViewModel.IsSelected)
else
{
return RightFileViewModel;
}
throw new Exception(Resources.ErrorNoPane);
}
set
{
if (RightFileViewModel == value && !RightFileViewModel.IsSelected)
{
LeftFileViewModel.IsSelected = false;
RightFileViewModel.IsSelected = true;
}
else if (LeftFileViewModel == value && !LeftFileViewModel.IsSelected)
{
RightFileViewModel.IsSelected = false;
LeftFileViewModel.IsSelected = true;
}
}
}

public FilesPaneViewModel SelectedPane { get; set; }

public void Execute()
{
SelectedPane.Execute(CommandText);
Expand Down
7 changes: 5 additions & 2 deletions src/SmartCommander/Views/FilesPane.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@
</Grid.ColumnDefinitions>
<TextBox IsTabStop="False" Text="{Binding CurrentDirectory}" >
</TextBox>
<ComboBox Grid.Column="1" IsVisible="{Binding IsWindows}" Name="driveCombo" SelectedItem="{Binding SelectedDrive, Mode=TwoWay}">
<ComboBox Grid.Column="1" IsVisible="{Binding IsWindows}" Name="driveCombo" SelectedItem="{Binding SelectedDrive, Mode=TwoWay}" IsTabStop="False">
</ComboBox>
</Grid>
<DataGrid Margin="5" Grid.Row="1" IsTabStop="True"
<DataGrid Name="PaneDataGrid" Loaded="OnLoaded"
IsFocused="{Binding IsSelected, Mode=OneWayToSource}"

Margin="5" Grid.Row="1" IsTabStop="True"
ItemsSource="{Binding FoldersFilesList}"
AutoGenerateColumns="False"
CanUserResizeColumns="True"
Expand Down
8 changes: 8 additions & 0 deletions src/SmartCommander/Views/FilesPane.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using System;
using System.IO;
Expand All @@ -22,6 +23,13 @@ public FilesPane()
comboBox.SelectedIndex = 0;
}
}

}

private void OnLoaded(object sender, RoutedEventArgs e)
{
var PaneDataGrid = this.Get<DataGrid>("PaneDataGrid");
PaneDataGrid.Focus();
}

private void InitializeComponent()
Expand Down
1 change: 0 additions & 1 deletion src/SmartCommander/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
</Design.DataContext>

<Window.KeyBindings>
<KeyBinding Gesture="Tab" Command="{Binding TabCommand}" />
<KeyBinding Gesture="F3" Command="{Binding F3Command}" />
<KeyBinding Gesture="F4" Command="{Binding F4Command}" />
<KeyBinding Gesture="F5" Command="{Binding F5Command}" />
Expand Down

0 comments on commit e01ad10

Please sign in to comment.