[Gambas-user] Drag & drop files

Maria geaplanet at ...397...
Fri Dec 2 18:54:51 CET 2011


Thanks, Pham

I can't find libgvfscommon in debian, is it an old library pearhaps?


In gambas-es comunity, jguardon, resolved the problem using a function for automatic conversion: http://www.gambas-es.org/viewtopic.php?f=1&t=2054&postdays=0&postorder=asc&start=10


Here it is the code of jguardon:

' Gambas class file

Public Sub Form_Open()

End

Public Sub boton_Drop()

  Dim a As String
  Dim b As String[]

  a = Drag.Paste("text/uri-list") ' limitamos el tipo de los datos pegados
  b = Split(a, gb.CrLf, "", True) ' cargamos la lista de rutas en un array b
                                  ' escapando las terminaciones de línea
  a = Null  ' reutilizamos la variable "a"

  For Each a In b
    a = Right$(a, -7) ' quitamos "file://"
    a = URLDecode(a)  ' descodificamos las cadenas
    Print a
    Desktop.Open(a)   ' para probar, abrimos cada tipo de 
                      ' fichero con la aplicacion correspondiente
  Next

End

Static Private Function URLDecode(txt As String) As String
  ''' Descodifica los caracteres hexadecimales en las URI's recorriendo la cadena dada
  ''' Params: txt la URI a descodificar
  ''' Return: la URI descodificada
  
  Dim txt_len As Integer
  Dim i As Integer
  Dim ch As String
  Dim digits As String
  Dim resultado As String

  resultado = ""
  txt_len = Len(txt)
  i = 1
  Do While i <= txt_len
    ' Examinar el siguiente caracter
    ch = Mid$(txt, i, 1)
    If ch = "+" Then
      ' Convertir a espacio
      resultado = resultado & " "
    Else If ch <> "%" Then
      ' Normal, no cambiar
      resultado = resultado & ch
    Else If i > txt_len - 2 Then
      resultado = resultado & ch
    Else
      ' Obtener los siguientes caracteres hex.
      digits = Mid$(txt, i + 1, 2)
      ' Debug digits
      ' aquí convertimos el valor hexadecimal a entero y
      ' se lo pasamos a Chr que devuelve el carácter correcto.
      resultado = resultado & Chr$(CInt(Val("&" & digits)))
      i = i + 2
    Endif
    i = i + 1
  Loop

  Return resultado

End


More information about the User mailing list