Skip to content

Commit c5724e6

Browse files
committed
Improvements to filters
Added new Disk Type filter
1 parent b296373 commit c5724e6

File tree

10 files changed

+465
-130
lines changed

10 files changed

+465
-130
lines changed

DiskImageTool/ComboFilter.vb

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
Public Class ComboFilter
2+
Private ReadOnly _Filter As Dictionary(Of String, ComboFilterItem)
3+
Private ReadOnly _Combo As ToolStripComboBox
4+
5+
Public Sub New(ComboBox As ToolStripComboBox)
6+
_Combo = ComboBox
7+
_Combo.ComboBox.DrawMode = DrawMode.OwnerDrawFixed
8+
AddHandler _Combo.ComboBox.DrawItem, AddressOf DrawItem
9+
10+
_Filter = New Dictionary(Of String, ComboFilterItem)
11+
End Sub
12+
13+
Public Sub Add(Name As String, UpdateFilters As Boolean)
14+
If Name = "" Then
15+
Return
16+
End If
17+
18+
If _Filter.ContainsKey(Name) Then
19+
Dim Item = _Filter.Item(Name)
20+
Item.Count += 1
21+
22+
If UpdateFilters Then
23+
Dim Index = _Combo.Items.IndexOf(Item)
24+
_Combo.Items.Item(Index) = Item
25+
End If
26+
Else
27+
Dim Item = New ComboFilterItem With {
28+
.Name = Name,
29+
.Count = 1
30+
}
31+
_Filter.Add(Item.Name, Item)
32+
33+
If UpdateFilters Then
34+
_Combo.Items.Add(Item)
35+
End If
36+
End If
37+
End Sub
38+
39+
Public Sub Clear()
40+
_Filter.Clear()
41+
_Combo.Items.Clear()
42+
End Sub
43+
44+
Public Sub ClearFilter()
45+
If _Combo.Items.Count > 0 Then
46+
_Combo.SelectedIndex = 0
47+
End If
48+
End Sub
49+
50+
Public Sub Populate()
51+
Dim Item As ComboFilterItem
52+
53+
_Combo.BeginUpdate()
54+
_Combo.Items.Clear()
55+
_Combo.Sorted = True
56+
For Each Item In _Filter.Values
57+
_Combo.Items.Add(Item)
58+
Next
59+
Item = New ComboFilterItem With {
60+
.AllItems = True
61+
}
62+
_Combo.Sorted = False
63+
_Combo.Items.Insert(0, Item)
64+
_Combo.SelectedIndex = 0
65+
_Combo.EndUpdate()
66+
End Sub
67+
68+
Public Sub Remove(Name As String, UpdateFilters As Boolean)
69+
If Name = "" Then
70+
Return
71+
End If
72+
73+
If _Filter.ContainsKey(Name) Then
74+
Dim Item = _Filter.Item(Name)
75+
Item.Count -= 1
76+
If Item.Count = 0 Then
77+
_Filter.Remove(Item.Name)
78+
79+
If UpdateFilters Then
80+
_Combo.Items.Remove(Item)
81+
If _Combo.SelectedIndex = -1 Then
82+
_Combo.SelectedIndex = 0
83+
End If
84+
End If
85+
Else
86+
If UpdateFilters Then
87+
Dim Index = _Combo.Items.IndexOf(Item)
88+
_Combo.Items.Item(Index) = Item
89+
End If
90+
End If
91+
End If
92+
End Sub
93+
94+
Private Sub DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)
95+
e.DrawBackground()
96+
97+
If e.Index >= 0 Then
98+
Dim Item As ComboFilterItem = _Combo.Items(e.Index)
99+
100+
Dim Brush As Brush
101+
Dim tBrush As Brush
102+
Dim nBrush As Brush
103+
104+
If e.State And DrawItemState.Selected Then
105+
Brush = New SolidBrush(SystemColors.Highlight)
106+
tBrush = New SolidBrush(SystemColors.HighlightText)
107+
nBrush = New SolidBrush(SystemColors.HighlightText)
108+
Else
109+
Brush = New SolidBrush(SystemColors.Window)
110+
tBrush = New SolidBrush(SystemColors.WindowText)
111+
nBrush = New SolidBrush(Color.Blue)
112+
End If
113+
114+
e.Graphics.FillRectangle(Brush, e.Bounds)
115+
116+
Dim Name As String
117+
Dim Count As String
118+
If Item.AllItems Then
119+
Name = "(ALL)"
120+
Count = ""
121+
Else
122+
Name = Item.Name
123+
Count = Item.Count
124+
End If
125+
126+
Dim r1 As Rectangle = e.Bounds
127+
128+
If (e.State And DrawItemState.ComboBoxEdit) <> DrawItemState.ComboBoxEdit Then
129+
If Count <> "" Then
130+
Dim Width = TextRenderer.MeasureText(Count, e.Font).Width + 2
131+
r1.Width -= Width
132+
Dim r2 As Rectangle = e.Bounds
133+
r2.X = r2.Width - Width
134+
e.Graphics.DrawString(Count, e.Font, nBrush, r2, StringFormat.GenericDefault)
135+
End If
136+
End If
137+
138+
e.Graphics.DrawString(Name, e.Font, tBrush, r1, StringFormat.GenericDefault)
139+
140+
nBrush.Dispose()
141+
tBrush.Dispose()
142+
Brush.Dispose()
143+
End If
144+
145+
e.DrawFocusRectangle()
146+
End Sub
147+
End Class
148+
149+
Public Class ComboFilterItem
150+
Public Property AllItems As Boolean = False
151+
Public Property Count As Integer
152+
Public Property Name As String
153+
154+
Public Overrides Function ToString() As String
155+
If AllItems Then
156+
Return "(ALL)"
157+
Else
158+
Return Name & " [" & _Count & "]"
159+
End If
160+
End Function
161+
162+
End Class

