Explorar o código

Fix crash on delete by removing book from cover queue; restore drag reorder

- Add CoverWorkerRemoveBook and call it before freeing a book\n- Set TImage.DragMode=dmAutomatic to re-enable drag-and-drop reordering
Codex CLI hai 4 meses
pai
achega
45f779a279
Modificáronse 3 ficheiros con 38 adicións e 13 borrados
  1. 2 0
      src/book.pas
  2. 15 13
      src/main.pas
  3. 21 0
      src/unitCoverWorker.pas

+ 2 - 0
src/book.pas

@@ -246,6 +246,8 @@ begin
   mCover.OnMouseDown := @BookMouseDown;
   mCover.OnDblClick  := @BookDoubleClick;
   mCover.Cursor    := crHandPoint;
+  // Enable drag-and-drop reordering (handled by PanelBackground handlers)
+  mCover.DragMode  := dmAutomatic;
   // Back-reference for selection management among sibling controls
   mCover.Tag       := PtrInt(Self);
 

+ 15 - 13
src/main.pas

@@ -564,21 +564,23 @@ var i:Integer;
     b:TBook;
 begin
 
- if Key = VK_DELETE then
- begin
-   for i:= bookList.Count-1 downto 0 do
-   begin
-    if bookList.Books[i].isSelected = True then
+  if Key = VK_DELETE then
+  begin
+    for i:= bookList.Count-1 downto 0 do
     begin
-       // Remove the cover control first (owned by PanelBackground), then free book
-       b := bookList.Books[i];
-       if Assigned(b.Cover) then b.Cover.Free;
-       bookList.Remove(b);
-       b.Free;
+      if bookList.Books[i].isSelected = True then
+      begin
+         // Remove the cover control first (owned by PanelBackground), then free book
+         b := bookList.Books[i];
+         // Ensure the background worker won't touch this book anymore
+         CoverWorkerRemoveBook(b);
+         if Assigned(b.Cover) then b.Cover.Free;
+         bookList.Remove(b);
+         b.Free;
+      end;
     end;
-   end;
-   RearrangeBooksOnScreen();
- end;
+    RearrangeBooksOnScreen();
+  end;
 end;
 
 

+ 21 - 0
src/unitCoverWorker.pas

@@ -23,6 +23,9 @@ procedure CoverWorkerStart;
 { Stops the background worker and clears any pending books }
 procedure CoverWorkerStop;
 
+{ Remove a specific book from the pending queue (e.g., before deleting it) }
+procedure CoverWorkerRemoveBook(B: TBook);
+
 implementation
 
 type
@@ -171,6 +174,24 @@ begin
   end;
 end;
 
+procedure CoverWorkerRemoveBook(B: TBook);
+var
+  l: TList;
+  idx: Integer;
+begin
+  if (B = nil) or (GPdfQueue = nil) then Exit;
+  l := GPdfQueue.LockList;
+  try
+    idx := l.IndexOf(B);
+    if idx >= 0 then
+    begin
+      l.Delete(idx);
+      LogDebugFmt('Removed book from cover queue: %s', [B.FilePath]);
+    end;
+  finally
+    GPdfQueue.UnlockList;
+  end;
+end;
 procedure CoverWorkerEnqueueBookIfMissing(B: TBook);
 var
   l: TList;