Skip to content

Commit

Permalink
Added support for enabling/disabling Hydra Settings panel
Browse files Browse the repository at this point in the history
  • Loading branch information
maris123 committed Oct 22, 2017
1 parent 901936a commit ebd31d9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
5 changes: 3 additions & 2 deletions scala/scala-impl/resources/META-INF/scala-plugin-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<projectConfigurable groupId="language" displayName="Scala" instance="org.jetbrains.plugins.scala.settings.ScalaProjectSettingsConfigurable"/>
<applicationConfigurable displayName="Scala Compile Server" parentId="Scala Compiler"
instance="org.jetbrains.plugins.scala.compiler.ScalaCompileServerForm"/>
<projectConfigurable groupId="language" displayName="Hydra Compiler" instance="org.jetbrains.plugins.scala.compiler.HydraCompilerConfigurable"/>
<applicationService serviceInterface="org.jetbrains.plugins.scala.settings.ScalaApplicationSettings"
serviceImplementation="org.jetbrains.plugins.scala.settings.ScalaApplicationSettings"/>
<applicationService serviceInterface="org.jetbrains.plugins.scala.settings.ScalaCodeFoldingSettings"
Expand Down Expand Up @@ -437,7 +436,6 @@
<projectService serviceImplementation="org.jetbrains.plugins.scala.lang.macros.evaluator.ScalaMacroEvaluator"/>
<projectConfigurable id="Scala Compiler" displayName="Scala Compiler" parentId="project.propCompiler" dynamic="true"
instance="org.jetbrains.plugins.scala.project.settings.ScalaCompilerConfigurable" />

<quoteHandler fileType="Scala" className="org.jetbrains.plugins.scala.lang.editor.ScalaQuoteHandler"/>

<extendWordSelectionHandler implementation="org.jetbrains.plugins.scala.editor.selectioner.ScalaAttributeValueSelectioner"/>
Expand Down Expand Up @@ -1484,6 +1482,9 @@
<action id="Scala.EnableErrors" class="org.jetbrains.plugins.scala.actions.ToggleTypeAwareHighlightingAction">
<keyboard-shortcut first-keystroke="alt control shift E" keymap="$default"/>
</action>
<action id="Hydra.EnableSettings" class="org.jetbrains.plugins.scala.actions.EnableHydraSettingsAction"
text="Enable/Disable Hydra Settings" description="Enables or Disables Hydra Settings Panel">
</action>
<action id="ScalaConsole.Execute" class="org.jetbrains.plugins.scala.console.ScalaConsoleExecuteAction" text="Execute Console Statement">
<keyboard-shortcut first-keystroke="control ENTER" keymap="$default"/>
<keyboard-shortcut keymap="Mac OS X" first-keystroke="meta shift ENTER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jetbrains.plugins.scala.actions

import com.intellij.openapi.actionSystem.{AnAction, AnActionEvent, CommonDataKeys}
import com.intellij.openapi.project.Project
import org.jetbrains.plugins.scala.compiler.HydraCompilerSettings

/**
* @author Maris Alexandru
*/
class EnableHydraSettingsAction extends AnAction{
def actionPerformed(e: AnActionEvent) {
CommonDataKeys.PROJECT.getData(e.getDataContext) match {
case project: Project => {
val settings = HydraCompilerSettings.getInstance(project)
settings.isHydraSettingsEnabled = !settings.isHydraSettingsEnabled
}
case _ =>
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import org.jetbrains.plugins.scala.settings.HydraApplicationSettings
/**
* @author Maris Alexandru
*/
class HydraCompilerConfigurable (project: Project, settings: HydraCompilerSettings, hydraGlobalSettings: HydraApplicationSettings) extends AbstractConfigurable("Hydra Compiler"){
class HydraCompilerConfigurable (project: Project) extends AbstractConfigurable("Hydra Compiler"){
private val settings = HydraCompilerSettings.getInstance(project)
private val hydraGlobalSettings = HydraApplicationSettings.getInstance()
private val form = new ScalaHydraCompilerConfigurationPanel(project, settings, hydraGlobalSettings)

override def createComponent(): JPanel = form.getContentPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class HydraCompilerSettings(project: Project) extends PersistentStateComponent[H

var isHydraEnabled: Boolean = false

var isHydraSettingsEnabled: Boolean = false

var hydraVersion: String = "0.9.5"

var noOfCores: String = Math.ceil(Runtime.getRuntime.availableProcessors()/2D).toInt.toString
Expand All @@ -37,6 +39,7 @@ class HydraCompilerSettings(project: Project) extends PersistentStateComponent[H
state.hydraStorePath = hydraStorePath
state.sourcePartitioner = sourcePartitioner
state.projectRoot = ProjectRoot
state.isHydraSettingsEnabled = isHydraSettingsEnabled
state
}

Expand All @@ -46,6 +49,7 @@ class HydraCompilerSettings(project: Project) extends PersistentStateComponent[H
noOfCores = state.noOfCores
hydraStorePath = state.hydraStorePath
sourcePartitioner = state.sourcePartitioner
isHydraSettingsEnabled = state.isHydraSettingsEnabled
}

def getDefaultHydraStorePath: String = ProjectRoot + File.separator + ".hydra"
Expand Down Expand Up @@ -75,6 +79,9 @@ class HydraCompilerSettingsState {

@BeanProperty
var projectRoot: String = ""

@BeanProperty
var isHydraSettingsEnabled: Boolean = false
}

object SourcePartitioner {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.compiler.server.BuildManager
import com.intellij.openapi.project.Project
import org.jetbrains.plugins.scala.project.AbstractConfigurable

import scala.collection.JavaConverters._
import scala.util.Random

import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.Configurable.Composite
import com.intellij.openapi.util.registry.Registry
import org.jetbrains.plugins.scala.compiler.{ScalaCompileServerForm, ScalaCompileServerSettings}
import org.jetbrains.plugins.scala.compiler.{HydraCompilerConfigurable, HydraCompilerSettings, ScalaCompileServerForm, ScalaCompileServerSettings}

/**
* @author Pavel Fatin
Expand Down Expand Up @@ -42,5 +42,10 @@ class ScalaCompilerConfigurable(project: Project, configuration: ScalaCompilerCo
BuildManager.getInstance().clearState(project)
}

override def getConfigurables(): Array[Configurable] = Array()
}
override def getConfigurables(): Array[Configurable] = {
if (HydraCompilerSettings.getInstance(project).isHydraSettingsEnabled)
Array(new HydraCompilerConfigurable(project))
else
Array()
}
}

0 comments on commit ebd31d9

Please sign in to comment.