Skip to content

Commit d493809

Browse files
committed
Add drag-and-drop file import to ImportFileForm
Refactored ImportFileForm event handlers into a dedicated region for better organization. Added drag-and-drop support to ListViewFiles, allowing users to import files by dragging them into the control. Ensured imported file list remains unique with the new AppendDistinct helper. Updated application and file version to 2.36.0.
1 parent 17be336 commit d493809

File tree

3 files changed

+123
-84
lines changed

3 files changed

+123
-84
lines changed

DiskImageTool/DiskImageTool.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<ProductName>DiskImageTool</ProductName>
3232
<PublisherName>Digitoxin</PublisherName>
3333
<ApplicationRevision>0</ApplicationRevision>
34-
<ApplicationVersion>2.35.0.%2a</ApplicationVersion>
34+
<ApplicationVersion>2.36.0.%2a</ApplicationVersion>
3535
<UseApplicationTrust>false</UseApplicationTrust>
3636
<PublishWizardCompleted>true</PublishWizardCompleted>
3737
<BootstrapperEnabled>true</BootstrapperEnabled>

DiskImageTool/Forms/ImportFileForm.vb

Lines changed: 121 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ Public Class ImportFileForm
55
Private Const COLUMN_CREATION_TIME As String = "CreationTime"
66
Private Const COLUMN_IS_SELECTED As String = "IsSelected"
77
Private Const COLUMN_LAST_ACCESS_TIME As String = "LastAccessTime"
8-
Private ReadOnly _FileNames() As String
8+
Private _FileNames() As String
99
Private ReadOnly _SelectionByPath As New Dictionary(Of String, Boolean)
1010
Private _FileList As ImportDirectoryRoot
1111
Private _HasLFN As Boolean
1212
Private _HasNTExtensions As Boolean
1313
Private _IgnoreEvent As Boolean = False
1414
Private _LastSelectedIndex As Integer = -1
1515
Private _ListViewHeader As ListViewHeader
16+
1617
Public Sub New(CurrentDirectory As IDirectory, FileNames() As String)
1718

1819
' This call is required by the designer.
@@ -95,46 +96,15 @@ Public Class ImportFileForm
9596
cbo.Width = maxWidth
9697
End Sub
9798

98-
Private Sub ChkCreated_CheckedChanged(sender As Object, e As EventArgs) Handles ChkCreated.CheckedChanged
99-
If _IgnoreEvent Then Exit Sub
100-
101-
_FileList.Options.UseCreatedDate = ChkCreated.Checked
102-
RefreshCreated()
103-
End Sub
104-
105-
Private Sub ChkLastAccessed_CheckedChanged(sender As Object, e As EventArgs) Handles ChkLastAccessed.CheckedChanged
106-
If _IgnoreEvent Then Exit Sub
107-
108-
_FileList.Options.UseLastAccessedDate = ChkLastAccessed.Checked
109-
RefreshLastAccessed()
110-
End Sub
111-
112-
Private Sub ChkLFN_CheckedChanged(sender As Object, e As EventArgs) Handles ChkLFN.CheckedChanged
113-
If _IgnoreEvent Then Exit Sub
114-
115-
ChkNTExtensions.Enabled = ChkLFN.Checked
116-
_FileList.SetOptions(ChkLFN.Checked, ChkLFN.Checked And ChkNTExtensions.Checked)
117-
RefreshTotals()
118-
End Sub
119-
120-
Private Sub ChkNTExtensions_CheckedChanged(sender As Object, e As EventArgs) Handles ChkNTExtensions.CheckedChanged
121-
If _IgnoreEvent Then Exit Sub
122-
123-
_FileList.SetOptions(ChkLFN.Checked, ChkLFN.Checked And ChkNTExtensions.Checked)
124-
RefreshTotals()
125-
End Sub
126-
127-
Private Sub ComboDirectoryList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboDirectoryList.SelectedIndexChanged
128-
If _IgnoreEvent Then Exit Sub
129-
130-
If _LastSelectedIndex = ComboDirectoryList.SelectedIndex Then
131-
Exit Sub
99+
Private Function GetForeColor(IsFileTooLarge As Boolean, IsEnabled As Boolean) As Color
100+
If IsFileTooLarge Then
101+
Return Color.Gray
102+
ElseIf Not IsEnabled Then
103+
Return Color.Gray
104+
Else
105+
Return SystemColors.WindowText
132106
End If
133-
134-
_LastSelectedIndex = ComboDirectoryList.SelectedIndex
135-
136-
RefreshFileList()
137-
End Sub
107+
End Function
138108

