Improve PanelManager

This commit is contained in:
Jonathan Jenne 2019-03-11 16:32:51 +01:00
parent 896426da3b
commit 53f0632f4e
3 changed files with 55 additions and 18 deletions

View File

@ -13,7 +13,6 @@ Public Class ClassPanelManager
Private _dockManager As DockManager Private _dockManager As DockManager
Private _view As TabbedView Private _view As TabbedView
Private _panels As New List(Of DockPanel)
Private _documents As New List(Of Document) Private _documents As New List(Of Document)
Public Sub New(LogConfig As LogConfig, DocumentManager As DocumentManager, DockManager As DockManager) Public Sub New(LogConfig As LogConfig, DocumentManager As DocumentManager, DockManager As DockManager)
@ -38,28 +37,55 @@ Public Class ClassPanelManager
End Try End Try
End Sub End Sub
Private Sub View_DocumentDeactivated(sender As Object, e As DocumentEventArgs) Private Sub View_DocumentDeactivated(sender As Object, e As DocumentEventArgs)
Dim oDocument As BaseDocument = e.Document
Dim oHashcode As Integer = oDocument.Control.GetHashCode
If oDocument Is Nothing Then
Exit Sub
End If
' Maybe hide panels for this form ' Maybe hide panels for this form
For Each oPanel As DockPanel In _dockManager.Panels
Dim oTag As Integer = oPanel.Tag
If oTag = oHashcode Then
oPanel.Hide()
End If
Next
End Sub End Sub
Private Sub View_DocumentActivated(sender As Object, e As DocumentEventArgs) Private Sub View_DocumentActivated(sender As Object, e As DocumentEventArgs)
Dim oDocument As BaseDocument = e.Document Dim oDocument As BaseDocument = e.Document
Dim oHashcode As Integer = oDocument.Control.GetHashCode
If oDocument Is Nothing Then If oDocument Is Nothing Then
Exit Sub Exit Sub
End If End If
' Show Panels for this form ' 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 For Each oPanel As DockPanel In _dockManager.Panels
Dim oTag As Integer = oPanel.Tag Dim oTag As Integer = oPanel.Tag
If oTag = e.Document.Control.GetHashCode() Then If oTag = oHashcode Then
oPanel.Show()
End If
Next
End Sub
Private Sub View_DocumentClosing(sender As Object, e As DocumentCancelEventArgs)
Dim oDocument As BaseDocument = e.Document
Dim oHashcode As Integer = oDocument.Control.GetHashCode
If oDocument Is Nothing Then
Exit Sub
End If
' close all related panels.
For Each oPanel As DockPanel In _dockManager.Panels
Dim oTag As Integer = oPanel.Tag
If oTag = oHashcode Then
oPanel.Close() oPanel.Close()
End If End If
Next Next
@ -84,16 +110,14 @@ Public Class ClassPanelManager
_documents.Add(e.Document) _documents.Add(e.Document)
Dim oForm As BaseRibbonForm = e.Document.Control Dim oForm As BaseRibbonForm = e.Document.Control
Dim oFormHash As Integer = oForm.GetHashCode
Dim oInitialPanelInfo As List(Of PanelInfo) = oForm.GetInitialPanels() Dim oInitialPanelInfo As List(Of PanelInfo) = oForm.GetInitialPanels()
' TODO: determine how much panels at most can be added ' TODO: determine how much panels at most can be added
' check if initial panels should be loaded ' check if initial panels should be loaded
For Each oPanelInfo As PanelInfo In oInitialPanelInfo For Each oPanelInfo As PanelInfo In oInitialPanelInfo
' create the panel
Dim oPanel = _dockManager.AddPanel(oPanelInfo.Position)
' create the control ' create the control
Dim oControl As BasePanel = GetPanelControl(oPanelInfo) Dim oControl As BasePanel = GetPanelControl(oPanelInfo, oFormHash)
If oControl Is Nothing Then If oControl Is Nothing Then
Dim oPanelType = oPanelInfo.PanelControl.GetType.ToString Dim oPanelType = oPanelInfo.PanelControl.GetType.ToString
@ -101,14 +125,21 @@ Public Class ClassPanelManager
Continue For Continue For
End If End If
' configure the panel ' create panel
Dim oPanel = _dockManager.AddPanel(oPanelInfo.Position)
' configure panel
oPanel.Options.ShowCloseButton = oPanelInfo.CanBeClosed oPanel.Options.ShowCloseButton = oPanelInfo.CanBeClosed
oPanel.Options.ShowAutoHideButton = oPanelInfo.CanBePinned oPanel.Options.ShowAutoHideButton = oPanelInfo.CanBePinned
oPanel.Options.ShowMaximizeButton = oPanelInfo.CanBeMaximized oPanel.Options.ShowMaximizeButton = oPanelInfo.CanBeMaximized
oPanel.Options.AllowFloating = oPanelInfo.CanBeUndocked oPanel.Options.AllowFloating = oPanelInfo.CanBeUndocked
' hashcode is needed to know which form a panel belongs to ' relation is defined through HashCode of form saved in Tag property of panel
oPanel.Tag = oForm.GetHashCode '
' Form Panel
' GetHashCode --------> Tag
'
oPanel.Tag = oFormHash
oPanel.Text = oPanelInfo.Title oPanel.Text = oPanelInfo.Title
oPanel.Controls.Add(oControl) oPanel.Controls.Add(oControl)
Next Next
@ -116,7 +147,7 @@ Public Class ClassPanelManager
' TODO: establish communication channel to load panels on-demand ' TODO: establish communication channel to load panels on-demand
End Sub End Sub
Private Function GetPanelControl(PanelInfo As PanelInfo) As BasePanel Private Function GetPanelControl(PanelInfo As PanelInfo, FormHash As Integer) As BasePanel
If TypeOf PanelInfo.PanelControl Is DocumentPanel Then If TypeOf PanelInfo.PanelControl Is DocumentPanel Then
Dim oPanelControl As DocumentPanel = DirectCast(PanelInfo.PanelControl, DocumentPanel) Dim oPanelControl As DocumentPanel = DirectCast(PanelInfo.PanelControl, DocumentPanel)
oPanelControl.Datasource = PanelInfo.Datasource oPanelControl.Datasource = PanelInfo.Datasource

View File

@ -1,4 +1,8 @@
Public Class BasePanel Public Class BasePanel
Public Property Caption As String Public Property Caption As String
Public ReadOnly Property OwnerForm As Integer
Get
Return Parent?.Parent?.Tag
End Get
End Property
End Class End Class

View File

@ -20,7 +20,9 @@ Public Class DocumentPanel
Private Sub GridViewMain_RowClick(sender As Object, e As RowClickEventArgs) Handles GridViewMain.RowClick Private Sub GridViewMain_RowClick(sender As Object, e As RowClickEventArgs) Handles GridViewMain.RowClick
If e.Button = MouseButtons.Left And e.Clicks = 2 Then If e.Button = MouseButtons.Left And e.Clicks = 2 Then
MsgBox("Open Preview") MsgBox($"Open Preview for form {OwnerForm}")
'TODO: Open Preview Panel for OwnerForm
End If End If
End Sub End Sub
End Class End Class