Skip to content

Commit fa9b79d

Browse files
authored
accept starting location (#64)
* accept starting location * 1.0.20
1 parent ae0dffb commit fa9b79d

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Module Maker Changelog
22

3+
## [1.0.20]
4+
- Accept starting file location when starting Module Maker
5+
36
## [1.0.19]
47
- Dependency updates
58

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ tasks {
133133
// The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
134134
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
135135
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
136-
channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) }
136+
// channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) }
137137
}
138138
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = com.joetr.modulemaker
44
pluginName = ModuleMaker
55
pluginRepositoryUrl = https://github.com/j-roskopf/ModuleMakerPlugin
66
# SemVer format -> https://semver.org
7-
pluginVersion = 1.0.19
7+
pluginVersion = 1.0.20
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 222

src/main/kotlin/com/joetr/modulemaker/ModuleMakerAction.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import com.intellij.openapi.actionSystem.AnAction
44
import com.intellij.openapi.actionSystem.AnActionEvent
55
import com.intellij.openapi.actionSystem.CommonDataKeys
66
import com.intellij.openapi.project.Project
7+
import com.intellij.openapi.vfs.VirtualFile
78

89
class ModuleMakerAction : AnAction() {
910
override fun actionPerformed(event: AnActionEvent) {
1011
val project: Project = event.getRequiredData(CommonDataKeys.PROJECT)
1112

13+
val startingLocation: VirtualFile? = event.getData(CommonDataKeys.VIRTUAL_FILE)
14+
15+
// we only want to use a starting location if it's coming from a directory
16+
val shouldUseStartingLocation = startingLocation != null && startingLocation.isDirectory
17+
1218
ModuleMakerDialogWrapper(
13-
project = project
19+
project = project,
20+
startingLocation = if (shouldUseStartingLocation) startingLocation else null
1421
).show()
1522
}
1623
}

src/main/kotlin/com/joetr/modulemaker/ModuleMakerDialogWrapper.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemUtil
3333
import com.intellij.openapi.project.Project
3434
import com.intellij.openapi.ui.DialogWrapper
3535
import com.intellij.openapi.vfs.VfsUtil
36+
import com.intellij.openapi.vfs.VirtualFile
3637
import com.joetr.modulemaker.data.analytics.ModuleCreationAnalytics
3738
import com.joetr.modulemaker.data.analytics.ModuleCreationErrorAnalytics
3839
import com.joetr.modulemaker.data.toProjectFile
@@ -62,7 +63,8 @@ private const val DEFAULT_MODULE_NAME = ":repository:database (as an example)"
6263
private const val DEFAULT_SRC_VALUE = "EMPTY"
6364

6465
class ModuleMakerDialogWrapper(
65-
private val project: Project
66+
private val project: Project,
67+
private val startingLocation: VirtualFile?
6668
) : DialogWrapper(true) {
6769

6870
private val preferenceService = PreferenceServiceImpl.instance
@@ -91,9 +93,16 @@ class ModuleMakerDialogWrapper(
9193
init {
9294
title = "Module Maker"
9395
init()
94-
// give default value of just the root project
95-
selectedSrcValue.value = File(rootDirectoryString()).absolutePath.removePrefix(rootDirectoryStringDropLast())
96-
.removePrefix(File.separator)
96+
97+
selectedSrcValue.value = if (startingLocation != null) {
98+
// give default of starting location
99+
File(startingLocation.path).absolutePath.removePrefix(rootDirectoryStringDropLast())
100+
.removePrefix(File.separator)
101+
} else {
102+
// give default value of the root project
103+
File(rootDirectoryString()).absolutePath.removePrefix(rootDirectoryStringDropLast())
104+
.removePrefix(File.separator)
105+
}
97106
}
98107

99108
@Nullable

0 commit comments

Comments
 (0)