Implemented Delete menu item in file item's context menu.
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
<MenuItem Header="_Move to" Name="MoveToMenuItem"/>
|
<MenuItem Header="_Move to" Name="MoveToMenuItem"/>
|
||||||
<!--<MenuItem Header="_Paste"/>-->
|
<!--<MenuItem Header="_Paste"/>-->
|
||||||
<Separator/>
|
<Separator/>
|
||||||
<MenuItem Header="_Delete"/>
|
<MenuItem Header="_Delete" Name="DeleteMenuItem" Click="DeleteMenuItem_Click"/>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</Button.ContextMenu>
|
</Button.ContextMenu>
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|||||||
@@ -282,4 +282,20 @@ public partial class FileItem : UserControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void DeleteMenuItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var content = new ConfirmationDialog("Are you sure?", "This operation cannot be undone.");
|
||||||
|
content.onOK = async () =>
|
||||||
|
{
|
||||||
|
if (currentItem is not null)
|
||||||
|
await currentItem.DeleteAsync();
|
||||||
|
if (this.Parent is StackPanel panel)
|
||||||
|
{
|
||||||
|
panel.Children.Remove(this);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
await DialogHost.Show(content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
<TextBlock FontSize="18" Name="TitleBlock" TextWrapping="Wrap">
|
<TextBlock FontSize="18" Name="TitleBlock" TextWrapping="Wrap">
|
||||||
Unsaved Changes
|
Unsaved Changes
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
<TextBlock Name="MssageBlock" TextWrapping="Wrap">
|
<TextBlock Name="MessageBlock" TextWrapping="Wrap">
|
||||||
Save all files or discard changes?
|
Save all files or discard changes?
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|||||||
23
Progrart/Dialogs/ConfirmationDialog.axaml
Normal file
23
Progrart/Dialogs/ConfirmationDialog.axaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="Progrart.Dialogs.ConfirmationDialog">
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock FontSize="18" Name="TitleBlock" TextWrapping="Wrap">
|
||||||
|
Title
|
||||||
|
</TextBlock>
|
||||||
|
<TextBlock Name="MessageBlock" TextWrapping="Wrap">
|
||||||
|
Content
|
||||||
|
</TextBlock>
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Classes="accent" Name="OKBtn" Content="OK"/>
|
||||||
|
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Name="CancelBtn" Grid.Column="2" Content="Cancel"/>
|
||||||
|
</Grid>
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
||||||
60
Progrart/Dialogs/ConfirmationDialog.axaml.cs
Normal file
60
Progrart/Dialogs/ConfirmationDialog.axaml.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using DialogHostAvalonia;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Progrart.Dialogs;
|
||||||
|
|
||||||
|
public partial class ConfirmationDialog : UserControl
|
||||||
|
{
|
||||||
|
public Func<Task<bool>>? onOK = null;
|
||||||
|
public Func<bool>? onCancel = null;
|
||||||
|
public ConfirmationDialog()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
SetupEvents();
|
||||||
|
}
|
||||||
|
public ConfirmationDialog(string title,string message)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
SetupEvents();
|
||||||
|
this.TitleBlock.Text = title;
|
||||||
|
this.MessageBlock.Text = message;
|
||||||
|
}
|
||||||
|
void SetupEvents()
|
||||||
|
{
|
||||||
|
OKBtn.Click += OKBtn_Click;
|
||||||
|
CancelBtn.Click += CancelBtn_Click;
|
||||||
|
}
|
||||||
|
private void CancelBtn_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cancel()
|
||||||
|
{
|
||||||
|
if (!(onCancel?.Invoke()) ?? true)
|
||||||
|
{
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private async Task Confirmed()
|
||||||
|
{
|
||||||
|
if (onOK is not null)
|
||||||
|
{
|
||||||
|
if (!await onOK())
|
||||||
|
{
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OKBtn_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
await Confirmed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -88,7 +88,7 @@ public partial class MainView : UserControl
|
|||||||
};
|
};
|
||||||
NewFileButton.Click += (_, _) =>
|
NewFileButton.Click += (_, _) =>
|
||||||
{
|
{
|
||||||
MainTabHost.AddPage(new EditorPage());
|
MainTabHost.AddPage(new ProgrartEditorPage());
|
||||||
};
|
};
|
||||||
AboutItem.Click += (_, _) =>
|
AboutItem.Click += (_, _) =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user