[GB.FORM]
* NEW: Now FileView use DesktopMime to set the files icon if it is loaded. git-svn-id: svn://localhost/gambas/trunk@5276 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
44cb9d7563
commit
4414985b24
1 changed files with 55 additions and 4 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Inherits UserControl
|
Inherits UserControl
|
||||||
Export
|
Export
|
||||||
|
Class DesktopMime
|
||||||
Public Const _Properties As String = "*,Border=True,Mode{Select.*},Dir,ShowDetailed,ShowHidden,ShowDirectory"
|
Public Const _Properties As String = "*,Border=True,Mode{Select.*},Dir,ShowDetailed,ShowHidden,ShowDirectory"
|
||||||
Public Const _DefaultEvent As String = "Click"
|
Public Const _DefaultEvent As String = "Click"
|
||||||
Public Const _Group As String = "View"
|
Public Const _Group As String = "View"
|
||||||
|
@ -44,7 +44,7 @@ Private $hPict As Picture
|
||||||
Private $hRefresh As Timer
|
Private $hRefresh As Timer
|
||||||
Private $bRefreshTriggered As Boolean
|
Private $bRefreshTriggered As Boolean
|
||||||
Private $iIconSize As Integer = 32
|
Private $iIconSize As Integer = 32
|
||||||
|
Private $bDesktopIsLoaded As Boolean
|
||||||
Static Public Sub _init()
|
Static Public Sub _init()
|
||||||
|
|
||||||
$cExt["html"] = "html"
|
$cExt["html"] = "html"
|
||||||
|
@ -97,6 +97,8 @@ Public Sub _new()
|
||||||
.Resizable = True
|
.Resizable = True
|
||||||
End With
|
End With
|
||||||
|
|
||||||
|
$bDesktopIsLoaded = Component.IsLoaded("gb.desktop")
|
||||||
|
|
||||||
Me.Proxy = GetView()
|
Me.Proxy = GetView()
|
||||||
|
|
||||||
$hRefresh = New Timer As "Refresh"
|
$hRefresh = New Timer As "Refresh"
|
||||||
|
@ -117,6 +119,50 @@ Private Function CheckFilter(sFile As String) As Boolean
|
||||||
|
|
||||||
End
|
End
|
||||||
|
|
||||||
|
Private Sub GetMimeIcon(hMime As DesktopMime, sPath As String, iSize As Integer) As Picture
|
||||||
|
|
||||||
|
Dim hImage As Image
|
||||||
|
Dim hIcon As Image
|
||||||
|
Dim sIcon As String
|
||||||
|
$hPict = Null
|
||||||
|
Try Raise Icon(sPath)
|
||||||
|
If $hPict Then Return $hPict
|
||||||
|
|
||||||
|
If IsDir(sPath) Then Return
|
||||||
|
|
||||||
|
'****** show the image content
|
||||||
|
If $aImgExt.Exist(File.Ext(sPath)) < 0 Then
|
||||||
|
If Stat(sPath).Size > 65536 Then Return Picture["icon:/" & iSize & "/image"]
|
||||||
|
|
||||||
|
hImage = Image.Load(sPath)
|
||||||
|
If Not (hImage.Width = iSize And hImage.Height = iSize) Then
|
||||||
|
If hImage.Width > hImage.Height Then
|
||||||
|
hImage = hImage.Stretch(iSize, (iSize * hImage.Height) \ hImage.Width)
|
||||||
|
Else
|
||||||
|
hImage = hImage.Stretch((iSize * hImage.Width) \ hImage.Height, iSize)
|
||||||
|
Endif
|
||||||
|
Endif
|
||||||
|
|
||||||
|
hIcon = New Image(hImage.W + 4, hImage.H + 4, Color.Transparent)
|
||||||
|
Paint.Begin(hIcon)
|
||||||
|
Paint.AntiAlias = False
|
||||||
|
Paint.Rectangle(0, 0, hIcon.W, hIcon.H)
|
||||||
|
Paint.Brush = Paint.Color(Color.Gray)
|
||||||
|
Paint.Stroke
|
||||||
|
Paint.End
|
||||||
|
hIcon.DrawImage(hImage, 2, 2)
|
||||||
|
|
||||||
|
Return hIcon.Picture
|
||||||
|
|
||||||
|
Endif
|
||||||
|
|
||||||
|
'*************
|
||||||
|
|
||||||
|
Return hMime.GetIcon(iSize).Picture
|
||||||
|
End
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Private Sub GetIcon(sPath As String, iSize As Integer) As Picture
|
Private Sub GetIcon(sPath As String, iSize As Integer) As Picture
|
||||||
|
|
||||||
Dim hImage As Image
|
Dim hImage As Image
|
||||||
|
@ -220,7 +266,7 @@ Private Sub RefreshView()
|
||||||
Dim aSel As String[]
|
Dim aSel As String[]
|
||||||
Dim aDir As New String[]
|
Dim aDir As New String[]
|
||||||
Dim I As Integer
|
Dim I As Integer
|
||||||
|
Dim hMime As DesktopMime
|
||||||
Inc Application.Busy
|
Inc Application.Busy
|
||||||
|
|
||||||
aSel = GetSelection()
|
aSel = GetSelection()
|
||||||
|
@ -252,7 +298,12 @@ Private Sub RefreshView()
|
||||||
If $aFilter And If CheckFilter(sFile) Then Continue
|
If $aFilter And If CheckFilter(sFile) Then Continue
|
||||||
sPrefix = "1"
|
sPrefix = "1"
|
||||||
Endif
|
Endif
|
||||||
hPict = GetIcon(sDir &/ sFile, iSize)
|
If $bDesktopIsLoaded Then
|
||||||
|
hMime = DesktopMime.FromFile(sDir &/ sFile)
|
||||||
|
hPict = GetMimeIcon(hMime, sDir &/ sFile, iSize)
|
||||||
|
Else
|
||||||
|
hPict = GetIcon(sDir &/ sFile, iSize)
|
||||||
|
Endif
|
||||||
If Not hPict Then
|
If Not hPict Then
|
||||||
If .Type = gb.Directory Then
|
If .Type = gb.Directory Then
|
||||||
hPict = hPictFolder
|
hPict = hPictFolder
|
||||||
|
|
Loading…
Reference in a new issue