-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathModelPickerWindow.axaml.cs
More file actions
120 lines (100 loc) · 2.96 KB
/
Copy pathModelPickerWindow.axaml.cs
File metadata and controls
120 lines (100 loc) · 2.96 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
111
112
113
114
115
116
117
118
119
120
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using LlamaServerLauncher.Models;
using LlamaServerLauncher.Services;
using LlamaServerLauncher.ViewModels;
namespace LlamaServerLauncher;
public partial class ModelPickerWindow : Window
{
private ModelPickerViewModel? _viewModel;
public DialogGeometry? CapturedGeometry { get; private set; }
public bool IsConfirmed { get; private set; }
public string? SelectedPath => _viewModel?.ConfirmedPath;
public string ScannedFolder => _viewModel?.FolderPath ?? "";
public bool ScannedRecursive => _viewModel?.Recursive ?? false;
public ModelPickerWindow()
{
InitializeComponent();
}
public void SetViewModel(ModelPickerViewModel vm, Dictionary<string, DialogGeometry>? dialogGeometryDict = null)
{
_viewModel = vm;
DataContext = vm;
vm.RequestClose += OnRequestClose;
if (dialogGeometryDict != null)
DialogPositionHelper.ApplySavedGeometry(this, dialogGeometryDict, "ModelPicker");
}
private void OnRequestClose()
{
Avalonia.Threading.Dispatcher.UIThread.Post(() => Close());
}
protected override void OnOpened(System.EventArgs e)
{
base.OnOpened(e);
if (_viewModel != null)
_ = _viewModel.RescanAsync();
}
private async void BrowseClick(object? sender, RoutedEventArgs e)
{
if (_viewModel != null)
await _viewModel.BrowseFolderAsync();
}
private async void RescanClick(object? sender, RoutedEventArgs e)
{
if (_viewModel != null)
await _viewModel.RescanAsync();
}
private async void RecursiveClick(object? sender, RoutedEventArgs e)
{
if (_viewModel != null)
await _viewModel.RescanAsync();
}
private void ListDoubleTapped(object? sender, TappedEventArgs e)
{
Confirm();
}
private void SelectClick(object? sender, RoutedEventArgs e)
{
Confirm();
}
private void CancelClick(object? sender, RoutedEventArgs e)
{
_viewModel?.Cancel();
}
private void Confirm()
{
if (_viewModel != null && _viewModel.Confirm())
IsConfirmed = true;
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Confirm();
e.Handled = true;
return;
}
if (e.Key == Key.Escape)
{
_viewModel?.Cancel();
e.Handled = true;
return;
}
base.OnKeyDown(e);
}
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);
}
}