TerminalView: Support for file URL drops.

[GB.FORM.TERMINAL]
* NEW: TerminalView: Support for file URL drops.
This commit is contained in:
gambas 2021-02-26 20:18:50 +01:00 committed by Christof Thalhofer
parent bca4f6ef85
commit 77db48a6a8

View file

@ -181,6 +181,7 @@ Public Sub _new()
$hView.Focus = True
$hView.Tracking = True
$hView.Mouse = Mouse.Text
$hView.Drop = True
'$hView.NoBackground = True
Me.Background = Color.TextForeground
@ -1450,17 +1451,20 @@ Public Sub Copy()
End
Private Sub PasteText(sText As String)
If Not sText Then Return
If $hFilter.BracketedPasteActive Then sText = "\e[200~" & sText & "\e[200~"
Input(sText)
End
'' Paste the clipboard contents into the terminal, as if it has been entered through the keyboard.
Public Sub Paste()
Dim sText As String
sText = Clipboard.Paste("text/plain;charset=utf-8")
If Not sText Then Return
If $hFilter.BracketedPasteActive Then sText = "\e[200~" & sText & "\e[200~"
Input(sText)
PasteText(Clipboard.Paste("text/plain;charset=utf-8"))
End
@ -1762,3 +1766,45 @@ Private Function Link_Read() As TerminalLink
Return $hTerminalLink
End
Private Sub UrlUnquote(Path As String) As String
Dim iInd As Integer
Dim sRes As String
Dim sCar As String
For iInd = 1 To Len(Path)
sCar = Mid$(Path, iInd, 1)
If sCar = "%" Then
sCar = Chr$(Val("&H" & Mid$(Path, iInd + 1, 2)))
iInd += 2
Else If sCar = "+" Then
sCar = " "
Endif
sRes &= sCar
Next
Return sRes
End
Public Sub View_Drop()
Dim sText As String
Dim aText As String[]
Dim I As Integer
If Drag.Formats.Exist("text/uri-list") Then
sText = Trim(Drag.Paste("text/uri-list"))
If sText Then
aText = Split(sText, "\r\n", "", True)
For I = 0 To aText.Max
sText = aText[I]
If sText Begins "file://" Then aText[I] = UrlUnquote(Mid$(sText, 8))
aText[I] = Shell$(aText[I])
Next
PasteText(aText.Join(" ") & " ")
Endif
Endif
End