The FileProperties control (gb.form) displays essential properties of a file or directory in a TabPanel. You can add additional tabs to the TabPanel by using the FileProperties.Add(…) method. The DirChooser and FileChooser controls also internally use the FileProperties control to display selected properties of a file or directory (blue button with i symbol):
Figure 6.9.6.1: Use of control element FileProperties in DirChooser
You can create this class:
Dim hFileProperties As FileProperties hFileProperties = New FileProperties ( Parent As Container ) As "EventName"
The FileProperties class has these properties, among others:
Property | Data type | Description |
---|---|---|
Data | _FileProperties | Returns a virtual object to be filled by the data event handler to describe the file type and set the displayed icon. |
Path | String | Returns or sets the path of the file whose properties are displayed. If the path is a directory, the size of the directory contents is automatically calculated by a background task. |
Table 6.9.6.1.1 : Selected properties of the FileProperties class
The FileProperties control element displays a preview image in addition to selected properties (type, directory, size, date last modified (mtime), permissions, owner and group) for image files only.
Figure 6.9.6.2.1: Display of selected properties
Figure 6.9.6.2.2: Display thumbnail image
The Add( Panel As Control, Title As String ) method adds an existing container or control to a new tab of the FileProperties control. Panel is the control that is inserted and Title is the title of the new tab.
Figure 6.9.6.2.3: New tab with the title “Text Preview”.
A new tab can be created with this source code:
Public Sub FileView1_Click() Dim sFileName, sFilePath As String sFileName = FileView1.Current sFilePath = DirBox1.Value &/ sFileName FileProperties1.Path = sFilePath Select Lower(File.Ext(sFileName)) Case "txt", "xml", "conf", "class", "log", "dat", "py", "pl", "php", "html" If k = 0 Then hTextArea = New TextArea(FileProperties1) hTextArea.Background = &HFFFFE1 FileProperties1.Add(hTextArea, ("Text preview")) Inc k Endif hTextArea.Text = File.Load(sFilePath) hTextArea.Pos = 0 End Select End
With the above source code, you can extend the default behaviour to also display the contents of selected text files.
Among the events of the control element, the Data() event is of particular interest: The FileProperties.Data() event can be handled to define the type of a special group of files - criterion is a list of extensions - and their symbol by filling the Data property during the event handler. If the default behaviour of the FileProperties dialogue is desired in the event handler, then the event must be stopped.
Figure 6.9.6.3.1: Extended display of file type with matching icon.
Source code section:
[1] Public Sub FileProperties1_Data() [2] [3] If IsDir(FileProperties1.Path) Then [4] ' Default behavior [5] Stop Event [6] Return [7] Else [8] Select Lower(File.Ext(FileView1.Current)) [9] Case "txt", "xml", "conf", "class", "log", "dat", "py", "pl", "php", "html" [10] FileProperties1.Data.Type = ("Text file") [11] FileProperties1.Data.Icon = Picture["icon:/48/shortcut"] [12] Case "pdf" [13] FileProperties1.Data.Type = ("PDF-File") [14] FileProperties1.Data.Icon = Picture["icon:/48/pdf"] [15] Case "png", "jpg", "jpeg", "gif" [16] ' Default behavior of the FileProperties dialog for these selected file extensions [17] Stop Event [18] Return [19] Case Else [20] FileProperties1.Data.Type = ("File") [21] FileProperties1.Data.Icon = Picture["icon:/48/office"] [22] End Select [23] Endif [24] [25] End
Project