-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented AnimatedPopUp for dialog view. New option to ask for conf…
…irmation upon exit and confirmation dialog when permanently deleting file #171
- Loading branch information
Showing
38 changed files
with
610 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Metadata; | ||
using Avalonia.Controls.Primitives; | ||
using Avalonia.Input; | ||
using PicView.Avalonia.Animations; | ||
using PicView.Avalonia.UI; | ||
|
||
namespace PicView.Avalonia.CustomControls; | ||
|
||
[TemplatePart("PART_Overlay", typeof(Panel))] | ||
[TemplatePart("PART_Border", typeof(Border))] | ||
public class AnimatedPopUp : ContentControl | ||
{ | ||
private Panel? _partOverlay; | ||
private Border? _partBorder; | ||
|
||
public static readonly AvaloniaProperty<bool> ClickingOutSideClosesProperty = | ||
AvaloniaProperty.Register<CopyButton, bool>(nameof(ClickingOutSideCloses)); | ||
|
||
public bool ClickingOutSideCloses | ||
{ | ||
get => (bool)GetValue(ClickingOutSideClosesProperty)!; | ||
set => SetValue(ClickingOutSideClosesProperty, value); | ||
} | ||
|
||
protected override Type StyleKeyOverride => typeof(AnimatedPopUp); | ||
|
||
protected AnimatedPopUp() | ||
{ | ||
Loaded += async delegate | ||
{ | ||
await AnimatedOpening(); | ||
}; | ||
} | ||
|
||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e) | ||
{ | ||
base.OnApplyTemplate(e); | ||
_partOverlay = e.NameScope.Find<Panel>("PART_Overlay"); | ||
_partBorder = e.NameScope.Find<Border>("PART_Border"); | ||
|
||
_partOverlay.Opacity = 0; | ||
_partBorder.Opacity = 0; | ||
|
||
// Handle click outside to close | ||
_partOverlay.PointerPressed += async delegate | ||
{ | ||
if (!ClickingOutSideCloses) | ||
{ | ||
return; | ||
} | ||
if (!_partBorder.IsPointerOver) | ||
{ | ||
await AnimatedClosing(); | ||
} | ||
}; | ||
} | ||
|
||
public async Task AnimatedOpening() | ||
{ | ||
UIHelper.IsDialogOpen = true; | ||
var fadeIn = AnimationsHelper.OpacityAnimation(0, 1, 0.3); | ||
var centering = AnimationsHelper.CenteringAnimation(50, 100, 0, 0, 0.3); | ||
await Task.WhenAll(fadeIn.RunAsync(_partOverlay), fadeIn.RunAsync(_partBorder), centering.RunAsync(_partBorder)); | ||
} | ||
|
||
public async Task AnimatedClosing() | ||
{ | ||
UIHelper.IsDialogOpen = false; | ||
var fadeIn = AnimationsHelper.OpacityAnimation(1, 0, 0.3); | ||
var centering = AnimationsHelper.CenteringAnimation(0, 0, 50, 100, 0.3); | ||
await Task.WhenAll(fadeIn.RunAsync(_partOverlay), fadeIn.RunAsync(_partBorder), centering.RunAsync(_partBorder)); | ||
UIHelper.GetMainView.MainGrid.Children.Remove(this); | ||
} | ||
|
||
public void KeyDownHandler(object? sender, KeyEventArgs e) | ||
{ | ||
RaiseEvent(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using PicView.Avalonia.UI; | ||
using PicView.Avalonia.ViewModels; | ||
using PicView.Avalonia.Views.UC.PopUps; | ||
using PicView.Core.FileHandling; | ||
using PicView.Core.Localization; | ||
|
||
namespace PicView.Avalonia.FileSystem; | ||
|
||
public static class FileManager | ||
{ | ||
public static async Task DeleteFile(bool recycle, MainViewModel vm) | ||
{ | ||
if (vm.FileInfo is null) | ||
{ | ||
return; | ||
} | ||
|
||
var errorMsg = string.Empty; | ||
|
||
if(!recycle) | ||
{ | ||
var prompt = $"{TranslationHelper.GetTranslation("DeleteFilePermanently")}"; | ||
var deleteDialog = new DeleteDialog(prompt, vm.FileInfo.FullName); | ||
UIHelper.GetMainView.MainGrid.Children.Add(deleteDialog); | ||
} | ||
else | ||
{ | ||
errorMsg = await Task.FromResult(FileDeletionHelper.DeleteFileWithErrorMsg(vm.FileInfo.FullName, recycle)); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(errorMsg)) | ||
{ | ||
await TooltipHelper.ShowTooltipMessageAsync(errorMsg, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/PicView.Avalonia/PicViewTheme/Controls/AnimatedPopUp.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<ResourceDictionary | ||
x:ClassModifier="internal" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:customControls="clr-namespace:PicView.Avalonia.CustomControls" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
<ControlTheme TargetType="customControls:AnimatedPopUp" x:Key="{x:Type customControls:AnimatedPopUp}"> | ||
<Setter Property="Template"> | ||
<ControlTemplate> | ||
<Panel Background="#A8000000" x:Name="PART_Overlay"> | ||
<Border | ||
Background="{DynamicResource MainBackgroundColor}" | ||
BorderBrush="{DynamicResource MainBorderColor}" | ||
BorderThickness="1" | ||
CornerRadius="8" | ||
HorizontalAlignment="Center" | ||
Padding="{TemplateBinding Padding}" | ||
VerticalAlignment="Center" | ||
x:Name="PART_Border"> | ||
<ContentPresenter Content="{TemplateBinding Content}" /> | ||
</Border> | ||
</Panel> | ||
</ControlTemplate> | ||
</Setter> | ||
</ControlTheme> | ||
</ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.