-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSBdeviceView.cs
83 lines (71 loc) · 2.34 KB
/
USBdeviceView.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlashUSB
{
internal class USBdeviceView
{
private const string activatedGroupName = "listViewGroupAktivert";
readonly USBmemoryDevice mDevice;
readonly ListView myView;
ListViewItem? mItem = null;
public ListView.ListViewItemCollection Items { get { return myView.Items; } }
public ListView View { get { return myView; } }
public USBdeviceView(USBmemoryDevice device, ListView view)
{
mDevice = device;
myView = view;
}
internal void UpdateDisk(string drive, string? diskName)
{
if (mItem != null)
{
mItem.SubItems[1].Text = drive;
mItem.SubItems[2].Text = diskName;
}
}
internal void UpdateColorActionItem(Color backColor, Color foreColor, string newText)
{
if (mItem != null)
{
mItem.UseItemStyleForSubItems = false;
var subIt = mItem.SubItems[0];
subIt.Text = newText;
subIt.BackColor = backColor;
subIt.ForeColor = foreColor;
}
}
internal void Add2View(ListViewItem listViewItem, string groupNavn, string toolTipText="")
{
mItem = listViewItem;
mItem.Tag = mDevice;
ListViewGroup group = myView.Groups[groupNavn];
mItem.Group = group;
myView.Items.Add(mItem);
SetHubColor(mItem.SubItems[^1], group.Name == activatedGroupName);
mItem.ToolTipText = toolTipText; // Doesn't seem to work
}
private static void SetHubColor(ListViewItem.ListViewSubItem hubItem, bool activated)
{
hubItem.BackColor = activated ? Color.Red : Color.White;
}
internal void Remove()
{
if (mItem != null)
{
mItem.Remove();
mItem = null;
}
}
internal void ChangeGroup(string group)
{
if (mItem != null)
{
mItem.Group = myView.Groups[group];
SetHubColor(mItem.SubItems[^1], group == activatedGroupName);
}
}
}
}