From 2b67868513f9a6d7f7510d9bf50eb978e313ab68 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Tue, 20 Jan 2015 23:55:14 +0300 Subject: [PATCH] actions for Emmet edit point navigation (WEB-362) --- .../src/META-INF/XmlActions.xml | 13 ++++ .../emmet/actions/EmmetEditPointUtil.java | 1 + .../emmet/actions/GoToEditPointAction.java | 59 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 xml/impl/src/com/intellij/codeInsight/template/emmet/actions/GoToEditPointAction.java diff --git a/platform/platform-resources/src/META-INF/XmlActions.xml b/platform/platform-resources/src/META-INF/XmlActions.xml index 5b4e97e19fe2..afb8af84a266 100644 --- a/platform/platform-resources/src/META-INF/XmlActions.xml +++ b/platform/platform-resources/src/META-INF/XmlActions.xml @@ -97,6 +97,19 @@ text="Update tag with Emmet" description="Update existing HTML tag with Emmet abbreviation"> + + + + + + + + + + + diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/actions/EmmetEditPointUtil.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/actions/EmmetEditPointUtil.java index 54da1a872fa5..24fd7faaeee1 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/actions/EmmetEditPointUtil.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/actions/EmmetEditPointUtil.java @@ -87,6 +87,7 @@ public class EmmetEditPointUtil { } static boolean isApplicableFile(PsiFile file) { + if (file == null) return false; for (Language language : file.getViewProvider().getLanguages()) { if (language.isKindOf(XMLLanguage.INSTANCE)) return true; } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/actions/GoToEditPointAction.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/actions/GoToEditPointAction.java new file mode 100644 index 000000000000..f6c66a88931f --- /dev/null +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/actions/GoToEditPointAction.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.template.emmet.actions; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.psi.PsiFile; +import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; + +/** + * @author Dennis.Ushakov + */ +public abstract class GoToEditPointAction extends DumbAwareAction { + @Override + public void update(AnActionEvent e) { + final Editor editor = getEditor(e); + final PsiFile file = getFile(e); + final boolean isApplicable = editor != null && EmmetEditPointUtil.isApplicableFile(file); + e.getPresentation().setEnabledAndVisible(isApplicable); + } + + private static PsiFile getFile(AnActionEvent e) { + return CommonDataKeys.PSI_FILE.getData(e.getDataContext()); + } + + private static Editor getEditor(AnActionEvent e) { + final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext()); + return editor != null ? InjectedLanguageUtil.getTopLevelEditor(editor) : null; + } + + public static class Forward extends GoToEditPointAction { + @Override + public void actionPerformed(AnActionEvent e) { + EmmetEditPointUtil.moveForward(getEditor(e), getFile(e)); + } + } + + public static class Backward extends GoToEditPointAction { + @Override + public void actionPerformed(AnActionEvent e) { + EmmetEditPointUtil.moveBackward(getEditor(e), getFile(e)); + } + } +}