Ignore:
Timestamp:
11/05/19 16:16:11 (5 years ago)
Author:
bnemhaus
Message:

Added the ability to copy/paste recognised files (mostly images) into Expeditee. This functionality already existed when drag n dropping, but now also works when using copy/paste.

At this stage, recognised files get imported as a approapriate Text Item. For example, a image will create a @i Text Item and attach it to your cursor. Ideally this would be the image directly. Unfortunately, items attached to the cursor (FreeItems) are not currently parsed. This is something I will discuss with David as there are confounding issues to consider. For example: surrogates...

Attached to the bottom of this commit message are my current thoughts.

Also made it so when creating a @i through DND or Copy/Paste, that @i is as relative as possible. The users image directories setting is used to achieve this.


  • FreeItems need to be parsed...we would need to deal with primaries/surrogates in them...
  • Do we want FreeItems to be parsed? If I attach an item to my cursor and then enter surrogate mode, should it change?
  • My gut says no. Both because it would be work, and also because it kind of feels like a free win if we do not.
  • But we do want to replace @i with images etc. Therefore, we want an old style parse for FreeItems?
File:
1 edited

Legend:

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

    r1435 r1436  
    2929        private static ResolvedDirectoryList audio = instance.new ResolvedDirectoryList(FolderSettings.AudioDirs);
    3030       
    31         public static void invalidateAllResourceDirectories() {
    32                 commonInvalidated = true;
    33         }
    34        
    35         private static void refreshAll() {
    36                 Frame currentFrame = DisplayController.getCurrentFrame();
    37                 String framesetPath = currentFrame == null ? null : currentFrame.getFramesetPath();
    38                 frames.refresh(framesetPath);
    39                 images.refresh(framesetPath);
    40                 audio.refresh(framesetPath);
    41         }
    42        
     31        /**
     32         * Attempts to relativise a image path using the users the directories listed for images in their settings.
     33         * @param path The path to attempt to relativise
     34         * @param context The context to use.  Most likely the Frame that the image is on.
     35         * @return Returns the most relativised path if one exists, otherwise returns a copy of the ref parameter passed in.
     36         */
     37        public static Path relativiseImagePath(Path path, Frame context) {
     38                String pathStr = path.toString();
     39               
     40                // Consult the resolved images directory for a list of paths to relativise too.
     41                List<String> directories = images.getDirectories(context);
     42               
     43                // Find the longest match that can be used to relativise the path.
     44                String longestMatch = "";
     45                for (String dir: directories) {
     46                        if (pathStr.startsWith(dir) && (dir.length() > longestMatch.length())) {
     47                                longestMatch = dir;
     48                        }
     49                }
     50               
     51                return Paths.get(pathStr.replace(longestMatch, ""));
     52        }
     53                       
    4354        /**
    4455         * Creates a Frame object from an associated resour
     
    224235        }
    225236       
     237        public static void invalidateAllResourceDirectories() {
     238                commonInvalidated = true;
     239        }
     240       
     241        private static void refreshAll() {
     242                Frame currentFrame = DisplayController.getCurrentFrame();
     243                String framesetPath = currentFrame == null ? null : currentFrame.getFramesetPath();
     244                frames.refresh(framesetPath);
     245                images.refresh(framesetPath);
     246                audio.refresh(framesetPath);
     247        }
     248       
    226249        private class ResolvedDirectoryList {
    227250                private List<String> directories = null;
     
    262285               
    263286                private void refresh(String context) {
     287                       
    264288                        List<String> unresolved = source.getAbsoluteDirs();
    265289                        directories = resolve(unresolved, context);
Note: See TracChangeset for help on using the changeset viewer.