/
MainWindow.Actions.cs
142 lines (122 loc) · 5.01 KB
/
MainWindow.Actions.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
using MultiEdit.Functions;
using MultiEdit.Model;
using MultiEdit.Types;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace MultiEdit
{
public partial class MainWindow
{
public class LanguageFile
{
public string file;
public LanguageTypes.Languages language;
}
public LanguageFile[] filesForProceed = new LanguageFile[]
{
new LanguageFile { file = @"Resources\StringResources.lv-LV.xaml", language = LanguageTypes.Languages.lLV },
new LanguageFile { file = @"Resources\StringResources.ru-RU.xaml", language = LanguageTypes.Languages.lRU },
new LanguageFile { file = @"Resources\StringResources.en-US.xaml", language = LanguageTypes.Languages.lEN },
new LanguageFile { file = @"Resources\StringResources.de-LI.xaml", language = LanguageTypes.Languages.lDE }
};
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
ActionLoad();
}
private void ActionLoad()
{
// Read data
foreach (LanguageFile file in filesForProceed)
{
ResourcesDictionary[(int)file.language] = ResourceDictionaryFunctions.LoadResourceDictionaryFromFile(file.file);
}
bool result;
// Verify data (quick way 1)
result = ResourceDictionaryFunctions.VerifySizeOfResourcesDictionary(ResourcesDictionary);
if (!result)
{
MessageBox.Show("Size of resources doesnot match!");
return;
}
// Verify data (way 2)
result = ResourceDictionaryFunctions.VerifyKeysInResourcesDictionary(ResourcesDictionary);
if (!result)
{
MessageBox.Show("Keys in resources does not match!");
return;
}
// Build list of Keys and values
EditorDataModel.Items.Clear();
foreach (DictionaryEntry key in ResourcesDictionary[(int)LanguageTypes.Languages.lLV])
{
ItemModel myData = new ItemModel
{
KeyName = key.Key.ToString(),
Value1 = key.Value.ToString(),
Value2 = ResourcesDictionary[(int)LanguageTypes.Languages.lRU][key.Key].ToString(),
Value3 = ResourcesDictionary[(int)LanguageTypes.Languages.lEN][key.Key].ToString(),
Value4 = ResourcesDictionary[(int)LanguageTypes.Languages.lDE][key.Key].ToString()
};
EditorDataModel.Items.Add(myData);
}
//ResourceDictionaryKeys = ResourceDictionaryFunctions.GetListOfAllKeysAsObservableCollection(ResourcesDictionary[(int)LanguageTypes.Languages.lLV]);
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
ActionSave();
}
private void ActionSave()
{
bool result;
// надо скопировать данные из EditorDataModel.Items в новый ResourcesDictionary
// need to copy data from EditorDataModel.Items to new ResourcesDictionary
ResourceDictionary newResourceDictionary = new ResourceDictionary();
foreach (LanguageFile file in filesForProceed)
{
string value;
newResourceDictionary.Clear();
foreach (ItemModel itemModel in EditorDataModel.Items)
{
switch (file.language)
{
case LanguageTypes.Languages.lLV:
{
value = itemModel.Value1;
break;
}
case LanguageTypes.Languages.lRU:
{
value = itemModel.Value2;
break;
}
case LanguageTypes.Languages.lEN:
{
value = itemModel.Value3;
break;
}
default:
{
value = itemModel.Value4;
break;
}
}
newResourceDictionary.Add(itemModel.KeyName, value);
}
result = ResourceDictionaryFunctions.SaveResourceDictionaryToFile(file.file, newResourceDictionary);
if (!result)
{
MessageBox.Show(
String.Format("Cannot save resources dictionary '{0}'!", file.language)
);
return;
}
}
}
}
}