Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Commit

Permalink
disable copying to root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
UnforgivenZZZ committed Oct 11, 2018
1 parent 048ab4c commit a390633
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
25 changes: 16 additions & 9 deletions src/main/java/org/tron/studio/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ public void initialize() throws IOException {
});

ShareData.currentContractFileName.addListener((observable, oldValue, currentContractName) -> {
if(currentContractName == null || currentContractName.length() == 0) return;
boolean alreadyOpen = false;
for (Tab tab : codeAreaTabPane.getTabs()) {
if (StringUtils.equals(tab.getText(), currentContractName)) {
codeAreaTabPane.getSelectionModel().select(tab);
alreadyOpen = true;
break;
}
}
if (!alreadyOpen) {
System.out.println(currentContractName);
createTabForFileSystemFile(currentContractName);
}
});
Expand All @@ -115,14 +118,18 @@ public void initialize() throws IOException {
});

ShareData.openContractFileName.addListener((observable, oldValue, newValue) ->{
String filePath = ShareData.openContractFileName.get();
File newFile = new File(filePath);

Tab newTab = setTab(newFile);
newTab.setClosable(true);
ShareData.currentContractName.set(newFile.getName());
ShareData.allContractFileName.add(newFile.getName());
codeAreaTabPane.getSelectionModel().select(newTab);
if (newValue != null && newValue.length() > 0) {
String filePath = ShareData.openContractFileName.get();
System.out.println(filePath);
// File newFile = new File(filePath);

// Tab newTab = setTab(newFile);
// newTab.setClosable(true);
ShareData.currentContractFileName.set(null);
ShareData.currentContractFileName.set(filePath);
ShareData.allContractFileName.add(filePath);
// codeAreaTabPane.getSelectionModel().select(newTab);
}
});

ShareData.debugTransactionAction.addListener((observable, oldValue, newValue) -> {
Expand Down Expand Up @@ -154,7 +161,7 @@ private Tab setTab(File file) {
AutoCompletion autoCompletion = new AutoCompletion(codeArea);
autoCompletion.autoComplete(codeArea);

codeTab.setText(file.getName());
codeTab.setText(file.getPath());
//Just not allow to close the default tab
codeTab.setClosable(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public static void createNewFile(String fileName) {
}

public static File getExistFile(String fileName) {
return new File(Config.SOLIDITY_SOURCE_PATH, fileName.trim());
File file = new File(fileName.trim());
if (!file.exists())
return new File(Config.SOLIDITY_SOURCE_PATH, fileName.trim());
return file;
}

public static String getSourceCode(String fileName) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/tron/studio/solc/SolidityCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static Result compile(byte[] source, boolean combinedJson, Option... opti
public Result compileSrc(File source, boolean optimize, boolean combinedJson, Option... options) throws IOException {
List<String> commandParts = prepareCommandOptions(optimize, combinedJson, options);

commandParts.add(source.getName());
commandParts.add(source.getPath());

ProcessBuilder processBuilder = new ProcessBuilder(commandParts)
.directory(new File(SolidityFileUtil.getSourcePath()));
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/org/tron/studio/ui/LeftCodeListController.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ private void saveContractContent() {

private void openFile(File file) {
try {
System.out.println(file.getPath());
ShareData.openContractFileName.set(file.getPath());
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -241,17 +242,18 @@ private File copyFile(File file) {
}

public void openContract(MouseEvent mouseEvent) {
ShareData.newContractFileName.set(null);
ShareData.openContractFileName.set(null);

File file = fileChooser.showOpenDialog(null);
if (file != null) {
File newFile = copyFile(file);
openFile(newFile);
String fileName = newFile.getName();
fileName = SolidityFileUtil.formatFileName(fileName);
// SolidityFileUtil.createNewFile(fileName);
ShareData.newContractFileName.set(fileName);
ShareData.allContractFileName.get().add(fileName);
ShareData.currentContractName.set(fileName);
// File newFile = copyFile(file);
openFile(file);
// String fileName = newFile.getName();
// fileName = SolidityFileUtil.formatFileName(fileName);
//// SolidityFileUtil.createNewFile(fileName);
//// ShareData.newContractFileName.set(fileName);
// ShareData.allContractFileName.get().add(fileName);
// ShareData.currentContractName.set(fileName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected void onClickCompile() {
}
isCompiling = true;
contractFileName = ShareData.currentContractFileName.getValue();
System.out.println(contractFileName);
ShareData.currentSolidityCompilerResult.set(null);
new Thread(() -> {
boolean compileSuccess = true;
Expand All @@ -70,7 +71,7 @@ protected void onClickCompile() {
SolidityFileUtil.getExistFile(contractFileName), true, ABI, BIN, HASHES, INTERFACE,
METADATA);

Platform.runLater(() -> ShareData.setSolidityCompilerResult(contractFileName, solidityCompilerResult));
Platform.runLater(() -> ShareData.setSolidityCompilerResult(contractFileName.trim(), solidityCompilerResult));
CompilationErrorResult.parse(solidityCompilerResult.errors);

//There are errors
Expand Down

0 comments on commit a390633

Please sign in to comment.