139109
Private Function GetPathString(Directory As IDirectory) As String
140110
Dim PathString As String = ""
@@ -245,38 +215,6 @@ Public Class ImportFileForm
245215
ProcessFiles(ImportDirectory, Group, Folder.GetFiles.ToList)
246216
End Sub
247217

248-
Private Sub ImportFileForm_Load(sender As Object, e As EventArgs) Handles Me.Load
249-
ListViewFiles.DoubleBuffer
250-
_ListViewHeader = New ListViewHeader(ListViewFiles.Handle)
251-
End Sub
252-
253-
Private Sub ListViewFiles_ColumnWidthChanging(sender As Object, e As ColumnWidthChangingEventArgs) Handles ListViewFiles.ColumnWidthChanging
254-
e.NewWidth = Me.ListViewFiles.Columns(e.ColumnIndex).Width
255-
e.Cancel = True
256-
End Sub
257-
258-
Private Sub ListViewFiles_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles ListViewFiles.ItemCheck
259-
If _IgnoreEvent Then Exit Sub
260-
261-
If e.NewValue = e.CurrentValue Then
262-
Exit Sub
263-
End If
264-
265-
Dim Item As ListViewItem = ListViewFiles.Items(e.Index)
266-
267-
Dim FileData As ImportFile = Item.Tag
268-
269-
If FileData.IsFileTooLarge Then
270-
If e.NewValue Then
271-
e.NewValue = False
272-
End If
273-
Else
274-
FileData.IsSelected = e.NewValue
275-
End If
276-
277-
RefreshTotals()
278-
End Sub
279-
280218
Private Sub LocalizeForm()
281219
BtnCancel.Text = WithoutHotkey(My.Resources.Menu_Cancel)
282220
BtnOK.Text = WithoutHotkey(My.Resources.Label_Import)
@@ -443,16 +381,6 @@ Public Class ImportFileForm
443381
_IgnoreEvent = False
444382
End Sub
445383

