-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathOptimizationWindow.axaml.cs
More file actions
89 lines (78 loc) · 2.47 KB
/
Copy pathOptimizationWindow.axaml.cs
File metadata and controls
89 lines (78 loc) · 2.47 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
using System;
using System.Collections.Generic;
using System.IO;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform;
using LlamaServerLauncher.Models;
using LlamaServerLauncher.Resources;
using LlamaServerLauncher.Services;
using LlamaServerLauncher.ViewModels;
namespace LlamaServerLauncher;
public partial class OptimizationWindow : Window
{
private OptimizationViewModel? _viewModel;
private Dictionary<string, DialogGeometry>? _dialogGeometryDict;
public DialogGeometry? CapturedGeometry { get; private set; }
public OptimizationWindow()
{
InitializeComponent();
}
public void SetViewModel(OptimizationViewModel vm, Dictionary<string, DialogGeometry>? dialogGeometryDict = null)
{
_viewModel = vm;
_dialogGeometryDict = dialogGeometryDict;
DataContext = vm;
vm.RequestClose += Close;
if (dialogGeometryDict != null)
DialogPositionHelper.ApplySavedGeometry(this, dialogGeometryDict, "Optimization");
}
private async void OpenGuideClick(object? sender, RoutedEventArgs e)
{
await MarkdownViewerWindow.ShowAsync(this, LoadGuide(), LocalizedStrings.Instance.OptGuideTitle, _dialogGeometryDict);
}
private static string LoadGuide()
{
bool ru = LocalizedStrings.CurrentCulture.TwoLetterISOLanguageName == "ru";
var uri = new Uri($"avares://LlamaServerLauncher/Resources/Docs/optimization-guide.{(ru ? "ru" : "en")}.md");
try
{
using var stream = AssetLoader.Open(uri);
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
catch (Exception ex)
{
return $"```\n{ex.Message}\n```";
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
Close();
e.Handled = true;
return;
}
if (e.Key == Key.F1 && e.KeyModifiers == KeyModifiers.None)
{
OpenGuideClick(this, new RoutedEventArgs());
e.Handled = true;
return;
}
base.OnKeyDown(e);
}
protected override void OnClosing(WindowClosingEventArgs e)
{
CapturedGeometry = new DialogGeometry
{
Width = Width,
Height = Height,
Left = Position.X,
Top = Position.Y
};
_viewModel?.Cancel();
base.OnClosing(e);
}
}