forked from nbauernfeind/deephaven-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionManagerDialog.cs
More file actions
75 lines (61 loc) · 2.27 KB
/
ConnectionManagerDialog.cs
File metadata and controls
75 lines (61 loc) · 2.27 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
using Deephaven.ExcelAddIn.Util;
using Deephaven.ExcelAddIn.Viewmodels;
namespace Deephaven.ExcelAddIn.Views;
using SelectedRowsAction = Action<ConnectionManagerDialogRow[]>;
public partial class ConnectionManagerDialog : Form {
public event Action? OnNewButtonClicked;
public event SelectedRowsAction? OnDeleteButtonClicked;
public event SelectedRowsAction? OnReconnectButtonClicked;
public event SelectedRowsAction? OnMakeDefaultButtonClicked;
public event SelectedRowsAction? OnEditButtonClicked;
private readonly BindingSource _bindingSource = new();
public ConnectionManagerDialog() {
InitializeComponent();
_bindingSource.DataSource = typeof(ConnectionManagerDialogRow);
dataGridView1.DataSource = _bindingSource;
versionLabel.Text = Utility.VersionString;
}
public void AddRow(ConnectionManagerDialogRow row) {
if (InvokeRequired) {
Invoke(() => AddRow(row));
return;
}
_bindingSource.Add(row);
dataGridView1.ClearSelection();
}
public void RemoveRow(ConnectionManagerDialogRow row) {
if (InvokeRequired) {
Invoke(() => RemoveRow(row));
return;
}
_bindingSource.Remove(row);
}
private void newButton_Click(object sender, EventArgs e) {
OnNewButtonClicked?.Invoke();
}
private void reconnectButton_Click(object sender, EventArgs e) {
var selections = GetSelectedRows();
OnReconnectButtonClicked?.Invoke(selections);
}
private void editButton_Click(object sender, EventArgs e) {
var selections = GetSelectedRows();
OnEditButtonClicked?.Invoke(selections);
}
private void deleteButton_Click(object sender, EventArgs e) {
var selections = GetSelectedRows();
OnDeleteButtonClicked?.Invoke(selections);
}
private void makeDefaultButton_Click(object sender, EventArgs e) {
var selections = GetSelectedRows();
OnMakeDefaultButtonClicked?.Invoke(selections);
}
private ConnectionManagerDialogRow[] GetSelectedRows() {
var result = new List<ConnectionManagerDialogRow>();
var sr = dataGridView1.SelectedRows;
var count = sr.Count;
for (var i = 0; i != count; ++i) {
result.Add((ConnectionManagerDialogRow)sr[i].DataBoundItem);
}
return result.ToArray();
}
}