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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using MessageBox.Avalonia.Enums;
using UVtools.Core.FileFormats;
using UVtools.WPF.Controls;
using UVtools.WPF.Extensions;
using Color = UVtools.WPF.Structures.Color;
namespace UVtools.WPF.Windows
{
public class SettingsWindow : WindowEx
{
private double _scrollViewerMaxHeight;
private int _selectedTabIndex;
public UserSettings SettingsBackup { get; }
public UserSettings Settings => UserSettings.Instance;
public string[] FileOpenDialogFilters { get; }
public string[] ZoomRanges { get; }
public int SelectedTabIndex
{
get => _selectedTabIndex;
set
{
if(!RaiseAndSetIfChanged(ref _selectedTabIndex, value)) return;
SizeToContent = SizeToContent.Manual;
SizeToContent = SizeToContent.Height;
}
}
public double ScrollViewerMaxHeight
{
get => _scrollViewerMaxHeight;
set => RaiseAndSetIfChanged(ref _scrollViewerMaxHeight, value);
}
public SettingsWindow()
{
Title += $" [v{AppSettings.Version}]";
SettingsBackup = UserSettings.Instance.Clone();
var fileFormats = new List<string>
{
FileFormat.AllSlicerFiles.Replace("*", string.Empty)
};
fileFormats.AddRange(from format in FileFormat.AvaliableFormats from extension in format.FileExtensions select $"{extension.Description} (.{extension.Extension})");
FileOpenDialogFilters = fileFormats.ToArray();
// Derive strings for the zoom lock and crosshair fade combo-boxes from the
// ZoomLevels constant array, and add those strings to the comboboxes.
ZoomRanges = AppSettings.ZoomLevels.Skip(AppSettings.ZoomLevelSkipCount).Select(
s => Convert.ToString(s / 100, CultureInfo.InvariantCulture) + "x").ToArray();
//MaxHeight = Screens.Primary.WorkingArea.Height - 50;
ScrollViewerMaxHeight = Screens.Primary.WorkingArea.Height - 200;
DataContext = this;
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
if (DialogResult != DialogResults.OK)
{
UserSettings.Instance = SettingsBackup;
}
else
{
UserSettings.Save();
}
}
public async void GeneralOpenFolderField(string field)
{
foreach (PropertyInfo propertyInfo in Settings.General.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (propertyInfo.Name != field) continue;
OpenFolderDialog dialog = new OpenFolderDialog();
var filename = await dialog.ShowAsync(this);
if (string.IsNullOrEmpty(filename)) return;
propertyInfo.SetValue(Settings.General, filename);
return;
}
}
public void GeneralClearField(string field)
{
var properties = Settings.General.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo.Name != field) continue;
propertyInfo.SetValue(Settings.General, null);
return;
}
}
public async void SelectColor(string property)
{
foreach (var packObject in UserSettings.PackObjects)
{
var properties = packObject.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var propertyInfo in properties)
{
if (propertyInfo.Name != property) continue;
var color = (Color)propertyInfo.GetValue(packObject, null) ?? new Color(0,255,255,255);
var window = new ColorPickerWindow(color.ToAvalonia());
var result = await window.ShowDialog<DialogResults>(this);
if (result != DialogResults.OK) return;
propertyInfo.SetValue(packObject, new Color(window.ResultColor));
return;
}
}
}
public async void OnClickResetAllDefaults()
{
var result = await this.MessageBoxQuestion("Are you sure you want to reset all settings to the default values?", "Reset settings?");
if (result != ButtonResult.Yes) return;
UserSettings.Reset();
ResetDataContext();
}
public void OnClickSave()
{
DialogResult = DialogResults.OK;
CloseWithResult();
}
}
}
|