-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShortlistManagerForm.cs
117 lines (99 loc) · 3.83 KB
/
ShortlistManagerForm.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
using Microsoft.Win32;
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
namespace CefSharp.MinimalExample.WinForms
{
public partial class ShortlistManagerForm : Form
{
public ShortlistManagerForm()
{
InitializeComponent();
InitialiseShortlistNameComboBoxValues();
EnsureButtonStateCorrect();
cbShortlistName.Width -= 1;
cbShortlistName.Height -= 1;
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (DialogResult.Yes == MessageBox.Show("Are you sure you want to delete? This action cannot be undone.", "Confirm deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
{
var shortlistId = (cbShortlistName.SelectedItem as ComboBoxItem).Value.ToString();
Registry.CurrentUser.DeleteSubKey(@"SOFTWARE\HomeHunter\Shortlists\" + shortlistId);
InitialiseShortlistNameComboBoxValues();
EnsureButtonStateCorrect();
}
}
private void EnsureButtonStateCorrect()
{
if (!string.IsNullOrEmpty(cbShortlistName.Text))
{
btnDelete.Enabled = true;
btnEdit.Enabled = true;
}
else
{
btnDelete.Enabled = false;
btnEdit.Enabled = false;
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
ShortlistEditor.Open((cbShortlistName.SelectedItem as ComboBoxItem).Value.ToString(), () =>
{
var shortlistManagerForm = new ShortlistManagerForm();
shortlistManagerForm.Show();
});
Close();
}
private void InitialiseShortlistNameComboBoxValues()
{
cbShortlistName.Items.Clear();
var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\HomeHunter\Shortlists");
if (key == null)
return;
foreach (string subKeyName in key.GetSubKeyNames())
{
using (RegistryKey tempKey = key.OpenSubKey(subKeyName))
{
string shortlistName = tempKey.GetValue("Name").ToString();
var item = new ComboBoxItem();
item.Text = shortlistName;
item.Value = subKeyName;
cbShortlistName.Items.Add(item);
}
}
ResortComboBoxItemCollection(cbShortlistName.Items);
if (cbShortlistName.Items.Count > 0)
{
cbShortlistName.SelectedIndex = 0;
}
}
private void ResortComboBoxItemCollection(ComboBox.ObjectCollection coll)
{
var oAList = new ArrayList(coll);
oAList.Sort(new ComboBoxItemComparer());
coll.Clear();
foreach (object oItem in oAList)
{
coll.Add(oItem);
}
}
// Fix combox box style.
protected override void OnPaint(PaintEventArgs e)
{
//TODO: Black is the wrong color it is too dark.
SolidBrush myBrush = new SolidBrush(Color.Black);
Graphics formGraphics;
formGraphics = CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(cbShortlistName.Left - 1, cbShortlistName.Top - 1, cbShortlistName.Width + 2, cbShortlistName.Height + 2));
formGraphics.Dispose();
myBrush.Dispose();
}
private void cbShortlistName_SelectedIndexChanged(object sender, EventArgs e)
{
EnsureButtonStateCorrect();
}
}
}