This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RepositotyItemMRUComboBox.vb
95 lines (80 loc) · 2.49 KB
/
RepositotyItemMRUComboBox.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
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports DevExpress.XtraEditors.Drawing
Imports DevExpress.XtraEditors.Registrator
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraEditors.ViewInfo
Namespace MRUComboBox
Public Class RepositoryItemMRUComboBox
Inherits RepositoryItemComboBox
Friend Const EditorName As String = "MRUComboBoxEdit"
Private recentItems As New List(Of Object)()
Private lineItemIndex_Renamed As Integer = -1
Shared Sub New()
Register()
End Sub
Public Sub New()
MRUItemsCount = 5
End Sub
Public Shared Sub Register()
EditorRegistrationInfo.Default.Editors.Add(New EditorClassInfo(EditorName, GetType(MRUComboBoxEdit), GetType(RepositoryItemMRUComboBox), GetType(ComboBoxViewInfo), New ButtonEditPainter(), True))
End Sub
Public Sub StoreRecentItem(ByVal item As Object)
If item Is Nothing OrElse MRUItemsCount = 0 Then
Return
End If
If (Not recentItems.Contains(item)) Then
Dim lastItem As Object = If(recentItems.Count > 0, recentItems(0), Nothing)
Dim lastItemIndex As Integer = Items.IndexOf(lastItem)
If recentItems.Count + 1 > MRUItemsCount Then
Items.RemoveAt(lastItemIndex)
recentItems.Remove(lastItem)
End If
recentItems.Add(item)
Items.Insert(0, item)
If lastItemIndex = -1 Then
lineItemIndex_Renamed = 0
ElseIf recentItems.Count = MRUItemsCount Then
lineItemIndex_Renamed = MRUItemsCount - 1
Else
lineItemIndex_Renamed = lastItemIndex + 1
End If
End If
End Sub
Public Overrides Sub Assign(ByVal item As RepositoryItem)
BeginUpdate()
Try
If Not(TypeOf item Is RepositoryItemMRUComboBox) Then
Return
End If
Dim source As RepositoryItemMRUComboBox = CType(item, RepositoryItemMRUComboBox)
MyBase.Assign(item)
Me.MRUItemsCount = source.MRUItemsCount
Me.lineItemIndex_Renamed = source.lineItemIndex
Me.recentItems.Clear()
Me.recentItems.AddRange(source.recentItems)
Finally
EndUpdate()
End Try
End Sub
Public Overrides ReadOnly Property EditorTypeName() As String
Get
Return EditorName
End Get
End Property
Private privateMRUItemsCount As Integer
Public Property MRUItemsCount() As Integer
Get
Return privateMRUItemsCount
End Get
Set(ByVal value As Integer)
privateMRUItemsCount = value
End Set
End Property
Friend ReadOnly Property LineItemIndex() As Integer
Get
Return lineItemIndex_Renamed
End Get
End Property
End Class
End Namespace