Namespace UI
    Public Class MenuTemplateForm
        Inherits ExtendedForm

#Region " Windows Form Designer generated code "
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents TheTreeView As System.Windows.Forms.TreeView
        Public WithEvents bCancel As System.Windows.Forms.Button
        Friend WithEvents SmartTagProvider As Stax.UI.Design.SmartTagProvider
        Friend WithEvents bHelp As System.Windows.Forms.Button
        Public WithEvents bOK As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.TheTreeView = New System.Windows.Forms.TreeView
            Me.bCancel = New System.Windows.Forms.Button
            Me.bOK = New System.Windows.Forms.Button
            Me.SmartTagProvider = New Stax.UI.Design.SmartTagProvider
            Me.bHelp = New System.Windows.Forms.Button
            Me.SuspendLayout()
            '
            'TheTreeView
            '
            Me.TheTreeView.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.TheTreeView.Location = New System.Drawing.Point(13, 13)
            Me.TheTreeView.Name = "TheTreeView"
            Me.TheTreeView.Size = New System.Drawing.Size(355, 364)
            Me.TheTreeView.TabIndex = 0
            '
            'bCancel
            '
            Me.bCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.bCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.bCancel.Location = New System.Drawing.Point(212, 383)
            Me.bCancel.Name = "bCancel"
            Me.bCancel.Size = New System.Drawing.Size(75, 24)
            Me.bCancel.TabIndex = 1
            Me.bCancel.Text = "Cancel"
            '
            'bOK
            '
            Me.bOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.bOK.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.bOK.Location = New System.Drawing.Point(131, 383)
            Me.bOK.Name = "bOK"
            Me.bOK.Size = New System.Drawing.Size(75, 24)
            Me.bOK.TabIndex = 2
            Me.bOK.Text = "OK"
            '
            'bHelp
            '
            Me.bHelp.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.bHelp.Location = New System.Drawing.Point(293, 383)
            Me.bHelp.Name = "bHelp"
            Me.bHelp.Size = New System.Drawing.Size(75, 24)
            Me.bHelp.TabIndex = 3
            Me.bHelp.Text = "Help"
            Me.bHelp.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
            '
            'MenuTemplateForm
            '
            Me.AcceptButton = Me.bOK
            Me.CancelButton = Me.bCancel
            Me.ClientSize = New System.Drawing.Size(380, 419)
            Me.Controls.Add(Me.bHelp)
            Me.Controls.Add(Me.bOK)
            Me.Controls.Add(Me.bCancel)
            Me.Controls.Add(Me.TheTreeView)
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
            Me.MaximizeBox = False
            Me.MinimizeBox = False
            Me.Name = "MenuTemplateForm"
            Me.ShowInTaskbar = False
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
            Me.Text = "Default Menu"
            Me.ResumeLayout(False)

        End Sub

#End Region

        Public TreeNode As TreeNode

        Public Sub New(ByVal item As GenericMenuItem)
            MyBase.New()
            InitializeComponent()
            PopulateTreeView(item, Nothing)
            TheTreeView.ExpandAll()
        End Sub

        Private Sub PopulateTreeView(ByVal item As GenericMenuItem, ByVal node As TreeNode)
            Dim newNode As New TreeNode(item.Text)
            newNode.Tag = item

            If node Is Nothing Then
                TheTreeView.Nodes.Add(newNode)
            Else
                node.Nodes.Add(newNode)
            End If

            For Each i As GenericMenuItem In item.SubItems
                PopulateTreeView(i, newNode)
            Next
        End Sub

        Private Sub TheTreeView_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles TheTreeView.AfterSelect
            If Not TheTreeView.SelectedNode Is Nothing Then
                TreeNode = TheTreeView.SelectedNode
                bOK.Enabled = Not TreeNode.Parent Is Nothing
            End If
        End Sub

        Private Sub bOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bOK.Click
            DialogResult = Windows.Forms.DialogResult.OK
        End Sub

        Private Sub bHelp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bHelp.Click
            Dim p As New PopUp
            p.Title = Text
            p.Text = "The new item will be a clone of the selected item."
            p.Image = My.Resources.Help16
            p.Show()
        End Sub
    End Class
End Namespace