Skip to content

Commit

Permalink
Give feedback to the user when they clear engines/clear server content
Browse files Browse the repository at this point in the history
  • Loading branch information
Visne committed Aug 19, 2023
1 parent df3138a commit 22ce7d5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
21 changes: 21 additions & 0 deletions SS14.Launcher/Utility/ButtonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Threading.Tasks;
using Avalonia.Controls;

namespace SS14.Launcher.Utility;

public static class ButtonExtensions
{
/// <summary>
/// Sets the content of a button to a specified message ("Done!" by default) for a specified duration (2s by
/// default), and disabled the button for this duration.
/// </summary>
public static async Task DisplayDoneMessage(this Button button, string message = "Done!", int duration = 2000)
{
var previousContent = button.Content;
button.Content = message;
button.IsEnabled = false;
await Task.Delay(duration);
button.Content = previousContent;
button.IsEnabled = true;
}
}
8 changes: 4 additions & 4 deletions SS14.Launcher/Views/MainWindowTabs/OptionsTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
<DockPanel>
<Button Content="*flip" DockPanel.Dock="Bottom" HorizontalAlignment="Right" Name="Flip" />
<Button Content="Clear installed engines" DockPanel.Dock="Bottom" HorizontalAlignment="Left"
Command="{Binding ClearEngines}"/>
<Button Content="Clear installed server content" DockPanel.Dock="Bottom" HorizontalAlignment="Left"
Command="{Binding ClearServerContent}"/>
<Button Name="ClearEnginesButton" Content="Clear installed engines" DockPanel.Dock="Bottom"
HorizontalAlignment="Left" Click="ClearEnginesPressed" />
<Button Name="ClearServerContentButton" Content="Clear installed server content" DockPanel.Dock="Bottom"
HorizontalAlignment="Left" Click="ClearServerContentPressed" />
<Button Content="Open log directory" DockPanel.Dock="Bottom" HorizontalAlignment="Left"
Command="{Binding OpenLogDirectory}"/>

Expand Down
16 changes: 15 additions & 1 deletion SS14.Launcher/Views/MainWindowTabs/OptionsTabView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Interactivity;
using Avalonia.Threading;
using ReactiveUI;
using SS14.Launcher.Utility;
using SS14.Launcher.ViewModels.MainWindowTabs;

namespace SS14.Launcher.Views.MainWindowTabs;

Expand All @@ -24,4 +26,16 @@ public OptionsTabView()
DispatcherTimer.RunOnce(() => { window.Classes.Remove("DoAFlip"); }, TimeSpan.FromSeconds(1));
});
}

public async void ClearEnginesPressed(object? _1, RoutedEventArgs _2)
{
(DataContext as OptionsTabViewModel)!.ClearEngines();
await ClearEnginesButton.DisplayDoneMessage();
}

public async void ClearServerContentPressed(object? _1, RoutedEventArgs _2)
{
(DataContext as OptionsTabViewModel)!.ClearServerContent();
await ClearServerContentButton.DisplayDoneMessage();
}
}

0 comments on commit 22ce7d5

Please sign in to comment.