Author:水如烟
Namespace
LzmTW.uSystem.uWindows.uForms.uMainForm.Menu
Public Class MenuManager
Private gCollection As New MenusCollection
Private gMenuStrip As MenuStrip
Public ReadOnly Property MenuStrip() As MenuStrip
Get
Return gMenuStrip
End Get
End Property
Sub New ()
gMenuStrip = New MenuStrip
End Sub
Sub New ( ByVal menuStrip As MenuStrip)
gMenuStrip = menuStrip
UpdateCollection()
End Sub
Public Sub Clear()
Me .gCollection.Clear()
UpdateMenuStrip()
End Sub
Public Sub UpdateTo( ByVal treeView As TreeView, ByVal memberName As String )
Me .gCollection.ExportTo(treeView, memberName)
End Sub
Public Sub UpdateTo( ByRef table As DataTable)
Me .gCollection.ExportTo(table)
End Sub
Public Sub ReadFile( ByVal file As String )
Me .gCollection.ReadFormFile(file)
updateMenuStrip()
End Sub
Public Sub ReadLicenseFile( ByVal file As String , ByVal password As String )
End Sub
Public Sub SaveFile( ByVal file As String )
Me .gCollection.SaveToFile(file)
End Sub
Public Sub SaveLicenseFile( ByVal file As String , ByVal password As String )
End Sub
Public Sub GetDefault()
Me .gCollection.ImportFromResource()
updateMenuStrip()
End Sub
Public Sub RefleshBy( ByVal treeView As TreeView)
Me .gCollection.ImportFrom(treeView)
updateMenuStrip()
End Sub
Public Sub RefleshBy( ByVal table As DataTable)
Me .gCollection.ImportFrom(table)
UpdateMenuStrip()
End Sub
Private Sub UpdateMenuStrip()
gCollection.ExportTo( Me .gMenuStrip)
End Sub
Private Sub UpdateCollection()
Me .gCollection.ImportFrom(gMenuStrip)
End Sub
Public Function SetMainFormMenuStrip( ByVal mainForm As Form) As MenuStrip
Dim mMenuStrip As MenuStrip = Nothing
For Each ctr As Control In mainForm.Controls
If TypeOf ctr Is MenuStrip Then
mMenuStrip = CType (ctr, MenuStrip)
Exit For
End If
Next
If mMenuStrip Is Nothing Then
mMenuStrip = Me .gMenuStrip
mainForm.Controls.Add( Me .gMenuStrip)
Else
Me .gMenuStrip = mMenuStrip
Me .UpdateCollection()
End If
Return mMenuStrip
End Function
Public Function FindMenuItem( ByVal shortName As String ) As MenuItem
Return Me .gCollection.gCollection.Find( " Name " , shortName)
End Function
Public Function FindToolStripItem( ByVal shortName As String ) As ToolStripItem
Dim mMenuItem As MenuItem = FindMenuItem(shortName)
If mMenuItem Is Nothing Then Return Nothing
Return ToolStripItemInformation.FindItem(MenuFunction.GetFullName(shortName, mMenuItem.ToolStripType), Me .gMenuStrip)
End Function
Public Function FindToolStripItem1( ByVal fullName As String ) As ToolStripItem
Return ToolStripItemInformation.FindItem(fullName, Me .gMenuStrip)
End Function
Public Function InsertBefore( ByVal beforeShortName As String , ByVal item As ToolStripItem) As ToolStripItem
Dim mToolStripItem As ToolStripItem = ToolStripItemInformation.InsertBefore(FindToolStripItem(beforeShortName), item)
Me .UpdateCollection()
Return mToolStripItem
End Function
Public Function AppendAfter( ByVal afterShortName As String , ByVal item As ToolStripItem) As ToolStripItem
Dim mToolStripItem As ToolStripItem = ToolStripItemInformation.AppendAfter(FindToolStripItem(afterShortName), item)
Me .UpdateCollection()
Return mToolStripItem
End Function
Public Sub RemoveToolStripItem( ByVal shortName As String )
ToolStripItemInformation.Remove(FindToolStripItem(shortName))
Me .UpdateCollection()
End Sub
Public Sub AddClickHandler( ByVal shortName As String , ByVal action As EventHandler)
RemoveClickHandler(shortName, action)
ToolStripItemInformation.AddClickHandler(FindToolStripItem(shortName), action)
End Sub
Public Sub RemoveClickHandler( ByVal shortName As String , ByVal action As EventHandler)
ToolStripItemInformation.RemoveClickHandler(FindToolStripItem(shortName), action)
End Sub
Public Sub AddActionHandler( ByVal shortName As String , ByVal EventName As String , ByVal instanceMethodName As String , ByVal instance As Object )
Dim item As ToolStripItem = FindToolStripItem(shortName)
If item Is Nothing Then Exit Sub
RemoveActionHandler(shortName, EventName, instanceMethodName, instance)
ToolStripItemInformation.AddActionHandler(item, EventName, instanceMethodName, instance)
End Sub
Public Sub RemoveActionHandler( ByVal shortName As String , ByVal EventName As String , ByVal instanceMethodName As String , ByVal instance As Object )
Dim item As ToolStripItem = FindToolStripItem(shortName)
If item Is Nothing Then Exit Sub
ToolStripItemInformation.RemoveActionHandler(item, EventName, instanceMethodName, instance)
End Sub
Public Sub AddDefaultClickHandler()
With Me .gCollection.gCollection.GetEnumerator
While .MoveNext
With CType (.Current, MenuItem)
If ( Not String .IsNullOrEmpty(.EventAction)) AndAlso .EventAction = " Default " Then
AddActionHandler(.Name, " Click " , String .Format( " On{0}Click " , .Name), Me .gMenuStrip.FindForm)
End If
End With
End While
End With
End Sub
Public Sub RemoveDefaultClickHandler()
With Me .gCollection.gCollection.GetEnumerator
While .MoveNext
With CType (.Current, MenuItem)
If ( Not String .IsNullOrEmpty(.EventAction)) AndAlso .EventAction = " Default " Then
RemoveActionHandler(.Name, " Click " , String .Format( " On{0}Click " , .Name), Me .gMenuStrip.FindForm)
End If
End With
End While
End With
End Sub
Public Function AddParentToolStripMenuItem( ByVal shortName As String , ByVal text As String ) As ToolStripMenuItem
Dim tmp As ToolStripMenuItem = MenuItem.CreateToolStripMenuItem(shortName, text, Nothing )
ToolStripItemInformation.AddParentItem( Me .gMenuStrip, tmp)
Me .UpdateCollection()
Return tmp
End Function
Public Function AddParentToolStripMenuItem( ByVal item As MenuItem) As ToolStripMenuItem
Return AddParentToolStripMenuItem(item.Name, item.Text)
End Function
Public Function AddToolStripMenuItem( ByVal parentShortName As String , ByVal shortName As String , ByVal text As String , ByVal tooltipText As String ) As ToolStripMenuItem
Dim tmp As ToolStripMenuItem = MenuItem.CreateToolStripMenuItem(shortName, text, tooltipText)
ToolStripItemInformation.AddItem( Me .FindToolStripItem(parentShortName), tmp)
Me .UpdateCollection()
Return tmp
End Function
Public Function AddToolStripMenuItem( ByVal parentShortName As String , ByVal item As MenuItem) As ToolStripMenuItem
Return AddToolStripMenuItem(parentShortName, item.Name, item.Text, item.ToolTipText)
End Function
Public Function InsertToolStripMenuItemBefore( ByVal beforeShortName As String , ByVal shortName As String , ByVal text As String , ByVal tooltipText As String ) As ToolStripMenuItem
Return CType (InsertBefore(beforeShortName, MenuItem.CreateToolStripMenuItem(shortName, text, tooltipText)), ToolStripMenuItem)
End Function
Public Function InsertToolStripMenuItemBefore( ByVal beforeShortName As String , ByVal item As MenuItem) As ToolStripMenuItem
If item.ToolStripType <> ToolStripType.ToolStripMenuItem Then Return Nothing
Return InsertToolStripMenuItemBefore(beforeShortName, item.Name, item.Text, item.ToolTipText)
End Function
Public Function AppendToolStripMenuItemAfter( ByVal afterShortName As String , ByVal shortName As String , ByVal text As String , ByVal tooltipText As String , ByVal firstAddToolStripSeparator As Boolean ) As ToolStripMenuItem
If firstAddToolStripSeparator Then
Me .AppendAfter(afterShortName, MenuItem.CreateToolStripSeparator( " s_ " & afterShortName))
afterShortName = " s_ " & afterShortName
End If
Return CType ( Me .AppendAfter(afterShortName, MenuItem.CreateToolStripMenuItem(shortName, text, tooltipText)), ToolStripMenuItem)
End Function
Public Function AppendToolStripMenuItemAfter( ByVal afterShortName As String , ByVal item As MenuItem, ByVal firstAddToolStripSeparator As Boolean ) As ToolStripMenuItem
If item.ToolStripType <> ToolStripType.ToolStripMenuItem Then Return Nothing
Return Me .AppendToolStripMenuItemAfter(afterShortName, item.Name, item.Text, item.ToolTipText, firstAddToolStripSeparator)
End Function
Public Shared Function GetDefaultMenuItem( ByVal shortName As String ) As MenuItem
Return DefaultMenuItemCollection.Find( " Name " , shortName)
End Function
Private Shared Function DefaultMenuItemCollection() As uCollection.SinceLink.SinceLinkItemCollection( Of Integer , MenuItem)
If gDefaultMenusCollection Is Nothing Then
gDefaultMenusCollection = New MenusCollection
gDefaultMenusCollection.ImportFromResource()
End If
Return gDefaultMenusCollection.gCollection
End Function
Private Shared gDefaultMenusCollection As MenusCollection
End Class
End Namespace
Public Class MenuManager
Private gCollection As New MenusCollection
Private gMenuStrip As MenuStrip
Public ReadOnly Property MenuStrip() As MenuStrip
Get
Return gMenuStrip
End Get
End Property
Sub New ()
gMenuStrip = New MenuStrip
End Sub
Sub New ( ByVal menuStrip As MenuStrip)
gMenuStrip = menuStrip
UpdateCollection()
End Sub
Public Sub Clear()
Me .gCollection.Clear()
UpdateMenuStrip()
End Sub
Public Sub UpdateTo( ByVal treeView As TreeView, ByVal memberName As String )
Me .gCollection.ExportTo(treeView, memberName)
End Sub
Public Sub UpdateTo( ByRef table As DataTable)
Me .gCollection.ExportTo(table)
End Sub
Public Sub ReadFile( ByVal file As String )
Me .gCollection.ReadFormFile(file)
updateMenuStrip()
End Sub
Public Sub ReadLicenseFile( ByVal file As String , ByVal password As String )
End Sub
Public Sub SaveFile( ByVal file As String )
Me .gCollection.SaveToFile(file)
End Sub
Public Sub SaveLicenseFile( ByVal file As String , ByVal password As String )
End Sub
Public Sub GetDefault()
Me .gCollection.ImportFromResource()
updateMenuStrip()
End Sub
Public Sub RefleshBy( ByVal treeView As TreeView)
Me .gCollection.ImportFrom(treeView)
updateMenuStrip()
End Sub
Public Sub RefleshBy( ByVal table As DataTable)
Me .gCollection.ImportFrom(table)
UpdateMenuStrip()
End Sub
Private Sub UpdateMenuStrip()
gCollection.ExportTo( Me .gMenuStrip)
End Sub
Private Sub UpdateCollection()
Me .gCollection.ImportFrom(gMenuStrip)
End Sub
Public Function SetMainFormMenuStrip( ByVal mainForm As Form) As MenuStrip
Dim mMenuStrip As MenuStrip = Nothing
For Each ctr As Control In mainForm.Controls
If TypeOf ctr Is MenuStrip Then
mMenuStrip = CType (ctr, MenuStrip)
Exit For
End If
Next
If mMenuStrip Is Nothing Then
mMenuStrip = Me .gMenuStrip
mainForm.Controls.Add( Me .gMenuStrip)
Else
Me .gMenuStrip = mMenuStrip
Me .UpdateCollection()
End If
Return mMenuStrip
End Function
Public Function FindMenuItem( ByVal shortName As String ) As MenuItem
Return Me .gCollection.gCollection.Find( " Name " , shortName)
End Function
Public Function FindToolStripItem( ByVal shortName As String ) As ToolStripItem
Dim mMenuItem As MenuItem = FindMenuItem(shortName)
If mMenuItem Is Nothing Then Return Nothing
Return ToolStripItemInformation.FindItem(MenuFunction.GetFullName(shortName, mMenuItem.ToolStripType), Me .gMenuStrip)
End Function
Public Function FindToolStripItem1( ByVal fullName As String ) As ToolStripItem
Return ToolStripItemInformation.FindItem(fullName, Me .gMenuStrip)
End Function
Public Function InsertBefore( ByVal beforeShortName As String , ByVal item As ToolStripItem) As ToolStripItem
Dim mToolStripItem As ToolStripItem = ToolStripItemInformation.InsertBefore(FindToolStripItem(beforeShortName), item)
Me .UpdateCollection()
Return mToolStripItem
End Function
Public Function AppendAfter( ByVal afterShortName As String , ByVal item As ToolStripItem) As ToolStripItem
Dim mToolStripItem As ToolStripItem = ToolStripItemInformation.AppendAfter(FindToolStripItem(afterShortName), item)
Me .UpdateCollection()
Return mToolStripItem
End Function
Public Sub RemoveToolStripItem( ByVal shortName As String )
ToolStripItemInformation.Remove(FindToolStripItem(shortName))
Me .UpdateCollection()
End Sub
Public Sub AddClickHandler( ByVal shortName As String , ByVal action As EventHandler)
RemoveClickHandler(shortName, action)
ToolStripItemInformation.AddClickHandler(FindToolStripItem(shortName), action)
End Sub
Public Sub RemoveClickHandler( ByVal shortName As String , ByVal action As EventHandler)
ToolStripItemInformation.RemoveClickHandler(FindToolStripItem(shortName), action)
End Sub
Public Sub AddActionHandler( ByVal shortName As String , ByVal EventName As String , ByVal instanceMethodName As String , ByVal instance As Object )
Dim item As ToolStripItem = FindToolStripItem(shortName)
If item Is Nothing Then Exit Sub
RemoveActionHandler(shortName, EventName, instanceMethodName, instance)
ToolStripItemInformation.AddActionHandler(item, EventName, instanceMethodName, instance)
End Sub
Public Sub RemoveActionHandler( ByVal shortName As String , ByVal EventName As String , ByVal instanceMethodName As String , ByVal instance As Object )
Dim item As ToolStripItem = FindToolStripItem(shortName)
If item Is Nothing Then Exit Sub
ToolStripItemInformation.RemoveActionHandler(item, EventName, instanceMethodName, instance)
End Sub
Public Sub AddDefaultClickHandler()
With Me .gCollection.gCollection.GetEnumerator
While .MoveNext
With CType (.Current, MenuItem)
If ( Not String .IsNullOrEmpty(.EventAction)) AndAlso .EventAction = " Default " Then
AddActionHandler(.Name, " Click " , String .Format( " On{0}Click " , .Name), Me .gMenuStrip.FindForm)
End If
End With
End While
End With
End Sub
Public Sub RemoveDefaultClickHandler()
With Me .gCollection.gCollection.GetEnumerator
While .MoveNext
With CType (.Current, MenuItem)
If ( Not String .IsNullOrEmpty(.EventAction)) AndAlso .EventAction = " Default " Then
RemoveActionHandler(.Name, " Click " , String .Format( " On{0}Click " , .Name), Me .gMenuStrip.FindForm)
End If
End With
End While
End With
End Sub
Public Function AddParentToolStripMenuItem( ByVal shortName As String , ByVal text As String ) As ToolStripMenuItem
Dim tmp As ToolStripMenuItem = MenuItem.CreateToolStripMenuItem(shortName, text, Nothing )
ToolStripItemInformation.AddParentItem( Me .gMenuStrip, tmp)
Me .UpdateCollection()
Return tmp
End Function
Public Function AddParentToolStripMenuItem( ByVal item As MenuItem) As ToolStripMenuItem
Return AddParentToolStripMenuItem(item.Name, item.Text)
End Function
Public Function AddToolStripMenuItem( ByVal parentShortName As String , ByVal shortName As String , ByVal text As String , ByVal tooltipText As String ) As ToolStripMenuItem
Dim tmp As ToolStripMenuItem = MenuItem.CreateToolStripMenuItem(shortName, text, tooltipText)
ToolStripItemInformation.AddItem( Me .FindToolStripItem(parentShortName), tmp)
Me .UpdateCollection()
Return tmp
End Function
Public Function AddToolStripMenuItem( ByVal parentShortName As String , ByVal item As MenuItem) As ToolStripMenuItem
Return AddToolStripMenuItem(parentShortName, item.Name, item.Text, item.ToolTipText)
End Function
Public Function InsertToolStripMenuItemBefore( ByVal beforeShortName As String , ByVal shortName As String , ByVal text As String , ByVal tooltipText As String ) As ToolStripMenuItem
Return CType (InsertBefore(beforeShortName, MenuItem.CreateToolStripMenuItem(shortName, text, tooltipText)), ToolStripMenuItem)
End Function
Public Function InsertToolStripMenuItemBefore( ByVal beforeShortName As String , ByVal item As MenuItem) As ToolStripMenuItem
If item.ToolStripType <> ToolStripType.ToolStripMenuItem Then Return Nothing
Return InsertToolStripMenuItemBefore(beforeShortName, item.Name, item.Text, item.ToolTipText)
End Function
Public Function AppendToolStripMenuItemAfter( ByVal afterShortName As String , ByVal shortName As String , ByVal text As String , ByVal tooltipText As String , ByVal firstAddToolStripSeparator As Boolean ) As ToolStripMenuItem
If firstAddToolStripSeparator Then
Me .AppendAfter(afterShortName, MenuItem.CreateToolStripSeparator( " s_ " & afterShortName))
afterShortName = " s_ " & afterShortName
End If
Return CType ( Me .AppendAfter(afterShortName, MenuItem.CreateToolStripMenuItem(shortName, text, tooltipText)), ToolStripMenuItem)
End Function
Public Function AppendToolStripMenuItemAfter( ByVal afterShortName As String , ByVal item As MenuItem, ByVal firstAddToolStripSeparator As Boolean ) As ToolStripMenuItem
If item.ToolStripType <> ToolStripType.ToolStripMenuItem Then Return Nothing
Return Me .AppendToolStripMenuItemAfter(afterShortName, item.Name, item.Text, item.ToolTipText, firstAddToolStripSeparator)
End Function
Public Shared Function GetDefaultMenuItem( ByVal shortName As String ) As MenuItem
Return DefaultMenuItemCollection.Find( " Name " , shortName)
End Function
Private Shared Function DefaultMenuItemCollection() As uCollection.SinceLink.SinceLinkItemCollection( Of Integer , MenuItem)
If gDefaultMenusCollection Is Nothing Then
gDefaultMenusCollection = New MenusCollection
gDefaultMenusCollection.ImportFromResource()
End If
Return gDefaultMenusCollection.gCollection
End Function
Private Shared gDefaultMenusCollection As MenusCollection
End Class
End Namespace
Namespace
LzmTW.uSystem.uWindows.uForms.uMainForm.Menu
Friend Class MenusCollection
Protected Friend gCollection As New uCollection.SinceLink.SinceLinkItemCollection( Of Integer , MenuItem)
Public Sub ReadFormFile( ByVal file As String )
gCollection.Clear()
gCollection.Read(file)
End Sub
Public Sub SaveToFile( ByVal file As String )
gCollection.Save(file)
End Sub
Public Sub ExportTo( ByVal menuStrip As MenuStrip)
menuStrip.Items.Clear()
If gCollection.Count = 0 Then Return
ExportToMenuStrip(gCollection.Node, menuStrip)
End Sub
Public Sub ExportTo( ByVal treeView As TreeView, ByVal memberName As String )
treeView.Nodes.Clear()
If gCollection.Count = 0 Then Return
treeView.Nodes.Add(gCollection.Node.ConvertToTreeNode(memberName, " Code " , True ))
End Sub
Public Sub ExportTo( ByRef table As DataTable)
table = gCollection.ExportSinceLinkDataSet.Tables( 0 )
End Sub
Public Sub ImportFromResource()
gCollection.Clear()
gCollection.AppendItemsFromSinceLinkTable(DefaultMenusSinceLinkTable)
gCollection.RefleshNode()
End Sub
Public Sub ImportFrom( ByVal menuStrip As MenuStrip)
gCollection.Clear()
If menuStrip.Items.Count = 0 Then GoTo LabelRefleshNode
gCollection.AppendItemsFromTree( Me .GetMenuStripNode(menuStrip))
LabelRefleshNode:
gCollection.RefleshNode()
End Sub
Public Sub ImportFrom( ByVal table As DataTable)
gCollection.Clear()
If table Is Nothing OrElse table.Rows.Count = 0 Then GoTo LabelRefleshNode
table.AcceptChanges()
gCollection.AppendItemsFromSinceLinkTable(table)
LabelRefleshNode:
gCollection.RefleshNode()
End Sub
Public Sub ImportFrom( ByVal treeView As TreeView)
gCollection.Clear()
If treeView.Nodes.Count = 0 Then GoTo LabelRefleshNode
Dim mNode As New uCollection.Node( Of MenuItem)
mNode.ImportFromTreeNodeChild(treeView.Nodes( 0 ))
gCollection.AppendItemsFromTree(mNode)
LabelRefleshNode:
gCollection.RefleshNode()
End Sub
Public ReadOnly Property SinceLintTable() As DataTable
Get
Return gCollection.ExportSinceLinkDataSet.Tables( 0 )
End Get
End Property
Public Sub Clear()
gCollection.Clear()
Dim mNode As New uCollection.Node( Of MenuItem)( New MenuItem())
mNode.Item.Name = " Root "
gCollection.AppendItemsFromTree(mNode)
gCollection.RefleshNode()
End Sub
Private Function GetMenuStripNode( ByVal menuStrip As MenuStrip) As uCollection.Node( Of MenuItem)
Dim mNode As New uCollection.Node( Of MenuItem)( New MenuItem)
mNode.Item.Name = " Root "
For Each item As ToolStripItem In menuStrip.Items
AppendNode(mNode, item)
Next
Return mNode
End Function
Private Sub AppendNode( ByVal node As LzmTW.uSystem.uCollection.Node( Of MenuItem), ByVal stripItem As ToolStripItem)
Dim mCurrentNode As uCollection.Node( Of MenuItem) = Nothing
mCurrentNode = node.Nodes.Add(MenuItemConverter.ConvertFrom(stripItem))
If TypeOf stripItem Is ToolStripDropDownItem Then
For Each item As ToolStripItem In CType (stripItem, ToolStripDropDownItem).DropDownItems
AppendNode(mCurrentNode, item)
Next
End If
End Sub
Private Sub ExportToMenuStrip( ByVal node As uCollection.Node( Of MenuItem), ByVal menuStrip As MenuStrip)
If node Is Nothing Then
menuStrip.Items.Clear()
Exit Sub
End If
Dim mCurrentItem As ToolStripItem = Nothing
For Each n As uCollection.Node( Of MenuItem) In node.Nodes
If n.Item Is Nothing Then Continue For
mCurrentItem = uMainForm.Menu.MenuItemConverter.ConvertTo(n.Item)
menuStrip.Items.Add(mCurrentItem)
AppendToolStripItem(n, mCurrentItem)
Next
End Sub
Private Sub AppendToolStripItem( ByVal node As uCollection.Node( Of MenuItem), ByVal parentItem As ToolStripItem)
If node Is Nothing Then Exit Sub
For Each n As uCollection.Node( Of MenuItem) In node.Nodes
Dim mCurrentItem As ToolStripItem = Nothing
If n.Item IsNot Nothing Then
mCurrentItem = uMainForm.Menu.MenuItemConverter.ConvertTo(n.Item)
CType (parentItem, ToolStripDropDownItem).DropDownItems.Add(mCurrentItem)
End If
If TypeOf mCurrentItem Is ToolStripDropDownItem Then
AppendToolStripItem(n, mCurrentItem)
End If
Next
End Sub
Private Function DefaultMenusSinceLinkTable() As DataTable
Dim mTable As DataTable = uReflection.DatasFunction.CreateTableFromType( GetType (MenuItem))
mTable.Columns.Add( " ID " , GetType ( Integer ))
mTable.Columns.Add( " ParentID " , GetType ( Integer ))
Dim i As Integer = - 1
For Each line As String In SR.GetObject( " DefaultMenus " ).ToString.Split( CChar (vbCrLf))
line = line.Replace(vbLf, Nothing )
i += 1
If i = 0 OrElse line.Length < 10 Then Continue For
mTable.Rows.Add(GetItem(line))
Next
mTable.AcceptChanges()
Return mTable
End Function
Private Function GetItem( ByVal line As String ) As Object ()
' ID0,ParentID1,ShortName2,Text3,Shortcut4,ToolStripType5,Visible6,Enabled7
Dim mArray() As String = line.Split( " , " c)
Dim mResult( 11 ) As Object
mResult( 0 ) = mArray( 5 ) ' ToolStripType
mResult( 1 ) = mArray( 3 ) ' Text
If mArray( 3 ).IndexOf( " ( " ) > - 1 Then
mResult( 2 ) = mArray( 3 ).Substring( 0 , mArray( 3 ).IndexOf( " ( " )) ' Declare
mResult( 3 ) = mArray( 3 ).Substring( 0 , mArray( 3 ).IndexOf( " ( " )) ' ToolTipText
Else
mResult( 2 ) = mArray( 3 ) ' Declare
mResult( 3 ) = mArray( 3 ) ' ToolTipText
End If
mResult( 4 ) = mArray( 4 ) ' ShortCut
mResult( 6 ) = mArray( 6 ) ' Visible
mResult( 7 ) = mArray( 7 ) ' Enabled
mResult( 8 ) = String .Empty ' Code
mResult( 9 ) = mArray( 2 ) ' Name
mResult( 10 ) = mArray( 0 ) ' ID
mResult( 11 ) = mArray( 1 ) ' ParentID
mResult( 5 ) = String .Empty ' ClickAction
If CInt (mResult( 11 )) <> 1 Then
If CInt (mResult( 0 )) <> 1 Then
If mResult( 9 ).ToString <> " PanelFunction " Then
mResult( 5 ) = " Default "
End If
End If
End If
Return mResult
End Function
End Class
End Namespace
Friend Class MenusCollection
Protected Friend gCollection As New uCollection.SinceLink.SinceLinkItemCollection( Of Integer , MenuItem)
Public Sub ReadFormFile( ByVal file As String )
gCollection.Clear()
gCollection.Read(file)
End Sub
Public Sub SaveToFile( ByVal file As String )
gCollection.Save(file)
End Sub
Public Sub ExportTo( ByVal menuStrip As MenuStrip)
menuStrip.Items.Clear()
If gCollection.Count = 0 Then Return
ExportToMenuStrip(gCollection.Node, menuStrip)
End Sub
Public Sub ExportTo( ByVal treeView As TreeView, ByVal memberName As String )
treeView.Nodes.Clear()
If gCollection.Count = 0 Then Return
treeView.Nodes.Add(gCollection.Node.ConvertToTreeNode(memberName, " Code " , True ))
End Sub
Public Sub ExportTo( ByRef table As DataTable)
table = gCollection.ExportSinceLinkDataSet.Tables( 0 )
End Sub
Public Sub ImportFromResource()
gCollection.Clear()
gCollection.AppendItemsFromSinceLinkTable(DefaultMenusSinceLinkTable)
gCollection.RefleshNode()
End Sub
Public Sub ImportFrom( ByVal menuStrip As MenuStrip)
gCollection.Clear()
If menuStrip.Items.Count = 0 Then GoTo LabelRefleshNode
gCollection.AppendItemsFromTree( Me .GetMenuStripNode(menuStrip))
LabelRefleshNode:
gCollection.RefleshNode()
End Sub
Public Sub ImportFrom( ByVal table As DataTable)
gCollection.Clear()
If table Is Nothing OrElse table.Rows.Count = 0 Then GoTo LabelRefleshNode
table.AcceptChanges()
gCollection.AppendItemsFromSinceLinkTable(table)
LabelRefleshNode:
gCollection.RefleshNode()
End Sub
Public Sub ImportFrom( ByVal treeView As TreeView)
gCollection.Clear()
If treeView.Nodes.Count = 0 Then GoTo LabelRefleshNode
Dim mNode As New uCollection.Node( Of MenuItem)
mNode.ImportFromTreeNodeChild(treeView.Nodes( 0 ))
gCollection.AppendItemsFromTree(mNode)
LabelRefleshNode:
gCollection.RefleshNode()
End Sub
Public ReadOnly Property SinceLintTable() As DataTable
Get
Return gCollection.ExportSinceLinkDataSet.Tables( 0 )
End Get
End Property
Public Sub Clear()
gCollection.Clear()
Dim mNode As New uCollection.Node( Of MenuItem)( New MenuItem())
mNode.Item.Name = " Root "
gCollection.AppendItemsFromTree(mNode)
gCollection.RefleshNode()
End Sub
Private Function GetMenuStripNode( ByVal menuStrip As MenuStrip) As uCollection.Node( Of MenuItem)
Dim mNode As New uCollection.Node( Of MenuItem)( New MenuItem)
mNode.Item.Name = " Root "
For Each item As ToolStripItem In menuStrip.Items
AppendNode(mNode, item)
Next
Return mNode
End Function
Private Sub AppendNode( ByVal node As LzmTW.uSystem.uCollection.Node( Of MenuItem), ByVal stripItem As ToolStripItem)
Dim mCurrentNode As uCollection.Node( Of MenuItem) = Nothing
mCurrentNode = node.Nodes.Add(MenuItemConverter.ConvertFrom(stripItem))
If TypeOf stripItem Is ToolStripDropDownItem Then
For Each item As ToolStripItem In CType (stripItem, ToolStripDropDownItem).DropDownItems
AppendNode(mCurrentNode, item)
Next
End If
End Sub
Private Sub ExportToMenuStrip( ByVal node As uCollection.Node( Of MenuItem), ByVal menuStrip As MenuStrip)
If node Is Nothing Then
menuStrip.Items.Clear()
Exit Sub
End If
Dim mCurrentItem As ToolStripItem = Nothing
For Each n As uCollection.Node( Of MenuItem) In node.Nodes
If n.Item Is Nothing Then Continue For
mCurrentItem = uMainForm.Menu.MenuItemConverter.ConvertTo(n.Item)
menuStrip.Items.Add(mCurrentItem)
AppendToolStripItem(n, mCurrentItem)
Next
End Sub
Private Sub AppendToolStripItem( ByVal node As uCollection.Node( Of MenuItem), ByVal parentItem As ToolStripItem)
If node Is Nothing Then Exit Sub
For Each n As uCollection.Node( Of MenuItem) In node.Nodes
Dim mCurrentItem As ToolStripItem = Nothing
If n.Item IsNot Nothing Then
mCurrentItem = uMainForm.Menu.MenuItemConverter.ConvertTo(n.Item)
CType (parentItem, ToolStripDropDownItem).DropDownItems.Add(mCurrentItem)
End If
If TypeOf mCurrentItem Is ToolStripDropDownItem Then
AppendToolStripItem(n, mCurrentItem)
End If
Next
End Sub
Private Function DefaultMenusSinceLinkTable() As DataTable
Dim mTable As DataTable = uReflection.DatasFunction.CreateTableFromType( GetType (MenuItem))
mTable.Columns.Add( " ID " , GetType ( Integer ))
mTable.Columns.Add( " ParentID " , GetType ( Integer ))
Dim i As Integer = - 1
For Each line As String In SR.GetObject( " DefaultMenus " ).ToString.Split( CChar (vbCrLf))
line = line.Replace(vbLf, Nothing )
i += 1
If i = 0 OrElse line.Length < 10 Then Continue For
mTable.Rows.Add(GetItem(line))
Next
mTable.AcceptChanges()
Return mTable
End Function
Private Function GetItem( ByVal line As String ) As Object ()
' ID0,ParentID1,ShortName2,Text3,Shortcut4,ToolStripType5,Visible6,Enabled7
Dim mArray() As String = line.Split( " , " c)
Dim mResult( 11 ) As Object
mResult( 0 ) = mArray( 5 ) ' ToolStripType
mResult( 1 ) = mArray( 3 ) ' Text
If mArray( 3 ).IndexOf( " ( " ) > - 1 Then
mResult( 2 ) = mArray( 3 ).Substring( 0 , mArray( 3 ).IndexOf( " ( " )) ' Declare
mResult( 3 ) = mArray( 3 ).Substring( 0 , mArray( 3 ).IndexOf( " ( " )) ' ToolTipText
Else
mResult( 2 ) = mArray( 3 ) ' Declare
mResult( 3 ) = mArray( 3 ) ' ToolTipText
End If
mResult( 4 ) = mArray( 4 ) ' ShortCut
mResult( 6 ) = mArray( 6 ) ' Visible
mResult( 7 ) = mArray( 7 ) ' Enabled
mResult( 8 ) = String .Empty ' Code
mResult( 9 ) = mArray( 2 ) ' Name
mResult( 10 ) = mArray( 0 ) ' ID
mResult( 11 ) = mArray( 1 ) ' ParentID
mResult( 5 ) = String .Empty ' ClickAction
If CInt (mResult( 11 )) <> 1 Then
If CInt (mResult( 0 )) <> 1 Then
If mResult( 9 ).ToString <> " PanelFunction " Then
mResult( 5 ) = " Default "
End If
End If
End If
Return mResult
End Function
End Class
End Namespace
资源文件,DefaultMenus.txt
ID,ParentID,ShortName,Text,Shortcut,ToolStripType,Visible,Enabled
1 , 0 ,Root,, 0 , 0 , TRUE , TRUE
2 , 1 ,File,文件( & F), 0 , 0 , TRUE , TRUE
3 , 2 , New ,新建( & N)..., 131150 , 0 , TRUE , TRUE
4 , 2 ,Open,打开( & O)..., 131151 , 0 , TRUE , TRUE
5 , 2 ,Close,关闭( & C), 0 , 0 , TRUE , TRUE
6 , 2 ,s_Close,, 0 , 1 , TRUE , TRUE
7 , 2 ,Config,本地配置( & I)..., 0 , 0 , TRUE , TRUE
8 , 2 ,s_Config,, 0 , 1 , TRUE , TRUE
9 , 2 ,Save,保存( & S), 131155 , 0 , TRUE , TRUE
10 , 2 ,SaveAs,另存为( & A)..., 0 , 0 , TRUE , TRUE
11 , 2 ,s_SaveAs,, 0 , 1 , TRUE , TRUE
12 , 2 ,PageSetup,页面设置( & U)..., 0 , 0 , TRUE , TRUE
13 , 2 , Print ,打印( & P)..., 0 , 0 , TRUE , TRUE
14 , 2 ,s_Print,, 0 , 1 , TRUE , TRUE
15 , 2 , Exit ,退出( & X), 0 , 0 , TRUE , TRUE
16 , 1 ,Edit,编辑( & E), 0 , 0 , TRUE , TRUE
17 , 16 ,Find,查找( & F)..., 131142 , 0 , TRUE , TRUE
18 , 16 , Replace ,替换( & E)..., 131144 , 0 , TRUE , TRUE
19 , 16 , Goto ,定位( & G)..., 0 , 0 , TRUE , TRUE
20 , 1 ,View,视图( & V), 0 , 0 , TRUE , TRUE
21 , 20 ,PanelFunction,功能块, 0 , 0 , TRUE , TRUE
22 , 21 ,HideDetailPanel,隐藏数据区( & D), 0 , 0 , TRUE , TRUE
23 , 21 ,HideDeclarePanel,隐藏附加区( & O), 0 , 0 , TRUE , TRUE
24 , 21 ,HideToolPanel,隐藏功能区( & F), 0 , 0 , TRUE , TRUE
25 , 21 ,s_HideToolPanel,, 0 , 1 , TRUE , TRUE
26 , 21 ,PanelWindow,隐藏功能块( & P), 0 , 0 , TRUE , TRUE
27 , 20 ,s_PanelFunctio,, 0 , 1 , TRUE , TRUE
28 , 20 ,Icon,图标( & N), 0 , 0 , TRUE , TRUE
29 , 20 ,List,列表( & L), 0 , 0 , TRUE , TRUE
30 , 20 ,Details,详细信息( & D), 0 , 0 , TRUE , TRUE
31 , 20 ,s_Details,, 0 , 1 , TRUE , TRUE
32 , 20 ,HideToolBars,隐藏工具条, 0 , 0 , TRUE , TRUE
33 , 20 ,HideStatusBar,隐藏状态栏, 0 , 0 , TRUE , TRUE
34 , 1 ,Data,数据(D), 0 , 0 , TRUE , TRUE
35 , 34 ,Export,导出( & O)..., 0 , 0 , TRUE , TRUE
36 , 34 ,Import,导入( & I)..., 0 , 0 , TRUE , TRUE
37 , 34 ,s_Import,, 0 , 1 , TRUE , TRUE
38 , 34 ,Backup,备份( & B)..., 0 , 0 , TRUE , TRUE
39 , 34 ,Restore,还原( & R)..., 0 , 0 , TRUE , TRUE
40 , 1 , Format ,格式( & O), 0 , 0 , TRUE , TRUE
41 , 40 ,Font,字体( & F)..., 0 , 0 , TRUE , TRUE
42 , 40 ,s_Font,, 0 , 1 , TRUE , TRUE
43 , 40 ,Backgroup,背景( & K)..., 0 , 0 , TRUE , TRUE
44 , 40 ,s_Backgroup,, 0 , 1 , TRUE , TRUE
45 , 40 ,Style,样式( & S)..., 0 , 0 , TRUE , TRUE
46 , 1 ,Tools,工具( & T), 0 , 0 , TRUE , TRUE
47 , 46 ,AddIns,插件管理( & A)..., 0 , 0 , TRUE , TRUE
48 , 46 ,s_AddIns,, 0 , 1 , TRUE , TRUE
49 , 46 ,Options,选项( & O)..., 0 , 0 , TRUE , TRUE
50 , 1 ,Window,窗口( & W), 0 , 0 , TRUE , TRUE
51 , 50 ,Cascade,层 叠( & C), 0 , 0 , TRUE , TRUE
52 , 50 ,TileVertical,水平平铺( & V), 0 , 0 , TRUE , TRUE
53 , 50 ,TileHorizontal,竖直平铺( & H), 0 , 0 , TRUE , TRUE
54 , 50 ,s_TileHorizontal,, 0 , 1 , TRUE , TRUE
55 , 50 ,CloseWindows,关闭所有窗口, 0 , 0 , TRUE , TRUE
56 , 1 ,Community,交流( & C), 0 , 0 , TRUE , TRUE
57 , 56 ,Thinking,记录想法..., 0 , 0 , TRUE , TRUE
58 , 56 ,Sendto,反馈..., 0 , 0 , TRUE , TRUE
59 , 1 ,Help,帮助( & H), 0 , 0 , TRUE , TRUE
60 , 59 ,How,如何使用..., 131184 , 0 , TRUE , TRUE
61 , 59 ,s_How,, 0 , 1 , TRUE , TRUE
62 , 59 ,Update,检查更新( & U)..., 0 , 0 , TRUE , TRUE
63 , 59 ,s_Update,, 0 , 1 , TRUE , TRUE
64 , 59 ,About,关于 { 0 }( & A)..., 0 , 0 , TRUE , TRUE
1 , 0 ,Root,, 0 , 0 , TRUE , TRUE
2 , 1 ,File,文件( & F), 0 , 0 , TRUE , TRUE
3 , 2 , New ,新建( & N)..., 131150 , 0 , TRUE , TRUE
4 , 2 ,Open,打开( & O)..., 131151 , 0 , TRUE , TRUE
5 , 2 ,Close,关闭( & C), 0 , 0 , TRUE , TRUE
6 , 2 ,s_Close,, 0 , 1 , TRUE , TRUE
7 , 2 ,Config,本地配置( & I)..., 0 , 0 , TRUE , TRUE
8 , 2 ,s_Config,, 0 , 1 , TRUE , TRUE
9 , 2 ,Save,保存( & S), 131155 , 0 , TRUE , TRUE
10 , 2 ,SaveAs,另存为( & A)..., 0 , 0 , TRUE , TRUE
11 , 2 ,s_SaveAs,, 0 , 1 , TRUE , TRUE
12 , 2 ,PageSetup,页面设置( & U)..., 0 , 0 , TRUE , TRUE
13 , 2 , Print ,打印( & P)..., 0 , 0 , TRUE , TRUE
14 , 2 ,s_Print,, 0 , 1 , TRUE , TRUE
15 , 2 , Exit ,退出( & X), 0 , 0 , TRUE , TRUE
16 , 1 ,Edit,编辑( & E), 0 , 0 , TRUE , TRUE
17 , 16 ,Find,查找( & F)..., 131142 , 0 , TRUE , TRUE
18 , 16 , Replace ,替换( & E)..., 131144 , 0 , TRUE , TRUE
19 , 16 , Goto ,定位( & G)..., 0 , 0 , TRUE , TRUE
20 , 1 ,View,视图( & V), 0 , 0 , TRUE , TRUE
21 , 20 ,PanelFunction,功能块, 0 , 0 , TRUE , TRUE
22 , 21 ,HideDetailPanel,隐藏数据区( & D), 0 , 0 , TRUE , TRUE
23 , 21 ,HideDeclarePanel,隐藏附加区( & O), 0 , 0 , TRUE , TRUE
24 , 21 ,HideToolPanel,隐藏功能区( & F), 0 , 0 , TRUE , TRUE
25 , 21 ,s_HideToolPanel,, 0 , 1 , TRUE , TRUE
26 , 21 ,PanelWindow,隐藏功能块( & P), 0 , 0 , TRUE , TRUE
27 , 20 ,s_PanelFunctio,, 0 , 1 , TRUE , TRUE
28 , 20 ,Icon,图标( & N), 0 , 0 , TRUE , TRUE
29 , 20 ,List,列表( & L), 0 , 0 , TRUE , TRUE
30 , 20 ,Details,详细信息( & D), 0 , 0 , TRUE , TRUE
31 , 20 ,s_Details,, 0 , 1 , TRUE , TRUE
32 , 20 ,HideToolBars,隐藏工具条, 0 , 0 , TRUE , TRUE
33 , 20 ,HideStatusBar,隐藏状态栏, 0 , 0 , TRUE , TRUE
34 , 1 ,Data,数据(D), 0 , 0 , TRUE , TRUE
35 , 34 ,Export,导出( & O)..., 0 , 0 , TRUE , TRUE
36 , 34 ,Import,导入( & I)..., 0 , 0 , TRUE , TRUE
37 , 34 ,s_Import,, 0 , 1 , TRUE , TRUE
38 , 34 ,Backup,备份( & B)..., 0 , 0 , TRUE , TRUE
39 , 34 ,Restore,还原( & R)..., 0 , 0 , TRUE , TRUE
40 , 1 , Format ,格式( & O), 0 , 0 , TRUE , TRUE
41 , 40 ,Font,字体( & F)..., 0 , 0 , TRUE , TRUE
42 , 40 ,s_Font,, 0 , 1 , TRUE , TRUE
43 , 40 ,Backgroup,背景( & K)..., 0 , 0 , TRUE , TRUE
44 , 40 ,s_Backgroup,, 0 , 1 , TRUE , TRUE
45 , 40 ,Style,样式( & S)..., 0 , 0 , TRUE , TRUE
46 , 1 ,Tools,工具( & T), 0 , 0 , TRUE , TRUE
47 , 46 ,AddIns,插件管理( & A)..., 0 , 0 , TRUE , TRUE
48 , 46 ,s_AddIns,, 0 , 1 , TRUE , TRUE
49 , 46 ,Options,选项( & O)..., 0 , 0 , TRUE , TRUE
50 , 1 ,Window,窗口( & W), 0 , 0 , TRUE , TRUE
51 , 50 ,Cascade,层 叠( & C), 0 , 0 , TRUE , TRUE
52 , 50 ,TileVertical,水平平铺( & V), 0 , 0 , TRUE , TRUE
53 , 50 ,TileHorizontal,竖直平铺( & H), 0 , 0 , TRUE , TRUE
54 , 50 ,s_TileHorizontal,, 0 , 1 , TRUE , TRUE
55 , 50 ,CloseWindows,关闭所有窗口, 0 , 0 , TRUE , TRUE
56 , 1 ,Community,交流( & C), 0 , 0 , TRUE , TRUE
57 , 56 ,Thinking,记录想法..., 0 , 0 , TRUE , TRUE
58 , 56 ,Sendto,反馈..., 0 , 0 , TRUE , TRUE
59 , 1 ,Help,帮助( & H), 0 , 0 , TRUE , TRUE
60 , 59 ,How,如何使用..., 131184 , 0 , TRUE , TRUE
61 , 59 ,s_How,, 0 , 1 , TRUE , TRUE
62 , 59 ,Update,检查更新( & U)..., 0 , 0 , TRUE , TRUE
63 , 59 ,s_Update,, 0 , 1 , TRUE , TRUE
64 , 59 ,About,关于 { 0 }( & A)..., 0 , 0 , TRUE , TRUE