By: Paul S. Cilwa | Viewed: 5/8/2024 Posted: 8/3/2018 |
Page Views: 668 | |
Topics: #Computers #Programming #Organica #VB.NET | |||
A derived Document class to represent a Folder (a collection of documents and/or additional folders. |
When Organica first starts up, typically it will display contents of the user's root folder. This is the class that understands what a Folder is, and how to display and allow interaction with it.
In addition to its New procedure, the FolderDocument class only needs to override the RenderHeader, RenderContent and RenderProperties functions to generate a more appropriate display than does the generic Document class (which is actually used only for unknown document types).
Documents.vb (append)
Class FolderDocument
Inherits Document
Public MySelf As New ThisUser
Private Properties As ProfileDocument
Private i_DocList As New SortedList
Private i_DisplayName As String
Public Sub New(ByVal a_Pathname)
MyBase.New(a_Pathname)
IconPath = "Icons\Folder.png"
Dim IniFile As String = _
My.Computer.FileSystem.CombinePath(Pathname, "Organica.ini")
If File.Exists(IniFile) Then
Properties = New ProfileDocument(IniFile)
IconPath = Properties.GetData("IconPath", "Icons\Folder.png")
If IconPath.Substring(0, 1) = "[" Then
Select Case IconPath.ToLower()
Case "[userphoto]"
IconPath = MySelf.PhotoPath
End Select
End If
i_DisplayName = Properties.GetData("DisplayName", Filename)
If i_DisplayName.Substring(0, 1) = "[" Then
Select Case i_DisplayName.ToLower()
Case "[userdisplayname]"
i_DisplayName = MySelf.DisplayName
End Select
End If
End If
End Sub
Public Sub Populate()
Dim VirtualFolders As ProfileDocument
Dim Folders As String()
Dim Files As String()
Dim i As String
Dim D As Document
Dim IniFile As String = _
My.Computer.FileSystem.CombinePath(Pathname, "Organica.ini")
If File.Exists(IniFile) Then
VirtualFolders = New ProfileDocument(IniFile)
For Each i In .Sections
D = New LinkDocument(.LinkPathname(i), .LinkIcon(i), i)
i_DocList.Add(D.Pathname, D)
Next
End With
If Directory.Exists(Pathname) Then
Folders = Directory.GetDirectories(Pathname)
For Each i In Folders
D = Document.CreateObject(i)
If Not D Is Nothing Then
If Not D.IsSystem And Not D.IsHidden And Not _
D.Filename.ToString.Substring(0, 1) = "." Then
i_DocList.Add(D.Pathname, D)
End If
End If
Next
Files = Directory.GetFiles(Pathname)
For Each i In Files
D = Document.CreateObject(i)
If Not D Is Nothing Then
If Not D.IsSystem And Not D.IsHidden And Not _
D.Filename.ToString.Substring(0, 1) = "." Then
i_DocList.Add(D.Pathname, D)
End If
End If
Next
End If
End Sub
Public Overloads Overrides Function Find(ByVal Key As String) As Document
Return i_DocList.Item(Key)
End Function
Public Overloads Overrides ReadOnly Property RenderHeader As String
Get
Dim Buffer As String
Buffer = "<div class='organica_Document organica_Folder'>"
ConCat(Buffer, "<img src='TypeFolder.png'><div>")
ConCat(Buffer, "<h1>" & Filename & "</h1>")
ConCat(Buffer, "<p>" & Pathname & "</p>")
ConCat(Buffer, "</div>""</div>")
Return Buffer
End Get
End Property
End Class
Public Overloads Overrides ReadOnly Property RenderContent As String
Get
Dim Buffer As String = ""
For Each D As Document In i_DocList.Values
If D.Visible Then
Buffer = Buffer & D.RenderHeader
End If
Next
Return Buffer
End Get
End Property