2
0
Эх сурвалжийг харах

disable xmake for non-xmake project

ruki 2 өдөр өмнө
parent
commit
e02509d31b

+ 1 - 1
src/main/kotlin/io/xmake/actions/BuildAction.kt

@@ -35,7 +35,7 @@ import io.xmake.utils.exception.XMakeRunConfigurationNotSetException
 import com.intellij.openapi.fileEditor.FileDocumentManager
 import io.xmake.project.xmakeSettings
 
-class BuildAction : AnAction() {
+class BuildAction : XMakeBaseAction() {
 
     override fun actionPerformed(e: AnActionEvent) {
 

+ 1 - 1
src/main/kotlin/io/xmake/actions/CleanAction.kt

@@ -32,7 +32,7 @@ import io.xmake.shared.xmakeConfiguration
 import io.xmake.utils.SystemUtils
 import io.xmake.utils.exception.XMakeRunConfigurationNotSetException
 
-class CleanAction : AnAction() {
+class CleanAction : XMakeBaseAction() {
 
     override fun actionPerformed(e: AnActionEvent) {
 

+ 1 - 1
src/main/kotlin/io/xmake/actions/CleanConfigurationAction.kt

@@ -30,7 +30,7 @@ import io.xmake.shared.xmakeConfiguration
 import io.xmake.utils.SystemUtils
 import io.xmake.utils.exception.XMakeRunConfigurationNotSetException
 
-class CleanConfigurationAction : AnAction() {
+class CleanConfigurationAction : XMakeBaseAction() {
 
     override fun actionPerformed(e: AnActionEvent) {
 

+ 1 - 1
src/main/kotlin/io/xmake/actions/QuickStartAction.kt

@@ -30,7 +30,7 @@ import io.xmake.shared.xmakeConfiguration
 import io.xmake.utils.SystemUtils
 import io.xmake.utils.exception.XMakeRunConfigurationNotSetException
 
-class QuickStartAction : AnAction() {
+class QuickStartAction : XMakeBaseAction() {
 
     override fun actionPerformed(e: AnActionEvent) {
 

+ 1 - 1
src/main/kotlin/io/xmake/actions/RebuildAction.kt

@@ -33,7 +33,7 @@ import io.xmake.shared.xmakeConfiguration
 import io.xmake.utils.SystemUtils
 import io.xmake.utils.exception.XMakeRunConfigurationNotSetException
 
-class RebuildAction : AnAction() {
+class RebuildAction : XMakeBaseAction() {
 
     override fun actionPerformed(e: AnActionEvent) {
 

+ 1 - 1
src/main/kotlin/io/xmake/actions/RunAction.kt

@@ -33,7 +33,7 @@ import io.xmake.utils.SystemUtils
 import io.xmake.utils.exception.XMakeRunConfigurationNotSetException
 import com.intellij.openapi.fileEditor.FileDocumentManager
 
-class RunAction : AnAction() {
+class RunAction : XMakeBaseAction() {
 
     override fun actionPerformed(e: AnActionEvent) {
 

+ 1 - 1
src/main/kotlin/io/xmake/actions/UpdateCmakeListsAction.kt

@@ -35,7 +35,7 @@ import io.xmake.utils.exception.XMakeRunConfigurationNotSetException
 import io.xmake.utils.execute.fetchGeneratedFile
 import io.xmake.utils.execute.syncBeforeFetch
 
-class UpdateCmakeListsAction : AnAction() {
+class UpdateCmakeListsAction : XMakeBaseAction() {
     override fun actionPerformed(e: AnActionEvent) {
         // the project
         val project = e.project ?: return

+ 1 - 1
src/main/kotlin/io/xmake/actions/UpdateCompileCommandsAction.kt

@@ -39,7 +39,7 @@ import io.xmake.utils.exception.XMakeRunConfigurationNotSetException
 import io.xmake.utils.execute.fetchGeneratedFile
 import io.xmake.utils.execute.syncBeforeFetch
 
-class UpdateCompileCommandsAction : AnAction() {
+class UpdateCompileCommandsAction : XMakeBaseAction() {
     override fun actionPerformed(e: AnActionEvent) {
         // the project
         val project = e.project ?: return

+ 20 - 0
src/main/kotlin/io/xmake/actions/XMakeBaseAction.kt

@@ -0,0 +1,20 @@
+package io.xmake.actions
+
+import com.intellij.openapi.actionSystem.AnAction
+import com.intellij.openapi.actionSystem.AnActionEvent
+import io.xmake.utils.SystemUtils
+
+abstract class XMakeBaseAction : AnAction() {
+
+    override fun update(e: AnActionEvent) {
+        val project = e.project
+        val presentation = e.presentation
+        
+        if (project == null) {
+            presentation.isEnabledAndVisible = false
+            return
+        }
+        
+        presentation.isEnabledAndVisible = SystemUtils.isXMakeProject(project)
+    }
+}

+ 19 - 0
src/main/kotlin/io/xmake/actions/XMakeMenuGroup.kt

@@ -0,0 +1,19 @@
+package io.xmake.actions
+
+import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.openapi.actionSystem.DefaultActionGroup
+import io.xmake.utils.SystemUtils
+
+class XMakeMenuGroup : DefaultActionGroup() {
+    override fun update(e: AnActionEvent) {
+        val project = e.project
+        val presentation = e.presentation
+        
+        if (project == null) {
+            presentation.isEnabledAndVisible = false
+            return
+        }
+        
+        presentation.isEnabledAndVisible = SystemUtils.isXMakeProject(project)
+    }
+}

+ 0 - 5
src/main/kotlin/io/xmake/project/XMakeModuleConfigurationEditorProvider.kt

@@ -20,7 +20,6 @@
  */
 package io.xmake.project
 
-import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.module.ModuleConfigurationEditor
 //import com.intellij.openapi.roots.ui.configuration.DefaultModuleConfigurationEditorFactory
 import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationEditorProvider
@@ -39,8 +38,4 @@ class XMakeModuleConfigurationEditorProvider : ModuleConfigurationEditorProvider
         */
         return editors
     }
-
-    companion object {
-        private val Log = Logger.getInstance(XMakeModuleConfigurationEditorProvider::class.java.getName())
-    }
 }

+ 6 - 0
src/main/kotlin/io/xmake/project/XMakeToolWindowFactory.kt

@@ -27,8 +27,14 @@ import com.intellij.openapi.wm.ToolWindowFactory
 import com.intellij.openapi.wm.ToolWindowManager
 import com.intellij.ui.content.ContentFactory
 import io.xmake.shared.XMakeProblem
+import io.xmake.utils.SystemUtils
 
 class XMakeToolWindowFactory : ToolWindowFactory {
+
+    override fun isApplicable(project: Project): Boolean {
+        return SystemUtils.isXMakeProject(project)
+    }
+
     override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
 
         // add output tab/panel

+ 0 - 5
src/main/kotlin/io/xmake/project/XMakeToolWindowOutputPanel.kt

@@ -26,7 +26,6 @@ import com.intellij.openapi.Disposable
 import com.intellij.openapi.actionSystem.ActionManager
 import com.intellij.openapi.actionSystem.ActionToolbar
 import com.intellij.openapi.actionSystem.DefaultActionGroup
-import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.ui.SimpleToolWindowPanel
 import com.intellij.openapi.util.Disposer
@@ -74,8 +73,4 @@ class XMakeToolWindowOutputPanel(// the project
         val contentManager = project.xmakeToolWindow?.contentManager
         contentManager?.setSelectedContent(contentManager.getContent(0)!!)
     }
-
-    companion object {
-        private val Log = Logger.getInstance(XMakeToolWindowOutputPanel::class.java.getName())
-    }
 }

+ 0 - 5
src/main/kotlin/io/xmake/project/XMakeToolWindowProblemPanel.kt

@@ -24,7 +24,6 @@ import com.intellij.execution.RunManager
 import com.intellij.openapi.actionSystem.ActionManager
 import com.intellij.openapi.actionSystem.ActionToolbar
 import com.intellij.openapi.actionSystem.DefaultActionGroup
-import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.editor.markup.EffectType
 import com.intellij.openapi.editor.markup.TextAttributes
 import com.intellij.openapi.fileEditor.FileEditorManager
@@ -186,8 +185,4 @@ class XMakeToolWindowProblemPanel(project: Project) : SimpleToolWindowPanel(fals
             }
         })
     }
-
-    companion object {
-        private val Log = Logger.getInstance(XMakeToolWindowProblemPanel::class.java.getName())
-    }
 }

+ 0 - 2
src/main/kotlin/io/xmake/run/XMakeRunConfiguration.kt

@@ -29,7 +29,6 @@ import com.intellij.execution.process.ProcessHandler
 import com.intellij.execution.process.ProcessEvent
 import com.intellij.execution.process.ProcessListener
 import com.intellij.execution.runners.ExecutionEnvironment
-import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.options.SettingsEditor
 import com.intellij.openapi.project.Project
 import com.intellij.util.execution.ParametersListUtil
@@ -239,7 +238,6 @@ class XMakeRunConfiguration(
     }
 
     companion object {
-        private val Log = Logger.getInstance(XMakeRunConfiguration::class.java.getName())
         
         fun getDefaultLaunchConfigJson(): String {
             return """{

+ 6 - 7
src/main/kotlin/io/xmake/run/XMakeRunConfigurationProducer.kt

@@ -23,9 +23,9 @@ package io.xmake.run
 import com.intellij.execution.actions.ConfigurationContext
 import com.intellij.execution.actions.LazyRunConfigurationProducer
 import com.intellij.execution.configurations.ConfigurationFactory
-import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.util.Ref
 import com.intellij.psi.PsiElement
+import io.xmake.utils.SystemUtils
 
 class XMakeRunConfigurationProducer : LazyRunConfigurationProducer<XMakeRunConfiguration>() {
     override fun getConfigurationFactory(): ConfigurationFactory {
@@ -46,12 +46,11 @@ class XMakeRunConfigurationProducer : LazyRunConfigurationProducer<XMakeRunConfi
             sourceElement: Ref<PsiElement>
     ): Boolean {
 
-        return true
-    }
+        // check xmake project
+        if (!SystemUtils.isXMakeProject(context.project)) {
+            return false
+        }
 
-    companion object {
-
-        // get log
-        private val Log = Logger.getInstance(XMakeRunConfigurationProducer::class.java.getName())
+        return true
     }
 }

+ 0 - 4
src/main/kotlin/io/xmake/run/XMakeRunConfigurationType.kt

@@ -25,7 +25,6 @@ import com.intellij.execution.configurations.ConfigurationFactory
 import com.intellij.execution.configurations.ConfigurationTypeBase
 import com.intellij.execution.configurations.ConfigurationTypeUtil
 import com.intellij.execution.configurations.RunConfiguration
-import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.util.Key
 import io.xmake.icons.XMakeIcons
@@ -65,8 +64,5 @@ class XMakeRunConfigurationType : ConfigurationTypeBase(
     companion object {
         fun getInstance(): XMakeRunConfigurationType =
             ConfigurationTypeUtil.findConfigurationType(XMakeRunConfigurationType::class.java)
-
-        // get log
-        private val Log = Logger.getInstance(XMakeRunConfigurationType::class.java.getName())
     }
 }

+ 0 - 6
src/main/kotlin/io/xmake/shared/XMakeConfiguration.kt

@@ -24,7 +24,6 @@ import com.intellij.execution.RunManager
 import com.intellij.execution.configuration.EnvironmentVariablesData
 import com.intellij.execution.configurations.GeneralCommandLine
 import com.intellij.openapi.components.Service
-import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.project.Project
 import com.intellij.util.execution.ParametersListUtil
 import io.xmake.project.toolkit.activatedToolkit
@@ -195,11 +194,6 @@ class XMakeConfiguration(val project: Project) {
                 configuration.runArchitecture = architectures[0]
             }
         }*/
-
-    companion object {
-        // get log
-        private val Log = Logger.getInstance(XMakeConfiguration::class.java.getName())
-    }
 }
 
 val Project.xmakeConfiguration: XMakeConfiguration

+ 8 - 0
src/main/kotlin/io/xmake/utils/SystemUtils.kt

@@ -253,6 +253,14 @@ object SystemUtils {
             false
         }
     }
+
+    /**
+     * Check if the project is a XMake project (has xmake.lua in root)
+     */
+    fun isXMakeProject(project: Project): Boolean {
+        val basePath = project.basePath ?: return false
+        return File(basePath, "xmake.lua").exists()
+    }
 }
 
 val VirtualFile.pathAsPath: Path get() = Paths.get(path)

+ 2 - 2
src/main/resources/META-INF/plugin.xml

@@ -15,7 +15,7 @@
     <depends>com.intellij.modules.xml</depends>
     <depends>com.intellij.modules.xdebugger</depends>
 
-    <depends optional="true" config-file="io.xmake-native-debug.xml">com.intellij.modules.nativeDebug</depends>
+    <depends optional="true">com.intellij.modules.nativeDebug</depends>
 
     <depends optional="true" config-file="io.xmake-ssh.xml">
         com.intellij.modules.ssh
@@ -74,7 +74,7 @@
          https://github.com/centic9/IntelliJ-Action-IDs
     -->
     <actions>
-        <group id="XMake.Menu" text="Xmake" popup="true" description="XMake menu">
+        <group id="XMake.Menu" class="io.xmake.actions.XMakeMenuGroup" text="Xmake" popup="true" description="XMake menu">
             <add-to-group group-id="MainMenu"
                           anchor="after"
                           relative-to-action="RunMenu"/>