-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaggingForm.cs
113 lines (99 loc) · 3.48 KB
/
TaggingForm.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
// Copyright Bastian Eicher
// Licensed under the MIT License
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using NanoByte.Common.Controls;
using NanoByte.Common.Storage;
namespace NanoByte.LightTag
{
public partial class TaggingForm : Form
{
public TaggingForm(string[] paths)
{
InitializeComponent();
AddFiles(paths);
}
private void TaggingForm_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
}
private void TaggingForm_DragDrop(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
var paths = e.Data.GetData(DataFormats.FileDrop) as string[];
if (paths == null) return;
AddFiles(paths);
}
private void AddFiles(string[] paths)
{
try
{
var files = Paths.ResolveFiles(paths);
listFiles.BeginUpdate();
foreach (var file in files)
{
listFiles.Items.Add(new ListViewItem(file.Name) {Tag = file});
foreach (string tagName in file.ReadTags())
tags.TreeView.CheckedEntries.Add(tags[tagName]);
}
listFiles.EndUpdate();
tags.TreeView.UpdateList();
}
#region Error handling
catch (IOException ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
catch (UnauthorizedAccessException ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
catch (Win32Exception ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
#endregion
}
private void listFiles_DoubleClick(object sender, EventArgs e)
{
if (listFiles.SelectedItems.Count == 0) return;
Process.Start(((FileInfo)listFiles.SelectedItems[0].Tag).FullName);
}
private void menuFilesRemove_Click(object sender, EventArgs e)
{
listFiles.BeginUpdate();
foreach (ListViewItem item in listFiles.SelectedItems)
listFiles.Items.Remove(item);
listFiles.EndUpdate();
}
private void buttonApply_Click(object sender, EventArgs e)
{
try
{
foreach (ListViewItem item in listFiles.Items)
((FileInfo)item.Tag).WriteTags(tags.TreeView.CheckedEntries.Select(x => x.Name));
}
#region Error handling
catch (IOException ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
catch (UnauthorizedAccessException ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
catch (Win32Exception ex)
{
Msg.Inform(this, ex.Message, MsgSeverity.Error);
}
#endregion
listFiles.Items.Clear();
tags.TreeView.CheckedEntries.Clear();
tags.TreeView.UpdateList();
}
}
}