Better handling of user provided paths.
This commit is contained in:
@@ -26,11 +26,18 @@ import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.jgoodies.looks.Fonts;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.io.File;
|
||||
|
||||
import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName;
|
||||
|
||||
@@ -88,6 +95,32 @@ public final class K2JSRunConfigurationEditor extends SettingsEditor<K2JSRunConf
|
||||
FileChooserDescriptorFactory.getDirectoryChooserDescriptor("directory where generated files will be stored");
|
||||
fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots());
|
||||
generatedChooseFile.addBrowseFolderListener(null, null, project, fileChooserDescriptor);
|
||||
final JTextField textField = generatedChooseFile.getTextField();
|
||||
textField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
onChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
onChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
onChange();
|
||||
}
|
||||
|
||||
private void onChange() {
|
||||
File file = new File(generatedChooseFile.getText());
|
||||
if (!file.isFile()) {
|
||||
textField.setForeground(Color.RED);
|
||||
} else {
|
||||
textField.setForeground(Color.BLACK);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setUpShowInBrowserCheckBox() {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.k2js.facade;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -57,7 +58,9 @@ public final class K2JSTranslator {
|
||||
throw new RuntimeException("No file with main detected.");
|
||||
}
|
||||
String callToMain = generateCallToMain(fileWithMain, "");
|
||||
FileWriter writer = new FileWriter(new File(outputPath));
|
||||
File file = new File(outputPath);
|
||||
FileUtil.createParentDirs(file);
|
||||
FileWriter writer = new FileWriter(file);
|
||||
try {
|
||||
writer.write(programCode + callToMain);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user