Skip to content

Commit e9ad9dd

Browse files
committed
Source file or external sources viewer can have space in path, fixed icon in Select Roots | Subfolders
1 parent 884c297 commit e9ad9dd

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

plugins/sources/src/org/graalvm/visualvm/sources/options/SourcesOptionsPanel.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ public String getDescription() {
318318
}
319319
});
320320

321-
SourceRootsCustomizer customizer = new SourceRootsCustomizer();
321+
String aFile = System.getProperties().getProperty("netbeans.home"); // NOI18N
322+
Icon fileIcon = fileChooser.getIcon(new File(aFile));
323+
SourceRootsCustomizer customizer = new SourceRootsCustomizer(fileIcon);
322324
fileChooser.setAccessory(customizer);
323325
fileChooser.addPropertyChangeListener(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY, customizer);
324326

@@ -561,10 +563,10 @@ private static final class SourceRootsCustomizer extends JPanel implements Prope
561563
private RequestProcessor processor;
562564

563565

564-
SourceRootsCustomizer() {
566+
SourceRootsCustomizer(Icon fileIcon) {
565567
super(null);
566568

567-
initUI();
569+
initUI(fileIcon);
568570
}
569571

570572

@@ -586,7 +588,7 @@ String createRootString(String root) {
586588
}
587589

588590

589-
private void initUI() {
591+
private void initUI(Icon fileIcon) {
590592
setLayout(new GridBagLayout());
591593

592594
GridBagConstraints c;
@@ -629,9 +631,11 @@ private void initUI() {
629631
add(commonFolderChoice, c);
630632

631633
subdirectoryList = new JList();
632-
subdirectoryList.setCellRenderer(new DefaultListCellRenderer() {
634+
DefaultListCellRenderer renderer = new DefaultListCellRenderer() {
633635
@Override public void setIcon(Icon icon) { if (icon != null) super.setIcon(icon); }
634-
});
636+
};
637+
renderer.setIcon(fileIcon);
638+
subdirectoryList.setCellRenderer(renderer);
635639
c = new GridBagConstraints();
636640
c.gridx = 0;
637641
c.gridy = y++;
@@ -706,19 +710,13 @@ public void propertyChange(PropertyChangeEvent evt) {
706710

707711
final File[] subdirs = (File[])evt.getNewValue();
708712

709-
JFileChooser source = evt.getSource() instanceof JFileChooser ? (JFileChooser)evt.getSource() : null;
710-
final Icon icon = source != null && subdirs != null && subdirs.length > 0 ? source.getIcon(subdirs[0]) : null;
711-
712713
if (processor == null) processor = new RequestProcessor("Source Roots Subfoldes Processor"); // NOI18N
713714

714715
processor.post(new Runnable() {
715716
public void run() {
716717
final List<String> subdirsL = getCommonSubDirs(subdirs);
717718
SwingUtilities.invokeLater(new Runnable() {
718719
public void run() {
719-
if (!subdirsL.isEmpty())
720-
((DefaultListCellRenderer)subdirectoryList.getCellRenderer()).setIcon(icon);
721-
722720
subdirectoryList.setListData(subdirsL.toArray(new String[0]));
723721
subdirectoryList.setEnabled(true);
724722

plugins/sources/src/org/graalvm/visualvm/sources/viewer/ExternalSourcesViewer.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.io.IOException;
3232
import java.util.Arrays;
3333
import java.util.Comparator;
34+
import java.util.List;
3435
import java.util.logging.Level;
3536
import java.util.logging.Logger;
3637
import javax.swing.Box;
@@ -88,7 +89,7 @@ private static enum IdePreset {
8889
ECLIPSE("Eclipse", "eclipse " + SourceHandle.Feature.FILE.getCode() + ":" + SourceHandle.Feature.LINE.getCode()), // NOI18N
8990
IDEA("IntelliJ IDEA", "idea --line " + SourceHandle.Feature.LINE.getCode() + " --column " + SourceHandle.Feature.COLUMN.getCode() + " " + SourceHandle.Feature.FILE.getCode()), // NOI18N
9091
VSCODE("Visual Studio Code", "code -g " + SourceHandle.Feature.FILE.getCode() + ":" + SourceHandle.Feature.LINE.getCode()), // NOI18N
91-
XCODE("Xcode", "open -a Xcode " + SourceHandle.Feature.FILE.getCode() + " ???"); // NOI18N
92+
XCODE("Xcode", "open -a Xcode " + SourceHandle.Feature.FILE.getCode()); // NOI18N
9293

9394
private final String name;
9495
private final String command;
@@ -173,7 +174,16 @@ public boolean open(SourceHandle handle) {
173174
if (expandedCommand.isEmpty()) {
174175
ProfilerDialogs.displayError(Bundle.ExternalSourcesViewer_EmptyCommand());
175176
} else {
176-
new ExternalViewerLauncher(expandedCommand) {
177+
String commandS = getCommand();
178+
List<String> commandL = ExternalViewerLauncher.getCommandStrings(commandS);
179+
180+
for (int i = 0; i < commandL.size(); i++) {
181+
String command = commandL.get(i);
182+
command = handle.expandFeatures(command);
183+
commandL.set(i, command);
184+
}
185+
186+
new ExternalViewerLauncher(commandL) {
177187
@Override protected void failed(IOException e) {
178188
ProfilerDialogs.displayError(Bundle.ExternalSourcesViewer_CommandFailed(e.getMessage()));
179189
LOGGER.log(Level.INFO, "Opening external sources viewer failed", e); // NOI18N
@@ -326,21 +336,11 @@ private static String appendSpaces(String string, int targetLength) {
326336
}
327337

328338
private static void insertFile(JTextField textField, File file) {
329-
Document document = textField.getDocument();
330-
int length = document.getLength();
331-
int position = textField.getCaretPosition();
332-
333-
boolean dir = file.isDirectory();
334339
String path = file.getAbsolutePath();
340+
if (path.contains(" ")) path = "\"" + path + "\""; // NOI18N
335341

336-
try {
337-
if (dir && position == 0 && length > 0) {
338-
String nextChar = document.getText(position, 1);
339-
if (!" ".equals(nextChar) && !"{".equals(nextChar)) path = path + File.separator; // NOI18N
340-
}
341-
342-
textField.getDocument().insertString(position, path, null);
343-
} catch (BadLocationException ex) {}
342+
try { textField.getDocument().insertString(textField.getCaretPosition(), path, null); }
343+
catch (BadLocationException ex) {}
344344
}
345345

346346
private static void insertParameter(JTextField textField, String parameter) {

plugins/sources/src/org/graalvm/visualvm/sources/viewer/ExternalViewerLauncher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ class ExternalViewerLauncher implements Runnable {
3939
private static final String COMMAND_STRINGS_REGEX = "\"[^\"]*\"|\\S+"; // NOI18N
4040

4141

42-
private final String command;
42+
private final List<String> command;
4343

4444

45-
ExternalViewerLauncher(String command) {
45+
ExternalViewerLauncher(List<String> command) {
4646
this.command = command;
4747
}
4848

4949

5050
public final void run() {
5151
ProcessBuilder builder = new ProcessBuilder();
52-
builder.command(getCommandStrings(command));
52+
builder.command(command);
5353
builder.directory(Storage.getTemporaryStorageDirectory());
5454

5555
try { builder.start(); }

0 commit comments

Comments
 (0)