use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.
the class Source method onGetEditorContext.
@Override
public void onGetEditorContext(GetEditorContextEvent event) {
GetEditorContextEvent.Data data = event.getData();
int type = data.getType();
if (type == GetEditorContextEvent.TYPE_ACTIVE_EDITOR) {
if (consoleEditorHadFocusLast() || activeEditor_ == null)
type = GetEditorContextEvent.TYPE_CONSOLE_EDITOR;
else
type = GetEditorContextEvent.TYPE_SOURCE_EDITOR;
}
if (type == GetEditorContextEvent.TYPE_CONSOLE_EDITOR) {
InputEditorDisplay editor = consoleEditorProvider_.getConsoleEditor();
if (editor != null && editor instanceof DocDisplay) {
getEditorContext("#console", "", (DocDisplay) editor);
return;
}
} else if (type == GetEditorContextEvent.TYPE_SOURCE_EDITOR) {
EditingTarget target = activeEditor_;
if (target != null && target instanceof TextEditingTarget) {
getEditorContext(target.getId(), target.getPath(), ((TextEditingTarget) target).getDocDisplay());
return;
}
}
// We need to ensure a 'getEditorContext' event is always
// returned as we have a 'wait-for' event on the server side
server_.getEditorContextCompleted(GetEditorContextEvent.SelectionData.create(), new VoidServerRequestCallback());
}
use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.
the class Source method restoreDocuments.
private void restoreDocuments(final Session session) {
final JsArray<SourceDocument> docs = session.getSessionInfo().getSourceDocuments();
for (int i = 0; i < docs.length(); i++) {
// restore the docs assigned to this source window
SourceDocument doc = docs.get(i);
String docWindowId = doc.getProperties().getString(SourceWindowManager.SOURCE_WINDOW_ID);
if (docWindowId == null)
docWindowId = "";
String currentSourceWindowId = SourceWindowManager.getSourceWindowId();
// is the main window, and the window it's assigned to isn't open.
if (currentSourceWindowId == docWindowId || (SourceWindowManager.isMainSourceWindow() && !windowManager_.isSourceWindowOpen(docWindowId))) {
// attempt to add a tab for the current doc; try/catch this since
// we don't want to allow one failure to prevent all docs from
// opening
EditingTarget sourceEditor = null;
try {
sourceEditor = addTab(doc, true, OPEN_REPLAY);
} catch (Exception e) {
Debug.logException(e);
}
// next one
if (sourceEditor == null)
continue;
final EditingTarget editor = sourceEditor;
// pop out a particular doc, and restore that doc's position if so
if (!SourceWindowManager.isMainSourceWindow()) {
final SourceWindow sourceWindow = RStudioGinjector.INSTANCE.getSourceWindow();
if (sourceWindow.getInitialDocId() == doc.getId() && sourceWindow.getInitialSourcePosition() != null) {
// restore position deferred; restoring it immediately after
// instantiating the editor causes inaccurate scroll position
// reads elsewhere
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
editor.restorePosition(sourceWindow.getInitialSourcePosition());
editor.ensureCursorVisible();
}
});
}
}
}
}
}
use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget 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.studio.client.workbench.views.source.editors.EditingTarget 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.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.
the class Source method closeAllLocalSourceDocs.
private void closeAllLocalSourceDocs(String caption, Command onCompleted, final boolean excludeActive) {
// save active editor for exclusion (it changes as we close tabs)
final EditingTarget activeEditor = activeEditor_;
// collect up a list of dirty documents
ArrayList<EditingTarget> dirtyTargets = new ArrayList<EditingTarget>();
for (EditingTarget target : editors_) {
if (excludeActive && target == activeEditor)
continue;
if (target.dirtyState().getValue())
dirtyTargets.add(target);
}
// create a command used to close all tabs
final Command closeAllTabsCommand = new Command() {
@Override
public void execute() {
cpsExecuteForEachEditor(editors_, new CPSEditingTargetCommand() {
@Override
public void execute(EditingTarget target, Command continuation) {
if (excludeActive && target == activeEditor) {
continuation.execute();
return;
} else {
view_.closeTab(target.asWidget(), false, continuation);
}
}
});
}
};
// save targets
saveEditingTargetsWithPrompt(caption, dirtyTargets, CommandUtil.join(closeAllTabsCommand, onCompleted), null);
}
Aggregations