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

Adding support for creating sbt files #659

Open
wants to merge 3 commits into
base: idea241.x
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions scala/scala-impl/resources/META-INF/scala-plugin-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
<internalFileTemplate name="Package Object"/>
<internalFileTemplate name="Scala File"/>
<internalFileTemplate name="Scala Enum"/>
<internalFileTemplate name="Sbt File"/>
<defaultTemplatePropertiesProvider implementation="org.jetbrains.plugins.scala.actions.ScalaDefaultTemplatePropertiesProvider"/>

<indexPatternBuilder implementation="org.jetbrains.plugins.scala.editor.todo.ScalaIndexPatternBuilder"/>
Expand Down Expand Up @@ -1982,6 +1983,15 @@
class="org.jetbrains.plugins.scala.components.TypeAwareWidgetFactory$Listener"/>
</projectListeners>
<actions>

<group id="SbtFileAction" icon="org.jetbrains.sbt.icons.Icons.SBT_FILE" popup="true" text="Sbt File">
<separator/>
<action id="Scala.NewSbtFileAction" class="org.jetbrains.plugins.scala.actions.NewSbtFileAction"/>
<action id="Scala.NewSbtBuildFileAction" class="org.jetbrains.plugins.scala.actions.NewSbtBuildFileAction"/>
<action id="Scala.NewSbtPluginFileAction" class="org.jetbrains.plugins.scala.actions.NewSbtPluginFileAction"/>
Sa1to marked this conversation as resolved.
Show resolved Hide resolved
<add-to-group group-id="NewGroup" anchor="last"/>
</group>

<action id="Scala.NewClass" class="org.jetbrains.plugins.scala.actions.NewScalaFileAction">
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewGroup1"/>
</action>
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<body>
<table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td colspan="3">
<font face="verdana" size="-1">
This is a built-in template used by <b>IntelliJ IDEA</b> each time you create a
Sbt File
</font>
</td>
</tr>
</table>
</body>
</html>
11 changes: 11 additions & 0 deletions scala/scala-impl/resources/messages/ScalaBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ newclassorfile.menu.action.description=Creates new Scala Class or File
create.new.scala.class.or.file=Create New Scala Class/File
this.is.not.a.valid.scala.qualified.name=This is not a valid Scala qualified name

newclassorfile.menu.action.sbt.text=Sbt File
newclassorfile.menu.action.build.sbt.text=Sbt Build File
newclassorfile.menu.action.build.sbt.defaultName=build
newclassorfile.menu.action.plugin.sbt.text=Sbt Plugin File
newclassorfile.menu.action.plugin.sbt.defaultName=plugin
newclassorfile.menu.action.sbt.description=Create new Sbt File

error.package.already.contains.build.sbt=''build.sbt'' already exists for package ''{0}''
error.package.already.contains.plugin.sbt=''plugin.sbt'' already exists for package ''{0}''
error.title.package.already.contains.file=Cannot Create File

### org/jetbrains/plugins/scala/actions/ShowTypeInfoAction.scala
type.info.text=Type Info
type.info.description=Show Type Info
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jetbrains.plugins.scala.actions

import com.intellij.ide.IdeView
import com.intellij.ide.fileTemplates.actions.CreateFromTemplateActionBase
import com.intellij.ide.fileTemplates.{FileTemplate, FileTemplateManager}
import com.intellij.openapi.actionSystem.{CommonDataKeys, DataContext}
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.NlsActions
import com.intellij.psi.PsiDirectory
import org.jetbrains.plugins.scala.ScalaBundle
import org.jetbrains.plugins.scala.extensions.PsiNamedElementExt

import javax.swing.Icon

abstract class NewPredefinedSbtFileAction(@NlsActions.ActionText title: String, @NlsActions.ActionDescription description: String, icon: Icon, fileName: String) extends CreateFromTemplateActionBase(title, description, icon) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line with class parameters is too long. Each parameter should be in a separate line. The same like in methods.
Screenshot 2024-05-15 at 17 55 00


override def getTemplate(project: Project, dir: PsiDirectory): FileTemplate = FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text")) should be in a new line. It is not readable in IDE


override def getTargetDirectory(dataContext: DataContext, view: IdeView): PsiDirectory = {
val directories: Array[PsiDirectory] = view.getDirectories
directories.find(directory => directory.findFile(fileName + ".sbt") != null).exists(dir => {
Messages.showErrorDialog(CommonDataKeys.PROJECT.getData(dataContext),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each operation on directories should be in a new line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists takes a predicate as a parameter. What's your predicate here?

ScalaBundle.message("error.package.already.contains.build.sbt", dir.name),
ScalaBundle.message("error.title.package.already.contains.file", dir.name))
return null
}
)
super.getTargetDirectory(dataContext, view)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.jetbrains.plugins.scala.actions

import com.intellij.ide.fileTemplates.actions.AttributesDefaults
import com.intellij.openapi.actionSystem.DataContext
import org.jetbrains.plugins.scala.ScalaBundle
import org.jetbrains.sbt.icons.Icons

final class NewSbtBuildFileAction extends NewPredefinedSbtFileAction(
ScalaBundle.message("newclassorfile.menu.action.build.sbt.text"),
ScalaBundle.message("newclassorfile.menu.action.sbt.description"),
Icons.SBT_FILE,
ScalaBundle.message("newclassorfile.menu.action.build.sbt.defaultName")
) {
protected override def getAttributesDefaults(dataContext: DataContext): AttributesDefaults = new AttributesDefaults(ScalaBundle.message("newclassorfile.menu.action.build.sbt.defaultName")).withFixedName(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new AttributesDefaults(ScalaBundle.message("newclassorfile.menu.action.build.sbt.defaultName")).withFixedName(true) should be in a new line

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.jetbrains.plugins.scala.actions

import com.intellij.ide.fileTemplates.actions.CreateFromTemplateActionBase
import com.intellij.ide.fileTemplates.{FileTemplate, FileTemplateManager}
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiDirectory
import org.jetbrains.sbt.icons.Icons
import org.jetbrains.plugins.scala.ScalaBundle

final class NewSbtFileAction extends CreateFromTemplateActionBase(
ScalaBundle.message("newclassorfile.menu.action.sbt.text"),
ScalaBundle.message("newclassorfile.menu.action.sbt.description"),
Icons.SBT_FILE
) {

override def getTemplate(project: Project, dir: PsiDirectory): FileTemplate = FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text")) should be in a new line


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.jetbrains.plugins.scala.actions

import com.intellij.ide.fileTemplates.actions.AttributesDefaults
import com.intellij.openapi.actionSystem.DataContext
import org.jetbrains.plugins.scala.ScalaBundle
import org.jetbrains.sbt.icons.Icons

final class NewSbtPluginFileAction extends NewPredefinedSbtFileAction(
ScalaBundle.message("newclassorfile.menu.action.plugin.sbt.text"),
ScalaBundle.message("newclassorfile.menu.action.sbt.description"),
Icons.SBT_FILE,
ScalaBundle.message("newclassorfile.menu.action.plugin.sbt.defaultName")
) {
protected override def getAttributesDefaults(dataContext: DataContext): AttributesDefaults = new AttributesDefaults(ScalaBundle.message("newclassorfile.menu.action.plugin.sbt.defaultName")).withFixedName(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same comment about the new line as above

}