-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrm_Actions.cs
112 lines (97 loc) · 3.11 KB
/
frm_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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Paster.Classes;
namespace Paster
{
public partial class frm_Actions : Form
{
private PasteAction selectedPasteAction;
public frm_Actions()
{
InitializeComponent();
dgv_Actions.DataSource = Global.Actions;
}
private void btn_Edit_Click(object sender, EventArgs e)
{
if(this.selectedPasteAction != null)
{
using(frm_ActionEditor dialog = new frm_ActionEditor(selectedPasteAction))
{
dialog.ShowDialog();
if(dialog.DialogResult == DialogResult.OK)
{
Global.RegisterActionHotkeys();
}
}
}
UpdateControls();
UpdateDataGridView();
}
private void UpdateControls()
{
if (dgv_Actions.SelectedRows.Count >= 1) {
this.btn_Edit.Enabled = true;
if (PasteAction.ReservedIDs.Contains(this.selectedPasteAction.ID))
{
this.btn_Delete.Enabled = false;
}
else
{
this.btn_Delete.Enabled = true;
}
}
else { this.btn_Edit.Enabled = false; }
}
private void UpdateDataGridView()
{
dgv_Actions.DataSource = null;
dgv_Actions.DataSource = Global.Actions;
}
private void dgv_Actions_SelectionChanged(object sender, EventArgs e)
{
if(dgv_Actions.SelectedRows.Count >= 1)
{
selectedPasteAction = dgv_Actions.SelectedRows[0].DataBoundItem as PasteAction;
}
else
{
selectedPasteAction = null;
}
UpdateControls();
}
private void btn_Add_Click(object sender, EventArgs e)
{
using (frm_ActionEditor dialog = new frm_ActionEditor())
{
dialog.ShowDialog();
UpdateControls();
UpdateDataGridView();
Global.RegisterActionHotkeys();
}
}
private void btn_Delete_Click(object sender, EventArgs e)
{
if(selectedPasteAction != null)
{
DialogResult result = MessageBox.Show("Are you sure you want to delete " + selectedPasteAction.Name, "Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if(result == DialogResult.Yes)
{
Global.Actions.Remove(selectedPasteAction);
Global.SaveActions();
UpdateDataGridView();
}
}
}
private void btn_Close_Click(object sender, EventArgs e)
{
this.Close();
}
}
}