use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Presentation method onPresentationSaveAsStandalone.
@Handler
void onPresentationSaveAsStandalone() {
// determine the default file name
if (saveAsStandaloneDefaultPath_ == null) {
FileSystemItem presFilePath = FileSystemItem.createFile(currentState_.getFilePath());
saveAsStandaloneDefaultPath_ = FileSystemItem.createFile(presFilePath.getParentPath().completePath(presFilePath.getStem() + ".html"));
}
fileDialogs_.saveFile("Save Presentation As", fileSystemContext_, saveAsStandaloneDefaultPath_, ".html", false, new ProgressOperationWithInput<FileSystemItem>() {
@Override
public void execute(final FileSystemItem targetFile, ProgressIndicator indicator) {
if (targetFile == null) {
indicator.onCompleted();
return;
}
indicator.onProgress("Saving Presentation...");
server_.createStandalonePresentation(targetFile.getPath(), new VoidServerRequestCallback(indicator) {
@Override
public void onSuccess() {
saveAsStandaloneDefaultPath_ = targetFile;
}
});
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Source method attemptSourceNavigation.
private void attemptSourceNavigation(final SourceNavigation navigation, final AppCommand retryCommand) {
// see if we can navigate by id
String docId = navigation.getDocumentId();
final EditingTarget target = getEditingTargetForId(docId);
if (target != null) {
// case execute the retry command
if ((target == activeEditor_) && target.isAtSourceRow(navigation.getPosition())) {
if (retryCommand.isEnabled())
retryCommand.execute();
} else {
suspendSourceNavigationAdding_ = true;
try {
view_.selectTab(target.asWidget());
target.restorePosition(navigation.getPosition());
} finally {
suspendSourceNavigationAdding_ = false;
}
}
} else // check for code browser navigation
if ((navigation.getPath() != null) && navigation.getPath().startsWith(CodeBrowserEditingTarget.PATH)) {
activateCodeBrowser(navigation.getPath(), false, new SourceNavigationResultCallback<CodeBrowserEditingTarget>(navigation.getPosition(), retryCommand));
} else // check for file path navigation
if ((navigation.getPath() != null) && !navigation.getPath().startsWith(DataItem.URI_PREFIX)) {
FileSystemItem file = FileSystemItem.createFile(navigation.getPath());
TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
// open the file and restore the position
openFile(file, fileType, new SourceNavigationResultCallback<EditingTarget>(navigation.getPosition(), retryCommand));
} else {
// couldn't navigate to this item, retry
if (retryCommand.isEnabled())
retryCommand.execute();
}
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Source method onNewRPresentationDoc.
@Handler
public void onNewRPresentationDoc() {
dependencyManager_.withRMarkdown("Authoring R Presentations", new Command() {
@Override
public void execute() {
fileDialogs_.saveFile("New R Presentation", fileContext_, workbenchContext_.getDefaultFileDialogDir(), ".Rpres", true, new ProgressOperationWithInput<FileSystemItem>() {
@Override
public void execute(final FileSystemItem input, final ProgressIndicator indicator) {
if (input == null) {
indicator.onCompleted();
return;
}
indicator.onProgress("Creating Presentation...");
server_.createNewPresentation(input.getPath(), new VoidServerRequestCallback(indicator) {
@Override
public void onSuccess() {
openFile(input, FileTypeRegistry.RPRESENTATION, new CommandWithArg<EditingTarget>() {
@Override
public void execute(EditingTarget arg) {
server_.showPresentationPane(input.getPath(), new VoidServerRequestCallback());
}
});
}
});
}
});
}
});
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Source method openProjectDocs.
private void openProjectDocs(final Session session) {
JsArrayString openDocs = session.getSessionInfo().getProjectOpenDocs();
if (openDocs.length() > 0) {
// set new tab pending for the duration of the continuation
newTabPending_++;
// create a continuation for opening the source docs
SerializedCommandQueue openCommands = new SerializedCommandQueue();
for (int i = 0; i < openDocs.length(); i++) {
String doc = openDocs.get(i);
final FileSystemItem fsi = FileSystemItem.createFile(doc);
openCommands.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
openFile(fsi, fileTypeRegistry_.getTextTypeForFile(fsi), new CommandWithArg<EditingTarget>() {
@Override
public void execute(EditingTarget arg) {
continuation.execute();
}
});
}
});
}
// decrement newTabPending and select first tab when done
openCommands.addCommand(new SerializedCommand() {
@Override
public void onExecute(Command continuation) {
newTabPending_--;
onFirstTab();
continuation.execute();
}
});
// execute the continuation
openCommands.run();
}
}
use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.
the class Source method doOpenSourceFile.
private void doOpenSourceFile(final FileSystemItem file, final TextFileType fileType, final FilePosition position, final String pattern, final int navMethod, final boolean forceHighlightMode) {
// if the navigation should happen in another window, do that instead
NavigationResult navResult = windowManager_.navigateToFile(file, position, navMethod);
// we navigated externally, just skip this
if (navResult.getType() == NavigationResult.RESULT_NAVIGATED)
return;
// we're about to open in this window--if it's the main window, focus it
if (SourceWindowManager.isMainSourceWindow() && Desktop.isDesktop())
Desktop.getFrame().bringMainFrameToFront();
final boolean isDebugNavigation = navMethod == NavigationMethods.DEBUG_STEP || navMethod == NavigationMethods.DEBUG_END;
final CommandWithArg<EditingTarget> editingTargetAction = new CommandWithArg<EditingTarget>() {
@Override
public void execute(EditingTarget target) {
if (position != null) {
SourcePosition endPosition = null;
if (isDebugNavigation) {
DebugFilePosition filePos = (DebugFilePosition) position.cast();
endPosition = SourcePosition.create(filePos.getEndLine() - 1, filePos.getEndColumn() + 1);
if (Desktop.isDesktop() && navMethod != NavigationMethods.DEBUG_END)
Desktop.getFrame().bringMainFrameToFront();
}
navigate(target, SourcePosition.create(position.getLine() - 1, position.getColumn() - 1), endPosition);
} else if (pattern != null) {
Position pos = target.search(pattern);
if (pos != null) {
navigate(target, SourcePosition.create(pos.getRow(), 0), null);
}
}
}
private void navigate(final EditingTarget target, final SourcePosition srcPosition, final SourcePosition srcEndPosition) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
if (navMethod == NavigationMethods.DEBUG_STEP) {
target.highlightDebugLocation(srcPosition, srcEndPosition, true);
} else if (navMethod == NavigationMethods.DEBUG_END) {
target.endDebugHighlighting();
} else {
// force highlight mode if requested
if (forceHighlightMode)
target.forceLineHighlighting();
// now navigate to the new position
boolean highlight = navMethod == NavigationMethods.HIGHLIGHT_LINE && !uiPrefs_.highlightSelectedLine().getValue();
target.navigateToPosition(srcPosition, false, highlight);
}
}
});
}
};
if (navResult.getType() == NavigationResult.RESULT_RELOCATE) {
server_.getSourceDocument(navResult.getDocId(), new ServerRequestCallback<SourceDocument>() {
@Override
public void onResponseReceived(final SourceDocument doc) {
editingTargetAction.execute(addTab(doc, OPEN_REPLAY));
}
@Override
public void onError(ServerError error) {
globalDisplay_.showErrorMessage("Document Tab Move Failed", "Couldn't move the tab to this window: \n" + error.getMessage());
}
});
return;
}
final CommandWithArg<FileSystemItem> action = new CommandWithArg<FileSystemItem>() {
@Override
public void execute(FileSystemItem file) {
openFile(file, fileType, editingTargetAction);
}
};
// highlight in place.
if (isDebugNavigation) {
setPendingDebugSelection();
for (int i = 0; i < editors_.size(); i++) {
EditingTarget target = editors_.get(i);
String path = target.getPath();
if (path != null && path.equalsIgnoreCase(file.getPath())) {
// the file's open; just update its highlighting
if (navMethod == NavigationMethods.DEBUG_END) {
target.endDebugHighlighting();
} else {
view_.selectTab(i);
editingTargetAction.execute(target);
}
return;
}
}
// open a file just to turn off debug highlighting in the file!
if (navMethod == NavigationMethods.DEBUG_END)
return;
}
// Warning: event.getFile() can be null (e.g. new Sweave document)
if (file != null && file.getLength() < 0) {
// If the file has no size info, stat the file from the server. This
// is to prevent us from opening large files accidentally.
server_.stat(file.getPath(), new ServerRequestCallback<FileSystemItem>() {
@Override
public void onResponseReceived(FileSystemItem response) {
action.execute(response);
}
@Override
public void onError(ServerError error) {
// Couldn't stat the file? Proceed anyway. If the file doesn't
// exist, we'll let the downstream code be the one to show the
// error.
action.execute(file);
}
});
} else {
action.execute(file);
}
}
Aggregations