Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/ParallelSpace/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ public override void OnFrameworkInitializationCompleted()

var window = new MainWindow { DataContext = vm };

// Wire the add/edit dialog now that both window and view model exist.
// Wire dialogs now that both window and view model exist.
vm.ShowEditor = async editor =>
{
var dialog = new EditSpaceWindow { DataContext = editor };
return await dialog.ShowDialog<bool>(window);
};
vm.ShowConfirmation = async (title, message) =>
{
var dialog = new ConfirmActionWindow(title, message);
return await dialog.ShowDialog<bool>(window);
};

desktop.MainWindow = window;
desktop.ShutdownRequested += (_, _) => launcher.Dispose();
Expand All @@ -42,3 +47,4 @@ public override void OnFrameworkInitializationCompleted()
base.OnFrameworkInitializationCompleted();
}
}

18 changes: 16 additions & 2 deletions src/ParallelSpace/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public sealed partial class MainWindowViewModel : ObservableObject
/// <summary>Set by the app: shows the add/edit dialog and returns true if saved.</summary>
public Func<EditSpaceViewModel, Task<bool>>? ShowEditor { get; set; }

/// <summary>Set by the app: shows a confirmation dialog and returns true if accepted.</summary>
public Func<string, string, Task<bool>>? ShowConfirmation { get; set; }

[ObservableProperty] private string _statusMessage = "Ready.";
[ObservableProperty] private bool _hasDetectedApps;
[ObservableProperty] private NavPage _selectedPage = NavPage.Spaces;
Expand Down Expand Up @@ -344,15 +347,25 @@ public void LaunchSpace(SpaceViewModel vm)
RefreshStatuses();
}

public void CloseSpace(SpaceViewModel vm)
public async Task CloseSpace(SpaceViewModel vm)
{
if (ShowConfirmation is null || !await ShowConfirmation(
"Close application?",
"This application will be closed. You may need to sign in again the next time you launch it."))
return;

_launcher.CloseAll(vm.Model);
StatusMessage = $"Closed {vm.Name}.";
RefreshStatuses();
}

public void RemoveSpace(SpaceViewModel vm)
public async Task RemoveSpace(SpaceViewModel vm)
{
if (ShowConfirmation is null || !await ShowConfirmation(
"Remove application?",
"This application will be removed from your Spaces list. Its profile data folder will remain on your device."))
return;

var index = Spaces.IndexOf(vm);
Spaces.Remove(vm);

Expand Down Expand Up @@ -413,3 +426,4 @@ private void OpenUrl(string url)
catch (Exception ex) { StatusMessage = $"Couldn't open browser: {ex.Message}"; }
}
}

5 changes: 3 additions & 2 deletions src/ParallelSpace/ViewModels/SpaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ public void NotifyEdited()
private bool CanClose() => IsRunning;

[RelayCommand(CanExecute = nameof(CanClose))]
private void Close() => _owner.CloseSpace(this);
private Task Close() => _owner.CloseSpace(this);

[RelayCommand]
private void OpenDataFolder() => _owner.OpenDataFolder(this);

[RelayCommand]
private void Remove() => _owner.RemoveSpace(this);
private Task Remove() => _owner.RemoveSpace(this);
}

48 changes: 48 additions & 0 deletions src/ParallelSpace/Views/ConfirmActionWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ParallelSpace.Views.ConfirmActionWindow"
Width="430" SizeToContent="Height" MinHeight="170"
CanResize="False"
WindowStartupLocation="CenterOwner"
Background="{DynamicResource AppBackgroundBrush}"
Icon="/Assets/appicon.ico"
Title="Confirm action">

<Window.Styles>
<Style Selector="Button.primary">
<Setter Property="Background" Value="{DynamicResource AccentBrush}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Padding" Value="15,9" />
<Setter Property="CornerRadius" Value="7" />
<Setter Property="FontWeight" Value="SemiBold" />
</Style>
<Style Selector="Button.primary:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource AccentHoverBrush}" />
</Style>
<Style Selector="Button.subtle">
<Setter Property="Background" Value="{DynamicResource SubtleBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
<Setter Property="Padding" Value="12,9" />
<Setter Property="CornerRadius" Value="7" />
</Style>
<Style Selector="Button.subtle:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource SubtleHoverBrush}" />
</Style>
</Window.Styles>

<StackPanel Margin="24" Spacing="18">
<StackPanel Spacing="8">
<TextBlock x:Name="TitleText" FontSize="17" FontWeight="Bold"
Foreground="{DynamicResource TextBrush}" />
<TextBlock x:Name="MessageText" FontSize="13" TextWrapping="Wrap"
Foreground="{DynamicResource MutedTextBrush}" />
</StackPanel>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
<Button Classes="subtle" Content="Cancel" IsCancel="True"
Click="OnCancel" />
<Button Classes="primary" Content="Accept" Click="OnAccept" />
</StackPanel>
</StackPanel>
</Window>

20 changes: 20 additions & 0 deletions src/ParallelSpace/Views/ConfirmActionWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Avalonia.Controls;
using Avalonia.Interactivity;

namespace ParallelSpace.Views;

public partial class ConfirmActionWindow : Window
{
public ConfirmActionWindow(string title, string message)
{
InitializeComponent();
Title = title;
TitleText.Text = title;
MessageText.Text = message;
}

private void OnAccept(object? sender, RoutedEventArgs e) => Close(true);

private void OnCancel(object? sender, RoutedEventArgs e) => Close(false);
}