|
| 1 | +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package software.aws.toolkits.jetbrains.services.cwc.inline |
| 5 | + |
| 6 | +import com.intellij.openapi.actionSystem.ActionPromoter |
| 7 | +import com.intellij.openapi.actionSystem.AnAction |
| 8 | +import com.intellij.openapi.actionSystem.CommonDataKeys |
| 9 | +import com.intellij.openapi.actionSystem.DataContext |
| 10 | +import com.intellij.openapi.keymap.KeymapUtil |
| 11 | +import com.intellij.openapi.util.SystemInfo |
| 12 | + |
| 13 | +class InlineChatActionPromoter : ActionPromoter { |
| 14 | + // temporary until we find a better key binding |
| 15 | + override fun promote(actions: MutableList<out AnAction>, context: DataContext): MutableList<AnAction> { |
| 16 | + val results = actions.toMutableList() |
| 17 | + if (context.getData(CommonDataKeys.EDITOR) == null || |
| 18 | + context.getData(CommonDataKeys.PROJECT) == null |
| 19 | + ) { |
| 20 | + return results |
| 21 | + } |
| 22 | + val shortCut = KeymapUtil.getShortcutText("aws.toolkit.jetbrains.core.services.cwc.inline.openChat") |
| 23 | + // only promote for the default key bindings |
| 24 | + if (SystemInfo.isMac && shortCut != "⌘I") return results |
| 25 | + if (!SystemInfo.isMac && shortCut != "Ctrl+I") return results |
| 26 | + |
| 27 | + results.sortWith { a, b -> |
| 28 | + when { |
| 29 | + isOpenChatInputAction(a) -> -1 |
| 30 | + isOpenChatInputAction(b) -> 1 |
| 31 | + else -> 0 |
| 32 | + } |
| 33 | + } |
| 34 | + return results |
| 35 | + } |
| 36 | + |
| 37 | + private fun isOpenChatInputAction(action: AnAction): Boolean = |
| 38 | + action is OpenChatInputAction |
| 39 | +} |
0 commit comments