Search in sources :

Example 1 with FilePosition

use of org.rstudio.core.client.FilePosition in project rstudio by rstudio.

the class EnvironmentPresenter method openOrUpdateFileBrowsePoint.

private void openOrUpdateFileBrowsePoint(boolean debugging, boolean sourceChanged) {
    String file = currentBrowseFile_;
    // if we have no file and no source code, we can do no navigation 
    if (!CallFrame.isNavigableFilename(file) && !useCurrentBrowseSource_) {
        return;
    }
    // file itself
    if (currentBrowsePosition_ != null && !useCurrentBrowseSource_) {
        FileSystemItem sourceFile = FileSystemItem.createFile(file);
        eventBus_.fireEvent(new OpenSourceFileEvent(sourceFile, (FilePosition) currentBrowsePosition_.cast(), FileTypeRegistry.R, debugging ? NavigationMethods.DEBUG_STEP : NavigationMethods.DEBUG_END));
    } else // the copy from the server into the code browser window
    if (useCurrentBrowseSource_ && currentBrowseSource_.length() > 0) {
        if (debugging) {
            // create the function name for the code browser by removing the
            // () indicator supplied by the server
            String functionName = environmentName_;
            int idx = functionName.indexOf('(');
            if (idx > 0) {
                functionName = functionName.substring(0, idx);
            }
            // omit qualifiers
            idx = functionName.indexOf("::");
            if (idx > 0) {
                functionName = functionName.substring(idx + 1);
                // :::, too
                if (functionName.startsWith(":"))
                    functionName = functionName.substring(1);
            }
            // create the function definition
            searchFunction_ = SearchPathFunctionDefinition.create(functionName, StringUtil.isNullOrEmpty(functionEnvName_) ? "debugging" : functionEnvName_, currentBrowseSource_, true);
            if (sourceChanged) {
                // if this is a different source file than we already have open,
                // open it 
                eventBus_.fireEvent(new CodeBrowserNavigationEvent(searchFunction_, currentBrowsePosition_.functionRelativePosition(currentFunctionLineNumber_), contextDepth_ == 1, false));
            } else if (currentBrowsePosition_.getLine() > 0) {
                // if this is the same one currently open, just move the 
                // highlight
                eventBus_.fireEvent(new CodeBrowserHighlightEvent(searchFunction_, currentBrowsePosition_.functionRelativePosition(currentFunctionLineNumber_)));
            }
        } else {
            eventBus_.fireEvent(new CodeBrowserFinishedEvent(searchFunction_));
        }
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) CodeBrowserNavigationEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserNavigationEvent) OpenSourceFileEvent(org.rstudio.studio.client.common.filetypes.events.OpenSourceFileEvent) CodeBrowserHighlightEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserHighlightEvent) CodeBrowserFinishedEvent(org.rstudio.studio.client.workbench.views.source.events.CodeBrowserFinishedEvent) JsArrayString(com.google.gwt.core.client.JsArrayString) DebugFilePosition(org.rstudio.core.client.DebugFilePosition) FilePosition(org.rstudio.core.client.FilePosition)

Example 2 with FilePosition

use of org.rstudio.core.client.FilePosition in project rstudio by rstudio.

the class FileTypeRegistry method satelliteEditFile.

private void satelliteEditFile(JavaScriptObject file, JavaScriptObject position, boolean highlightLine) {
    FileSystemItem fsi = file.cast();
    FilePosition pos = position.cast();
    editFile(fsi, pos);
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) FilePosition(org.rstudio.core.client.FilePosition)

Example 3 with FilePosition

use of org.rstudio.core.client.FilePosition in project rstudio by rstudio.

the class ProfilerEditingTarget method onGotoProfileSource.

@Handler
public void onGotoProfileSource() {
    FilePosition filePosition = FilePosition.create(selectedLine_, 0);
    fileTypeRegistry_.editFile(FileSystemItem.createFile(selectedPath_), filePosition);
}
Also used : FilePosition(org.rstudio.core.client.FilePosition) Handler(org.rstudio.core.client.command.Handler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) SelectionCommitHandler(org.rstudio.core.client.events.SelectionCommitHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) CloseHandler(com.google.gwt.event.logical.shared.CloseHandler)

Example 4 with FilePosition

use of org.rstudio.core.client.FilePosition 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 5 with FilePosition

use of org.rstudio.core.client.FilePosition in project rstudio by rstudio.

the class CodeSearchOracle method navigationTarget.

public CodeNavigationTarget navigationTarget(String query, Suggestion suggestion) {
    CodeSearchSuggestion codeSearchSuggestion = (CodeSearchSuggestion) suggestion;
    // Allow queries of the form e.g. 'foo:15' to go to line '15' of a file.
    // We parse the integer following the ':' if possible.
    FilePosition filePos = codeSearchSuggestion.getNavigationTarget().getPosition();
    if (codeSearchSuggestion.isFileTarget()) {
        int colonIndex = query.indexOf(":");
        if (colonIndex > 0) {
            String[] splat = query.split(":");
            if (splat.length > 1) {
                int rowToNavigateTo = 0;
                try {
                    rowToNavigateTo = Integer.parseInt(splat[1]);
                } catch (Exception e) {
                }
                int colToNavigateTo = 0;
                if (splat.length > 2) {
                    try {
                        colToNavigateTo = Integer.parseInt(splat[2]);
                    } catch (Exception e) {
                    }
                }
                filePos = FilePosition.create(rowToNavigateTo, colToNavigateTo);
            }
        }
    }
    String fileName = codeSearchSuggestion.getNavigationTarget().getFile();
    CodeNavigationTarget target = new CodeNavigationTarget(fileName, filePos);
    return target;
}
Also used : CodeNavigationTarget(org.rstudio.core.client.CodeNavigationTarget) FilePosition(org.rstudio.core.client.FilePosition)

Aggregations

FilePosition (org.rstudio.core.client.FilePosition)7 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 DebugFilePosition (org.rstudio.core.client.DebugFilePosition)2 OpenSourceFileEvent (org.rstudio.studio.client.common.filetypes.events.OpenSourceFileEvent)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 CloseHandler (com.google.gwt.event.logical.shared.CloseHandler)1 CodeNavigationTarget (org.rstudio.core.client.CodeNavigationTarget)1 Handler (org.rstudio.core.client.command.Handler)1 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)1 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)1 SelectionCommitHandler (org.rstudio.core.client.events.SelectionCommitHandler)1 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)1 OpenPresentationSourceFileEvent (org.rstudio.studio.client.common.filetypes.events.OpenPresentationSourceFileEvent)1 CodeBrowserFinishedEvent (org.rstudio.studio.client.workbench.views.source.events.CodeBrowserFinishedEvent)1 CodeBrowserHighlightEvent (org.rstudio.studio.client.workbench.views.source.events.CodeBrowserHighlightEvent)1 CodeBrowserNavigationEvent (org.rstudio.studio.client.workbench.views.source.events.CodeBrowserNavigationEvent)1