use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class DesktopHooks method openFile.
void openFile(String filePath) {
// get the file system item
FileSystemItem file = FileSystemItem.createFile(filePath);
if (file.isDirectory())
return;
// within DesktopMain.cpp
if (file.getExtension().equalsIgnoreCase(".rproj"))
return;
// open the file. pass false for second param to prevent
// the default handler (the browser) from taking it
fileTypeRegistry_.openFile(file, false);
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class TextEditingTarget method saveNewFileWithEncoding.
private void saveNewFileWithEncoding(String suggestedPath, final String encoding, final Command executeOnSuccess) {
view_.ensureVisible();
FileSystemItem fsi;
if (suggestedPath != null)
fsi = FileSystemItem.createFile(suggestedPath);
else
fsi = getSaveFileDefaultDir();
fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {
public void execute(final FileSystemItem saveItem, ProgressIndicator indicator) {
if (saveItem == null)
return;
try {
workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
final TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(saveItem);
final Command saveCommand = new Command() {
@Override
public void execute() {
if (!getPath().equals(saveItem.getPath())) {
// breakpoints are file-specific, so when saving
// as a different file, clear the display of
// breakpoints from the old file name
docDisplay_.removeAllBreakpoints();
// update publish settings
syncPublishPath(saveItem.getPath());
}
fixupCodeBeforeSaving();
docUpdateSentinel_.save(saveItem.getPath(), fileType.getTypeId(), encoding, new SaveProgressIndicator(saveItem, fileType, executeOnSuccess));
events_.fireEvent(new SourceFileSavedEvent(getId(), saveItem.getPath()));
}
};
// to a non-R file type then confirm
if (fileType_.isR() && !fileType.isR()) {
globalDisplay_.showYesNoMessage(MessageDialog.WARNING, "Confirm Change File Type", "This file was created as an R script however " + "the file extension you specified will change " + "it into another file type that will no longer " + "open as an R script.\n\n" + "Are you sure you want to change the type of " + "the file so that it is no longer an R script?", new Operation() {
@Override
public void execute() {
saveCommand.execute();
}
}, false);
} else {
saveCommand.execute();
}
} catch (Exception e) {
indicator.onError(e.toString());
return;
}
indicator.onCompleted();
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class TextEditingTarget method registerPrefs.
public static void registerPrefs(ArrayList<HandlerRegistration> releaseOnDismiss, UIPrefs prefs, final DocDisplay docDisplay, final PrefsContext context) {
releaseOnDismiss.add(prefs.highlightSelectedLine().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setHighlightSelectedLine(arg);
}
}));
releaseOnDismiss.add(prefs.highlightSelectedWord().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setHighlightSelectedWord(arg);
}
}));
releaseOnDismiss.add(prefs.showLineNumbers().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setShowLineNumbers(arg);
}
}));
releaseOnDismiss.add(prefs.useSpacesForTab().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
// Makefile always uses tabs
FileSystemItem file = context.getActiveFile();
if ((file != null) && ("Makefile".equals(file.getName()) || "Makevars".equals(file.getName()) || "Makevars.win".equals(file.getName()))) {
docDisplay.setUseSoftTabs(false);
} else {
docDisplay.setUseSoftTabs(arg);
}
}
}));
releaseOnDismiss.add(prefs.numSpacesForTab().bind(new CommandWithArg<Integer>() {
public void execute(Integer arg) {
docDisplay.setTabSize(arg);
}
}));
releaseOnDismiss.add(prefs.showMargin().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setShowPrintMargin(arg);
}
}));
releaseOnDismiss.add(prefs.blinkingCursor().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setBlinkingCursor(arg);
}
}));
releaseOnDismiss.add(prefs.printMarginColumn().bind(new CommandWithArg<Integer>() {
public void execute(Integer arg) {
docDisplay.setPrintMarginColumn(arg);
}
}));
releaseOnDismiss.add(prefs.showInvisibles().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setShowInvisibles(arg);
}
}));
releaseOnDismiss.add(prefs.showIndentGuides().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setShowIndentGuides(arg);
}
}));
releaseOnDismiss.add(prefs.scrollPastEndOfDocument().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setScrollPastEndOfDocument(arg);
}
}));
releaseOnDismiss.add(prefs.highlightRFunctionCalls().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setHighlightRFunctionCalls(arg);
}
}));
releaseOnDismiss.add(prefs.useVimMode().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setUseVimMode(arg);
}
}));
releaseOnDismiss.add(prefs.enableEmacsKeybindings().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.setUseEmacsKeybindings(arg);
}
}));
releaseOnDismiss.add(prefs.codeCompleteOther().bind(new CommandWithArg<String>() {
public void execute(String arg) {
docDisplay.syncCompletionPrefs();
}
}));
releaseOnDismiss.add(prefs.alwaysCompleteCharacters().bind(new CommandWithArg<Integer>() {
public void execute(Integer arg) {
docDisplay.syncCompletionPrefs();
}
}));
releaseOnDismiss.add(prefs.alwaysCompleteDelayMs().bind(new CommandWithArg<Integer>() {
public void execute(Integer arg) {
docDisplay.syncCompletionPrefs();
}
}));
releaseOnDismiss.add(prefs.enableSnippets().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.syncCompletionPrefs();
}
}));
releaseOnDismiss.add(prefs.showDiagnosticsOther().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.syncDiagnosticsPrefs();
}
}));
releaseOnDismiss.add(prefs.diagnosticsOnSave().bind(new CommandWithArg<Boolean>() {
@Override
public void execute(Boolean arg) {
docDisplay.syncDiagnosticsPrefs();
}
}));
releaseOnDismiss.add(prefs.backgroundDiagnosticsDelayMs().bind(new CommandWithArg<Integer>() {
public void execute(Integer arg) {
docDisplay.syncDiagnosticsPrefs();
}
}));
releaseOnDismiss.add(prefs.showInlineToolbarForRCodeChunks().bind(new CommandWithArg<Boolean>() {
public void execute(Boolean arg) {
docDisplay.forceImmediateRender();
}
}));
releaseOnDismiss.add(prefs.foldStyle().bind(new CommandWithArg<String>() {
public void execute(String style) {
docDisplay.setFoldStyle(style);
}
}));
releaseOnDismiss.add(prefs.surroundSelection().bind(new CommandWithArg<String>() {
public void execute(String string) {
docDisplay.setSurroundSelectionPref(string);
}
}));
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class TextEditingTarget method isPackageFile.
private boolean isPackageFile() {
// not a package file if we're not in package development mode
String type = session_.getSessionInfo().getBuildToolsType();
if (!type.equals(SessionInfo.BUILD_TOOLS_PACKAGE)) {
return false;
}
// get the directory associated with the project and see if the file is
// inside that directory
FileSystemItem projectDir = session_.getSessionInfo().getActiveProjectDir();
return getPath().startsWith(projectDir.getPath() + "/R");
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class TextEditingTarget method fireVcsViewOnGithubEvent.
private void fireVcsViewOnGithubEvent(int type) {
FileSystemItem file = FileSystemItem.createFile(docUpdateSentinel_.getPath());
if (docDisplay_.getSelectionValue().length() > 0) {
int start = docDisplay_.getSelectionStart().getRow() + 1;
int end = docDisplay_.getSelectionEnd().getRow() + 1;
events_.fireEvent(new VcsViewOnGitHubEvent(new GitHubViewRequest(file, type, start, end)));
} else {
events_.fireEvent(new VcsViewOnGitHubEvent(new GitHubViewRequest(file, type)));
}
}
Aggregations