diff --git a/protocol/src/main/kotlin/model/rider/ProtocolModel.kt b/protocol/src/main/kotlin/model/rider/ProtocolModel.kt index 62be65e..571f76a 100644 --- a/protocol/src/main/kotlin/model/rider/ProtocolModel.kt +++ b/protocol/src/main/kotlin/model/rider/ProtocolModel.kt @@ -4,8 +4,12 @@ import com.jetbrains.rd.generator.nova.* import com.jetbrains.rider.model.nova.ide.SolutionModel object ProtocolModel : Ext(SolutionModel.Solution) { + private val CliToolDefinition = structdef { + field("installed", PredefinedType.bool) + field("version", PredefinedType.string.nullable) + } + init { - property("cliVersion", PredefinedType.string) - call("getCliVersion", PredefinedType.void, PredefinedType.string) + call("getCliDefinition", PredefinedType.void, CliToolDefinition) } } \ No newline at end of file diff --git a/src/dotnet/ReSharperPlugin.ODataCliUi/PluginHost.cs b/src/dotnet/ReSharperPlugin.ODataCliUi/PluginHost.cs index b7f767f..574883d 100644 --- a/src/dotnet/ReSharperPlugin.ODataCliUi/PluginHost.cs +++ b/src/dotnet/ReSharperPlugin.ODataCliUi/PluginHost.cs @@ -13,38 +13,39 @@ namespace ReSharperPlugin.ODataCliUi; [SolutionComponent] public sealed class PluginHost : IDisposable { - private readonly ProtocolModel _protocolModel; private readonly Tracker _tracker; + + private CliToolDefinition _cliToolDefinition; public PluginHost(ISolution solution, Tracker tracker) { - _protocolModel = solution.GetProtocolSolution().GetProtocolModel(); - _protocolModel.GetCliVersion.SetSync(GetCliVersion); + var protocolModel = solution.GetProtocolSolution().GetProtocolModel(); + protocolModel.GetCliDefinition.SetSync(GetCliDefinition); _tracker = tracker; tracker.DotNetToolCacheChanged += OnDotNetToolCacheChanged; tracker.Start(); } - private string GetCliVersion(Lifetime lifetime, Unit unit) => _protocolModel.CliVersion.Value; + private CliToolDefinition GetCliDefinition(Lifetime lifetime, Unit unit) => _cliToolDefinition; private void OnDotNetToolCacheChanged(DotNetToolCache cache) { var localTool = cache.ToolLocalCache.GetAllLocalTools().FirstOrDefault(t => t.PackageId == Constants.ODataCliPackageId); if (localTool is not null) { - _protocolModel.CliVersion.Value = $"Local, {localTool.Version}"; + _cliToolDefinition = new CliToolDefinition(true, $"Local, {localTool.Version}"); return; } var tool = cache.ToolGlobalCache.GetGlobalTool(Constants.ODataCliPackageId)?.FirstOrDefault(); if (tool is not null) { - _protocolModel.CliVersion.Value = $"Global, {tool.Version}"; + _cliToolDefinition = new CliToolDefinition(true, $"Global, {tool.Version}"); return; } - _protocolModel.CliVersion.Value = "Not installed"; + _cliToolDefinition = new CliToolDefinition(false, null); } public void Dispose() diff --git a/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/actions/OpenCliDialogAction.kt b/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/actions/OpenCliDialogAction.kt index b98efe0..8f8486d 100644 --- a/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/actions/OpenCliDialogAction.kt +++ b/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/actions/OpenCliDialogAction.kt @@ -18,11 +18,15 @@ import com.jetbrains.rider.projectView.workspace.isProject import com.jetbrains.rider.projectView.workspace.isWebReferenceFolder class OpenCliDialogAction : AnAction() { - override fun actionPerformed(e: AnActionEvent) { - val project = e.project ?: return - val actionMetadata = e.toMetadata() ?: return + override fun actionPerformed(event: AnActionEvent) { + val project = event.project ?: return + val actionMetadata = event.toMetadata() ?: return val dialogModel = CliDialogModel(project, actionMetadata) + + // launchOnUi is available since 233.11799.241 + // RD-2023.3 has build number 233.11799.261 + @Suppress("MissingRecentApi") project.lifetime.launchOnUi { val dialog = CliDialog(dialogModel) if (dialog.showAndGet()) { @@ -35,14 +39,14 @@ class OpenCliDialogAction : AnAction() { override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT - override fun update(e: AnActionEvent) { - val entity = e.entityForAction + override fun update(event: AnActionEvent) { + val entity = event.entityForAction if (entity == null) { - e.presentation.isVisible = false + event.presentation.isVisible = false return } - e.presentation.isEnabled = e.project?.isProjectModelReady() ?: false - e.presentation.isVisible = entity.isWebReferenceFolder() || entity.isProject() + event.presentation.isEnabled = event.project?.isProjectModelReady() ?: false + event.presentation.isVisible = entity.isWebReferenceFolder() || entity.isProject() } private suspend fun executeCommand(project: Project, model: CliDialogModel) diff --git a/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/dialogs/CliDialog.kt b/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/dialogs/CliDialog.kt index 6432092..30ecb9b 100644 --- a/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/dialogs/CliDialog.kt +++ b/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/dialogs/CliDialog.kt @@ -11,13 +11,26 @@ import com.jetbrains.rider.plugins.odatacliui.extensions.emptyText import com.jetbrains.rider.plugins.odatacliui.models.CliDialogModel import javax.swing.JComponent -@Suppress("UnstableApiUsage") class CliDialog(private val model: CliDialogModel) : DialogWrapper(false) { init { title = Constants.PLUGIN_NAME + setOKActionEnabled(true) init() } + override fun setOKActionEnabled(isEnabled: Boolean) { + if (!model.cliDefinition.installed) { + setOKButtonTooltip(UiBundle.text("cli.ok-action-button.tooltip.not-installed")) + super.setOKActionEnabled(false) + return + } + else { + setOKButtonTooltip(null) + } + + super.setOKActionEnabled(isEnabled) + } + override fun createCenterPanel(): JComponent { val tabbedPane = JBTabbedPane() val generationTab = buildGenerationArgumentsTab() @@ -27,7 +40,7 @@ class CliDialog(private val model: CliDialogModel) : DialogWrapper(false) { return panel { row { - label(model.cliVersion) + label(model.cliDefinition.version ?: UiBundle.text("cli.cli-version.label-value.not-installed")) .label(UiBundle.text("cli.cli-version.label")) .comment(UiBundle.text("cli.cli-version.comment")) }.bottomGap(BottomGap.SMALL) @@ -49,9 +62,6 @@ class CliDialog(private val model: CliDialogModel) : DialogWrapper(false) { row { cell(tabbedPane) }.resizableRow() - }.apply { - registerIntegratedPanel(generationTab) - registerIntegratedPanel(requestTab) } } diff --git a/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/extensions/AnActionEventEx.kt b/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/extensions/AnActionEventEx.kt index ea4ad02..db7ad8a 100644 --- a/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/extensions/AnActionEventEx.kt +++ b/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/extensions/AnActionEventEx.kt @@ -30,7 +30,7 @@ fun AnActionEvent.toMetadata(): ActionMetadata? { descriptor = entity.parentEntity!!.descriptor as RdProjectDescriptor } else { - throw IllegalStateException() + throw IllegalStateException("Selected item not supported") } val projectPath = (descriptor.location as RdCustomLocation).customLocation diff --git a/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/models/CliDialogModel.kt b/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/models/CliDialogModel.kt index 5fdcebc..8a8ad54 100644 --- a/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/models/CliDialogModel.kt +++ b/src/rider/main/kotlin/com/jetbrains/rider/plugins/odatacliui/models/CliDialogModel.kt @@ -1,6 +1,7 @@ package com.jetbrains.rider.plugins.odatacliui.models import com.intellij.openapi.project.Project +import com.jetbrains.rd.ide.model.CliToolDefinition import com.jetbrains.rd.ide.model.protocolModel import com.jetbrains.rider.plugins.odatacliui.Constants import com.jetbrains.rider.plugins.odatacliui.extensions.dotnetAddPackageCommand @@ -15,10 +16,10 @@ private const val CONNECTED_SERVICES = "Connected Services" class CliDialogModel(project: Project, private val actionMetadata: ActionMetadata) { val validator = CliDialogModelValidator() - val cliVersion: String + val cliDefinition: CliToolDefinition init { - cliVersion = getCliVersion(project) + cliDefinition = project.solution.protocolModel.getCliDefinition.sync(Unit) } val serviceName = MutableProperty("") @@ -37,11 +38,6 @@ class CliDialogModel(project: Project, private val actionMetadata: ActionMetadat val customHeaders = MutableProperty("") val proxy = MutableProperty("") - private fun getCliVersion(project: Project): String { - return project.solution.protocolModel.cliVersion.valueOrNull - ?: project.solution.protocolModel.getCliVersion.sync(Unit) - } - private fun getOutputDirectory(): String = Path(Path(actionMetadata.projectPath).parent.toString(), CONNECTED_SERVICES, serviceName.get()).toString() fun buildCommand(): BatchCommandLine = BatchCommandLineBuilder() diff --git a/src/rider/main/resources/UiBundle.properties b/src/rider/main/resources/UiBundle.properties index c48f455..c0df795 100644 --- a/src/rider/main/resources/UiBundle.properties +++ b/src/rider/main/resources/UiBundle.properties @@ -5,6 +5,7 @@ action.odatacliui.OpenCliDialogAction.text=OData Reference\u2026 cli.tab.generation=Generation Arguments cli.tab.request=Generation Arguments cli.cli-version.label=OData CLI Version: +cli.cli-version.label-value.not-installed=Not installed cli.cli-version.comment=Not installed? Follow instruction cli.service-name.row=Service name: cli.metadata-source.row=Metadata source: @@ -26,3 +27,4 @@ cli.custom-headers.empty-text=Example: Header1:HeaderValue, Header2:HeaderValue cli.custom-headers.comment=Headers that will get sent along with the request when fetching the metadata document from the service cli.proxy.empty-text=Example: domain\\user:password@SERVER:PORT cli.proxy.comment=Proxy settings +cli.ok-action-button.tooltip.not-installed=OData CLI not installed