ZooFlow: clean up class layout
This commit is contained in:
parent
0197835eee
commit
0bc57ca2bb
@ -1,37 +1,52 @@
|
|||||||
Imports System.Xml
|
Imports System.Xml
|
||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports DigitalData.Modules.Logging
|
Imports DigitalData.Modules.Logging
|
||||||
Public Class ClassWindowLocation
|
Public Class ClassWindowLayout
|
||||||
Private _Logger As Logger
|
Inherits Base.BaseClass
|
||||||
Public Sub New(LogConfig As LogConfig)
|
|
||||||
_Logger = LogConfig.GetLogger
|
Private _FileName As String
|
||||||
|
Private _Reader As XmlReader
|
||||||
|
Private _Settings As XmlWriterSettings
|
||||||
|
|
||||||
|
Public Sub New(pLogConfig As LogConfig)
|
||||||
|
MyBase.New(pLogConfig)
|
||||||
|
|
||||||
|
_Settings = New XmlWriterSettings With {
|
||||||
|
.Encoding = Text.Encoding.UTF8,
|
||||||
|
.Indent = True
|
||||||
|
}
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Sub LoadFormLocationSize(ByRef form As Form, Optional LoadSize As Boolean = True)
|
Public Sub LoadFormLocationSize(ByRef pForm As Form, Optional pLoadSize As Boolean = True)
|
||||||
Try
|
Try
|
||||||
Dim _path, _pathold As String
|
Dim oPath, oAlternatePath As String
|
||||||
|
|
||||||
|
oPath = Path.Combine(Application.UserAppDataPath(), pForm.Name & "-Layout.xml")
|
||||||
|
oAlternatePath = oPath.Replace("frm", "frmfrm")
|
||||||
|
If File.Exists(oAlternatePath) Then
|
||||||
|
Dim oNewFilename = Path.GetFileName(oPath)
|
||||||
|
|
||||||
_path = Path.Combine(Application.UserAppDataPath(), form.Name & "-Layout.xml")
|
|
||||||
_pathold = _path.Replace("frm", "frmfrm")
|
|
||||||
If File.Exists(_pathold) Then
|
|
||||||
Dim newfilename = Path.GetFileName(_path)
|
|
||||||
Try
|
Try
|
||||||
My.Computer.FileSystem.RenameFile(_pathold, newfilename)
|
My.Computer.FileSystem.RenameFile(oAlternatePath, oNewFilename)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
My.Computer.FileSystem.DeleteFile(_pathold)
|
Logger.Error(ex)
|
||||||
|
My.Computer.FileSystem.DeleteFile(oAlternatePath)
|
||||||
|
|
||||||
End Try
|
End Try
|
||||||
_path = Path.Combine(Application.UserAppDataPath(), form.Name & "-Layout.xml")
|
|
||||||
|
oPath = Path.Combine(Application.UserAppDataPath(), pForm.Name & "-Layout.xml")
|
||||||
End If
|
End If
|
||||||
Dim layout As ClassLayout = New ClassLayout(_path)
|
_FileName = oPath
|
||||||
|
|
||||||
Dim settings As System.Collections.Generic.List(Of ClassSetting)
|
Dim settings As System.Collections.Generic.List(Of ClassSetting)
|
||||||
settings = layout.Load()
|
settings = Load()
|
||||||
|
|
||||||
If settings.Count = 0 Then
|
If settings.Count = 0 Then
|
||||||
settings.Add(New ClassSetting("PositionX", form.Location.X))
|
settings.Add(New ClassSetting("PositionX", pForm.Location.X))
|
||||||
settings.Add(New ClassSetting("PositionY", form.Location.Y))
|
settings.Add(New ClassSetting("PositionY", pForm.Location.Y))
|
||||||
settings.Add(New ClassSetting("Width", form.Size.Width))
|
settings.Add(New ClassSetting("Width", pForm.Size.Width))
|
||||||
settings.Add(New ClassSetting("Height", form.Size.Height))
|
settings.Add(New ClassSetting("Height", pForm.Size.Height))
|
||||||
layout.Save(settings)
|
Save(settings)
|
||||||
End If
|
End If
|
||||||
Dim x, y, w, h As Integer
|
Dim x, y, w, h As Integer
|
||||||
For Each s As ClassSetting In settings
|
For Each s As ClassSetting In settings
|
||||||
@ -50,16 +65,16 @@ Public Class ClassWindowLocation
|
|||||||
Dim screenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
|
Dim screenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
|
||||||
Dim screenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
|
Dim screenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
|
||||||
If x = 5000 Then
|
If x = 5000 Then
|
||||||
form.WindowState = FormWindowState.Maximized
|
pForm.WindowState = FormWindowState.Maximized
|
||||||
Else
|
Else
|
||||||
|
|
||||||
Dim rect As New Rectangle(x, y, 0, 0)
|
Dim rect As New Rectangle(x, y, 0, 0)
|
||||||
If IsVisibleOnAnyScreen(rect) Then
|
If IsVisibleOnAnyScreen(rect) Then
|
||||||
If x >= 0 And y >= 0 Then
|
If x >= 0 And y >= 0 Then
|
||||||
form.Location = New Point(x, y)
|
pForm.Location = New Point(x, y)
|
||||||
End If
|
End If
|
||||||
If w > 0 And h > 0 And LoadSize = True Then
|
If w > 0 And h > 0 And pLoadSize = True Then
|
||||||
form.Size = New Size(w, h)
|
pForm.Size = New Size(w, h)
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
' form.Size = New Size(310, 190)
|
' form.Size = New Size(310, 190)
|
||||||
@ -81,12 +96,12 @@ Public Class ClassWindowLocation
|
|||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
If result = False Then
|
If result = False Then
|
||||||
_Logger.Info(">> Saved layout is not fitting to Resolution. Default is loaded.")
|
Logger.Info(">> Saved layout is not fitting to Resolution. Default is loaded.")
|
||||||
End If
|
End If
|
||||||
Return result
|
Return result
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_Logger.Info("Error in IsVisibleOnAnyScreen: " & ex.Message)
|
Logger.Info("Error in IsVisibleOnAnyScreen: " & ex.Message)
|
||||||
_Logger.Error(ex.Message)
|
Logger.Error(ex.Message)
|
||||||
Return False
|
Return False
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
@ -120,7 +135,7 @@ Public Class ClassWindowLocation
|
|||||||
settings.Add(New ClassSetting("Width", width))
|
settings.Add(New ClassSetting("Width", width))
|
||||||
settings.Add(New ClassSetting("Height", height))
|
settings.Add(New ClassSetting("Height", height))
|
||||||
|
|
||||||
layout.Save(settings)
|
Save(settings)
|
||||||
Catch notFoundEx As System.IO.FileNotFoundException
|
Catch notFoundEx As System.IO.FileNotFoundException
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
@ -129,77 +144,79 @@ Public Class ClassWindowLocation
|
|||||||
|
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
|
||||||
|
|
||||||
|
|
||||||
'-------------------------------------------------------------------
|
|
||||||
|
|
||||||
Public Class ClassSetting
|
|
||||||
Public _name As String
|
|
||||||
Public _value As Integer
|
|
||||||
|
|
||||||
Public Sub New(name As String, value As Integer)
|
|
||||||
_name = name
|
|
||||||
_value = value
|
|
||||||
End Sub
|
|
||||||
End Class
|
|
||||||
|
|
||||||
Public Class ClassLayout
|
|
||||||
Private _filename As String
|
|
||||||
Private _reader As XmlReader
|
|
||||||
Private _settings As XmlWriterSettings
|
|
||||||
|
|
||||||
Public Sub New(filename As String)
|
|
||||||
_filename = filename
|
|
||||||
|
|
||||||
_settings = New XmlWriterSettings()
|
|
||||||
_settings.Encoding = System.Text.Encoding.UTF8
|
|
||||||
_settings.Indent = True
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Public Sub Save(settings As System.Collections.Generic.List(Of ClassSetting))
|
Public Sub Save(settings As System.Collections.Generic.List(Of ClassSetting))
|
||||||
Dim w = XmlTextWriter.Create(_filename, _settings)
|
Try
|
||||||
|
Dim w = XmlWriter.Create(_FileName, _Settings)
|
||||||
|
|
||||||
w.WriteStartDocument()
|
w.WriteStartDocument()
|
||||||
w.WriteStartElement("Settings")
|
w.WriteStartElement("Settings")
|
||||||
|
|
||||||
|
For Each setting As ClassSetting In settings
|
||||||
|
w.WriteStartElement("Setting")
|
||||||
|
w.WriteAttributeString("name", setting._name)
|
||||||
|
w.WriteAttributeString("value", setting._value.ToString())
|
||||||
|
w.WriteEndElement()
|
||||||
|
Next
|
||||||
|
|
||||||
For Each setting As ClassSetting In settings
|
|
||||||
w.WriteStartElement("Setting")
|
|
||||||
w.WriteAttributeString("name", setting._name)
|
|
||||||
w.WriteAttributeString("value", setting._value.ToString())
|
|
||||||
w.WriteEndElement()
|
w.WriteEndElement()
|
||||||
Next
|
w.WriteEndDocument()
|
||||||
|
|
||||||
w.WriteEndElement()
|
w.Dispose()
|
||||||
w.WriteEndDocument()
|
w.Close()
|
||||||
|
Catch ex As Exception
|
||||||
w.Dispose()
|
Logger.Error(ex)
|
||||||
w.Close()
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Function Load() As System.Collections.Generic.List(Of ClassSetting)
|
Public Function Load() As List(Of ClassSetting)
|
||||||
Dim Result As System.Collections.Generic.List(Of ClassSetting) = New System.Collections.Generic.List(Of ClassSetting)()
|
Dim Result As List(Of ClassSetting) = New List(Of ClassSetting)()
|
||||||
|
|
||||||
If Not File.Exists(_filename) Then
|
If Not File.Exists(_FileName) Then
|
||||||
Return Result
|
Return Result
|
||||||
End If
|
End If
|
||||||
|
|
||||||
_reader = XmlReader.Create(_filename)
|
_Reader = XmlReader.Create(_FileName)
|
||||||
|
|
||||||
While _reader.Read()
|
While _Reader.Read()
|
||||||
If _reader.IsStartElement() Then
|
If _Reader.IsStartElement() Then
|
||||||
If _reader.Name = "Setting" Then
|
If _Reader.Name = "Setting" Then
|
||||||
Dim name As String = _reader("name")
|
Dim name As String = _Reader("name")
|
||||||
Dim value As Integer = Integer.Parse(_reader("value"))
|
Dim value As Integer = Integer.Parse(_Reader("value"))
|
||||||
Dim setting As ClassSetting = New ClassSetting(name, value)
|
Dim setting As ClassSetting = New ClassSetting(name, value)
|
||||||
Result.Add(setting)
|
Result.Add(setting)
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
End While
|
End While
|
||||||
|
|
||||||
_reader.Dispose()
|
_Reader.Dispose()
|
||||||
_reader.Close()
|
_Reader.Close()
|
||||||
|
|
||||||
Return Result
|
Return Result
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Public Class ClassSetting
|
||||||
|
Public _name As String
|
||||||
|
Public _value As Integer
|
||||||
|
|
||||||
|
Public Sub New(name As String, value As Integer)
|
||||||
|
_name = name
|
||||||
|
_value = value
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
|
End Class
|
||||||
|
|
||||||
|
|
||||||
|
'-------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Public Class ClassLayout
|
||||||
|
|
||||||
|
|
||||||
|
Public Sub New(filename As String)
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
@ -245,7 +245,7 @@
|
|||||||
<Compile Include="Globix\ClassFileDrop.vb" />
|
<Compile Include="Globix\ClassFileDrop.vb" />
|
||||||
<Compile Include="Globix\ClassFilehandle.vb" />
|
<Compile Include="Globix\ClassFilehandle.vb" />
|
||||||
<Compile Include="ClassInit.vb" />
|
<Compile Include="ClassInit.vb" />
|
||||||
<Compile Include="ClassLayout.vb" />
|
<Compile Include="ClassWindowLayout.vb" />
|
||||||
<Compile Include="ClipboardWatcher\State.vb" />
|
<Compile Include="ClipboardWatcher\State.vb" />
|
||||||
<Compile Include="ClassIDBData.vb" />
|
<Compile Include="ClassIDBData.vb" />
|
||||||
<Compile Include="DSIDB_Stammdaten.Designer.vb">
|
<Compile Include="DSIDB_Stammdaten.Designer.vb">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user