/
Form1.vb
224 lines (214 loc) · 7.67 KB
/
Form1.vb
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
Imports DevExpress.Utils.Animation
Imports DevExpress.Utils.Helpers
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.WinExplorer.ViewInfo
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Namespace dxSample
Partial Public Class Form1
Inherits XtraForm
Public Sub New()
InitializeComponent()
Dim startPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim startNode = New NodeNavigationInfo(startPath)
SetActivePath(startNode)
End Sub
Private currentPath As NodeNavigationInfo
Private Property CurrentNode() As NodeNavigationInfo
Get
Return currentPath
End Get
Set(ByVal value As NodeNavigationInfo)
If CurrentNode Is value Then
Return
End If
currentPath = value
UpdateDataSource()
End Set
End Property
Private ReadOnly Property GridClientBounds() As Rectangle
Get
Return New Rectangle(Point.Empty, Me.gridControl1.Size)
End Get
End Property
Private Shared ReadOnly ImageSize As New Size(256, 256)
Private Sub UpdateDataSource()
Dim oldCursor As Cursor = Cursor.Current
Cursor.Current = Cursors.WaitCursor
Try
If Not String.IsNullOrEmpty(CurrentNode.Path) Then
Me.gridControl1.DataSource = FileSystemHelper.GetFileSystemEntries(CurrentNode.Path, IconSizeType.ExtraLarge, ImageSize)
Else
Me.gridControl1.DataSource = Nothing
End If
Me.barEditItem1.EditValue = CurrentNode.Path
Finally
Cursor.Current = oldCursor
End Try
End Sub
Private Sub winExplorerView1_ItemKeyDown(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.WinExplorer.WinExplorerViewItemKeyEventArgs) Handles winExplorerView1.ItemKeyDown
If Me.transitionManager1.IsTransition Then
Return
End If
Select Case e.KeyInfo.KeyCode
Case Keys.Enter
OnItemClick(e.ItemInfo)
Case Keys.Back
RunZoomOutAnimation(Sub()
GoBackCore()
End Sub)
End Select
End Sub
Private Sub winExplorerView1_ItemDoubleClick(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.WinExplorer.WinExplorerViewItemDoubleClickEventArgs) Handles winExplorerView1.ItemDoubleClick
OnItemClick(e.ItemInfo)
End Sub
Private Sub OnItemClick(ByVal itemInfo As WinExplorerItemViewInfo)
If itemInfo Is Nothing OrElse TypeOf itemInfo.Row.RowKey Is FileEntry Then
Return
End If
Dim entry = CType(itemInfo.Row.RowKey, FileSystemEntry)
Dim activeNode = New NodeNavigationInfo(entry.Path, itemInfo.Bounds)
RunZoomInAnimation(activeNode, Sub()
SetActivePath(activeNode)
End Sub)
End Sub
Private Sub OnBackButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles backButton.ItemClick
If Me.transitionManager1.IsTransition Then
Return
End If
RunZoomOutAnimation(Sub()
GoBackCore()
End Sub)
End Sub
Private Sub OnForwardButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles forwardButton.ItemClick
If Me.transitionManager1.IsTransition Then
Return
End If
Dim currentIndex As Integer = PathHistory.IndexOf(CurrentNode)
If currentIndex >= PathHistory.Count - 1 Then
Return
End If
Dim activeNode = PathHistory(currentIndex + 1)
RunZoomInAnimation(activeNode, Sub()
GoForward()
End Sub)
End Sub
Private PathHistory As New List(Of NodeNavigationInfo)()
Private Sub SetActivePath(ByVal node As NodeNavigationInfo)
Dim currentIndex As Integer = PathHistory.IndexOf(CurrentNode)
CurrentNode = node
If currentIndex > -1 Then
Dim pathCount As Integer = PathHistory.Count
Do While pathCount > currentIndex + 1
PathHistory.RemoveAt(pathCount - 1)
pathCount -= 1
Loop
End If
PathHistory.Add(CurrentNode)
End Sub
Private Sub GoBackCore()
Dim currentIndex As Integer = PathHistory.IndexOf(CurrentNode)
If currentIndex < 1 Then
Return
End If
CurrentNode = PathHistory(currentIndex - 1)
End Sub
Private Sub GoForward()
Dim currentIndex As Integer = PathHistory.IndexOf(CurrentNode)
If currentIndex >= PathHistory.Count - 1 Then
Return
End If
CurrentNode = PathHistory(currentIndex + 1)
End Sub
Private Sub OnBreadCrumbValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles repositoryItemBreadCrumbEdit1.EditValueChanged
Dim breadCrumb = DirectCast(sender, BreadCrumbEdit)
Dim path = TryCast(breadCrumb.EditValue, String)
If Me.transitionManager1.IsTransition OrElse path Is Nothing Then
Return
End If
Dim activeNode = New NodeNavigationInfo(path, New Rectangle(GridClientBounds.Width \ 2, GridClientBounds.Height \ 2, 1, 1))
RunZoomInAnimation(activeNode, Sub()
SetActivePath(activeNode)
End Sub)
End Sub
Private Sub RunZoomInAnimation(ByVal activeNode As NodeNavigationInfo, ByVal action As Action)
Dim zoomTransition = Me.transitionManager1.GetTransition(Of ZoomTransition)(Me.gridControl1)
Me.transitionManager1.StartTransition(Me.gridControl1)
zoomTransition.ActiveSettings = New ZoomTransitionSettings() With {
.SourceBounds = activeNode.SourceBounds,
.TargetBounds = GridClientBounds
}
action()
Me.transitionManager1.EndTransition()
End Sub
Private Sub RunZoomOutAnimation(ByVal action As Action)
Dim zoomTransition = Me.transitionManager1.GetTransition(Of ZoomTransition)(Me.gridControl1)
Me.transitionManager1.StartTransition(Me.gridControl1)
zoomTransition.ActiveSettings = New ZoomTransitionSettings() With {
.Direction = ZoomTransitionDirection.ZoomOut,
.SourceBounds = GridClientBounds
}
action()
Me.transitionManager1.EndTransition()
End Sub
#Region "BreadCrumb node generation"
Private Sub repositoryItemBreadCrumbEdit1_ValidatePath(ByVal sender As Object, ByVal e As BreadCrumbValidatePathEventArgs) Handles repositoryItemBreadCrumbEdit1.ValidatePath
If Not FileSystemHelper.IsDirExists(e.Path) Then
e.ValidationResult = BreadCrumbValidatePathResult.Cancel
Return
End If
e.ValidationResult = BreadCrumbValidatePathResult.CreateNodes
End Sub
Private Sub repositoryItemBreadCrumbEdit1_NewNodeAdding(ByVal sender As Object, ByVal e As BreadCrumbNewNodeAddingEventArgs) Handles repositoryItemBreadCrumbEdit1.NewNodeAdding
e.Node.PopulateOnDemand = True
End Sub
Private Sub repositoryItemBreadCrumbEdit1_QueryChildNodes(ByVal sender As Object, ByVal e As BreadCrumbQueryChildNodesEventArgs) Handles repositoryItemBreadCrumbEdit1.QueryChildNodes
Dim dir As String = e.Node.Path
If Not FileSystemHelper.IsDirExists(dir) Then
Return
End If
Dim subDirs() As String = FileSystemHelper.GetSubFolders(dir)
For i As Integer = 0 To subDirs.Length - 1
e.Node.ChildNodes.Add(CreateNode(subDirs(i)))
Next i
End Sub
Private Function CreateNode(ByVal path As String) As BreadCrumbNode
Dim folderName As String = FileSystemHelper.GetDirName(path)
Return New BreadCrumbNode(folderName, folderName, True)
End Function
#End Region
End Class
Friend Class NodeNavigationInfo
Public Sub New(ByVal path As String)
Me.New(path, Rectangle.Empty)
End Sub
Public Sub New(ByVal path As String, ByVal sourceBounds As Rectangle)
Me.SourceBounds = sourceBounds
Me.Path = path
End Sub
Private privateSourceBounds As Rectangle
Public Property SourceBounds() As Rectangle
Get
Return privateSourceBounds
End Get
Private Set(ByVal value As Rectangle)
privateSourceBounds = value
End Set
End Property
Private privatePath As String
Public Property Path() As String
Get
Return privatePath
End Get
Private Set(ByVal value As String)
privatePath = value
End Set
End Property
End Class
End Namespace