Scripting - Add confirm dialog when discarding changes

Editor - Fix missing repeat mode button
Editor - Auto-save 1 sec after last change
General UI - Fix main window drag handle
This commit is contained in:
Robert committed 2022-07-16 10:42:20 +02:00
1 parent e3907e6a76
commit 311bdee8da
13 files changed
+103 -25

No files matched your search

@@ -132,6 +132,7 @@ public class MenuBarViewModel : ActivatableViewModelBase
return;
await _windowService.ShowDialogAsync<ScriptsDialogViewModel, object?>(("profile", ProfileConfiguration.Profile));
await _profileEditorService.SaveProfileAsync();
}
private async Task ExecuteAdaptProfile()
@@ -34,7 +34,7 @@
<avalonia:MaterialIcon Kind="SkipNext" />
</Button>
<ToggleButton Classes="icon-button icon-button-large"
IsChecked="{CompiledBinding Repeating}"
IsChecked="{CompiledBinding Repeating, Mode=OneWay}"
Focusable="False"
Command="{CompiledBinding CycleRepeating}">
<ToolTip.Tip>
@@ -28,7 +28,8 @@ public class PlaybackViewModel : ActivatableViewModelBase
{
_profileEditorService = profileEditorService;
_settingsService = settingsService;
_repeatTimeline = true;
this.WhenActivated(d =>
{
_profileEditorService.ProfileElement.Subscribe(e => _profileElement = e).DisposeWith(d);
@@ -142,6 +143,7 @@ public class PlaybackViewModel : ActivatableViewModelBase
{
RepeatTimeline = false;
RepeatSegment = true;
this.RaisePropertyChanged(nameof(Repeating));
}
else if (RepeatSegment)
{
@@ -149,6 +151,7 @@ public class PlaybackViewModel : ActivatableViewModelBase
RepeatSegment = false;
Repeating = false;
}
}
private TimeSpan GetCurrentSegmentStart()
@@ -6,6 +6,8 @@ namespace Artemis.UI.Screens.ProfileEditor.Properties.Windows;
public class BrushConfigurationWindowView : ReactiveCoreWindow<BrushConfigurationWindowViewModel>
{
private bool _canClose;
public BrushConfigurationWindowView()
{
InitializeComponent();
@@ -22,9 +24,14 @@ public class BrushConfigurationWindowView : ReactiveCoreWindow<BrushConfiguratio
private async void OnClosing(object? sender, CancelEventArgs e)
{
if (ViewModel == null)
if (_canClose)
return;
e.Cancel = !await ViewModel.CanClose();
e.Cancel = true;
if (ViewModel == null || await ViewModel.CanClose())
{
_canClose = true;
Close();
}
}
}
@@ -6,6 +6,8 @@ namespace Artemis.UI.Screens.ProfileEditor.Properties.Windows;
public class EffectConfigurationWindowView : ReactiveCoreWindow<EffectConfigurationWindowViewModel>
{
private bool _canClose;
public EffectConfigurationWindowView()
{
InitializeComponent();
@@ -22,9 +24,14 @@ public class EffectConfigurationWindowView : ReactiveCoreWindow<EffectConfigurat
private async void OnClosing(object? sender, CancelEventArgs e)
{
if (ViewModel == null)
if (_canClose)
return;
e.Cancel = !await ViewModel.CanClose();
e.Cancel = true;
if (ViewModel == null || await ViewModel.CanClose())
{
_canClose = true;
Close();
}
}
}
@@ -9,9 +9,11 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Scripting.ScriptsDialogView"
x:DataType="scripting:ScriptsDialogViewModel"
Title="ScriptsDialogView">
Title="Artemis | Scripts"
Width="1200"
Height="750">
<DockPanel>
<ScrollViewer DockPanel.Dock="Left" VerticalScrollBarVisibility="Auto" Width="240">
<ScrollViewer DockPanel.Dock="Left" VerticalScrollBarVisibility="Auto" Width="300" Margin="10">
<StackPanel>
<ListBox Items="{CompiledBinding ScriptConfigurations}" SelectedItem="{CompiledBinding SelectedScript}">
<ListBox.ItemTemplate>
@@ -29,7 +31,8 @@
Grid.Column="1"
VerticalAlignment="Center"
Text="{CompiledBinding ScriptConfiguration.Name}"
IsVisible="{CompiledBinding !ScriptConfiguration.HasChanges}" />
IsVisible="{CompiledBinding !ScriptConfiguration.HasChanges}"
TextTrimming="CharacterEllipsis" />
<StackPanel Grid.Row="0"
Grid.Column="1"
VerticalAlignment="Center"
@@ -78,7 +81,7 @@
</StackPanel>
</ScrollViewer>
<Border DockPanel.Dock="Top" Classes="router-container">
<Border DockPanel.Dock="Top" Classes="router-container" Margin="0 10 0 0">
<ContentControl Content="{CompiledBinding ScriptEditorViewModel}" />
</Border>
</DockPanel>
@@ -1,4 +1,5 @@
using Avalonia;
using System.ComponentModel;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
@@ -6,12 +7,28 @@ namespace Artemis.UI.Screens.Scripting;
public partial class ScriptsDialogView : ReactiveCoreWindow<ScriptsDialogViewModel>
{
private bool _canClose;
public ScriptsDialogView()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
Closing += OnClosing;
}
private async void OnClosing(object? sender, CancelEventArgs e)
{
if (_canClose)
return;
e.Cancel = true;
if (ViewModel == null || await ViewModel.CanClose())
{
_canClose = true;
Close();
}
}
private void InitializeComponent()
@@ -143,4 +143,18 @@ public class ScriptsDialogViewModel : DialogViewModelBase<object?>
// Select the new script
SelectedScript = ScriptConfigurations.LastOrDefault();
}
public async Task<bool> CanClose()
{
if (!ScriptConfigurations.Any(s => s.ScriptConfiguration.HasChanges))
return true;
bool result = await _windowService.ShowConfirmContentDialog("Discard changes", "One or more scripts still have pending changes, do you want to discard them?");
if (!result)
return false;
foreach (ScriptConfigurationViewModel scriptConfigurationViewModel in ScriptConfigurations)
scriptConfigurationViewModel.ScriptConfiguration.DiscardPendingChanges();
return true;
}
}