Skip to content

Commit

Permalink
Fix #24, additional checks for non-supported projects
Browse files Browse the repository at this point in the history
  • Loading branch information
seclerp committed Dec 5, 2021
1 parent 1e6e7a8 commit 03f66f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/dotnet/Plugin.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Title>Entity Framework Core</Title>
<Description>JetBrains Rider plugin for Entity Framework Core</Description>

<Authors>seclerp</Authors>
<Copyright>Copyright $([System.DateTime]::Now.Year) seclerp</Copyright>
<Authors>Andrew Rublyov</Authors>
<Copyright>Copyright $([System.DateTime]::Now.Year) Andrew Rublyov</Copyright>
<PackageTags>resharper plugin</PackageTags>

<PackageProjectUrl></PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ abstract class BaseEfCoreDialogWrapper(

private val migrationsProjects: Array<MigrationsProjectItem>
private val startupProjects: Array<StartupProjectItem>
private val dotnetProjectName: String
private val dotnetProjectId: UUID
private val dotnetProjectName: String?
private val dotnetProjectId: UUID?

@Suppress("MemberVisibilityCanBePrivate")
protected val migrationsProjectChangedEvent: Event<MigrationsProjectItem> = Event()
Expand Down Expand Up @@ -83,10 +83,10 @@ abstract class BaseEfCoreDialogWrapper(
.toTypedArray()

val dotnetProject = migrationsProjects.find { it.displayName == actionDotnetProjectName }
?: migrationsProjects.first()
?: migrationsProjects.firstOrNull()

dotnetProjectName = dotnetProject.displayName
dotnetProjectId = dotnetProject.data.id
dotnetProjectName = dotnetProject?.displayName
dotnetProjectId = dotnetProject?.data?.id

migrationsProjectChangedEvent += ::migrationsProjectChanged
startupProjectChangedEvent += ::startupProjectChanged
Expand Down Expand Up @@ -217,6 +217,11 @@ abstract class BaseEfCoreDialogWrapper(
}

private fun loadPreferredProjects() {
if (dotnetProjectId == null || dotnetProjectName == null) {
setDefaultProjects()
return
}

val preferredProjects = CommonOptionsStateService.getInstance(intellijProject).getPreferredProjectPair(dotnetProjectId)
if (preferredProjects != null) {
val (migrationsProjectId, startupProjectId) = preferredProjects
Expand All @@ -228,11 +233,15 @@ abstract class BaseEfCoreDialogWrapper(
migrationsProjectSetter(migrationsProject)
startupProjectSetter(startupProject)
} else {
migrationsProjectSetter(migrationsProjects.find { it.displayName == dotnetProjectName } ?: migrationsProjects.firstOrNull())
startupProjectSetter(startupProjects.find { it.displayName == dotnetProjectName } ?: startupProjects.firstOrNull())
setDefaultProjects()
}
}

private fun setDefaultProjects() {
migrationsProjectSetter(migrationsProjects.find { it.displayName == dotnetProjectName } ?: migrationsProjects.firstOrNull())
startupProjectSetter(startupProjects.find { it.displayName == dotnetProjectName } ?: startupProjects.firstOrNull())
}

private fun migrationsProjectValidation(): ValidationInfoBuilder.(ComboBox<MigrationsProjectItem>) -> ValidationInfo? = {
if (migrationsProject == null)
error("You should selected valid migrations project")
Expand Down
2 changes: 1 addition & 1 deletion src/rider/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<id>me.seclerp.rider.plugins.efcore</id>
<name>Entity Framework Core UI</name>
<version>1.0.0</version>
<vendor url="https://github.com/seclerp">seclerp</vendor>
<vendor url="https://github.com/seclerp">Andrew Rublyov</vendor>
<idea-version since-build="2021.2" />
<depends>com.intellij.modules.rider</depends>

Expand Down

0 comments on commit 03f66f8

Please sign in to comment.