Dropping a file onto TextArea

Post

Posted
Rating:
#1 (In Topic #1134)
Trainee
Hello all,

I am having a problem with a drop event that I hope someone can help with. I have simplified the problem to the following…

I have a form that contains only two controls; a TableView and a TextArea. The text area is set to allow drop by default.

When I drag a file off my desktop into the text area it catches the file name and allows me to open it and load the contents to the text area but it leaves the headings in the table view fixed in that I can no longer resize the heading by dragging them with the mouse pointer. Everything else about the table view works ok.

This is all the code in FMain.Class

Code

' Gambas class file


Public Sub Form_Open()

   TableView1.Columns.Count = 2
   TableView1.Rows.Count = 2
   
   TableView1.Columns[0].Text = "Heading 1"
   TableView1.Columns[1].Text = "Heading 2"
   
   TableView1[0, 0].Text = "123456"
   TableView1[0, 1].Text = "abcdefg"
   

End

Public Sub TextArea1_Drop()

   TextArea1.Text = Drag.Data

End

Thank you for looking
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
If the drag is a file drop then you should not use Drag.Data

Drag.Data for a file drop is a cr-lf terminated list and will look like this…

Code

file:///home/bonus/Desktop/gambas3.desktop\r\n


You should do something like this…

Code (gambas)

  1.  
  2. Public Sub TextArea1_Drop()
  3.  
  4.  Dim sText As String
  5.  
  6.   If Drag.Formats.Exist("text/uri-list") Then   ' uri-list dag.paste returns an array of String[]
  7.    sText = Drag.Paste("text/uri-list")[0]
  8.   Else If Drag.Format = "text/plain" Then  ' text/plain is just plain text String
  9.     sText = Drag.Paste("text/plain")
  10.  
  11.  If Not sText Then Return
  12.  
  13. TextArea1.Text = sText
  14.  
  15.  
  16.  


see the difference..

Code (gambas)

  1.   Debug Quote(Drag.Data)
  2.   Debug Quote(Drag.Paste("text/uri-list")[0])
  3.  
  4. ' Form1.TextArea1_Drop.40: "file:///home/bonus/env-outputs\r\n"
  5. ' Form1.TextArea1_Drop.43: "/home/bonus/env-outputs"
  6.  
  7.  
But after saying that it seems there is a bug with GTK3
It is different if you use QT
(PS. to use QT you must set the textarea.Drop property to false in the IDE then set TextArea1.Drop = True in Form_Open() to override QT default drop behavior)

I have reported the bug to the boss and sent a test project.
I also found after the file drop if you drag some text onto the TextArea again the program crashes with a segfault.
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
Thank you  :D

Made the changes you suggested and it works fine.
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
vuott is in the usergroup ‘Regular’
It was discussed here as well:

   Gambas One - Gambas ONE

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.