Changeset 1447 for trunk


Ignore:
Timestamp:
11/12/19 14:37:28 (4 years ago)
Author:
bnemhaus
Message:

When dnd'ing a or copy/pasting a image that is external to expeditee (not a sub file of expedite.home) then that image is imported into the expeditee file system with a randomly generated name. A users FolderSettings are used to determine location to import image too.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/management/ResourceUtil.java

    r1446 r1447  
    2626         * Attempts to relativise a image path using expeditee.home (FrameIO.PARENT_FOLDER).
    2727         * @param path The path to attempt to relativise
    28          * @return Returns the most relativised path if one exists, otherwise returns a copy of the ref parameter passed in.
     28         * @return Returns the most relativised path if one exists, otherwise returns the ref parameter passed in.
    2929         */
    3030        public static Path relativiseImagePath(Path path) {
     
    4949               
    5050                return null;
     51        }
     52       
     53        public static Path getImageSaveFileLocation(Frame context) {
     54                List<String> directories = ResourceManager.images.getDirectories(context);
     55                if (directories.isEmpty()) {
     56                        return Paths.get(FrameIO.PARENT_FOLDER).toAbsolutePath();
     57                } else {
     58                        return Paths.get(directories.get(0));
     59                }
    5160        }
    5261       
  • trunk/src/org/expeditee/importer/FilePathImporter.java

    r1436 r1447  
    4040                }
    4141
    42                 return null;
    43                
    44         }
    45 
    46        
     42                return null;           
     43        }       
    4744}
  • trunk/src/org/expeditee/importer/ImageImporter.java

    r1441 r1447  
    2121import java.io.File;
    2222import java.io.IOException;
     23import java.nio.file.Files;
    2324import java.nio.file.Path;
    2425import java.nio.file.Paths;
     26import java.nio.file.StandardCopyOption;
    2527import java.util.Collection;
    2628import java.util.HashSet;
     
    9092                Path imagePath = Paths.get(fullPath);
    9193                Path imagePathRelitivized = ResourceUtil.relativiseImagePath(imagePath);
     94                if (!isInternal(imagePathRelitivized)) {
     95                        Path destinationDirectoryPath = ResourceUtil.getImageSaveFileLocation(DisplayController.getCurrentFrame());
     96                        String extension = imagePathRelitivized.toString();
     97                        extension = extension.substring(extension.lastIndexOf('.'));
     98                        Path newFilePath = Files.createTempFile(destinationDirectoryPath, "", extension);
     99                        Files.copy(imagePathRelitivized, newFilePath, StandardCopyOption.REPLACE_EXISTING);
     100                        imagePathRelitivized = ResourceUtil.relativiseImagePath(newFilePath);
     101                }
    92102                source = DragAndDropManager.importString("@i: " + imagePathRelitivized.toString() + size, location, attachToFreeItems);
    93103//              final Path imagesPath = Paths.get(FrameIO.IMAGES_PATH);
     
    107117                return source.getEnclosures().iterator().next();
    108118        }
     119       
     120        private boolean isInternal(Path p) {
     121                Path expediteeHomePath = Paths.get(FrameIO.PARENT_FOLDER).toAbsolutePath();
     122                return p.startsWith(expediteeHomePath);
     123        }
    109124}
Note: See TracChangeset for help on using the changeset viewer.