-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigureCharacters.cs
148 lines (117 loc) · 4.49 KB
/
ConfigureCharacters.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
using Quiccent.Constants;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace Quiccent
{
public partial class ConfigureCharacters : Form
{
protected Accents Accents { get; set; }
protected object SelectedComboBoxItem { get; set; }
public ConfigureCharacters(Accents accents)
{
InitializeComponent();
InitializeAccents(accents);
InitializeCharacterComboBox();
InitializeSelectorLists();
}
private void InitializeSelectorLists()
{
CharacterSelector.AllowDrop = true;
RemovedCharactersSelector.AllowDrop = true;
}
private void InitializeCharacterComboBox()
{
foreach (var character in Accents.Mappings.Keys)
{
if (!string.IsNullOrWhiteSpace(character))
{
CharacterComboBox.Items.Add(character);
}
}
CharacterComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
CharacterComboBox.SelectedItem = CharacterComboBox.Items[0];
SelectedComboBoxItem = CharacterComboBox.SelectedItem;
}
private void InitializeAccents(Accents accents)
{
Accents = accents;
}
private void CharacterSelector_MouseDown(object sender, MouseEventArgs e)
{
if (CharacterSelector.SelectedItem == null)
{
return;
}
CharacterSelector.DoDragDrop(CharacterSelector.SelectedItem, DragDropEffects.Move);
}
private void CharacterSelector_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void CharacterSelector_DragDrop(object sender, DragEventArgs e)
{
var point = CharacterSelector.PointToClient(new Point(e.X, e.Y));
var index = CharacterSelector.IndexFromPoint(point);
if (index < 0)
{
index = CharacterSelector.Items.Count - 1;
}
var data = CharacterSelector.SelectedItem;
CharacterSelector.Items.Remove(data);
CharacterSelector.Items.Insert(index, data);
}
private void CharacterComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (CharacterSelector.Items.Count > 0 || RemovedCharactersSelector.Items.Count > 0)
{
SaveCurrentSelector();
}
SelectedComboBoxItem = CharacterComboBox.SelectedItem;
RemovedCharactersSelector.Items.Clear();
RemovedCharactersSelector.Items.AddRange(Accents.Mappings_Removed[(string)SelectedComboBoxItem].ToArray());
CharacterSelector.Items.Clear();
CharacterSelector.Items.AddRange(Accents.Mappings[(string)SelectedComboBoxItem].ToArray());
CharacterSelector.Items.Remove((string)SelectedComboBoxItem);
}
private void SaveCurrentSelector()
{
Accents.Mappings[(string)SelectedComboBoxItem] = CharacterSelector.Items.Cast<string>().Concat(new List<string>() { (string)SelectedComboBoxItem }).ToList();
Accents.Mappings_Removed[(string)SelectedComboBoxItem] = RemovedCharactersSelector.Items.Cast<string>().ToList();
}
private void SaveChangesToDisk()
{
Accents.Save();
}
private void Add_Click(object sender, EventArgs e)
{
var selectedItem = RemovedCharactersSelector.SelectedItem;
if (selectedItem == null)
{
return;
}
RemovedCharactersSelector.Items.Remove(selectedItem);
CharacterSelector.Items.Add(selectedItem);
}
private void Remove_Click(object sender, EventArgs e)
{
var selectedItem = CharacterSelector.SelectedItem;
if (selectedItem == null)
{
return;
}
CharacterSelector.Items.Remove(selectedItem);
RemovedCharactersSelector.Items.Add(selectedItem);
}
private void ConfigureCharacters_FormClosing(object sender, FormClosingEventArgs e)
{
if (CharacterSelector.Items.Count > 0 || RemovedCharactersSelector.Items.Count > 0)
{
SaveCurrentSelector();
}
SaveChangesToDisk();
}
}
}