Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New option for Organize Imports to always omit/prepend the scala pack…

…age.

Fixes #1001127
  • Loading branch information...
commit 9dbaafc825f9639cf2317b1e2bbc4f5ffc6496f4 1 parent f8776e5
@misto misto authored
View
15 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/OrganizeImportsPreferences.scala
@@ -19,6 +19,7 @@ import scala.tools.eclipse.ScalaPlugin
import org.eclipse.jface.preference.RadioGroupFieldEditor
import org.eclipse.jface.preference.FieldEditor
import scala.tools.eclipse.util.Utils
+import org.eclipse.jface.preference.BooleanFieldEditor
@@ -130,6 +131,7 @@ class OrganizeImportsPreferencesPage extends PropertyPage with IWorkbenchPrefere
)
new RadioGroupFieldEditor(expandCollapseKey, "Multiple imports from the same package or type:", 1, options, parent, true) {
allEnableDisableControls += getRadioBoxControl(parent)
+ allEnableDisableControls ++= getRadioBoxControl(parent).getChildren
}
}
@@ -157,6 +159,12 @@ class OrganizeImportsPreferencesPage extends PropertyPage with IWorkbenchPrefere
}
}
}
+
+ fieldEditors += addNewFieldEditorWrappedInComposite(parent = control) { parent =>
+ new BooleanFieldEditor(omitScalaPackage, "Omit the scala package prefix", parent) {
+ allEnableDisableControls += getChangeControl(parent)
+ }
+ }
if (!isWorkbenchPage) {
val enabled = getPreferenceStore.getBoolean(USE_PROJECT_SPECIFIC_SETTINGS_KEY)
@@ -190,6 +198,8 @@ object OrganizeImportsPreferences extends Enumeration {
val groupsKey = PREFIX +".groups"
val wildcardsKey = PREFIX +".wildcards"
val expandCollapseKey = PREFIX +".expandcollapse"
+
+ val omitScalaPackage = PREFIX +".scalapackage"
private def getPreferenceStore(project: IProject): IPreferenceStore = {
val workspaceStore = ScalaPlugin.prefStore
@@ -203,6 +213,10 @@ object OrganizeImportsPreferences extends Enumeration {
getPreferenceStore(project).getString(groupsKey).split("\\$")
}
+ def shouldOmitScalaPackage(project: IProject) = {
+ getPreferenceStore(project).getBoolean(omitScalaPackage)
+ }
+
def getWildcardImportsForProject(project: IProject) = {
getPreferenceStore(project).getString(wildcardsKey).split("\\$")
}
@@ -223,6 +237,7 @@ class OrganizeImportsPreferencesInitializer extends AbstractPreferenceInitialize
Utils.tryExecute {
val node = new DefaultScope().getNode(ScalaPlugin.plugin.pluginId)
+ node.put(OrganizeImportsPreferences.omitScalaPackage, "false")
node.put(OrganizeImportsPreferences.groupsKey, "java$scala$org$com")
node.put(OrganizeImportsPreferences.wildcardsKey, "scalaz$scalaz.Scalaz")
node.put(OrganizeImportsPreferences.expandCollapseKey, OrganizeImportsPreferences.ExpandImports.toString)
View
10 org.scala-ide.sdt.core/src/scala/tools/eclipse/refactoring/OrganizeImportsAction.scala
@@ -20,7 +20,7 @@ import org.eclipse.jface.action.IAction
import org.eclipse.jface.window.Window
import scala.tools.eclipse.javaelements.{ScalaSourceFile, ScalaElement, LazyToplevelClass}
-import scala.tools.eclipse.properties.OrganizeImportsPreferences.{getWildcardImportsForProject, getOrganizeImportStrategy, getGroupsForProject, PreserveExistingGroups, ExpandImports, CollapseImports}
+import scala.tools.eclipse.properties.OrganizeImportsPreferences._
import scala.tools.refactoring.implementations.{OrganizeImports, AddImportStatement}
/**
@@ -241,7 +241,13 @@ class OrganizeImportsAction extends RefactoringAction with ActionWithNoWizard {
val groups = getGroupsForProject(project).toList
- expandOrCollapse ::: List(wildcards, refactoring.SortImports, refactoring.GroupImports(groups))
+ val scalaPackageStrategy = if (shouldOmitScalaPackage(project)){
+ refactoring.DropScalaPackage
+ } else {
+ refactoring.PrependScalaPackage
+ }
+
+ expandOrCollapse ::: List(scalaPackageStrategy, wildcards, refactoring.SortImports, refactoring.GroupImports(groups))
}
val deps = {
Please sign in to comment.
Something went wrong with that request. Please try again.