-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilePickerDialog.cs
More file actions
157 lines (131 loc) · 4.56 KB
/
FilePickerDialog.cs
File metadata and controls
157 lines (131 loc) · 4.56 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
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;
namespace slidegrid;
public partial class FilePickerDialog : Form
{
public FilePickerDialog()
{
InitializeComponent();
trvLocation.BeginUpdate();
foreach(var drive in DriveInfo.GetDrives())
{
var name = drive.Name.Replace("\\", string.Empty);
trvLocation.Nodes.Add(name);
}
trvLocation.EndUpdate();
}
////////////////////////////////////////////////////////////////////////////////////////////////
// Set by Owner before form is shown
public Action<string> AddItemCallback { get; set; }
////////////////////////////////////////////////////////////////////////////////////////////////
private void FilePickerDialog_FormClosed(object sender, FormClosedEventArgs e)
{
AddItemCallback = null;
(Owner as MainForm).SetPreviewPath(null);
(Owner as MainForm).FilePickerClosed();
}
////////////////////////////////////////////////////////////////////////////////////////////////
private void trvLocation_AfterSelect(object sender, TreeViewEventArgs e)
{
var path = trvLocation.SelectedNode.FullPath + "\\";
if (trvLocation.SelectedNode.Nodes.Count == 0)
{
trvLocation.BeginUpdate();
foreach (var dir in new DirectoryInfo(path).EnumerateDirectories())
{
if((dir.Attributes & FileAttributes.Hidden) == 0 && (dir.Attributes & FileAttributes.System) == 0)
{
trvLocation.SelectedNode.Nodes.Add(dir.Name);
}
}
trvLocation.EndUpdate();
}
lstFiles.Items.Clear();
var files = new List<FileInfo>();
foreach (var file in new DirectoryInfo(path).EnumerateFiles())
{
if ((file.Attributes & FileAttributes.Hidden) == 0
&& (file.Attributes & FileAttributes.System) == 0
&& file.Name.IsSupportedFileType())
{
files.Add(file);
}
}
foreach (var file in files)
{
lstFiles.Items.Add($"{file.LastWriteTime:yyyy-MM-dd hh:mm:ss tt} {file.Name}");
}
}
private void btnAddDirectory_Click(object sender, EventArgs e)
{
var dir = GetCurrentDirectory();
if (dir is null) return;
AddItemCallback($"{dir}*");
}
private void btnNetwork_Click(object sender, EventArgs e)
{
// TODO prompt for network share
MessageBox.Show("TODO");
}
////////////////////////////////////////////////////////////////////////////////////////////////
private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
{
(Owner as MainForm).SetPreviewPath(GetFullPathname());
}
private void btnSort_Click(object sender, EventArgs e)
{
// TODO toggle sort mode
MessageBox.Show("TODO");
}
private void btnAddFile_Click(object sender, EventArgs e)
{
if (lstFiles.Items.Count == 0 || lstFiles.SelectedItems.Count == 0) return;
foreach(var item in lstFiles.SelectedItems)
{
AddItemCallback($"{GetCurrentDirectory()}{GetListFilename(item as string)}");
}
}
private void btnAddAll_Click(object sender, EventArgs e)
{
if (lstFiles.Items.Count == 0) return;
for(int i = 0; i < lstFiles.Items.Count; i++)
{
AddItemCallback(GetFullPathname(i));
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
private string GetFullPathname(int filenameIndex = -1)
{
if (trvLocation.SelectedNode is null) return null;
return $"{GetCurrentDirectory()}{GetListFilename(filenameIndex)}";
}
private string GetCurrentDirectory()
{
if (trvLocation.SelectedNode is null) return null;
return $"{trvLocation.SelectedNode.FullPath}\\";
}
private string GetListFilename(int filenameIndex = -1)
{
int i = lstFiles.SelectedIndex;
if(filenameIndex > -1 && filenameIndex < lstFiles.Items.Count)
{
i = filenameIndex;
}
else
{
if (i == -1) return null;
}
return GetListFilename(lstFiles.Items[i] as string);
}
private string GetListFilename(string itemText)
{
return itemText.Substring(24);
}
}