446-
Private Function GetForeColor(IsFileTooLarge As Boolean, IsEnabled As Boolean) As Color
447-
If IsFileTooLarge Then
448-
Return Color.Gray
449-
ElseIf Not IsEnabled Then
450-
Return Color.Gray
451-
Else
452-
Return SystemColors.WindowText
453-
End If
454-
End Function
455-
456384
Private Sub RefreshLastAccessed()
457385
For Each Item As ListViewItem In ListViewFiles.Items
458386
Dim FileData As ImportFile = Item.Tag
@@ -511,6 +439,117 @@ Public Class ImportFileForm
511439
SaveSelectionsFromDirectory(subDir)
512440
Next
513441
End Sub
442+
443+
Private Shared Function AppendDistinct(baseArray As String(), appendArray As String()) As String()
444+
Dim setSeen As New HashSet(Of String)(baseArray)
445+
Dim result As New List(Of String)(baseArray)
446+
447+
For Each s In appendArray
448+
If setSeen.Add(s) Then
449+
result.Add(s)
450+
End If
451+
Next
452+
453+
Return result.ToArray()
454+
End Function
455+
456+
#Region "Events"
457+
Private Sub ChkCreated_CheckedChanged(sender As Object, e As EventArgs) Handles ChkCreated.CheckedChanged
458+
If _IgnoreEvent Then Exit Sub
459+
460+
_FileList.Options.UseCreatedDate = ChkCreated.Checked
461+
RefreshCreated()
462+
End Sub
463+
464+
Private Sub ChkLastAccessed_CheckedChanged(sender As Object, e As EventArgs) Handles ChkLastAccessed.CheckedChanged
465+
If _IgnoreEvent Then Exit Sub
466+
467+
_FileList.Options.UseLastAccessedDate = ChkLastAccessed.Checked
468+
RefreshLastAccessed()
469+
End Sub
470+
471+
Private Sub ChkLFN_CheckedChanged(sender As Object, e As EventArgs) Handles ChkLFN.CheckedChanged
472+
If _IgnoreEvent Then Exit Sub
473+
474+
ChkNTExtensions.Enabled = ChkLFN.Checked
475+
_FileList.SetOptions(ChkLFN.Checked, ChkLFN.Checked And ChkNTExtensions.Checked)
476+
RefreshTotals()
477+
End Sub
478+
479+
Private Sub ChkNTExtensions_CheckedChanged(sender As Object, e As EventArgs) Handles ChkNTExtensions.CheckedChanged
480+
If _IgnoreEvent Then Exit Sub
481+
482+
_FileList.SetOptions(ChkLFN.Checked, ChkLFN.Checked And ChkNTExtensions.Checked)
483+
RefreshTotals()
484+
End Sub
485+
486+
Private Sub ComboDirectoryList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboDirectoryList.SelectedIndexChanged
487+
If _IgnoreEvent Then Exit Sub
488+
489+
If _LastSelectedIndex = ComboDirectoryList.SelectedIndex Then
490+
Exit Sub
491+
End If
492+
493+
_LastSelectedIndex = ComboDirectoryList.SelectedIndex
494+
495+
RefreshFileList()
496+
End Sub
497+
498+
Private Sub ImportFileForm_Load(sender As Object, e As EventArgs) Handles Me.Load
499+
ListViewFiles.DoubleBuffer
500+
_ListViewHeader = New ListViewHeader(ListViewFiles.Handle)
501+
End Sub
502+
503+
Private Sub ListViewFiles_ColumnWidthChanging(sender As Object, e As ColumnWidthChangingEventArgs) Handles ListViewFiles.ColumnWidthChanging
504+
e.NewWidth = Me.ListViewFiles.Columns(e.ColumnIndex).Width
505+
e.Cancel = True
506+
End Sub
507+
508+
Private Sub ListViewFiles_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles ListViewFiles.ItemCheck
509+
If _IgnoreEvent Then Exit Sub
510+
511+
If e.NewValue = e.CurrentValue Then
512+
Exit Sub
513+
End If
514+
515+
Dim Item As ListViewItem = ListViewFiles.Items(e.Index)
516+
517+
Dim FileData As ImportFile = Item.Tag
518+
519+
If FileData.IsFileTooLarge Then
520+
If e.NewValue Then
521+
e.NewValue = False
522+
End If
523+
Else
524+
FileData.IsSelected = e.NewValue
525+
End If
526+
527+
RefreshTotals()
528+
End Sub
529+
530+
Private Sub ListViewFiles_DragEnter(sender As Object, e As DragEventArgs) Handles ListViewFiles.DragEnter
531+
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
532+
e.Effect = DragDropEffects.Copy
533+
End If
534+
End Sub
535+
536+
Private Sub ListViewFiles_DragDrop(sender As Object, e As DragEventArgs) Handles ListViewFiles.DragDrop
537+
If Not e.Data.GetDataPresent(DataFormats.FileDrop) Then
538+
Exit Sub
539+
End If
540+
541+
Dim Files As String() = TryCast(e.Data.GetData(DataFormats.FileDrop), String())
542+
543+
If Files Is Nothing OrElse Files.Length = 0 Then
544+
Exit Sub
545+
End If
546+
547+
_FileNames = AppendDistinct(_FileNames, Files)
548+
549+
RefreshFileList()
550+
End Sub
551+
#End Region
552+
514553
Public Class ImportDirectory
515554
Inherits ImportFileBase
516555

DiskImageTool/My Project/AssemblyInfo.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ Imports System.Runtime.InteropServices
3131
' <Assembly: AssemblyVersion("1.0.*")>
3232

3333
<Assembly: AssemblyVersion("1.0.0.0")>
34-
<Assembly: AssemblyFileVersion("2.35.0.0")>
34+
<Assembly: AssemblyFileVersion("2.36.0.0")>

0 commit comments

Comments
 (0)