From d15d074bc9e7271307aba878cd0397a9f343e4ef Mon Sep 17 00:00:00 2001 From: "Arkady.Bazhanov" Date: Tue, 26 Mar 2024 16:33:25 +0100 Subject: [PATCH] KTNB-628 Add "Create Gist" action to the toolbar of Kotlin Notebooks GitOrigin-RevId: eedc263675c19eaf7f7dc8c98d14a9c9bf3395fb --- .../resources/META-INF/github-core-config.xml | 1 + .../GithubCreateGistAlwaysEnabledAction.kt | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 plugins/github/src/org/jetbrains/plugins/github/GithubCreateGistAlwaysEnabledAction.kt diff --git a/plugins/github/resources/META-INF/github-core-config.xml b/plugins/github/resources/META-INF/github-core-config.xml index 450ff5ac88ca..34e7f27c663b 100644 --- a/plugins/github/resources/META-INF/github-core-config.xml +++ b/plugins/github/resources/META-INF/github-core-config.xml @@ -111,6 +111,7 @@ + diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubCreateGistAlwaysEnabledAction.kt b/plugins/github/src/org/jetbrains/plugins/github/GithubCreateGistAlwaysEnabledAction.kt new file mode 100644 index 000000000000..57f3647084cd --- /dev/null +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubCreateGistAlwaysEnabledAction.kt @@ -0,0 +1,24 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.github + +import com.intellij.openapi.actionSystem.ActionPlaces +import com.intellij.openapi.actionSystem.AnActionEvent + +/** + * A wrapper around [GithubCreateGistAction]. + * This action can be used in toolbars and context menus, and it won't be disabled or hidden when the user + * does not have a GitHub account connected. If this behavior is desired, use this action. Otherwise, use + * [GithubCreateGistAction]. + * + * This action won't show up in search, otherwise it would be possible to have both this action and + * [GithubCreateGistAction] in the search results. + */ +class GithubCreateGistAlwaysEnabledAction : GithubCreateGistAction() { + override fun update(e: AnActionEvent) { + // We're intentionally not calling super.update(e), as it would check for a connected GitHub account, + // and we don't want that. + + /** We're hiding this action from search so that we won't show it alongside [GithubCreateGistAction] */ + e.presentation.isEnabledAndVisible = !ActionPlaces.isMainMenuOrActionSearch(e.place) + } +}