use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.
the class Source method openNotebook.
private void openNotebook(final FileSystemItem rmdFile, final SourceDocumentResult doc, final ResultCallback<EditingTarget, ServerError> resultCallback) {
if (!StringUtil.isNullOrEmpty(doc.getDocPath())) {
// this happens if we created the R Markdown file, or if the R Markdown
// file on disk matched the one inside the notebook
openFileFromServer(rmdFile, FileTypeRegistry.RMARKDOWN, resultCallback);
} else if (!StringUtil.isNullOrEmpty(doc.getDocId())) {
// this happens when we have to open an untitled buffer for the the
// notebook (usually because the of a conflict between the Rmd on disk
// and the one in the .nb.html file)
server_.getSourceDocument(doc.getDocId(), new ServerRequestCallback<SourceDocument>() {
@Override
public void onResponseReceived(SourceDocument doc) {
// create the editor
EditingTarget target = addTab(doc, OPEN_INTERACTIVE);
// show a warning bar
if (target instanceof TextEditingTarget) {
((TextEditingTarget) target).showWarningMessage("This notebook has the same name as an R Markdown " + "file, but doesn't match it.");
}
resultCallback.onSuccess(target);
}
@Override
public void onError(ServerError error) {
globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. " + "If the error persists, try removing the " + "accompanying R Markdown file. \n\n" + error.getMessage());
resultCallback.onFailure(error);
}
});
}
}
use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.
the class Source method openFileAlreadyOpen.
private boolean openFileAlreadyOpen(final FileSystemItem file, final ResultCallback<EditingTarget, ServerError> resultCallback) {
// check to see if any local editors have the file open
for (int i = 0; i < editors_.size(); i++) {
EditingTarget target = editors_.get(i);
String thisPath = target.getPath();
if (thisPath != null && thisPath.equalsIgnoreCase(file.getPath())) {
view_.selectTab(i);
pMruList_.get().add(thisPath);
if (resultCallback != null)
resultCallback.onSuccess(target);
return true;
}
}
return false;
}
use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.
the class Source method onInsertSource.
public void onInsertSource(final InsertSourceEvent event) {
if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget && commands_.executeCode().isEnabled()) {
TextEditingTarget textEditor = (TextEditingTarget) activeEditor_;
textEditor.insertCode(event.getCode(), event.isBlock());
} else {
newDoc(FileTypeRegistry.R, new ResultCallback<EditingTarget, ServerError>() {
public void onSuccess(EditingTarget arg) {
((TextEditingTarget) arg).insertCode(event.getCode(), event.isBlock());
}
});
}
}
use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.
the class Source method fireDocTabsChanged.
private void fireDocTabsChanged() {
if (!initialized_)
return;
// ensure we have a tab order (we want the popup list to match the order
// of the tabs)
syncTabOrder();
String[] ids = new String[editors_.size()];
ImageResource[] icons = new ImageResource[editors_.size()];
String[] names = new String[editors_.size()];
String[] paths = new String[editors_.size()];
for (int i = 0; i < ids.length; i++) {
EditingTarget target = editors_.get(tabOrder_.get(i));
ids[i] = target.getId();
icons[i] = target.getIcon();
names[i] = target.getName().getValue();
paths[i] = target.getPath();
}
events_.fireEvent(new DocTabsChangedEvent(ids, icons, names, paths));
view_.manageChevronVisibility();
}
use of org.rstudio.studio.client.workbench.views.source.editors.EditingTarget in project rstudio by rstudio.
the class Source method openFileFromServer.
private void openFileFromServer(final FileSystemItem file, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
final Command dismissProgress = globalDisplay_.showProgress("Opening file...");
server_.openDocument(file.getPath(), fileType.getTypeId(), uiPrefs_.defaultEncoding().getValue(), new ServerRequestCallback<SourceDocument>() {
@Override
public void onError(ServerError error) {
dismissProgress.execute();
pMruList_.get().remove(file.getPath());
Debug.logError(error);
if (resultCallback != null)
resultCallback.onFailure(error);
}
@Override
public void onResponseReceived(SourceDocument document) {
dismissProgress.execute();
pMruList_.get().add(document.getPath());
EditingTarget target = addTab(document, OPEN_INTERACTIVE);
if (resultCallback != null)
resultCallback.onSuccess(target);
}
});
}
Aggregations