double tap

main
Stepan Pilipenko 1 month ago
parent 55dd1d0034
commit b486f16f4a

@ -1,10 +1,33 @@
namespace CommanderApp using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace CommanderApp
{ {
public class FileSystemItem public class FileSystemItem : INotifyPropertyChanged
{ {
public string Name { get; set; } public string Name { get; set; }
public string FullName { get; set; } public string FullName { get; set; }
public bool IsDirectory { get; set; } public bool IsDirectory { get; set; }
public string Icon => IsDirectory ? "folder.png" : "file.png"; public string Icon => IsDirectory ? "folder.png" : "file.png";
private bool _isSelected;
public bool IsSelected
{
get => _isSelected;
set
{
_isSelected = value;
OnPropertyChanged();
}
}
// Событие из INotifyPropertyChanged
public event PropertyChangedEventHandler? PropertyChanged;
// Защищённый метод для вызова события
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
} }
} }

@ -4,43 +4,46 @@
x:Class="CommanderApp.MainPage" x:Class="CommanderApp.MainPage"
Title="MAUI Commander"> Title="MAUI Commander">
<Grid RowDefinitions="Auto, *, Auto" ColumnDefinitions="*, *"> <!-- Изменяем RowDefinitions: добавляем строку под заголовком -->
<!-- Заголовки панелей --> <Grid RowDefinitions="Auto, Auto, *, Auto" ColumnDefinitions="*, *">
<!-- Новая строка: пути над панелями (где были красные линии) -->
<Label Text="{Binding LeftPath}" <Label Text="{Binding LeftPath}"
Grid.Row="0" Grid.Column="0" Grid.Row="1" Grid.Column="0"
Padding="10" FontAttributes="Bold" BackgroundColor="#f0f0f0"/> Padding="12,6"
FontSize="14"
FontAttributes="Bold"
BackgroundColor="#f0f0f0"
TextColor="Black"
VerticalTextAlignment="Center"
LineBreakMode="MiddleTruncation" />
<Label Text="{Binding RightPath}" <Label Text="{Binding RightPath}"
Grid.Row="0" Grid.Column="1" Grid.Row="1" Grid.Column="1"
Padding="10" FontAttributes="Bold" BackgroundColor="#f0f0f0"/> Padding="12,6"
FontSize="14"
FontAttributes="Bold"
BackgroundColor="#f0f0f0"
TextColor="Black"
VerticalTextAlignment="Center"
LineBreakMode="MiddleTruncation" />
<!-- Левая панель --> <!-- Левая панель -->
<CollectionView x:Name="LeftPanel" <CollectionView x:Name="LeftPanel"
Grid.Row="1" Grid.Column="0" Grid.Row="2" Grid.Column="0"
ItemsSource="{Binding LeftItems}" ItemsSource="{Binding LeftItems}"
SelectionMode="Single" SelectionMode="None">
SelectionChanged="OnLeftSelectionChanged">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid Padding="10" Background="Transparent"> <Grid Padding="10" BackgroundColor="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="#d0e0ff" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<HorizontalStackLayout Spacing="10"> <HorizontalStackLayout Spacing="10">
<Image Source="{Binding Icon}" WidthRequest="20" HeightRequest="20" /> <Image Source="{Binding Icon}" WidthRequest="20" HeightRequest="20" />
<Label Text="{Binding Name}" VerticalOptions="Center" /> <Label Text="{Binding Name}" VerticalOptions="Center" />
</HorizontalStackLayout> </HorizontalStackLayout>
<Grid.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="OnLeftItemTapped" />
<TapGestureRecognizer NumberOfTapsRequired="2" Tapped="OnLeftItemDoubleTapped" />
</Grid.GestureRecognizers>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
@ -48,39 +51,28 @@
<!-- Правая панель --> <!-- Правая панель -->
<CollectionView x:Name="RightPanel" <CollectionView x:Name="RightPanel"
Grid.Row="1" Grid.Column="1" Grid.Row="2" Grid.Column="1"
ItemsSource="{Binding RightItems}" ItemsSource="{Binding RightItems}"
SelectionMode="Single" SelectionMode="None">
SelectionChanged="OnRightSelectionChanged">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid Padding="10" Background="Transparent"> <Grid Padding="10" BackgroundColor="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="#d0e0ff" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<HorizontalStackLayout Spacing="10"> <HorizontalStackLayout Spacing="10">
<Image Source="{Binding Icon}" WidthRequest="20" HeightRequest="20" /> <Image Source="{Binding Icon}" WidthRequest="20" HeightRequest="20" />
<Label Text="{Binding Name}" VerticalOptions="Center" /> <Label Text="{Binding Name}" VerticalOptions="Center" />
</HorizontalStackLayout> </HorizontalStackLayout>
<Grid.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="OnRightItemTapped" />
<TapGestureRecognizer NumberOfTapsRequired="2" Tapped="OnRightItemDoubleTapped" />
</Grid.GestureRecognizers>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<!-- Адаптивный Toolbar (Footer) --> <!-- Адаптивный Toolbar (Footer) -->
<FlexLayout Grid.Row="2" <FlexLayout Grid.Row="3"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Padding="10" Padding="10"
BackgroundColor="#e0e0e0" BackgroundColor="#e0e0e0"
@ -89,8 +81,7 @@
JustifyContent="Center" JustifyContent="Center"
AlignItems="Center"> AlignItems="Center">
<Button Text="F5 Copy" Clicked="OnCopyClicked" Padding="12,6" MinimumWidthRequest="80" Margin="0,0,8 <Button Text="F5 Copy" Clicked="OnCopyClicked" Padding="12,6" MinimumWidthRequest="80" Margin="0,0,8,8" />
,8" />
<Button Text="F6 Move" Clicked="OnMoveClicked" Padding="12,6" MinimumWidthRequest="80" Margin="0,0,8,8" /> <Button Text="F6 Move" Clicked="OnMoveClicked" Padding="12,6" MinimumWidthRequest="80" Margin="0,0,8,8" />
<Button Text="F7 Mkdir" Clicked="OnMkdirClicked" Padding="12,6" MinimumWidthRequest="80" Margin="0,0,8,8" /> <Button Text="F7 Mkdir" Clicked="OnMkdirClicked" Padding="12,6" MinimumWidthRequest="80" Margin="0,0,8,8" />
<Button Text="F8 Delete" Clicked="OnDeleteClicked" Padding="12,6" MinimumWidthRequest="80" Margin="0,0,8,8" /> <Button Text="F8 Delete" Clicked="OnDeleteClicked" Padding="12,6" MinimumWidthRequest="80" Margin="0,0,8,8" />

