Skip to content

Commit 5d53a63

Browse files
committed
Add simple feedback on save/revert
This action is very quick and without feedback the user might not realise it finished. This simple feedback should prevent the user clicking many times not realising something has happened.
1 parent 22c2737 commit 5d53a63

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

Loki/MainWindow.xaml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,38 @@
3131

3232
<!-- Revert / Save area -->
3333
<Border Margin="4" DockPanel.Dock="Bottom">
34-
<DockPanel HorizontalAlignment="Stretch">
34+
<Grid>
35+
<DockPanel HorizontalAlignment="Stretch">
3536

36-
<Button DockPanel.Dock="Right" Width="96" Height="26" Margin="2,0,0,0"
37+
<Button DockPanel.Dock="Right" Width="96" Height="26" Margin="2,0,0,0"
3738
Command="{x:Static loki:Commands.RevertCharacter}"
3839
ToolTip="Re-loads the file, reverting any unsaved changes">Revert</Button>
3940

40-
<Button DockPanel.Dock="Right" Width="96" Height="26" Margin="2,0"
41+
<Button DockPanel.Dock="Right" Width="96" Height="26" Margin="2,0"
4142
Command="{x:Static loki:Commands.SaveCharacter}"
4243
ToolTip="Saves all changes to the character file">Save</Button>
43-
44-
<CheckBox DockPanel.Dock="Right" VerticalAlignment="Center" Margin="4,0"
44+
45+
<CheckBox DockPanel.Dock="Right" VerticalAlignment="Center" Margin="4,0"
4546
ToolTip="If checked, will cause a backup to be automatically created upon saving"
4647
IsChecked="{Binding CreateBackup}">
47-
Backup Character
48-
</CheckBox>
48+
Backup Character
49+
</CheckBox>
4950

50-
<Button DockPanel.Dock="Right" Height="26" Margin="2,0" Padding="32,0"
51+
<Button DockPanel.Dock="Right" Height="26" Margin="2,0" Padding="32,0"
5152
ToolTip="Select a backup to restore the character from"
5253
Command="{x:Static loki:Commands.RestoreCharacter}">Backup Restore</Button>
5354

54-
<Label DockPanel.Dock="Left">Created by Wuffles</Label>
55-
</DockPanel>
55+
<Label DockPanel.Dock="Left">Created by Wuffles</Label>
56+
</DockPanel>
57+
58+
<!-- Save/Revert notification -->
59+
<Border Background="#000" HorizontalAlignment="Right" Padding="64,4" CornerRadius="2"
60+
Name="NotificationBorder" Visibility="Hidden">
61+
<TextBlock Name="NotifyText"
62+
FontSize="16" FontWeight="DemiBold"
63+
Foreground="White" VerticalAlignment="Center" Text="Notification" />
64+
</Border>
65+
</Grid>
5666
</Border>
5767

5868
<!-- Main Tab area -->

Loki/MainWindow.xaml.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Windows;
88
using System.Windows.Controls;
99
using System.Windows.Input;
10+
using System.Windows.Media.Animation;
1011
using System.Windows.Media.Media3D;
1112

1213
namespace Loki
@@ -131,6 +132,8 @@ await Task.Run(() =>
131132
using var fileStream = File.Create(character.FilePath);
132133
profile.Write(fileStream);
133134
});
135+
136+
ShowNotification("Character Saved");
134137
}
135138
catch (Exception ex)
136139
{
@@ -142,6 +145,7 @@ await Task.Run(() =>
142145
{
143146
SaveInProgress = false;
144147
Cursor = null;
148+
CommandManager.InvalidateRequerySuggested();
145149
}
146150
}
147151

@@ -153,12 +157,13 @@ public CharacterFile SelectedCharacterFile
153157

154158
private void CanSaveOrRevertExecute(object sender, CanExecuteRoutedEventArgs e)
155159
{
156-
e.CanExecute = SelectedCharacterFile != null;
160+
e.CanExecute = SelectedCharacterFile != null && !SaveInProgress;
157161
}
158162

159163
private void RevertExecuted(object sender, ExecutedRoutedEventArgs e)
160164
{
161165
LoadProfile(SelectedCharacterFile);
166+
ShowNotification("Character Reverted");
162167
}
163168

164169
private void SaveExecuted(object sender, ExecutedRoutedEventArgs e)
@@ -195,5 +200,19 @@ private void RestoreExecuted(object sender, ExecutedRoutedEventArgs e)
195200
LoadProfile(SelectedCharacterFile);
196201
}
197202
}
203+
204+
private async Task ShowNotification(string notifyText)
205+
{
206+
NotifyText.Text = notifyText;
207+
NotificationBorder.Opacity = 1;
208+
NotificationBorder.Visibility = Visibility.Visible;
209+
210+
await Task.Delay(2000);
211+
var opacityAnim = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(0.3)));
212+
opacityAnim.FillBehavior = FillBehavior.Stop;
213+
opacityAnim.Completed += (sender, args) => NotificationBorder.Visibility = Visibility.Hidden;
214+
NotificationBorder.BeginAnimation(OpacityProperty, opacityAnim);
215+
216+
}
198217
}
199218
}

0 commit comments

Comments
 (0)