Imports Stax.UI

Namespace AppFramework
    Public Class SettingTreeViewForm
        Inherits ExtendedForm

#Region " Designer "

        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

        Friend WithEvents bOK As System.Windows.Forms.Button
        Friend WithEvents bCancel As System.Windows.Forms.Button
        Friend WithEvents bHelp As System.Windows.Forms.Button
        Public WithEvents SettingTreeView As Stax.UI.SettingTreeView
        Friend WithEvents SmartTagProvider As Stax.UI.Design.SmartTagProvider

        Private components As System.ComponentModel.IContainer

        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.bOK = New System.Windows.Forms.Button
            Me.bCancel = New System.Windows.Forms.Button
            Me.bHelp = New System.Windows.Forms.Button
            Me.SettingTreeView = New Stax.UI.SettingTreeView
            Me.SmartTagProvider = New Stax.UI.Design.SmartTagProvider
            Me.SuspendLayout()
            '
            '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(256, 263)
            Me.bOK.Name = "bOK"
            Me.bOK.Size = New System.Drawing.Size(75, 24)
            Me.bOK.TabIndex = 0
            Me.bOK.Text = "OK"
            '
            '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(337, 263)
            Me.bCancel.Name = "bCancel"
            Me.bCancel.Size = New System.Drawing.Size(75, 24)
            Me.bCancel.TabIndex = 1
            Me.bCancel.Text = "Cancel"
            '
            '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(418, 263)
            Me.bHelp.Name = "bHelp"
            Me.bHelp.Size = New System.Drawing.Size(75, 24)
            Me.bHelp.TabIndex = 5
            Me.bHelp.Text = "Help"
            Me.bHelp.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
            '
            'SettingTreeView
            '
            Me.SettingTreeView.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.SettingTreeView.AutoCollaps = True
            Me.SettingTreeView.AutoExpand = True
            Me.SettingTreeView.HideSelection = False
            Me.SettingTreeView.Location = New System.Drawing.Point(13, 13)
            Me.SettingTreeView.Name = "SettingTreeView"
            Me.SettingTreeView.Scrollable = False
            Me.SettingTreeView.SelectOnMouseDown = True
            Me.SettingTreeView.Size = New System.Drawing.Size(480, 244)
            Me.SettingTreeView.TabIndex = 2
            '
            'SettingTreeViewForm
            '
            Me.AcceptButton = Me.bOK
            Me.CancelButton = Me.bCancel
            Me.ClientSize = New System.Drawing.Size(505, 299)
            Me.Controls.Add(Me.bHelp)
            Me.Controls.Add(Me.SettingTreeView)
            Me.Controls.Add(Me.bCancel)
            Me.Controls.Add(Me.bOK)
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
            Me.HelpButton = True
            Me.MaximizeBox = False
            Me.MinimizeBox = False
            Me.Name = "SettingTreeViewForm"
            Me.ShowIcon = False
            Me.ShowInTaskbar = False
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
            Me.Text = "SettingTreeViewForm"
            Me.ResumeLayout(False)

        End Sub

#End Region

        Private HelpParagraphs As String()

        Public Sub New(ByVal title As String, ByVal ParamArray helpParagraphs As String())
            MyBase.New()
            InitializeComponent()
            Text = title
            Me.HelpParagraphs = helpParagraphs
        End Sub

        Private DocumentValue As HelpDocument

        Public Property Document() As HelpDocument
            Get
                If DocumentValue Is Nothing Then
                    DocumentValue = New HelpDocument(HelpForm.AutoGenPath)
                    DocumentValue.WriteStart(Text)

                    If Not HelpParagraphs Is Nothing Then
                        For Each i As String In HelpParagraphs
                            DocumentValue.WriteElement("p", i)
                        Next
                    End If

                    DocumentValue.WriteTips(SettingTreeView.GetTips)
                End If

                Return DocumentValue
            End Get
            Set(ByVal Value As HelpDocument)
                DocumentValue = Value
            End Set
        End Property

        Private Sub bOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bOK.Click
            SettingTreeView.Apply()
        End Sub

        Private Sub bHelp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bHelp.Click
            Dim f As New HelpForm()
            f.Document = Document
            f.Show()
        End Sub

        Private Sub SettingTreeViewForm_ActivatedFirstTime() Handles Me.ActivatedFirstTime
            Document.WriteDocument()

            If Not HelpParagraphs Is Nothing AndAlso HelpParagraphs.Length > 0 AndAlso _
                Not AppFramework.StaxApplication.StringList.Contains(StringHelp.GetMD5Hash(HelpParagraphs(0))) Then

                bHelp.PerformClick()
                AppFramework.StaxApplication.StringList.Add(StringHelp.GetMD5Hash(HelpParagraphs(0)))
            End If
        End Sub
    End Class
End Namespace