-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathScenarioDialogWindow.axaml.cs
More file actions
110 lines (94 loc) · 3.1 KB
/
Copy pathScenarioDialogWindow.axaml.cs
File metadata and controls
110 lines (94 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Interactivity;
using LlamaServerLauncher.Models;
using LlamaServerLauncher.Resources;
using LlamaServerLauncher.Services;
using LlamaServerLauncher.ViewModels;
namespace LlamaServerLauncher;
public partial class ScenarioDialogWindow : Window
{
private ScenarioDialogViewModel? _viewModel;
private ConfigurationService? _configService;
private Dictionary<string, DialogGeometry>? _dialogGeometryDict;
/// <summary>Geometry captured in OnClosing for the caller to save asynchronously.</summary>
public DialogGeometry? CapturedGeometry { get; private set; }
public ScenarioDialogWindow()
{
InitializeComponent();
}
public void SetViewModel(ScenarioDialogViewModel viewModel, ConfigurationService configService, Dictionary<string, DialogGeometry>? dialogGeometryDict = null)
{
_viewModel = viewModel;
_configService = configService;
_dialogGeometryDict = dialogGeometryDict;
DataContext = _viewModel;
_viewModel.RequestClose += OnRequestClose;
if (dialogGeometryDict != null)
DialogPositionHelper.ApplySavedGeometry(this, dialogGeometryDict, "ScenarioDialog");
}
private async void HelpClick(object? sender, RoutedEventArgs e)
{
await HelpService.ShowAsync(this, HelpService.TopicScenarios,
LocalizedStrings.Instance.HelpTitleScenarios, _dialogGeometryDict);
}
protected override void OnKeyDown(Avalonia.Input.KeyEventArgs e)
{
if (e.Key == Avalonia.Input.Key.F1 && e.KeyModifiers == Avalonia.Input.KeyModifiers.None)
{
HelpClick(this, new RoutedEventArgs());
e.Handled = true;
return;
}
base.OnKeyDown(e);
}
private void OnRequestClose()
{
Avalonia.Threading.Dispatcher.UIThread.Post(() => Close());
}
private void AddProfileClick(object? sender, RoutedEventArgs e)
{
_viewModel?.AddProfile();
}
private void RemoveProfileClick(object? sender, RoutedEventArgs e)
{
_viewModel?.RemoveProfile();
}
private async void CloneToScenarioClick(object? sender, RoutedEventArgs e)
{
if (_viewModel != null)
await _viewModel.CloneToScenarioAsync(this);
}
private void MoveUpClick(object? sender, RoutedEventArgs e)
{
_viewModel?.MoveUp();
}
private void MoveDownClick(object? sender, RoutedEventArgs e)
{
_viewModel?.MoveDown();
}
private void OkClick(object? sender, RoutedEventArgs e)
{
_viewModel?.Save();
}
private void CancelClick(object? sender, RoutedEventArgs e)
{
_viewModel?.Cancel();
}
protected override void OnClosing(WindowClosingEventArgs e)
{
if (_viewModel != null)
{
_viewModel.RequestClose -= OnRequestClose;
}
CapturedGeometry = new DialogGeometry
{
Width = Width,
Height = Height,
Left = Position.X,
Top = Position.Y
};
base.OnClosing(e);
}
}