Recent

Author Topic: [Solved] Processing of selections in FileListBox content in order of selection?  (Read 2048 times)

loaded

  • Hero Member
  • *****
  • Posts: 569
Hi All,
I have a code that gets selected files in FileListBox.
But if I want to get them in the order of selection, things get complicated.

As an alternaive ;
I thought about moving the rows up and down, but that didn't seem very practical to me.
Is there a ready solution for this on the FileListBox side? Or should I create my own solution?
Code: Pascal  [Select][+][-]
  1. var
  2.   i:integer;
  3.   p1:UTF8String;
  4. begin
  5.   for i:=0 to FileListBox1.Items.Count-1 do
  6.   begin
  7.     if FileListBox1.Selected[i] then
  8.     begin
  9.        p1:= '"'+FileListBox1.Directory+'\'+FileListBox1.Items[i]+'" ';
  10.        // Todo
  11.     end;
  12.   end;
  13. end;
I would be glad if you share your thoughts on the subject. Respects.
« Last Edit: January 29, 2022, 09:44:14 am by loaded »
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

Thaddy

  • Hero Member
  • *****
  • Posts: 11543
On select, add the selection to a queue and do not process yet. Then process the items in the queue. A queue is FIFO. There are several good (de)queues available in the standard fpc distribution. E.g. fgl, generics.collections,  contnrs. You can also use a Tstrings descendant as a queue.
I am not aware that a listbox (any) has such functionality, although re-ordering is possible.
I always would go for a queue, it is easy and exactly what you asked.
« Last Edit: January 29, 2022, 08:13:58 am by Thaddy »
Путин преступник. Россияне дезинформированы.

loaded

  • Hero Member
  • *****
  • Posts: 569
Thank you so much for the reply Thaddy
Yes, as you said, I can do this if the selection process is made one by one, but if multiple selections are made with the "shift" key from time to time, the circuits light up.  %)
Or I should have a coffee now, maybe I can do it later.
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

ccrause

  • Hero Member
  • *****
  • Posts: 569
Thank you so much for the reply Thaddy
Yes, as you said, I can do this if the selection process is made one by one, but if multiple selections are made with the "shift" key from time to time, the circuits light up.  %)
Or I should have a coffee now, maybe I can do it later.
While you wait for the coffee to kick in - if you want to really mimick the user actions, expand Thaddy's suggestion by tracking selection changes via OnSelectionChange event. If this event doesn't give you the required resolution, then hook all possible user actions (OnKeyDown/Up, OnMouseDown/Up etc.) and track the selection process that way (although this will require quite a bit of extra work).

loaded

  • Hero Member
  • *****
  • Posts: 569
Thank you so much for the reply ccrause
Yes, you are right, I drank my coffee and Lazarus I'm driving at full speed on the streets  of FileListBox behind the wheel of  :)
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

engkin

  • Hero Member
  • *****
  • Posts: 3112
From user perspective, the order would not be clear. Find a better alternative like using two ListBoxes.

loaded

  • Hero Member
  • *****
  • Posts: 569
Thank you so much for the reply king
I specifically needed this feature for pdf merging with Ghostscript because pdfs need to be merged in the order they are selected.

Finally, a cup of coffee + 2 cups of linden + some inspiration and the result I want;

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FileListBox1SelectionChange(Sender: TObject; User: boolean);
  2. var
  3.   i,im:integer;
  4.   fsname:UTF8String;
  5.   mc:Boolean;
  6. begin
  7.   for im:=Memo_File_Selects.lines.count downto 0  do
  8.   begin
  9.     mc:=true;
  10.     for i:=0 to FileListBox1.Items.Count-1 do
  11.     begin
  12.       fsname:= '"'+FileListBox1.Directory+'\'+FileListBox1.Items[i]+'"';
  13.       if (FileListBox1.Selected[i]) and (fsname=Memo_File_Selects.Lines.Strings[im]) then
  14.       begin
  15.       mc:=false;
  16.       end;
  17.     end;
  18.     if mc then Memo_File_Selects.Lines.Delete(im);
  19.   end;
  20.  
  21.   for i:=0 to FileListBox1.Items.Count-1 do
  22.   begin
  23.     if FileListBox1.Selected[i] then
  24.     begin
  25.        fsname:= '"'+FileListBox1.Directory+'\'+FileListBox1.Items[i]+'"';
  26.        mc:=false;
  27.          for im:=0 to Memo_File_Selects.lines.count do
  28.          begin
  29.              if (fsname=Memo_File_Selects.Lines.Strings[im]) then
  30.              begin
  31.              mc:=true;
  32.              end;
  33.          end;
  34.          if not mc then  Memo_File_Selects.lines.Add(fsname);
  35.     end;
  36.   end;
  37. end;  


With the power of tea :)
I wrote a program on the subject and published it on my site, I also prepared a video and added it to youtube.
https://www.youtube.com/watch?v=_lNgJ1HuYHk
« Last Edit: January 29, 2022, 05:15:19 pm by loaded »
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

engkin

  • Hero Member
  • *****
  • Posts: 3112
Well done! It reminds me of PDFTools.

loaded

  • Hero Member
  • *****
  • Posts: 569
Well done! It reminds me of PDFTools.

Master engkin , I'm glad you like it. Whatever I did, I did it thanks to the masters in this forum. Thank you always be present.
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;

 

TinyPortal © 2005-2018