-
Notifications
You must be signed in to change notification settings - Fork 0
/
frm_ActionPicker.cs
173 lines (151 loc) · 5.88 KB
/
frm_ActionPicker.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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_ActionPicker : Form
{
private PasteAction selectedPasteAction;
public frm_ActionPicker()
{
InitializeComponent();
dgv_Actions.DataSource = Global.Actions;
UpdateLastApplications();
timer_ClipboardStatus.Start();
UpdateControls();
Global.OnLastActiveWindowIconChanged += Global_OnLastActiveWindowIconChanged;
Global.OnLastActiveWindowTitleChanged += Global_OnLastActiveWindowTitleChanged;
Global.LastApplications.ListChanged += LastApplications_ListChanged;
}
private void LastApplications_ListChanged(object sender, ListChangedEventArgs e)
{
UpdateLastApplications();
}
private void Global_OnLastActiveWindowTitleChanged(object sender, EventArgs e)
{
UpdateControls();
}
private void Global_OnLastActiveWindowIconChanged(object sender, EventArgs e)
{
UpdateControls();
}
private void UpdateLastApplications()
{
dgv_LastApplications.DataSource = null;
dgv_LastApplications.DataSource = Global.LastApplications;
if(dgv_LastApplications.Rows.Count >= 1)
{
dgv_LastApplications.Rows[0].Selected = true;
}
}
private void UpdateControls()
{
if (Clipboard.ContainsText() && dgv_LastApplications.SelectedRows.Count >= 1)
{
lbl_ClipboardStatus.Text = "Contains text";
lbl_ClipboardStatus.ForeColor = Color.Green;
btn_Paste.Enabled = true;
}
else if (dgv_Actions.SelectedRows.Count == 0)
{
lbl_ClipboardStatus.Text = "No action is selected";
lbl_ClipboardStatus.ForeColor = Color.Red;
btn_Paste.Enabled = false;
}
else if (dgv_LastApplications.SelectedRows.Count == 0)
{
lbl_ClipboardStatus.Text = "No application is selected";
lbl_ClipboardStatus.ForeColor = Color.Red;
btn_Paste.Enabled = false;
}
else if (Clipboard.ContainsImage())
{
lbl_ClipboardStatus.Text = "Contains image";
lbl_ClipboardStatus.ForeColor = Color.Red;
btn_Paste.Enabled = false;
}
else if (Clipboard.ContainsAudio())
{
lbl_ClipboardStatus.Text = "Contains audio";
lbl_ClipboardStatus.ForeColor = Color.Red;
btn_Paste.Enabled = false;
}
else if (Clipboard.ContainsFileDropList())
{
lbl_ClipboardStatus.Text = "Contains files";
lbl_ClipboardStatus.ForeColor = Color.Red;
btn_Paste.Enabled = false;
}
else
{
lbl_ClipboardStatus.Text = "Clipboard is empty";
lbl_ClipboardStatus.ForeColor = Color.Red;
btn_Paste.Enabled = false;
}
foreach(DataGridViewRow row in dgv_Actions.Rows)
{
if (row.DataBoundItem == null) { continue; }
try
{
PasteAction pa = row.DataBoundItem as PasteAction;
if (PasteAction.ReservedIDs.Contains(pa.ID))
{
row.Visible = false;
}
}
catch { }
}
}
private void timer_ClipboardStatus_Tick(object sender, EventArgs e)
{
UpdateControls();
}
private void btn_Execute_Click(object sender, EventArgs e)
{
if(dgv_Actions.SelectedRows.Count <= 0) { MessageBox.Show("No action is selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
if(dgv_LastApplications.SelectedRows.Count <= 0) { MessageBox.Show("No application is selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
selectedPasteAction = dgv_Actions.SelectedRows[0].DataBoundItem as PasteAction;
Classes.Application selectedApplication = dgv_LastApplications.SelectedRows[0].DataBoundItem as Classes.Application;
if(selectedApplication.WindowHandle == IntPtr.Zero)
{
MessageBox.Show("There is something wrong with the selected application", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
}
selectedPasteAction.Paste(selectedApplication.WindowHandle, selectedApplication.LastActiveWindowMode);
}
private void dgv_Actions_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dgv_Actions.SelectedRows.Count >= 1)
{
selectedPasteAction = dgv_Actions.SelectedRows[0].DataBoundItem as PasteAction;
}
else
{
selectedPasteAction = null;
}
UpdateControls();
}
private void dgv_Actions_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void frm_ActionPicker_Shown(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.Activate();
}
private void dgv_LastApplications_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
e.ThrowException = false;
}
}
}