@ -1,19 +1,52 @@
// MainPage.xaml.cs // MainPage.xaml.cs
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
namespace CommanderApp; namespace CommanderApp;
public partial class MainPage : ContentPage public partial class MainPage : ContentPage, INotifyPropertyChanged
{ {
private readonly IFileSystemService _fileService; private readonly IFileSystemService _fileService;
public ObservableCollection<FileSystemItem> LeftItems { get; set; } = new(); public ObservableCollection<FileSystemItem> LeftItems { get; set; } = new();
public ObservableCollection<FileSystemItem> RightItems { get; set; } = new(); public ObservableCollection<FileSystemItem> RightItems { get; set; } = new();
public string LeftPath { get; set; } = string.Empty;
public string RightPath { get; set; } = string.Empty;
private string _currentLeftPath; // --- Изменено: приватные поля + INotifyPropertyChanged ---
private string _currentRightPath; private string _leftPath = string.Empty;
private string _rightPath = string.Empty;
private Grid? _currentSelectedGrid; // только один выделенный элемент в интерфейсе
public string LeftPath
{
get => _leftPath;
set
{
if (_leftPath != value)
{
_leftPath = value;
NotifyPropertyChanged();
}
}
}
public string RightPath
{
get => _rightPath;
set
{
if (_rightPath != value)
{
_rightPath = value;
NotifyPropertyChanged();
}
}
}
private string _currentLeftPath = string.Empty;
private string _currentRightPath = string.Empty;
private FileSystemItem? _selectedLeftItem; private FileSystemItem? _selectedLeftItem;
private FileSystemItem? _selectedRightItem; private FileSystemItem? _selectedRightItem;
@ -38,14 +71,14 @@ public partial class MainPage : ContentPage
LeftItems.Clear(); LeftItems.Clear();
foreach (var item in items) LeftItems.Add(item); foreach (var item in items) LeftItems.Add(item);
_currentLeftPath = path; _currentLeftPath = path;
LeftPath = path; LeftPath = path; // Теперь это вызовет обновление UI
} }
else else
{ {
RightItems.Clear(); RightItems.Clear();
foreach (var item in items) RightItems.Add(item); foreach (var item in items) RightItems.Add(item);
_currentRightPath = path; _currentRightPath = path;
RightPath = path; RightPath = path; // И это тоже
} }
} }
@ -191,4 +224,86 @@ public partial class MainPage : ContentPage
await DisplayAlert("Error", $"{actionName} failed: {ex.Message}", "OK"); await DisplayAlert("Error", $"{actionName} failed: {ex.Message}", "OK");
} }
} }
private void OnLeftItemTapped(object sender, TappedEventArgs e)
{
var grid = (Grid)sender;
var item = (FileSystemItem)grid.BindingContext;
// Сбрасываем выделение у предыдущего элемента (где бы он ни был)
if (_currentSelectedGrid != null)
{
_currentSelectedGrid.BackgroundColor = Colors.Transparent;
}
// Выделяем новый элемент
grid.BackgroundColor = Color.FromArgb("#d0e0ff");
_currentSelectedGrid = grid;
// Обновляем активный выбор
_selectedLeftItem = item;
_selectedRightItem = null; // сбрасываем выбор в правой панели
}
private void OnLeftItemDoubleTapped(object sender, TappedEventArgs e)
{
var grid = (Grid)sender;
var item = (FileSystemItem)grid.BindingContext;
if (item.IsDirectory)
{
LoadDirectory(item.FullName, isLeft: true);
// Сбрасываем выделение, так как панель обновляется
if (_currentSelectedGrid != null)
{
_currentSelectedGrid.BackgroundColor = Colors.Transparent;
_currentSelectedGrid = null;
}
_selectedLeftItem = null;
_selectedRightItem = null;
}
}
private void OnRightItemTapped(object sender, TappedEventArgs e)
{
var grid = (Grid)sender;
var item = (FileSystemItem)grid.BindingContext;
if (_currentSelectedGrid != null)
{
_currentSelectedGrid.BackgroundColor = Colors.Transparent;
}
grid.BackgroundColor = Color.FromArgb("#d0e0ff");
_currentSelectedGrid = grid;
_selectedRightItem = item;
_selectedLeftItem = null; // сбрасываем выбор в левой панели
}
private void OnRightItemDoubleTapped(object sender, TappedEventArgs e)
{
var grid = (Grid)sender;
var item = (FileSystemItem)grid.BindingContext;
if (item.IsDirectory)
{
LoadDirectory(item.FullName, isLeft: false);
if (_currentSelectedGrid != null)
{
_currentSelectedGrid.BackgroundColor = Colors.Transparent;
_currentSelectedGrid = null;
}
_selectedLeftItem = null;
_selectedRightItem = null;
}
}
// --- Реализация INotifyPropertyChanged ---
public new event PropertyChangedEventHandler? PropertyChanged;
protected virtual void NotifyPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
} }
Loading…
Cancel
Save