Skip to content

Commit 63bafdc

Browse files
author
emmanue1
committed
Fix problem on "Select Location" popup
1 parent 15c2f61 commit 63bafdc

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

app/src/main/java/org/jd/gui/controller/SelectLocationController.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,9 @@ public void show(Point location, Collection<Container.Entry> entries, Consumer<C
6969
filteredContainerWrappers.add(new FilteredContainerWrapper(container, getOuterEntries(mapEntry.getValue())));
7070
}
7171

72-
selectLocationView.show(
73-
location, filteredContainerWrappers, entries.size(),
74-
new Consumer<URI>() {
75-
@Override public void accept(URI uri) { onLocationSelected(filteredContainerWrappers, uri, selectedLocationCallback); }
76-
},
77-
closeCallback);
72+
Consumer<URI> selectedEntryCallback = uri -> onLocationSelected(filteredContainerWrappers, uri, selectedLocationCallback);
73+
74+
selectLocationView.show(location, filteredContainerWrappers, entries.size(), selectedEntryCallback, closeCallback);
7875
}
7976

8077
protected Collection<Container.Entry> getOuterEntries(Collection<Container.Entry> entries) {

app/src/main/java/org/jd/gui/model/container/FilteredContainerWrapper.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.*;
1515

1616
public class FilteredContainerWrapper implements Container {
17+
protected static final URI DEFAULT_ROOT_URI = URI.create("file:.");
18+
1719
protected Container container;
1820
protected EntryWrapper root;
1921

@@ -48,11 +50,12 @@ protected EntryWrapper getEntryWrapper(Container.Entry entry) {
4850
return entryWrapper;
4951
}
5052

51-
protected ContainerWrapper getContainerWrapper(Container.Entry entry) {
52-
URI uri = entry.getContainer().getRoot().getUri();
53+
protected ContainerWrapper getContainerWrapper(Container container) {
54+
Entry root = container.getRoot();
55+
URI uri = (root == null) ? DEFAULT_ROOT_URI : root.getUri();
5356
ContainerWrapper containerWrapper = uriToContainerWrapper.get(uri);
5457
if (containerWrapper == null) {
55-
uriToContainerWrapper.put(uri, containerWrapper=new ContainerWrapper(entry.getContainer()));
58+
uriToContainerWrapper.put(uri, containerWrapper=new ContainerWrapper(container));
5659
}
5760
return containerWrapper;
5861
}
@@ -65,7 +68,7 @@ public EntryWrapper(Entry entry) {
6568
this.entry = entry;
6669
}
6770

68-
@Override public Container getContainer() { return getContainerWrapper(entry.getContainer().getRoot()); }
71+
@Override public Container getContainer() { return getContainerWrapper(entry.getContainer()); }
6972
@Override public Entry getParent() { return getEntryWrapper(entry.getParent()); }
7073
@Override public URI getUri() { return entry.getUri(); }
7174
@Override public String getPath() { return entry.getPath(); }

services/src/main/java/org/jd/gui/model/container/GenericContainer.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@
2424
import java.util.Iterator;
2525

2626
public class GenericContainer implements Container {
27+
protected static final long TIMESTAMP = System.currentTimeMillis();
28+
29+
protected static long tmpFileCounter = 0;
30+
2731
protected API api;
2832
protected int rootNameCount;
2933
protected Container.Entry root;
3034

3135
public GenericContainer(API api, Container.Entry parentEntry, Path rootPath) {
32-
this.api = api;
33-
this.rootNameCount = rootPath.getNameCount();
34-
this.root = new Entry(parentEntry, rootPath, parentEntry.getUri()) {
35-
public Entry newChildEntry(Path fsPath) {
36-
return new Entry(parent, fsPath, null);
37-
}
38-
};
36+
try {
37+
URI uri = parentEntry.getUri();
38+
39+
this.api = api;
40+
this.rootNameCount = rootPath.getNameCount();
41+
this.root = new Entry(parentEntry, rootPath, new URI(uri.getScheme(), uri.getHost(), uri.getPath() + "!/", null)) {
42+
public Entry newChildEntry(Path fsPath) {
43+
return new Entry(parent, fsPath, null);
44+
}
45+
};
46+
} catch (URISyntaxException e) {
47+
assert ExceptionUtil.printStackTrace(e);
48+
}
3949
}
4050

4151
public String getType() { return "generic"; }
@@ -66,7 +76,8 @@ public Entry(Container.Entry parent, Path fsPath, URI uri) {
6676
public URI getUri() {
6777
if (uri == null) {
6878
try {
69-
uri = new URI(root.getUri().getScheme(), root.getUri().getHost(), root.getUri().getPath() + "!/" + getPath(), null);
79+
URI rootUri = root.getUri();
80+
uri = new URI(rootUri.getScheme(), rootUri.getHost(), rootUri.getPath() + getPath(), null);
7081
} catch (URISyntaxException e) {
7182
assert ExceptionUtil.printStackTrace(e);
7283
}
@@ -146,7 +157,8 @@ protected Collection<Container.Entry> loadChildrenFromDirectoryEntry() throws IO
146157
}
147158

148159
protected Collection<Container.Entry> loadChildrenFromFileEntry() throws IOException {
149-
File tmpFile = File.createTempFile("jd-gui.", "." + fsPath.getFileName().toString());
160+
StringBuilder suffix = new StringBuilder(".").append(TIMESTAMP).append('.').append(tmpFileCounter++).append('.').append(fsPath.getFileName().toString());
161+
File tmpFile = File.createTempFile("jd-gui.tmp.", suffix.toString());
150162
Path tmpPath = Paths.get(tmpFile.toURI());
151163

152164
tmpFile.delete();
@@ -166,7 +178,6 @@ protected Collection<Container.Entry> loadChildrenFromFileEntry() throws IOExcep
166178
Container container = containerFactory.make(api, this, rootPath);
167179

168180
if (container != null) {
169-
tmpFile.delete();
170181
return container.getRoot().getChildren();
171182
}
172183
}

0 commit comments

Comments
 (0)