mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add legacy message with button
This commit is contained in:
parent
ad14684a98
commit
d313812580
2 changed files with 179 additions and 0 deletions
84
Flow.Launcher/MsgWithButton.xaml
Normal file
84
Flow.Launcher/MsgWithButton.xaml
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<Window
|
||||
x:Class="Flow.Launcher.MsgWithButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Msg"
|
||||
Width="420"
|
||||
Height="60"
|
||||
Background="#ebebeb"
|
||||
ResizeMode="NoResize"
|
||||
ShowInTaskbar="False"
|
||||
SizeToContent="Height"
|
||||
Topmost="True"
|
||||
WindowStyle="None">
|
||||
<Window.Triggers>
|
||||
<EventTrigger RoutedEvent="Window.Loaded">
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation
|
||||
x:Name="showAnimation"
|
||||
AccelerationRatio="0.2"
|
||||
Storyboard.TargetProperty="Top"
|
||||
Duration="0:0:0.3" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</Window.Triggers>
|
||||
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Grid
|
||||
Margin="5"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="32" />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="2.852" />
|
||||
<ColumnDefinition Width="13.148" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image
|
||||
x:Name="imgIco"
|
||||
Width="32"
|
||||
Height="32"
|
||||
Margin="0 9"
|
||||
HorizontalAlignment="Left" />
|
||||
<Grid
|
||||
Grid.Column="1"
|
||||
Margin="5 0 0 0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock
|
||||
x:Name="tbTitle"
|
||||
FontSize="16"
|
||||
FontWeight="Medium"
|
||||
Foreground="#37392c">
|
||||
Title
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
x:Name="tbSubTitle"
|
||||
Grid.Row="1"
|
||||
Foreground="#8e94a4">
|
||||
sdfdsf
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
<Image
|
||||
x:Name="imgClose"
|
||||
Grid.Column="2"
|
||||
Grid.ColumnSpan="2"
|
||||
Width="16"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Cursor="Hand" />
|
||||
</Grid>
|
||||
<Button
|
||||
x:Name="btn"
|
||||
Margin="5 0 5 5"
|
||||
HorizontalAlignment="Stretch"
|
||||
Content="fwafaw"
|
||||
Foreground="#dcdcdc" />
|
||||
</StackPanel>
|
||||
</Window>
|
||||
95
Flow.Launcher/MsgWithButton.xaml.cs
Normal file
95
Flow.Launcher/MsgWithButton.xaml.cs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Animation;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
public partial class MsgWithButton : Window
|
||||
{
|
||||
private readonly Storyboard fadeOutStoryboard = new();
|
||||
private bool closing;
|
||||
|
||||
public MsgWithButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||
var dipWorkingArea = Win32Helper.TransformPixelsToDIP(this,
|
||||
screen.WorkingArea.Width,
|
||||
screen.WorkingArea.Height);
|
||||
Left = dipWorkingArea.X - Width;
|
||||
Top = dipWorkingArea.Y;
|
||||
showAnimation.From = dipWorkingArea.Y;
|
||||
showAnimation.To = dipWorkingArea.Y - Height;
|
||||
|
||||
// Create the fade out storyboard
|
||||
fadeOutStoryboard.Completed += fadeOutStoryboard_Completed;
|
||||
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(5)))
|
||||
{
|
||||
AccelerationRatio = 0.2
|
||||
};
|
||||
Storyboard.SetTarget(fadeOutAnimation, this);
|
||||
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
|
||||
fadeOutStoryboard.Children.Add(fadeOutAnimation);
|
||||
|
||||
_ = LoadImageAsync();
|
||||
|
||||
imgClose.MouseUp += imgClose_MouseUp;
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task LoadImageAsync()
|
||||
{
|
||||
imgClose.Source = await App.API.LoadImageAsync(Path.Combine(Constant.ProgramDirectory, "Images\\close.png"));
|
||||
}
|
||||
|
||||
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (!closing)
|
||||
{
|
||||
closing = true;
|
||||
fadeOutStoryboard.Begin();
|
||||
}
|
||||
}
|
||||
|
||||
private void fadeOutStoryboard_Completed(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]
|
||||
public async void Show(string title, string buttonText, Action buttonAction, string subTitle, string iconPath)
|
||||
{
|
||||
tbTitle.Text = title;
|
||||
tbSubTitle.Text = subTitle;
|
||||
btn.Content = buttonText;
|
||||
btn.Click += (s, e) => buttonAction();
|
||||
if (string.IsNullOrEmpty(subTitle))
|
||||
{
|
||||
tbSubTitle.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
if (!File.Exists(iconPath))
|
||||
{
|
||||
imgIco.Source = await App.API.LoadImageAsync(Path.Combine(Constant.ProgramDirectory, "Images\\app.png"));
|
||||
}
|
||||
else
|
||||
{
|
||||
imgIco.Source = await App.API.LoadImageAsync(iconPath);
|
||||
}
|
||||
|
||||
Show();
|
||||
|
||||
await Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
if (!closing)
|
||||
{
|
||||
closing = true;
|
||||
await Dispatcher.InvokeAsync(fadeOutStoryboard.Begin);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue