Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor load/save console commands into common codepath
- Loading branch information
Showing
7 changed files
with
154 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/gwt/src/org/rstudio/studio/client/common/ConsoleDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package org.rstudio.studio.client.common; | ||
|
||
import org.rstudio.core.client.files.FileSystemItem; | ||
import org.rstudio.core.client.files.FilenameTransform; | ||
import org.rstudio.core.client.widget.ProgressIndicator; | ||
import org.rstudio.core.client.widget.ProgressOperationWithInput; | ||
import org.rstudio.studio.client.application.events.EventBus; | ||
import org.rstudio.studio.client.workbench.WorkbenchContext; | ||
import org.rstudio.studio.client.workbench.model.RemoteFileSystemContext; | ||
import org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
|
||
|
||
@Singleton | ||
public class ConsoleDispatcher | ||
{ | ||
@Inject | ||
public ConsoleDispatcher(EventBus eventBus, | ||
FileDialogs fileDialogs, | ||
WorkbenchContext workbenchContext, | ||
RemoteFileSystemContext fsContext) | ||
{ | ||
eventBus_ = eventBus; | ||
fileDialogs_ = fileDialogs; | ||
workbenchContext_ = workbenchContext; | ||
fsContext_ = fsContext; | ||
} | ||
|
||
public void executeSetWd(FileSystemItem dir) | ||
{ | ||
String escaped = dir.getPath().replaceAll("\\\\", "\\\\\\\\"); | ||
if (escaped.equals("~")) | ||
escaped = "~/"; | ||
eventBus_.fireEvent( | ||
new SendToConsoleEvent("setwd(\"" + escaped + "\")", true)); | ||
} | ||
|
||
public void executeCommand(String command, FileSystemItem targetFile) | ||
{ | ||
String code = command + "(\"" + targetFile.getPath() + "\")"; | ||
eventBus_.fireEvent(new SendToConsoleEvent(code, true)); | ||
} | ||
|
||
|
||
public void saveFileAsThenExecuteCommand(String caption, | ||
final String defaultExtension, | ||
final String command) | ||
{ | ||
fileDialogs_.saveFile( | ||
caption, | ||
fsContext_, | ||
workbenchContext_.getCurrentWorkingDir(), | ||
new FilenameTransform() | ||
{ | ||
public String transform(String filename) | ||
{ | ||
if (defaultExtension != null) | ||
{ | ||
// auto-append .RData if that isn't the extension | ||
String ext = FileSystemItem.getExtensionFromPath(filename); | ||
return ext.equalsIgnoreCase(defaultExtension) | ||
? filename | ||
: filename + defaultExtension; | ||
} | ||
else | ||
{ | ||
return filename; | ||
} | ||
} | ||
}, | ||
new ProgressOperationWithInput<FileSystemItem>() | ||
{ | ||
public void execute( | ||
FileSystemItem input, | ||
ProgressIndicator indicator) | ||
{ | ||
if (input == null) | ||
return; | ||
|
||
executeCommand(command, input); | ||
indicator.onCompleted(); | ||
} | ||
}); | ||
} | ||
|
||
public void chooseFileThenExecuteCommand(String caption, | ||
final String command) | ||
{ | ||
fileDialogs_.openFile( | ||
caption, | ||
fsContext_, | ||
workbenchContext_.getCurrentWorkingDir(), | ||
new ProgressOperationWithInput<FileSystemItem>() | ||
{ | ||
public void execute(FileSystemItem input, ProgressIndicator indicator) | ||
{ | ||
if (input == null) | ||
return; | ||
|
||
executeCommand(command, input); | ||
indicator.onCompleted(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
|
||
private final EventBus eventBus_; | ||
private final FileDialogs fileDialogs_; | ||
private final WorkbenchContext workbenchContext_; | ||
private final RemoteFileSystemContext fsContext_; | ||
} |
37 changes: 0 additions & 37 deletions
37
src/gwt/src/org/rstudio/studio/client/common/WorkbenchHelper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.