DiskImageTool/DiskImage/FloppyDiskFunctions.vb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,9 @@
286286
Public Function GetFloppyDiskTypeName(BootSector As BootSector) As String
287287
Return GetFloppyDiskTypeName(GetFloppyDiskType(BootSector))
288288
End Function
289+
290+
Public Function GetFloppyDiskTypeName(Size As Integer) As String
291+
Return GetFloppyDiskTypeName(GetFloppyDiskType(Size))
292+
End Function
289293
End Module
290294
End Namespace

DiskImageTool/DiskImageTool.vbproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ProductName>DiskImageTool</ProductName>
3131
<PublisherName>Digitoxin</PublisherName>
3232
<ApplicationRevision>0</ApplicationRevision>
33-
<ApplicationVersion>1.34.0.%2a</ApplicationVersion>
33+
<ApplicationVersion>1.35.0.%2a</ApplicationVersion>
3434
<UseApplicationTrust>false</UseApplicationTrust>
3535
<PublishWizardCompleted>true</PublishWizardCompleted>
3636
<BootstrapperEnabled>true</BootstrapperEnabled>
@@ -121,6 +121,7 @@
121121
<Import Include="System.Threading.Tasks" />
122122
</ItemGroup>
123123
<ItemGroup>
124+
<Compile Include="ComboFilter.vb" />
124125
<Compile Include="Controls\ToolStripCheckBox.vb">
125126
<SubType>Component</SubType>
126127
</Compile>
@@ -250,6 +251,7 @@
250251
<Compile Include="Controls\ToolStripNumericUpDown.vb">
251252
<SubType>Component</SubType>
252253
</Compile>
254+
<Compile Include="WindowsAPI.vb" />
253255
</ItemGroup>
254256
<ItemGroup>
255257
<EmbeddedResource Include="Forms\AboutBox.resx">

DiskImageTool/Forms/ItemScanForm.vb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Public Class ItemScanForm
77
Private _Activated As Boolean = False
88
Private _EndScan As Boolean = False
99
Private _ScanComplete As Boolean = False
10+
Private _ItemsRemaining As UInteger
1011

1112
Public Sub New(Parent As MainForm, ImageList As ComboBox.ObjectCollection, NewOnly As Boolean)
1213

@@ -17,24 +18,33 @@ Public Class ItemScanForm
1718
_Parent = Parent
1819
_ImageList = ImageList
1920
_NewOnly = NewOnly
21+
_ItemsRemaining = ImageList.Count
22+
If _NewOnly Then
23+
For Each ImageData As LoadedImageData In ImageList
24+
If ImageData.Scanned Then
25+
_ItemsRemaining -= 1
26+
End If
27+
Next
28+
End If
2029
End Sub
2130

31+
Public ReadOnly Property ItemsRemaining As Boolean
32+
Get
33+
Return _ItemsRemaining
34+
End Get
35+
End Property
36+
2237
Public ReadOnly Property ScanComplete As Boolean
2338
Get
2439
Return _ScanComplete
2540
End Get
2641
End Property
2742

2843
Private Function ProcessScan(bw As BackgroundWorker) As Boolean
29-
Dim ItemCount As Integer = 0
30-
If _NewOnly Then
31-
For Each ImageData As LoadedImageData In _ImageList
32-
If Not ImageData.Scanned Then
33-
ItemCount += 1
34-
End If
35-
Next
36-
Else
37-
ItemCount = _ImageList.Count
44+
Dim ItemCount As Integer = _ItemsRemaining
45+
46+
If ItemCount = 0 Then
47+
Return True
3848
End If
3949

4050
Dim PrevPercentage As Integer = 0
@@ -55,13 +65,15 @@ Public Class ItemScanForm
5565
_Parent.ItemScanModified(Disk, ImageData)
5666
_Parent.ItemScanDisk(Disk, ImageData)
5767
_Parent.ItemScanOEMName(Disk, ImageData)
58-
_Parent.UpdateOEMNameFilter(Disk, ImageData)
68+
_Parent.OEMNameFilterUpdate(Disk, ImageData)
69+
_Parent.DiskTypeFilterUpdate(Disk, ImageData)
5970
_Parent.ItemScanUnusedClusters(Disk, ImageData)
6071
_Parent.ItemScanDirectory(Disk, ImageData)
6172

6273
ImageData.Scanned = True
6374
End If
6475
Counter += 1
76+
_ItemsRemaining -= 1
6577
End If
6678
Next
6779

DiskImageTool/LoadedImageData.vb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Public Class ImageDataScanInfo
44
Public Property DirectoryHasAdditionalData As Boolean = False
55
Public Property DirectoryHasBootSector As Boolean = False
6+
Public Property DiskType As String = ""
67
Public Property HasBadSectors As Boolean = False
78
Public Property HasCreated As Boolean = False
89
Public Property HasFATChainingErrors As Boolean = False

DiskImageTool/MainForm.Designer.vb

Lines changed: 28 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DiskImageTool/MainForm.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@
493493
<metadata name="BtnResetSort.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
494494
<value>True</value>
495495
</metadata>
496+
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
497+
<value>True</value>
498+
</metadata>
496499
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
497500
<value>53</value>
498501
</metadata>

0 commit comments

Comments
 (0)