-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
110 lines (96 loc) · 3.41 KB
/
MainWindow.xaml.cs
File metadata and controls
110 lines (96 loc) · 3.41 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Diagnostics;
using KeyTrain;
using Pythonic;
using static Pythonic.ListHelpers;
using static KeyTrain.KeyTrainStatsConversion;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Dynamic;
using System.Threading;
using System.ComponentModel;
//using static KeyTrain.DarkStyles.MainWindow;
using Microsoft.Win32;
using System.IO;
namespace KeyTrain
{
public partial class MainWindow : Window
{
public MainPage mainPage { get; private set; } = new MainPage();
public SettingsPage settingsPage { get; private set; } = new SettingsPage();
public StatsPage statsPage { get; private set; } = null;
ChainMap<string,dynamic> CFG => ConfigManager.Settings;
Dictionary<string, object> windowPlacementBindings => new Dictionary<string, object>
{
{"windowWidth" , Width},
{"windowHeight", Height},
{"windowState" , WindowState.ToString()},
{"windowLeft" , Left},
{"windowTop", Top}
};
public MainWindow()
{
InitializeComponent();
ConfigManager.ReadConfigFile();
Focusable = true;
NavigationCommands.BrowseBack.InputGestures.Clear();
LoadMainPage(reset: true);
}
private void Window_Closing(object sender, CancelEventArgs e)
{
foreach (var pair in windowPlacementBindings)
{
CFG[pair.Key] = pair.Value;
}
mainPage.Window_Closing(sender, e);
}
public void LoadMainPage(bool reset = false, bool reEmphasize = true)
{
Frame.Content = mainPage;
if (reEmphasize && MainPage.Generator.GetType() == typeof(RandomizedLesson))
{
((RandomizedLesson)MainPage.Generator).Emphasize(MainPage.selectedChars);
MainPage.Text = MainPage.Generator.NextText();
}
if (reset)
{
mainPage.Reset();
}
mainPage.RatingsChanged();
}
public void LoadSettingsPage()
{
Frame.Content = settingsPage;
}
public void LoadStatsPage()
{
statsPage ??= new StatsPage();
Frame.Content = statsPage;
}
private void Window_StateChanged(object sender, EventArgs e)
{
//Making sure both mainRealEstate's margins and letterRatings' columns behave properly on maximize
mainPage.RatingsChanged();
}
private void Window_SourceInitialized(object sender, EventArgs e)
{
if (windowPlacementBindings.Keys.All(k => CFG.Keys.Contains(k)))
{
Left = CFG["windowLeft"];
Top = CFG["windowTop"];
WindowState = Enum.Parse(typeof(WindowState), CFG["windowState"]);
if (CFG["windowState"] == "Normal")
{
Width = CFG["windowWidth"];
Height = CFG["windowHeight"];
}
}
}
}
}