Search in sources :

Example 21 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class PackratUtil method packratProjectArg.

public String packratProjectArg() {
    String projectArg = "";
    FileSystemItem projectDir = session_.getSessionInfo().getActiveProjectDir();
    FileSystemItem workingDir = workbenchContext_.getCurrentWorkingDir();
    if (!projectDir.equalTo(workingDir))
        projectArg = "project = '" + projectDir.getPath() + "'";
    return projectArg;
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

Example 22 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class RmdOutput method onWebsiteFileSaved.

@Override
public void onWebsiteFileSaved(WebsiteFileSavedEvent event) {
    // skip if there is a build in progress
    if (workbenchContext_.isBuildInProgress())
        return;
    // skip if there is a render in progress
    if (renderInProgress_)
        return;
    // skip if there was a quit initiated since the last render
    if (quitInitiatedAfterLastRender_)
        return;
    // is there an output frame?
    if (outputFrame_ == null || outputFrame_.getWindowObject() == null)
        return;
    // is it showing a page from the current site?
    String websiteDir = session_.getSessionInfo().getBuildTargetDir();
    final RmdPreviewParams params = outputFrame_.getPreviewParams();
    if (!params.getTargetFile().startsWith(websiteDir))
        return;
    // is the changed file one that should always produce a rebuild?
    FileSystemItem file = event.getFileSystemItem();
    TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
    String typeId = fileType.getTypeId();
    if (fileType.isR() || typeId.equals(FileTypeRegistry.HTML.getTypeId()) || typeId.equals(FileTypeRegistry.YAML.getTypeId()) || typeId.equals(FileTypeRegistry.JSON.getTypeId())) {
        reRenderPreview();
    } else // is the changed file a markdown document
    if (fileType.isMarkdown()) {
        // included Rmd files always produce a rebuild of the current file
        if (file.getStem().startsWith("_"))
            reRenderPreview();
        // files in subdirectories are also includes so re-render them also
        if (!file.getParentPathString().equals(websiteDir))
            reRenderPreview();
    // ...otherwise leave it alone (requires a knit)
    } else // see if this should result in a copy + refresh
    {
        server_.maybeCopyWebsiteAsset(file.getPath(), new SimpleRequestCallback<Boolean>() {

            @Override
            public void onResponseReceived(Boolean copied) {
                if (copied)
                    outputFrame_.showRmdPreview(params, true);
            }
        });
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Example 23 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class ProfilerEditingTarget method saveNewFile.

private void saveNewFile(final String suggestedPath) {
    FileSystemItem fsi;
    if (suggestedPath != null)
        fsi = FileSystemItem.createFile(suggestedPath).getParentPath();
    else
        fsi = workbenchContext_.getDefaultFileDialogDir();
    fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {

        public void execute(final FileSystemItem saveItem, final ProgressIndicator indicator) {
            if (saveItem == null)
                return;
            workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
            final String toPath = saveItem.getPath();
            server_.copyProfile(htmlLocalPath_, toPath, new ServerRequestCallback<JavaScriptObject>() {

                @Override
                public void onResponseReceived(JavaScriptObject response) {
                    savePropertiesWithPath(saveItem.getPath());
                    persistDocumentProperty("isUserSaved", "saved");
                    isUserSaved_ = true;
                    indicator.onCompleted();
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    indicator.onCompleted();
                    globalDisplay_.showErrorMessage("Failed to Save Profile", error.getMessage());
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 24 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class PresentationDispatcher method performSourceCommand.

private void performSourceCommand(String param1, String param2) {
    if (param1 != null) {
        // get filename and type
        FileSystemItem file = FileSystemItem.createFile(getPresentationPath(param1));
        TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
        // check for a file position and/or pattern
        FilePosition pos = null;
        String pattern = null;
        if (param2 != null) {
            if (param2.length() > 2 && param2.startsWith("/") && param2.endsWith("/")) {
                pattern = param2.substring(1, param2.length() - 1);
            } else {
                int line = StringUtil.parseInt(param2, 0);
                if (line > 0)
                    pos = FilePosition.create(line, 1);
            }
        }
        // dispatch
        fireOpenSourceFileEvent(new OpenPresentationSourceFileEvent(file, fileType, pos, pattern));
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) FilePosition(org.rstudio.core.client.FilePosition) OpenPresentationSourceFileEvent(org.rstudio.studio.client.common.filetypes.events.OpenPresentationSourceFileEvent)

Example 25 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class PresentationDispatcher method fireEventFromTutorialDirectory.

private void fireEventFromTutorialDirectory(final GwtEvent<?> event) {
    SessionInfo sessionInfo = session_.getSessionInfo();
    PresentationState state = sessionInfo.getPresentationState();
    FileSystemItem projectDir = sessionInfo.getActiveProjectDir();
    if (state.isTutorial() && (projectDir != null)) {
        if (!workbenchContext_.getCurrentWorkingDir().equalTo(projectDir)) {
            server_.setWorkingDirectory(projectDir.getPath(), new VoidServerRequestCallback() {

                @Override
                protected void onSuccess() {
                    eventBus_.fireEvent(event);
                }
            });
        } else {
            eventBus_.fireEvent(event);
        }
    } else {
        eventBus_.fireEvent(event);
    }
}
Also used : PresentationState(org.rstudio.studio.client.workbench.views.presentation.model.PresentationState) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback)

Aggregations

FileSystemItem (org.rstudio.core.client.files.FileSystemItem)89 ServerError (org.rstudio.studio.client.server.ServerError)18 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)16 JsArrayString (com.google.gwt.core.client.JsArrayString)14 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)10 Handler (org.rstudio.core.client.command.Handler)10 Command (com.google.gwt.user.client.Command)9 ArrayList (java.util.ArrayList)7 AppCommand (org.rstudio.core.client.command.AppCommand)7 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)6 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)5 JsArray (com.google.gwt.core.client.JsArray)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 JSONString (com.google.gwt.json.client.JSONString)4 FilePosition (org.rstudio.core.client.FilePosition)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)4 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)4 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)4 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)4