Search in sources :

Example 66 with EditorPartPresenter

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

the class EditorAgentImpl method getState.

@Override
public JsonObject getState() {
    JsonObject state = Json.createObject();
    EditorMultiPartStackState stacks = null;
    try {
        stacks = editorMultiPartStack.getState();
    } catch (IllegalStateException ignore) {
    }
    if (stacks != null) {
        state.put("FILES", storeEditors(stacks));
    }
    EditorPartPresenter activeEditor = getActiveEditor();
    if (activeEditor != null) {
        state.put("ACTIVE_EDITOR", activeEditor.getEditorInput().getFile().getLocation().toString());
    }
    return state;
}
Also used : EditorMultiPartStackState(org.eclipse.che.ide.api.parts.EditorMultiPartStackState) JsonObject(elemental.json.JsonObject) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 67 with EditorPartPresenter

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

the class EditorCurrentFilePathMacro method expand.

/** {@inheritDoc} */
@Override
public Promise<String> expand() {
    final EditorPartPresenter editor = getActiveEditor();
    if (editor == null) {
        return promises.resolve("");
    }
    final Path absolutePath = appContext.getProjectsRoot().append(editor.getEditorInput().getFile().getLocation());
    return promises.resolve(absolutePath.toString());
}
Also used : Path(org.eclipse.che.ide.resource.Path) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 68 with EditorPartPresenter

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

the class EditorCurrentProjectNameMacro method expand.

/** {@inheritDoc} */
@Override
public Promise<String> expand() {
    final EditorPartPresenter editor = getActiveEditor();
    if (editor == null) {
        return promises.resolve("");
    }
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        if (!project.isPresent()) {
            return promises.resolve("");
        }
        return promises.resolve(project.get().getName());
    }
    return promises.resolve("");
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 69 with EditorPartPresenter

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

the class EditorCurrentProjectTypeMacro method expand.

/** {@inheritDoc} */
@Override
public Promise<String> expand() {
    final EditorPartPresenter editor = getActiveEditor();
    if (editor == null) {
        return promises.resolve("");
    }
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        if (!project.isPresent()) {
            return promises.resolve("");
        }
        return promises.resolve(project.get().getType());
    }
    return promises.resolve("");
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 70 with EditorPartPresenter

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

the class AppContextImpl method getRootProject.

@Override
public Project getRootProject() {
    if (projects == null) {
        return null;
    }
    if (currentResource == null || currentResources == null) {
        EditorAgent editorAgent = editorAgentProvider.get();
        if (editorAgent == null) {
            return null;
        }
        final EditorPartPresenter editor = editorAgent.getActiveEditor();
        if (editor == null) {
            return null;
        }
        final VirtualFile file = editor.getEditorInput().getFile();
        if (file instanceof SyntheticNode) {
            final Path projectPath = ((SyntheticNode) file).getProject();
            for (Project project : projects) {
                if (project.getLocation().equals(projectPath)) {
                    return project;
                }
            }
        }
    }
    if (currentResource == null) {
        return null;
    }
    Project root = null;
    for (Project project : projects) {
        if (project.getLocation().isPrefixOf(currentResource.getLocation())) {
            root = project;
        }
    }
    if (root == null) {
        return null;
    }
    for (int i = 1; i < currentResources.length; i++) {
        if (!root.getLocation().isPrefixOf(currentResources[i].getLocation())) {
            return null;
        }
    }
    return root;
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) EditorAgent(org.eclipse.che.ide.api.editor.EditorAgent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) SyntheticNode(org.eclipse.che.ide.project.node.SyntheticNode)

Aggregations

EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)79 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)21 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)19 OperationException (org.eclipse.che.api.promises.client.OperationException)13 Project (org.eclipse.che.ide.api.resources.Project)13 Resource (org.eclipse.che.ide.api.resources.Resource)11 Test (org.junit.Test)10 Operation (org.eclipse.che.api.promises.client.Operation)9 Path (org.eclipse.che.ide.resource.Path)8 File (org.eclipse.che.ide.api.resources.File)7 Scheduler (com.google.gwt.core.client.Scheduler)6 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)6 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)6 Optional (com.google.common.base.Optional)5 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 HandlesTextOperations (org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations)4 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 JsonObject (elemental.json.JsonObject)3