Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an action to create a new empty file #14

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## [Unreleased]

### Added
- Added an action to create a new empty file

### Fixed
- Fixed linear marker preview

## [0.2.7] - 2023-11-15

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.slint.ideaplugin.ide.actions

import com.intellij.ide.actions.CreateFileFromTemplateAction
import com.intellij.ide.actions.CreateFileFromTemplateDialog
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.client.currentSession
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.psi.PsiDirectory
import dev.slint.ideaplugin.SlintBundle
import dev.slint.ideaplugin.SlintIcons
import org.jetbrains.annotations.Nls

class SlintCreateFileAction : CreateFileFromTemplateAction(CAPTION, "", SlintIcons.SLINT),
DumbAware {

override fun getActionName(directory: PsiDirectory?, newName: String, templateName: String?): String = CAPTION

override fun isAvailable(dataContext: DataContext): Boolean {
if (!super.isAvailable(dataContext)) return false
CommonDataKeys.PROJECT.getData(dataContext) ?: return false
return true
}

override fun buildDialog(project: Project, directory: PsiDirectory, builder: CreateFileFromTemplateDialog.Builder) {
builder.setTitle(CAPTION)
.addKind(SlintBundle.message("list.item.empty.file"), SlintIcons.SLINT, "Slint File")
}

private companion object {
@Nls
private val CAPTION = SlintBundle.message("slint.file")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@ package dev.slint.ideaplugin.ide.lineMarkers

import com.intellij.execution.lineMarker.RunLineMarkerContributor
import com.intellij.psi.PsiElement
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.TokenType.WHITE_SPACE
import com.intellij.psi.util.elementType
import com.intellij.psi.util.nextLeafs
import dev.slint.ideaplugin.ide.actions.PreviewComponentAction
import dev.slint.ideaplugin.lang.psi.SlintElementTypes.COMPONENT
import dev.slint.ideaplugin.lang.psi.SlintElementTypes.IDENTIFIER
import dev.slint.ideaplugin.lang.psi.SlintFileElementType
import dev.slint.ideaplugin.lang.psi.SlintElementTypes.*

class PreviewRunLineMarkerContributor : RunLineMarkerContributor() {
override fun getInfo(element: PsiElement): Info? {
return when (element.elementType) {
SlintFileElementType -> {
Info(ActionManager.getInstance().getAction("Slint.Preview"))
}
COMPONENT -> {
COMPONENT_DEFINITION -> {
val componentName = getComponentName(element) ?: return null
Info(PreviewComponentAction(componentName))
}
Expand All @@ -29,16 +20,10 @@ class PreviewRunLineMarkerContributor : RunLineMarkerContributor() {
}

private fun getComponentName(element: PsiElement): String? {
val psiWhiteSpace = element.nextSibling
if (psiWhiteSpace.elementType != WHITE_SPACE) {
val componentName = element.children.firstOrNull() ?: return null
if (componentName.elementType != COMPONENT_NAME) {
return null
}

val component = psiWhiteSpace.nextSibling
if (component.elementType != IDENTIFIER) {
return null
}

return component.text
return componentName.text
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/dev/slint/ideaplugin/lang/SlintLanguage.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package dev.slint.ideaplugin.lang

import com.intellij.json.JsonLanguage
import com.intellij.lang.Language

object SlintLanguage : Language("Slint") {
private fun readResolve(): Any = SlintLanguage

val INSTANCE = SlintLanguage

override fun getDisplayName(): String = "Slint"
Expand Down

This file was deleted.

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<lang.parserDefinition language="Slint"
implementationClass="dev.slint.ideaplugin.lang.parser.SlintParserDefinition"/>
<annotator language="Slint" implementationClass="dev.slint.ideaplugin.ide.annotator.SlintAnnotator"/>
<internalFileTemplate name="Slint File"/>

<!--Syntax Highlighting-->
<lang.syntaxHighlighter language="Slint"
Expand All @@ -47,6 +48,11 @@
implementationClass="dev.slint.ideaplugin.ide.lineMarkers.PreviewRunLineMarkerContributor"/>
</extensions>
<actions>
<action id="Slint.NewSlintFile"
class="dev.slint.ideaplugin.ide.actions.SlintCreateFileAction">
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewFile"/>
</action>

<group id="SlintGroupedActions">
<separator/>
<add-to-group group-id="ProjectViewPopupMenu"/>
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Empty Slint file.
</body>
</html>
7 changes: 6 additions & 1 deletion src/main/resources/messages/SlintBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ settings.display.name=Slint
configurable.name.slint.settings=Slint Settings

# Filetype
filetype.slint.description=Slint
filetype.slint.description=Slint

# Actions
slint.file=Slint File

list.item.empty.file=Empty file
Loading