Dropping a file onto TextArea

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
pusherman
Posts: 16
Joined: Sunday 5th November 2023 11:45am

Dropping a file onto TextArea

Post by pusherman »

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: Select all

' 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
User avatar
BruceSteers
Posts: 1580
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Dropping a file onto TextArea

Post by BruceSteers »

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: Select all

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

You should do something like this...

Public Sub TextArea1_Drop()

 Dim sText As String

  If Drag.Formats.Exist("text/uri-list") Then   ' uri-list dag.paste returns an array of String[]
   sText = Drag.Paste("text/uri-list")[0]
  Else If Drag.Format = "text/plain" Then  ' text/plain is just plain text String
    sText = Drag.Paste("text/plain")
  Endif

 If Not sText Then Return

TextArea1.Text = sText

End




see the difference..
  Debug Quote(Drag.Data)
  Debug Quote(Drag.Paste("text/uri-list")[0])

' Form1.TextArea1_Drop.40: "file:///home/bonus/env-outputs\r\n"
' Form1.TextArea1_Drop.43: "/home/bonus/env-outputs"


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.
If at first you don't succeed , try doing something differently.
BruceS
pusherman
Posts: 16
Joined: Sunday 5th November 2023 11:45am

Re: Dropping a file onto TextArea

Post by pusherman »

Thank you :D

Made the changes you suggested and it works fine.
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Dropping a file onto TextArea

Post by vuott »

It was discussed here as well:

viewtopic.php?t=1619
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Post Reply