-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
251 lines (196 loc) · 10.6 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace DenseNumerics
{
public partial class MainWindow : Window
{
private readonly Dictionary<string, string> _translations = new Dictionary<string, string>();
private bool _isDarkTheme = false;
public MainWindow()
{
InitializeComponent();
InitializeTranslations();
// Az ApplyTranslation a Window Loaded eseményében fog futni
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// Alkalmazzuk az alapértelmezett fordítást az ablak teljes betöltése után
ApplyTranslation("en");
}
private void ThemeToggle_Click(object sender, RoutedEventArgs e)
{
_isDarkTheme = !_isDarkTheme;
// Ikon frissítés
((Path)ThemeToggle.Content).Data = Geometry.Parse(_isDarkTheme ?
"M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z" :
"M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z");
// Válaszd ki a megfelelő téma elérési útját
string themePath = _isDarkTheme ? "Themes/DarkTheme.xaml" : "Themes/LightTheme.xaml";
// Töröljük az összes meglévő erőforrást
var mergedDictionaries = Application.Current.Resources.MergedDictionaries;
mergedDictionaries.Clear();
// Új téma betöltése
var newTheme = new ResourceDictionary
{
Source = new Uri(themePath, UriKind.Relative)
};
mergedDictionaries.Add(newTheme);
// Loggolás a hibaelhárításhoz
foreach (var dict in mergedDictionaries)
{
Console.WriteLine($"Loaded dictionary: {dict.Source}");
}
// Kényszerítsük az UI frissítését
foreach (Window window in Application.Current.Windows)
{
window.InvalidateVisual();
window.UpdateLayout();
}
}
private void InitializeTranslations()
{
_translations.Clear();
// Headers
_translations["AsymptoticDensityHeader_en"] = "Asymptotic Density Analysis";
_translations["AsymptoticDensityHeader_hu"] = "Aszimptotikus Sűrűség Vizsgálatok";
_translations["ReciprocalSeriesHeader_en"] = "Reciprocal Series Analysis";
_translations["ReciprocalSeriesHeader_hu"] = "Reciprok Sorok Vizsgálata";
_translations["AdjacentElementsHeader_en"] = "Adjacent Elements Analysis";
_translations["AdjacentElementsHeader_hu"] = "Szomszédos Elemek Vizsgálata";
// Asymptotic Density Section
_translations["StartingWithOneBtn_Title_en"] = "Numbers Starting with One";
_translations["StartingWithOneBtn_Title_hu"] = "Egyessel Kezdődő Számok";
_translations["StartingWithOneBtn_Desc_en"] = "Analysis of numbers that start with digit 1";
_translations["StartingWithOneBtn_Desc_hu"] = "Egyessel kezdődő számok vizsgálata";
_translations["PowerNumbersBtn_Title_en"] = "Power Numbers";
_translations["PowerNumbersBtn_Title_hu"] = "Hatványszámok";
_translations["PowerNumbersBtn_Desc_en"] = "Analysis of numbers raised to arbitrary power (n^k)";
_translations["PowerNumbersBtn_Desc_hu"] = "Tetszőleges hatványra emelt számok vizsgálata (n^k)";
_translations["CongruentNumbersBtn_Title_en"] = "Congruent Numbers";
_translations["CongruentNumbersBtn_Title_hu"] = "Kongruens Számok";
_translations["CongruentNumbersBtn_Desc_en"] = "Analysis of numbers with specific remainder (n ≡ r (mod m))";
_translations["CongruentNumbersBtn_Desc_hu"] = "Adott maradékot adó számok vizsgálata (n ≡ r (mod m))";
// Reciprocal Series Section
_translations["ReciprocalPowerBtn_Title_en"] = "Power Number Series";
_translations["ReciprocalPowerBtn_Title_hu"] = "Hatványszám Sorozatok";
_translations["ReciprocalPowerBtn_Desc_en"] = "Analysis of series 1/n^k for arbitrary k";
_translations["ReciprocalPowerBtn_Desc_hu"] = "1/n^k alakú sorok vizsgálata tetszőleges k-ra";
_translations["ReciprocalCongruentBtn_Title_en"] = "Congruent Number Series";
_translations["ReciprocalCongruentBtn_Title_hu"] = "Kongruens Szám Sorozatok";
_translations["ReciprocalCongruentBtn_Desc_en"] = "Analysis of series 1/n where n ≡ r (mod m)";
_translations["ReciprocalCongruentBtn_Desc_hu"] = "1/n alakú sorok vizsgálata, ahol n ≡ r (mod m)";
// Adjacent Elements Section
_translations["AdjacentNumbersBtn_Title_en"] = "Special Number Sequences";
_translations["AdjacentNumbersBtn_Title_hu"] = "Speciális Számsorozatok";
_translations["AdjacentNumbersBtn_Desc_en"] = "Analysis of ratios for various number sequences";
_translations["AdjacentNumbersBtn_Desc_hu"] = "Különböző számsorozatok hányadosainak vizsgálata";
}
private void ApplyTranslation(string language)
{
// Helper function to safely get translations
string GetTranslation(string key) =>
_translations.TryGetValue($"{key}_{language}", out string value) ? value : $"[Missing:{key}]";
// Null-check and translation assignment for headers
if (AsymptoticDensityHeader != null)
AsymptoticDensityHeader.Text = GetTranslation("AsymptoticDensityHeader");
if (ReciprocalSeriesHeader != null)
ReciprocalSeriesHeader.Text = GetTranslation("ReciprocalSeriesHeader");
if (AdjacentElementsHeader != null)
AdjacentElementsHeader.Text = GetTranslation("AdjacentElementsHeader");
// Asymptotic Density Buttons
if (StartingWithOneBtnTitle != null)
StartingWithOneBtnTitle.Text = GetTranslation("StartingWithOneBtn_Title");
if (StartingWithOneBtnDesc != null)
StartingWithOneBtnDesc.Text = GetTranslation("StartingWithOneBtn_Desc");
if (PowerNumbersBtnTitle != null)
PowerNumbersBtnTitle.Text = GetTranslation("PowerNumbersBtn_Title");
if (PowerNumbersBtnDesc != null)
PowerNumbersBtnDesc.Text = GetTranslation("PowerNumbersBtn_Desc");
if (CongruentNumbersBtnTitle != null)
CongruentNumbersBtnTitle.Text = GetTranslation("CongruentNumbersBtn_Title");
if (CongruentNumbersBtnDesc != null)
CongruentNumbersBtnDesc.Text = GetTranslation("CongruentNumbersBtn_Desc");
// Reciprocal Series Buttons
if (ReciprocalPowerBtnTitle != null)
ReciprocalPowerBtnTitle.Text = GetTranslation("ReciprocalPowerBtn_Title");
if (ReciprocalPowerBtnDesc != null)
ReciprocalPowerBtnDesc.Text = GetTranslation("ReciprocalPowerBtn_Desc");
if (ReciprocalCongruentBtnTitle != null)
ReciprocalCongruentBtnTitle.Text = GetTranslation("ReciprocalCongruentBtn_Title");
if (ReciprocalCongruentBtnDesc != null)
ReciprocalCongruentBtnDesc.Text = GetTranslation("ReciprocalCongruentBtn_Desc");
// Adjacent Elements Buttons
if (AdjacentNumbersBtnTitle != null)
AdjacentNumbersBtnTitle.Text = GetTranslation("AdjacentNumbersBtn_Title");
if (AdjacentNumbersBtnDesc != null)
AdjacentNumbersBtnDesc.Text = GetTranslation("AdjacentNumbersBtn_Desc");
}
private void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LanguageComboBox.SelectedItem is ComboBoxItem selectedItem)
{
string language = selectedItem.Tag.ToString();
ApplyTranslation(language);
}
}
public void ApplyLanguage(string language)
{
ApplyTranslation(language);
}
// Event handlers for opening analysis windows
private void StartingWithOneBtn_Click(object sender, RoutedEventArgs e)
{
var window = new Windows.NumbersStartingWithOneWindow();
window.ApplyLanguage(GetSelectedLanguage());
window.Owner = this;
window.Show();
}
private void PowerNumbersBtn_Click(object sender, RoutedEventArgs e)
{
var window = new Windows.PowerNumbersWindow();
//window.ApplyLanguage(GetSelectedLanguage());
window.Owner = this;
window.Show();
}
private void CongruentNumbersBtn_Click(object sender, RoutedEventArgs e)
{
var window = new Windows.CongruenceAnalysisWindow();
window.ApplyLanguage(GetSelectedLanguage());
window.Owner = this;
window.Show();
}
private void ReciprocalPowerBtn_Click(object sender, RoutedEventArgs e)
{
var window = new Windows.ReciprocalSeriesWindow();
window.ApplyLanguage(GetSelectedLanguage());
window.Owner = this;
window.Show();
}
private void ReciprocalCongruentBtn_Click(object sender, RoutedEventArgs e)
{
var window = new Windows.ReciprocalSeriesWindow();
window.SetCongruentMode();
window.ApplyLanguage(GetSelectedLanguage());
window.Owner = this;
window.Show();
}
private void AdjacentNumbersBtn_Click(object sender, RoutedEventArgs e)
{
var window = new Windows.AdjacentElementsWindow();
window.ApplyLanguage(GetSelectedLanguage());
window.Owner = this;
window.Show();
}
private string GetSelectedLanguage()
{
return LanguageComboBox.SelectedItem is ComboBoxItem selectedItem
? selectedItem.Tag.ToString()
: "en"; // Default to English
}
}
}