[Lazarus] GTK2: Drag files to other applications (to the file manager, Thunar, Nautilus, etc)

Bernd prof7bit at gmail.com
Mon Aug 20 17:38:45 CEST 2012


I have made a working component. See attachment. Use it like this:

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  DragSource := TFileDragSource.Create(Self);
  DragSource.Control := ScrollBox1;
  DragSource.OnDragBegin := @OnScrollboxDragBegin;;
  DragSource.OnDragEnd := @OnScrollboxDragEnd;;
  DragSource.OnGetData := @OnScrollboxGetData;;
end;

procedure TForm1.OnScrollboxDragBegin(Sender: TObject);
begin
  WriteLn('scrollbox drag begin');
end;

procedure TForm1.OnScrollboxDragEnd(Sender: TObject);
begin
  WriteLn('scrollbox drag end');
end;

procedure TForm1.OnScrollboxGetData(Sender: TObject; Data: TStringList);
begin
  WriteLn('scrollbox drag get data');
  Data.Append('file:///home/bernd/file_a');
  Data.Append('file:///home/bernd/file_b');
end;

Now the Scrollbox on my form will act as a drag source for dragging
files to other applications (In a real world application the OnGetData
handler could for example create these files and supply the file names
and the OnDragEnd could delete them again). Dragging them to the file
manager would copy the files, dragging them to an editor would make it
open them.

Now it wold be nice if one of the local windows API Gurus could extend
this code to also work in windows and maybe someone else make it work
in Qt and on the Mac also. And eventually this code should go directly
into the LCL (maybe after also adding the ability to drag arbitrary
mime types and not only filenames).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: filedragsource.pas.tar.bz2
Type: application/x-bzip2
Size: 2597 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20120820/570f193a/attachment-0003.bin>


More information about the Lazarus mailing list