blob: 1b9664fe6fc60036d502715e7dd6b725c4d29318 (
plain)
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
|
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using UVtools.Core.FileFormats;
using UVtools.Core.Operations;
using UVtools.WPF.Windows;
namespace UVtools.WPF.Controls.Tools
{
public class ToolRedrawModelControl : ToolControl
{
public OperationRedrawModel Operation => BaseOperation as OperationRedrawModel;
public ToolRedrawModelControl()
{
BaseOperation = new OperationRedrawModel(SlicerFile);
if (!ValidateSpawn()) return;
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public override void Callback(ToolWindow.Callbacks callback)
{
switch (callback)
{
case ToolWindow.Callbacks.Init:
case ToolWindow.Callbacks.Loaded:
ParentWindow.ButtonOkEnabled = !string.IsNullOrWhiteSpace(Operation.FilePath);
Operation.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == nameof(Operation.FilePath))
{
ParentWindow.ButtonOkEnabled = !string.IsNullOrWhiteSpace(Operation.FilePath);
}
};
break;
}
}
public async void ImportFile()
{
var filters = Helpers.ToAvaloniaFileFilter(FileFormat.AllFileFiltersAvalonia);
var orderedFilters = new List<FileDialogFilter> { filters[UserSettings.Instance.General.DefaultOpenFileExtensionIndex] };
for (int i = 0; i < filters.Count; i++)
{
if (i == UserSettings.Instance.General.DefaultOpenFileExtensionIndex) continue;
orderedFilters.Add(filters[i]);
}
var dialog = new OpenFileDialog
{
AllowMultiple = false,
Filters = orderedFilters,
Directory = UserSettings.Instance.General.DefaultDirectoryOpenFile
};
var files = await dialog.ShowAsync(ParentWindow);
if (files is null || files.Length <= 0) return;
if (FileFormat.FindByExtensionOrFilePath(files[0]) is null) return;
Operation.FilePath = files[0];
}
}
}
|