Changeset 1448 for trunk


Ignore:
Timestamp:
11/12/19 15:39:05 (4 years ago)
Author:
bnemhaus
Message:

When deleting a picture on a expedite frame; if shift is held down, then the associated image file is now moved to the trash directory (FrameIO.TRASH_PATH).
When undoing the deletion of a picture, the associated image file is restored.

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gio/gesture/StandardGestureActions.java

    r1446 r1448  
    11package org.expeditee.gio.gesture;
    22
     3import java.io.File;
     4import java.io.IOException;
     5import java.nio.file.Files;
     6import java.nio.file.Path;
     7import java.nio.file.Paths;
     8import java.nio.file.StandardCopyOption;
    39import java.text.NumberFormat;
    410import java.util.ArrayList;
     
    32453251                        }
    32463252                        Collection<Item> toUndo = null;
     3253                        List<Path> canditateFilesToDelete = new ArrayList<Path>();
    32473254                        if (toDelete.isLineEnd()) {
    32483255                                // delete the entire connected shape if shift is down
     
    32903297                                bRecalculate |= toDelete.recalculateWhenChanged();
    32913298                                toUndo = toDelete.getConnected(); // copy(toDelete.getConnected());
     3299                                if (toDelete instanceof Picture && alternateMode) {
     3300                                        String pathStr = ((Picture) toDelete).getPath();
     3301                                        Path path = Paths.get(pathStr);
     3302                                        canditateFilesToDelete.add(path);
     3303                                }
    32923304                        }
    32933305                        SessionStats.DeletedItems(toUndo);
     
    32953307                                parent.addToUndoDelete(new ItemsList(toUndo));
    32963308                                parent.removeAllItems(toUndo); // toDelete.getConnected()
     3309                                deleteUnusedFiles(canditateFilesToDelete);
    32973310                        }
    32983311                        // reset the mouse cursor
     
    33143327
    33153328                DisplayController.requestRefresh(true);
     3329        }
     3330
     3331        private static void deleteUnusedFiles(List<Path> canditateFilesToDelete) {
     3332                for (Path p: canditateFilesToDelete) {
     3333                        try {
     3334                                Path trashPath = Paths.get(FrameIO.TRASH_PATH);
     3335                                trashPath.toFile().mkdirs();
     3336                                Path destination = trashPath.resolve(p.getFileName());
     3337                                Files.move(p, destination, StandardCopyOption.ATOMIC_MOVE);
     3338                        } catch (IOException e) {
     3339                                MessageBay.displayMessage("There was a problem moving a file to the trash.  File: " + p.getFileName());
     3340                        }
     3341                }
    33163342        }
    33173343
  • trunk/src/org/expeditee/gui/Frame.java

    r1445 r1448  
    2020
    2121import java.io.File;
     22import java.io.IOException;
     23import java.nio.file.Files;
     24import java.nio.file.Path;
    2225import java.nio.file.Paths;
     26import java.nio.file.StandardCopyOption;
    2327import java.sql.Time;
    2428import java.util.ArrayList;
     
    10961100                        _redo.push(undo);
    10971101                for(Item i : undo.items) {
     1102                        if (i instanceof org.expeditee.items.Picture) {
     1103                                String destination = ((org.expeditee.items.Picture) i).getPath();
     1104                                Path destinationPath = Paths.get(destination);
     1105                                Path sourcePath = Paths.get(FrameIO.TRASH_PATH).resolve(destinationPath.getFileName());
     1106                                try {
     1107                                                Files.move(sourcePath, destinationPath, StandardCopyOption.ATOMIC_MOVE);
     1108                                        } catch (IOException e) {
     1109                                                MessageBay.displayMessage("Unable to restore image file from trash, not undoing deletion of image.");
     1110                                                continue;
     1111                                        }
     1112                        }
    10981113                        this.addItem(i);
    10991114                                reparse |= i.hasOverlay();
Note: See TracChangeset for help on using the changeset viewer.