-
Notifications
You must be signed in to change notification settings - Fork 410
Adding support for creating sbt files #659
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
base: idea241.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
override def getTemplate(project: Project, dir: PsiDirectory): FileTemplate = FileTemplateManager.getDefaultInstance.getInternalTemplate(ScalaBundle.message("newclassorfile.menu.action.sbt.text")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. each operation on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
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")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
} |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same comment about the new line as above |
||
} |
Uh oh!
There was an error while loading. Please reload this page.