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

@ -1,19 +1,52 @@
// MainPage.xaml.cs
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls;
namespace CommanderApp;
public partial class MainPage : ContentPage
public partial class MainPage : ContentPage, INotifyPropertyChanged
{
private readonly IFileSystemService _fileService;
public ObservableCollection<FileSystemItem> LeftItems { 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;
private string _currentRightPath;
// --- Изменено: приватные поля + INotifyPropertyChanged ---
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? _selectedRightItem;
@ -38,14 +71,14 @@ public partial class MainPage : ContentPage
LeftItems.Clear();
foreach (var item in items) LeftItems.Add(item);
_currentLeftPath = path;
LeftPath = path;
LeftPath = path; // Теперь это вызовет обновление UI
}
else
{
RightItems.Clear();
foreach (var item in items) RightItems.Add(item);
_currentRightPath = path;
RightPath = path;
RightPath = path; // И это тоже
}
}
@ -191,4 +224,86 @@ public partial class MainPage : ContentPage
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