File tree Expand file tree Collapse file tree 2 files changed +26
-17
lines changed
src/main/kotlin/org/domaframework/doma/intellij Expand file tree Collapse file tree 2 files changed +26
-17
lines changed Original file line number Diff line number Diff line change 1515 */
1616package org.domaframework.doma.intellij.common.helper
1717
18+ import com.intellij.openapi.application.ApplicationManager
1819import com.intellij.openapi.project.Project
1920import com.intellij.openapi.project.ProjectManager
2021import com.intellij.openapi.wm.IdeFocusManager
@@ -27,22 +28,27 @@ object ActiveProjectHelper {
2728 }
2829
2930 fun getCurrentActiveProject (): Project ? {
30- val initProject = activeProject
31- val active = getActiveUIProject()
32- return active ? : initProject
31+ // If EDT, get from focus
32+ if (ApplicationManager .getApplication().isDispatchThread) {
33+ getActiveUIProject()?.let { return it }
34+ }
35+ // If not EDT, the top of openProjects
36+ ProjectManager
37+ .getInstance()
38+ .openProjects
39+ .firstOrNull()
40+ ?.let { return it }
41+
42+ return activeProject
3343 }
3444
3545 private fun getActiveUIProject (): Project ? {
3646 val openProjects: Array <out Project > = ProjectManager .getInstance().openProjects
37- var active: Project ? = null
38-
3947 for (project in openProjects) {
4048 if (IdeFocusManager .getInstance(project).focusOwner != null ) {
41- active = project
42- break
49+ return project
4350 }
4451 }
45-
46- return active
52+ return null
4753 }
4854}
Original file line number Diff line number Diff line change @@ -17,25 +17,28 @@ package org.domaframework.doma.intellij.setting
1717
1818import com.intellij.openapi.options.Configurable
1919import com.intellij.openapi.options.ConfigurationException
20+ import com.intellij.util.ui.UIUtil.setEnabledRecursively
2021import org.domaframework.doma.intellij.common.helper.ActiveProjectHelper
2122import org.domaframework.doma.intellij.setting.state.DomaToolsFormatEnableSettings
2223import javax.swing.JComponent
2324
2425class DomaToolsConfigurable : Configurable {
2526 private var mySettingsComponent: SettingComponent ? = SettingComponent ()
26- private val project = ActiveProjectHelper .getCurrentActiveProject()
2727
2828 private var formatSettings: DomaToolsFormatEnableSettings ? = null
2929
30- init {
31- project?.let {
32- formatSettings = DomaToolsFormatEnableSettings .getInstance(it)
33- }
34- }
35-
3630 override fun getDisplayName (): String = " Doma Tools"
3731
38- override fun createComponent (): JComponent ? = mySettingsComponent?.panel
32+ override fun createComponent (): JComponent ? {
33+ val project = ActiveProjectHelper .getCurrentActiveProject()
34+ val panel = mySettingsComponent?.panel ? : return null
35+ if (project == null ) {
36+ setEnabledRecursively(panel, false )
37+ return null
38+ }
39+ formatSettings = DomaToolsFormatEnableSettings .getInstance(project)
40+ return panel
41+ }
3942
4043 override fun isModified (): Boolean {
4144 val enableFormatModified = formatSettings?.isModified(mySettingsComponent) != false
You can’t perform that action at this time.
0 commit comments