-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Settings for Define Env Plugin Add a tool window to configure define_env for project Fix Process Env
- Loading branch information
1 parent
7e02275
commit 0fd4732
Showing
19 changed files
with
412 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kotlin.stdlib.default.dependency=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
studio-plugin/src/main/kotlin/com/flrx/define_env/EnvFileListener.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
studio-plugin/src/main/kotlin/com/flrx/define_env/OnFileChangedProcessor.kt
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
studio-plugin/src/main/kotlin/com/flrx/define_env/exceptions/DartSdkException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.flrx.define_env.exceptions | ||
|
||
class DartSdkException : Exception() |
3 changes: 3 additions & 0 deletions
3
studio-plugin/src/main/kotlin/com/flrx/define_env/exceptions/ProjectPathException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.flrx.define_env.exceptions | ||
|
||
class ProjectPathException : Exception() |
44 changes: 44 additions & 0 deletions
44
studio-plugin/src/main/kotlin/com/flrx/define_env/listeners/EnvFileListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.flrx.define_env.listeners | ||
|
||
import com.flrx.define_env.DefineEnvForProjectTask | ||
import com.flrx.define_env.utils.getProjects | ||
import com.intellij.openapi.progress.ProgressManager | ||
import com.intellij.openapi.project.ProjectManager | ||
import com.intellij.openapi.roots.ProjectFileIndex | ||
import com.intellij.openapi.vfs.AsyncFileListener | ||
import com.intellij.openapi.vfs.AsyncFileListener.ChangeApplier | ||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent | ||
|
||
class EnvFileListener : AsyncFileListener { | ||
override fun prepareChange(events: MutableList<out VFileEvent>): AsyncFileListener.ChangeApplier { | ||
val envFileEvents = events.filter { isValidEvent(it) } | ||
|
||
return object : ChangeApplier { | ||
override fun afterVfsChange() = envFileEvents | ||
.mapNotNull { it.file } | ||
.forEach { file -> | ||
file.getProjects().forEach { project -> | ||
ProgressManager.getInstance().run(DefineEnvForProjectTask(file, project)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun isValidEvent(event: VFileEvent): Boolean { | ||
val file = event.file ?: return false | ||
if (!file.exists()) return false | ||
if (!event.isFromSave && !event.isFromRefresh) return false | ||
if (!event.path.contains(".env")) return false | ||
|
||
|
||
val openProjects = ProjectManager.getInstance().openProjects | ||
|
||
val isInOpenProject = openProjects.fold(false) { prev, project -> | ||
return prev || ProjectFileIndex.getInstance(project).isInContent(file) | ||
} | ||
|
||
return isInOpenProject | ||
} | ||
} | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
studio-plugin/src/main/kotlin/com/flrx/define_env/model/DefineEnvModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.flrx.define_env.model | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.util.xmlb.annotations.XMap | ||
import io.flutter.run.SdkRunConfig | ||
import java.io.File | ||
|
||
data class DefineEnvModel( | ||
var isEnabled: Boolean?, | ||
var file: String?, | ||
var runConfiguration: RunConfigDetails? | ||
) { | ||
|
||
constructor() : this(null, null, null) | ||
|
||
constructor(project: Project, isEnabled: Boolean, file: VirtualFile, runConfiguration: SdkRunConfig) : | ||
this( | ||
isEnabled, | ||
file.path.replace(project.basePath + File.separator, ""), | ||
RunConfigDetails(runConfiguration.name, runConfiguration.type.displayName) | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
studio-plugin/src/main/kotlin/com/flrx/define_env/model/RunConfigDetails.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.flrx.define_env.model | ||
|
||
data class RunConfigDetails(var name: String? = null, var type: String? = null) { | ||
override fun toString() = name ?: super.toString() | ||
} |
24 changes: 24 additions & 0 deletions
24
studio-plugin/src/main/kotlin/com/flrx/define_env/settings/SettingsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.flrx.define_env.settings | ||
|
||
import com.intellij.openapi.components.PersistentStateComponent | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.components.State | ||
import com.intellij.openapi.components.Storage | ||
import com.intellij.openapi.project.Project | ||
|
||
@Service | ||
@State(name = "DefineEnvMap", storages = [Storage("define_env.xml")]) | ||
class SettingsService : PersistentStateComponent<SettingsState> { | ||
|
||
companion object { | ||
fun getInstance(project: Project): SettingsService = project.getService(SettingsService::class.java) | ||
} | ||
|
||
private var settingsState = SettingsState() | ||
|
||
override fun getState() = settingsState | ||
|
||
override fun loadState(state: SettingsState) { | ||
settingsState = state | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
studio-plugin/src/main/kotlin/com/flrx/define_env/settings/SettingsState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.flrx.define_env.settings | ||
|
||
import com.flrx.define_env.model.DefineEnvModel | ||
|
||
data class SettingsState(var envRunConfigs: MutableList<DefineEnvModel> = mutableListOf()) |
Oops, something went wrong.