-
Notifications
You must be signed in to change notification settings - Fork 37
/
MainWindow.xaml.cs
138 lines (120 loc) · 4.35 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
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Threading;
using System.Windows;
using System.Windows.Input;
namespace ssi
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainHandler viewh = null;
public MainWindow()
{
InitializeComponent();
view.OnHandlerLoaded += viewHandlerLoaded;
CultureInfo ci = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
Title = "NOVA | v" + MainHandler.BuildVersion + " | HCM-Lab, Augsburg University | http://openssi.net";
}
private void viewHandlerLoaded(MainHandler handler)
{
viewh = handler;
KeyDown += OnKeyDown;
PreviewKeyDown += handler.OnPreviewKeyDown;
KeyDown += handler.OnKeyDown;
KeyUp += handler.OnKeyUp;
HandleClArgs(Environment.GetCommandLineArgs());
((App)Application.Current).ReceiveExternalClArgs += (app, clArgs) =>
{
HandleClArgs(clArgs.Args);
};
}
public void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && e.KeyboardDevice.IsKeyDown(Key.Enter))
{
if (WindowStyle != WindowStyle.None)
{
WindowStyle = WindowStyle.None;
WindowState = WindowState.Normal;
WindowState = WindowState.Maximized;
}
}
else if (e.KeyboardDevice.IsKeyDown(Key.Escape))
{
if (WindowStyle != WindowStyle.SingleBorderWindow)
{
WindowStyle = WindowStyle.SingleBorderWindow;
WindowState = WindowState.Normal;
}
}
}
private void HandleClArgs(IList<string> args)
{
if (args.Count <= 1) return;
//for (var i = 1; i < args.Count; i++)
//{
// try
// {
// string filerooted;
// if (!Path.IsPathRooted(args[i]))
// {
// filerooted = Directory.GetCurrentDirectory() + "\\" + args[i];
// }
// else
// {
// filerooted = args[i];
// }
// viewh.loadMultipleFilesOrDirectory(new[] { filerooted });
// }
// catch (Exception)
// {
// // ignored
// }
//}
string path = args[1];
for (var i = 2; i < args.Count; i++)
{
path += " " + args[i];
}
if (!Path.IsPathRooted(path))
{
path = Directory.GetCurrentDirectory() + "\\" + path;
}
viewh.loadFile(path);
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MainHandler.ENABLE_PYTHON)
{
MainHandler.killExplanationBackend();
}
if (!viewh.clearWorkspace())
{
e.Cancel = true;
}
try
{
var dir = new DirectoryInfo(Path.GetDirectoryName(Properties.Settings.Default.CMLTempTrainerPath));
foreach (var file in dir.EnumerateFiles(Path.GetFileName(Properties.Settings.Default.CMLTempTrainerPath) + "latestcmlmodel*"))
{
file.Delete();
}
foreach (var file in dir.EnumerateFiles(Path.GetFileName(Properties.Settings.Default.CMLTempTrainerPath) + Properties.Settings.Default.CMLTempTrainerName + "*"))
{
file.Delete();
}
}
catch { }
}
}
}