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