-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
94 lines (88 loc) · 3.03 KB
/
MainWindow.xaml.cs
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
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Windows;
namespace ImageMerge
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private ViewModel VM => DataContext as ViewModel;
public MainWindow()
{
InitializeComponent();
}
void ReadSettings()
{
try
{
//System.Configuration.ConfigurationManager.
var settings = Properties.Settings.Default;
VM.ConcatNum = settings.ConcatNum;
VM.IsMergeLastToPrevious = settings.MergeLastToPrevious;
VM.ImageQuality = settings.ImageQuality;
VM.ResizeRatio = settings.ResizeRatio;
VM.FormatStr = settings.FormatStr;
}
catch
{
VM.ConcatNum = 5;
VM.IsMergeLastToPrevious = false;
VM.ImageQuality = 100;
VM.ResizeRatio = 100;
VM.FormatStr = "jpg";
}
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
VM.FolderPath = System.Configuration.ConfigurationManager.AppSettings["LastFolderPath"];
ReadSettings();
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
var settings = Properties.Settings.Default;
settings.ConcatNum = VM.ConcatNum;
settings.LastFolderPath = VM.FolderPath;
settings.Save();
}
private void OnBroserFolderClick(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog();
var result = dialog.ShowDialog(this) ?? false;
if (result)
{
var name = dialog.FileName;
var folderPath = name.Substring(0, name.LastIndexOf('\\'));
VM.SetFilePaths(folderPath);
}
}
private void OnOpenFolderClick(object sender, RoutedEventArgs e) => VM.SetFilePaths();
private async void OnSaveClickAsync(object sender, RoutedEventArgs e)
{
await VM.MergeAndSaveImagesAsync(this.Dispatcher);
}
private void OnOpenOutputClick(object sender, RoutedEventArgs e)
{
if (!VM.IsFinished) return;
Process.Start("explorer", VM.OutputPath);
}
private void OnSelectItemClick(object sender, RoutedEventArgs e)
{
VM.OnPropertyChanged("SelectedImagePaths");
VM.PreviewMergeResult();
//var vm = (sender as FrameworkElement).DataContext as SelectImageViewModel;
}
private void Option_Click(object sender, RoutedEventArgs e)
{
var result = new OptionWindow().ShowDialog() ?? false;
if (result)
{
ReadSettings();
}
}
}
}