source: trunk/src/org/expeditee/setting/DirectoryListSetting.java@ 1436

Last change on this file since 1436 was 1436, checked in by bnemhaus, 5 years ago

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?
  • Property svn:executable set to *
File size: 1.9 KB
Line 
1package org.expeditee.setting;
2
3import java.io.File;
4import java.util.ArrayList;
5import java.util.LinkedList;
6import java.util.List;
7
8import org.expeditee.gui.FrameIO;
9import org.expeditee.gui.FrameUtils;
10import org.expeditee.items.Text;
11
12public class DirectoryListSetting extends ListSetting<String> {
13
14 /*
15 public DirectoryListSetting(String tooltip, String name, List<String> value) {
16 super(tooltip, name, value);
17 }*/
18
19 public DirectoryListSetting(String tooltip, String name) {
20 super(tooltip, name, new LinkedList<String>());
21 }
22
23 @Override
24 public boolean setSetting(Text text) {
25 List<String> dirs = FrameUtils.getDirs(text);
26 if (!dirs.isEmpty()) {
27 _value.clear();
28 _value.addAll(dirs);
29 }
30 return true;
31 }
32
33 public List<String> getAbsoluteDirs() {
34 String parent_folder = FrameIO.PARENT_FOLDER;
35 boolean need_file_sep_replace = (!File.separator.equals("/"));
36
37 List<String> value_absolute_dir = new ArrayList<String>();
38
39 for (String rel : _value) {
40 if (need_file_sep_replace) {
41 rel = rel.replace("/",File.separator);
42 }
43
44 String abs = null;
45 File rel_file = new File(rel);
46 if (rel_file.isAbsolute()) {
47 // The directory being stored somehow wasn't relative to expeditee.home
48 // => use it 'as is'
49 abs = rel;
50 } else {
51 abs = parent_folder + rel;
52 }
53 value_absolute_dir.add(abs);
54 }
55
56 return value_absolute_dir;
57 }
58
59 public void addAbsoluteDir(String absolute_dir) {
60 boolean need_file_sep_replace = (!File.separator.equals("/"));
61
62 String rel = null;
63 if (absolute_dir.startsWith(FrameIO.PARENT_FOLDER)) {
64 // only remove parent_folder if it matches
65 rel = absolute_dir.substring(FrameIO.PARENT_FOLDER.length());
66 }
67 else {
68 rel = absolute_dir;
69 }
70
71 if (need_file_sep_replace) {
72 rel = rel.replace(File.separator,"/");
73 }
74
75 _value.add(rel);
76 }
77}
Note: See TracBrowser for help on using the repository browser.