Search in sources :

Example 6 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor in project che by eclipse.

the class EditorAgentImpl method closeEditor.

private void closeEditor(EditorTab tab) {
    checkArgument(tab != null, "Null editor tab occurred");
    EditorPartPresenter editor = tab.getRelativeEditorPart();
    if (editor == null) {
        return;
    }
    openedEditors.remove(editor);
    openedEditorsToProviders.remove(editor);
    editor.close(false);
    if (editor instanceof TextEditor) {
        editorContentSynchronizerProvider.get().unTrackEditor(editor);
    }
    if (activeEditor != null && activeEditor == editor) {
        activeEditor = null;
    }
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 7 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor in project che by eclipse.

the class BasicActiveFileHandler method scrollToLine.

protected void scrollToLine(EditorPartPresenter editor, int lineNumber) {
    if (editor instanceof TextEditor) {
        TextEditor textEditor = (TextEditor) editor;
        Document document = textEditor.getDocument();
        if (document != null) {
            TextPosition newPosition = new TextPosition(lineNumber, 0);
            document.setCursorPosition(newPosition);
        }
    }
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document)

Example 8 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor in project che by eclipse.

the class TestResultViewImpl method gotoClass.

@Override
public void gotoClass(String packagePath, int line) {
    lastWentLine = line;
    final Project project = appContext.getRootProject();
    String testSrcPath = project.getPath() + "/" + DEFAULT_TEST_SOURCE_FOLDER;
    appContext.getWorkspaceRoot().getFile(testSrcPath + packagePath).then(new Operation<Optional<File>>() {

        @Override
        public void apply(Optional<File> file) throws OperationException {
            if (file.isPresent()) {
                eventBus.fireEvent(FileEvent.createOpenFileEvent(file.get()));
                Timer t = new Timer() {

                    @Override
                    public void run() {
                        EditorPartPresenter editorPart = editorAgent.getActiveEditor();
                        Document doc = ((TextEditor) editorPart).getDocument();
                        doc.setCursorPosition(new TextPosition(lastWentLine - 1, 0));
                    }
                };
                t.schedule(500);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            Log.info(TestResultViewImpl.class, error);
        }
    });
}
Also used : Optional(com.google.common.base.Optional) Operation(org.eclipse.che.api.promises.client.Operation) Document(org.eclipse.che.ide.api.editor.document.Document) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Timer(com.google.gwt.user.client.Timer) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 9 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor in project che by eclipse.

the class OpenDeclarationFinder method openDeclaration.

public void openDeclaration() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    if (!(activeEditor instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    int offset = editor.getCursorOffset();
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
        navigationService.findDeclaration(project.get().getLocation(), fqn, offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(project.get().getLocation(), result);
                }
            }
        });
    } else if (file instanceof JarFileNode) {
        navigationService.findDeclaration(((JarFileNode) file).getProjectLocation(), file.getLocation().toString().replace('/', '.'), offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(((JarFileNode) file).getProject(), result);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 10 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor in project che by eclipse.

the class OpenDeclarationFinder method handleDescriptor.

private void handleDescriptor(final Path projectPath, final OpenDeclarationDescriptor descriptor) {
    final EditorPartPresenter openedEditor = editorAgent.getOpenedEditor(Path.valueOf(descriptor.getPath()));
    if (openedEditor != null) {
        editorAgent.openEditor(openedEditor.getEditorInput().getFile(), new OpenEditorCallbackImpl() {

            @Override
            public void onEditorOpened(EditorPartPresenter editor) {
                setCursorAndActivateEditor(editor, descriptor.getOffset());
            }

            @Override
            public void onEditorActivated(EditorPartPresenter editor) {
                setCursorAndActivateEditor(editor, descriptor.getOffset());
            }
        });
        return;
    }
    if (descriptor.isBinary()) {
        navigationService.getEntry(projectPath, descriptor.getLibId(), descriptor.getPath()).then(new Operation<JarEntry>() {

            @Override
            public void apply(final JarEntry entry) throws OperationException {
                navigationService.getContent(projectPath, descriptor.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {

                    @Override
                    public void apply(ClassContent content) throws OperationException {
                        final VirtualFile file = javaNodeFactory.newJarFileNode(entry, descriptor.getLibId(), projectPath, null);
                        editorAgent.openEditor(file, new OpenEditorCallbackImpl() {

                            @Override
                            public void onEditorOpened(final EditorPartPresenter editor) {
                                Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                                    @Override
                                    public void execute() {
                                        if (editor instanceof TextEditor) {
                                            ((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
                                            editor.activate();
                                        }
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    } else {
        appContext.getWorkspaceRoot().getFile(descriptor.getPath()).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> file) throws OperationException {
                if (file.isPresent()) {
                    editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {

                        @Override
                        public void onEditorOpened(final EditorPartPresenter editor) {
                            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                                @Override
                                public void execute() {
                                    if (editor instanceof TextEditor) {
                                        ((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
                                        editor.activate();
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) Optional(com.google.common.base.Optional) Scheduler(com.google.gwt.core.client.Scheduler) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) Operation(org.eclipse.che.api.promises.client.Operation) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)33 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)21 Project (org.eclipse.che.ide.api.resources.Project)8 Resource (org.eclipse.che.ide.api.resources.Resource)8 OperationException (org.eclipse.che.api.promises.client.OperationException)7 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)7 Operation (org.eclipse.che.api.promises.client.Operation)6 Document (org.eclipse.che.ide.api.editor.document.Document)5 TextEditorConfiguration (org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PromiseError (org.eclipse.che.api.promises.client.PromiseError)4 File (org.eclipse.che.ide.api.resources.File)4 Optional (com.google.common.base.Optional)3 ServerCapabilities (io.typefox.lsapi.ServerCapabilities)3 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)3 Collections.singletonList (java.util.Collections.singletonList)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 JsPromise (org.eclipse.che.api.promises.client.js.JsPromise)2