105 lines
3.4 KiB
VB.net
105 lines
3.4 KiB
VB.net
Imports DevExpress.XtraBars.Docking
|
|
Imports DevExpress.XtraBars.Docking2010
|
|
Imports DevExpress.XtraBars.Docking2010.Views
|
|
Imports DevExpress.XtraBars.Docking2010.Views.Tabbed
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Public Class ClassPanelManager
|
|
Private _logger As Logger
|
|
Private _logConfig As LogConfig
|
|
|
|
Private _documentManager As DocumentManager
|
|
Private _dockManager As DockManager
|
|
Private _view As TabbedView
|
|
|
|
Private _panels As New List(Of DockPanel)
|
|
Private _documents As New List(Of Document)
|
|
|
|
Public Sub New(LogConfig As LogConfig, DocumentManager As DocumentManager, DockManager As DockManager)
|
|
Try
|
|
Dim oView = DocumentManager.View
|
|
|
|
_logConfig = LogConfig
|
|
_logger = LogConfig.GetLogger()
|
|
|
|
_documentManager = DocumentManager
|
|
_dockManager = DockManager
|
|
_view = oView
|
|
|
|
AddHandler oView.DocumentAdded, AddressOf View_DocumentAdded
|
|
AddHandler oView.DocumentClosed, AddressOf View_DocumentClosed
|
|
AddHandler oView.DocumentClosing, AddressOf View_DocumentClosing
|
|
AddHandler oView.DocumentActivated, AddressOf View_DocumentActivated
|
|
AddHandler oView.DocumentDeactivated, AddressOf View_DocumentDeactivated
|
|
Catch ex As Exception
|
|
_logger.Error(ex)
|
|
Throw ex
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
|
|
Private Sub View_DocumentDeactivated(sender As Object, e As DocumentEventArgs)
|
|
' Maybe hide panels for this form
|
|
End Sub
|
|
|
|
Private Sub View_DocumentActivated(sender As Object, e As DocumentEventArgs)
|
|
Dim oDocument As BaseDocument = e.Document
|
|
|
|
If oDocument Is Nothing Then
|
|
Exit Sub
|
|
End If
|
|
|
|
' Show Panels for this form
|
|
End Sub
|
|
|
|
Private Sub View_DocumentClosing(sender As Object, e As DocumentCancelEventArgs)
|
|
' close all related panels
|
|
For Each oPanel As DockPanel In _dockManager.Panels
|
|
Dim oTag As Integer = oPanel.Tag
|
|
|
|
If oTag = e.Document.Control.GetHashCode() Then
|
|
oPanel.Close()
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub View_DocumentClosed(sender As Object, e As DocumentEventArgs)
|
|
' remove event handlers
|
|
_documents.Remove(e.Document)
|
|
End Sub
|
|
|
|
Private Sub View_DocumentAdded(sender As Object, e As DocumentEventArgs)
|
|
' Only Ribbon Forms can have panels!
|
|
If TypeOf e.Document.Control IsNot BaseRibbonForm Then
|
|
Exit Sub
|
|
End If
|
|
|
|
' Don't open panels for the same form twice!
|
|
If _documents.Contains(e.Document) Then
|
|
Exit Sub
|
|
End If
|
|
|
|
_documents.Add(e.Document)
|
|
|
|
Dim oForm As BaseRibbonForm = e.Document.Control
|
|
Dim oInitialPanelInfo As List(Of PanelInfo) = oForm.GetInitialPanels()
|
|
|
|
' TODO: determine how much panels at most can be added
|
|
' check if initial panels should be loaded
|
|
For Each oPanelInfo As PanelInfo In oInitialPanelInfo
|
|
' Create the control
|
|
Dim oControl = oPanelInfo.InnerControl
|
|
oControl.Dock = DockStyle.Fill
|
|
|
|
' Create the panel and add the control
|
|
Dim oPanel = _dockManager.AddPanel(oPanelInfo.Position)
|
|
oPanel.Tag = oForm.GetHashCode
|
|
oPanel.Text = oPanelInfo.Caption
|
|
oPanel.Controls.Add(oControl)
|
|
Next
|
|
|
|
' TODO: establish communication channel to load panels on-demand
|
|
End Sub
|
|
End Class
|