Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.ExpressApp.Templates
Imports DevExpress.ExpressApp.Editors

Public Class ActionToolTipforSysAdmin
    Inherits DevExpress.ExpressApp.ViewController

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()
        RegisterActions(components)

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        Dim _Container As IActionContainer
        Dim _Action As DevExpress.ExpressApp.Actions.ActionBase
        If Frame.Template IsNot Nothing Then
            For Each _Container In Frame.Template.GetContainers
                For Each _Action In _Container.Actions
                    CustomizeActionToolTip(_Action, View)
                Next
            Next
        End If
        If TryCast(Frame, NestedFrame) IsNot Nothing Then
            If TryCast(Frame, NestedFrame).Controllers.Count > 0 Then
                Dim _Controller As Controller
                For Each _Controller In TryCast(Frame, NestedFrame).Controllers
                    For Each _Action In _Controller.Actions
                        CustomizeActionToolTip(_Action, View)
                    Next
                Next
            End If
        End If
        AddHandler View.ControlsCreated, AddressOf View_ControlsCreated
        
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        RemoveHandler View.ControlsCreated, AddressOf View_ControlsCreated

    End Sub
    Private Sub View_ControlsCreated(sender As Object, e As EventArgs)
        If TryCast(View, DetailView) IsNot Nothing Then
            Dim _ViewItem As ViewItem
            Dim _ActionContainerViewItem As ActionContainerViewItem
            For Each _ViewItem In TryCast(View, DetailView).Items
                _ActionContainerViewItem = TryCast(_ViewItem, ActionContainerViewItem)
                If _ActionContainerViewItem IsNot Nothing Then
                    AddHandler _ActionContainerViewItem.ControlCreated, AddressOf ActionContainerViewItem_ControlCreated
                End If
            Next
        End If
    End Sub

    Private Sub ActionContainerViewItem_ControlCreated(sender As Object, e As EventArgs)
        For Each _Action In TryCast(sender, ActionContainerViewItem).Actions
            CustomizeActionToolTip(_Action, View)
        Next
    End Sub
    Private Sub CustomizeActionToolTip(_Action As ActionBase, _View As View)
        'Action.ToolTip += Chr(13) + Chr(10) & "View Id: " & View.Id & Chr(13) + Chr(10) & "Action Id : " & _Action.Id & Chr(13) & Chr(10) & "Controller Id : " & _Action.Controller.Name
        Dim _Line As String = "==============================="

        Dim sArray() As String

        sArray = Split(_Action.ToolTip, _Line)

        If sArray.Length = 1 Then
            _Action.ToolTip += vbNewLine + _Line + Chr(13) + Chr(10) & "View Id: " & View.Id & Chr(13) + Chr(10) & "Action Id : " & _Action.Id & Chr(13) & Chr(10) & "Controller Id : " & _Action.Controller.Name
        Else
            _Action.ToolTip = sArray(0) + _Line + Chr(13) + Chr(10) & "View Id: " & View.Id & Chr(13) + Chr(10) & "Action Id : " & _Action.Id & Chr(13) & Chr(10) & "Controller Id : " & _Action.Controller.Name
        End If
    End Sub
End Class


