-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChooser.cs
More file actions
161 lines (134 loc) · 4.9 KB
/
Copy pathChooser.cs
File metadata and controls
161 lines (134 loc) · 4.9 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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace RandomFilePicker
{
public partial class Chooser : Form
{
private List<FileShortInfo> allFiles = new List<FileShortInfo>();
public FileShortInfo result;
public Chooser()
{
allFiles.AddRange(PickRandomFile.allFiles);
InitializeComponent();
populateListView("");
txtSearch.Focus();
}
private void populateListView(string filterString)
{
listView1.BeginUpdate();
listView1.Items.Clear();
foreach (FileShortInfo fi in allFiles)
{
if (filterString == "" ||
fi.FullPath.ToUpper().Contains(filterString.ToUpper()) ||
fi.FullPath.ToUpper().Contains(filterString.ToUpper()))
{
ListViewItem li = new ListViewItem(fi.Directory);
li.SubItems.Add(fi.FileName);
li.Tag = fi;
listView1.Items.Add(li);
}
listView1.Refresh();
}
listView1.EndUpdate();
}
private void btngo_Click(object sender, EventArgs e)
{
if ( listView1.SelectedItems.Count == 1)
{
DialogResult = DialogResult.OK;
result = (FileShortInfo)listView1.SelectedItems[0].Tag;
}
else
{
DialogResult = DialogResult.Abort;
}
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
if (txtSearch.Text.Length > 1)
{
populateListView(txtSearch.Text);
}
}
private void Chooser_Activated(object sender, EventArgs e)
{
txtSearch.Focus();
}
private void Chooser_Shown(object sender, EventArgs e)
{
txtSearch.Focus();
}
private void txtSearch_KeyDown(object sender, KeyEventArgs e)
{
int i = -1;
if (listView1.SelectedItems.Count > 0 && listView1.SelectedIndices[0] > 0) { i = listView1.SelectedIndices[0];}
if (e.KeyData == Keys.Up && i > 0)
{
//deselect everything
foreach (ListViewItem li in listView1.Items) {li.Selected = false;}
listView1.Items[i-1].Selected = true;
}
else if (e.KeyData == Keys.Down && i >= 0 && i < listView1.Items.Count -1)
{
//deselect everything
foreach (ListViewItem li in listView1.Items) { li.Selected = false; }
listView1.Items[i + 1].Selected = true;
}
}
private void btnFolder_Click(object sender, EventArgs e)
{
foreach (ListViewItem li in listView1.SelectedItems)
{
FileShortInfo fi = (FileShortInfo)li.Tag;
System.Diagnostics.Process.Start("Explorer.exe", fi.Directory);
}
}
private void btn_Open_Only_Click(object sender, EventArgs e)
{
foreach (ListViewItem li in listView1.SelectedItems)
{
PickRandomFile.openFile((FileShortInfo)li.Tag);
}
}
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (listView1.SelectedItems.Count == 1)
{
PickRandomFile.openFile((FileShortInfo)listView1.SelectedItems[0].Tag);
}
}
private void btn_Delete_Click(object sender, EventArgs e)
{
foreach (ListViewItem li in listView1.SelectedItems)
{
FileShortInfo fi = (FileShortInfo)li.Tag;
DialogResult r = MessageBox.Show("Are you sure you want to delete this file / these files? \n\r" + fi.FullPath + "\n\r\n\rNote that the file will remain in the list until you search again", "Are you sure?", MessageBoxButtons.YesNo);
if (r == DialogResult.Yes)
{
FileInfo ffi = new FileInfo(fi.FullPath);
if (ffi.Exists)
{
ffi.Delete();
}
}
}
}
private void listView1_MouseHover(object sender, EventArgs e)
{
ListViewItem li = listView1.GetItemAt(ListBox.MousePosition.X, ListBox.MousePosition.Y);
if (li != null)
{
FileShortInfo fi = (FileShortInfo)li.Tag;
toolTip1.SetToolTip(listView1, fi.Directory);
toolTip1.Show(fi.Directory, this, 10000);
}
}
}
}