-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[js] custom floating toolbar for JS, TS and HTML WEB-68037
GitOrigin-RevId: c753f085abf154876ec739b1f192fa803590904f
- Loading branch information
1 parent
7bafe78
commit cc6bf30
Showing
7 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
xml/impl/src/com/intellij/xml/actions/XmlSurroundWithTagTemplateAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package com.intellij.xml.actions | ||
|
||
import com.intellij.codeInsight.actions.SimpleCodeInsightAction | ||
import com.intellij.codeInsight.template.TemplateActionContext | ||
import com.intellij.codeInsight.template.impl.InvokeTemplateAction | ||
import com.intellij.codeInsight.template.impl.TemplateImpl | ||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl | ||
import com.intellij.codeInsight.template.impl.TemplateSettings | ||
import com.intellij.openapi.actionSystem.* | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.fileEditor.FileDocumentManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.util.PsiUtilBase | ||
|
||
class XmlSurroundWithTagTemplateAction : SimpleCodeInsightAction() { | ||
|
||
init { | ||
setInjectedContext(true) | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
super.update(e) | ||
|
||
val project = e.project ?: return | ||
val editor = e.getData(CommonDataKeys.EDITOR) ?: return | ||
val file = PsiUtilBase.getPsiFileInEditor(editor, project) ?: return | ||
|
||
if (!e.place.contains(ActionPlaces.EDITOR_FLOATING_TOOLBAR) && !e.isFromContextMenu) { | ||
e.presentation.isEnabledAndVisible = false | ||
return | ||
} | ||
if (!editor.getSelectionModel().hasSelection()) { | ||
e.presentation.isEnabled = false | ||
return | ||
} | ||
e.presentation.isEnabled = createAction(editor, file) != null | ||
} | ||
|
||
override fun invoke(project: Project, editor: Editor, file: PsiFile) { | ||
if (!FileDocumentManager.getInstance().requestWriting(editor.document, project)) return | ||
createAction(editor, file)?.perform() | ||
} | ||
|
||
private fun createAction(editor: Editor, file: PsiFile): InvokeTemplateAction? { | ||
val templateActionContext = TemplateActionContext.surrounding(file, editor) | ||
val template = createTemplate()?.takeIf { TemplateManagerImpl.isApplicable(it, templateActionContext) } ?: return null | ||
return InvokeTemplateAction(template, editor, file.getProject(), mutableSetOf()) | ||
} | ||
|
||
private fun createTemplate(): TemplateImpl? { | ||
return TemplateSettings.getInstance().getTemplate("T", "HTML/XML") | ||
} | ||
} |