diff --git a/build.gradle.kts b/build.gradle.kts index 6458f9b7..f9738880 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -29,7 +29,7 @@ repositories { // Configure Gradle IntelliJ Plugin // Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html intellij { - version.set("2022.2.5") + version.set("2022.2.1") type.set("PC") // Target IDE Platform plugins.set(listOf("Git4Idea")) diff --git a/src/main/kotlin/com/smallcloud/refactai/Resources.kt b/src/main/kotlin/com/smallcloud/refactai/Resources.kt index ff4cfd11..89051bc1 100644 --- a/src/main/kotlin/com/smallcloud/refactai/Resources.kt +++ b/src/main/kotlin/com/smallcloud/refactai/Resources.kt @@ -6,11 +6,11 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.util.IconLoader import com.intellij.openapi.util.Key -//import com.intellij.ui.NewUI import com.intellij.util.IconUtil -import com.intellij.util.ui.StartupUiUtil import java.net.URI import javax.swing.Icon +import javax.swing.UIManager + fun getThisPlugin() = PluginManager.getPlugins().find { it.name == "Refact.ai" } private fun getVersion(): String { @@ -30,7 +30,7 @@ private fun getPluginId(): PluginId { } object Resources { -// val isNewUI: Boolean by lazy { NewUI.isEnabled() } + // val isNewUI: Boolean by lazy { NewUI.isEnabled() } const val defaultCloudAuthLink: String = "https://refact.smallcloud.ai/authentication?token=%s&utm_source=plugin&utm_medium=jetbrains&utm_campaign=login" val defaultCloudUrl: URI = URI("https://www.smallcloud.ai") val defaultContrastUrlSuffix = URI("v1/contrast") @@ -54,24 +54,29 @@ object Resources { val pluginId: PluginId = getPluginId() const val stagingFilterPrefix: String = "STAGING" val jbBuildVersion: String = ApplicationInfo.getInstance().build.toString() + const val refactAIRootSettingsID = "refactai_root" object Icons { private fun brushForTheme(icon: Icon): Icon { - return if (StartupUiUtil.isUnderDarcula()) { + return if (UIManager.getLookAndFeel().name.contains("Darcula")) { IconUtil.brighter(icon, 3) } else { IconUtil.darker(icon, 3) } } + fun resizeSquaredIcon(icon: Icon, width: Int): Icon { return IconUtil.resizeSquared(icon, width) } + private fun makeIcon12(path: String): Icon { return brushForTheme(resizeSquaredIcon(IconLoader.getIcon(path, Resources::class.java), 12)) } + private fun makeIcon16(path: String): Icon { return brushForTheme(resizeSquaredIcon(IconLoader.getIcon(path, Resources::class.java), 16)) } + private fun makeIcon24(path: String): Icon { return brushForTheme(resizeSquaredIcon(IconLoader.getIcon(path, Resources::class.java), 24)) } diff --git a/src/main/kotlin/com/smallcloud/refactai/aitoolbox/LongthinkAction.kt b/src/main/kotlin/com/smallcloud/refactai/aitoolbox/LongthinkAction.kt index 472c761b..4782017b 100644 --- a/src/main/kotlin/com/smallcloud/refactai/aitoolbox/LongthinkAction.kt +++ b/src/main/kotlin/com/smallcloud/refactai/aitoolbox/LongthinkAction.kt @@ -14,7 +14,7 @@ val LongthinkKey = Key.create("refact.longthink") class LongthinkAction: DumbAwareAction() { override fun actionPerformed(e: AnActionEvent) { - val longthink = (e.inputEvent.component as JComponent).getUserData(LongthinkKey) + val longthink = (e.inputEvent?.component as JComponent).getUserData(LongthinkKey) if (longthink?.entryName?.isNotEmpty() == true) { doActionPerformed(longthink.functions.first()) } diff --git a/src/main/kotlin/com/smallcloud/refactai/aitoolbox/ToolboxPane.kt b/src/main/kotlin/com/smallcloud/refactai/aitoolbox/ToolboxPane.kt index 3f36c902..043fb496 100644 --- a/src/main/kotlin/com/smallcloud/refactai/aitoolbox/ToolboxPane.kt +++ b/src/main/kotlin/com/smallcloud/refactai/aitoolbox/ToolboxPane.kt @@ -23,6 +23,7 @@ import com.intellij.util.ui.JBUI import com.intellij.util.ui.UIUtil.getLabelForeground import com.smallcloud.refactai.RefactAIBundle import com.smallcloud.refactai.Resources +import com.smallcloud.refactai.Resources.refactAIRootSettingsID import com.smallcloud.refactai.account.AccountManagerChangedNotifier import com.smallcloud.refactai.aitoolbox.table.LongthinkTable import com.smallcloud.refactai.aitoolbox.table.LongthinkTableModel @@ -437,8 +438,8 @@ class ToolboxPane(parent: Disposable) { override fun mouseEntered(e: MouseEvent?) {} override fun mouseExited(e: MouseEvent?) {} override fun mouseReleased(e: MouseEvent?) { - ShowSettingsUtilImpl.getInstance().showSettingsDialog(getLastUsedProject(), - AppRootConfigurable::class.java) + ShowSettingsUtilImpl.showSettingsDialog(getLastUsedProject(), + refactAIRootSettingsID, null) } }) }) diff --git a/src/main/kotlin/com/smallcloud/refactai/notifications/Notifications.kt b/src/main/kotlin/com/smallcloud/refactai/notifications/Notifications.kt index 7b920151..223f3811 100644 --- a/src/main/kotlin/com/smallcloud/refactai/notifications/Notifications.kt +++ b/src/main/kotlin/com/smallcloud/refactai/notifications/Notifications.kt @@ -21,12 +21,12 @@ import com.intellij.openapi.wm.ToolWindowManager import com.smallcloud.refactai.PluginState import com.smallcloud.refactai.RefactAIBundle import com.smallcloud.refactai.Resources +import com.smallcloud.refactai.Resources.refactAIRootSettingsID import com.smallcloud.refactai.account.login import com.smallcloud.refactai.aitoolbox.ToolboxPaneInvokeAction import com.smallcloud.refactai.panes.RefactAIToolboxPaneFactory import com.smallcloud.refactai.privacy.Privacy import com.smallcloud.refactai.privacy.PrivacyChangesNotifier -import com.smallcloud.refactai.settings.AppRootConfigurable import com.smallcloud.refactai.utils.getLastUsedProject import java.awt.event.FocusEvent import java.awt.event.FocusListener @@ -116,7 +116,7 @@ fun emitLogin(project: Project) { login() notification.expire() }).addAction(NotificationAction.createSimple(RefactAIBundle.message("notifications.settingsAndPrivacy")) { - ShowSettingsUtilImpl.getInstance().showSettingsDialog(project, AppRootConfigurable::class.java) + ShowSettingsUtilImpl.showSettingsDialog(project, refactAIRootSettingsID, null) notification.expire() }).notify(project) lastNotification = notification @@ -145,7 +145,7 @@ fun emitRegular(project: Project, editor: Editor) { notification.icon = Resources.Icons.LOGO_RED_16x16 notification.addAction(NotificationAction.createSimple(RefactAIBundle.message("notifications.settingsAndPrivacy")) { - ShowSettingsUtilImpl.getInstance().showSettingsDialog(project, AppRootConfigurable::class.java) + ShowSettingsUtilImpl.showSettingsDialog(project, refactAIRootSettingsID, null) notification.expire() }) @@ -179,7 +179,7 @@ fun emitInfo(msg: String) { notification.icon = Resources.Icons.LOGO_RED_16x16 notification.addAction(NotificationAction.createSimple(RefactAIBundle.message("notifications.settingsAndPrivacy")) { - ShowSettingsUtilImpl.getInstance().showSettingsDialog(project, AppRootConfigurable::class.java) + ShowSettingsUtilImpl.showSettingsDialog(project, refactAIRootSettingsID, null) notification.expire() }) notification.notify(project) @@ -193,7 +193,7 @@ fun emitError(msg: String) { notification.icon = Resources.Icons.LOGO_RED_16x16 notification.addAction(NotificationAction.createSimple(RefactAIBundle.message("notifications.settingsAndPrivacy")) { - ShowSettingsUtilImpl.getInstance().showSettingsDialog(project, AppRootConfigurable::class.java) + ShowSettingsUtilImpl.showSettingsDialog(project, refactAIRootSettingsID, null) notification.expire() }) notification.notify(project) diff --git a/src/main/kotlin/com/smallcloud/refactai/panes/gptchat/ui/CustomSearchTextArea.kt b/src/main/kotlin/com/smallcloud/refactai/panes/gptchat/ui/CustomSearchTextArea.kt index d3f5a7c2..35797379 100644 --- a/src/main/kotlin/com/smallcloud/refactai/panes/gptchat/ui/CustomSearchTextArea.kt +++ b/src/main/kotlin/com/smallcloud/refactai/panes/gptchat/ui/CustomSearchTextArea.kt @@ -26,7 +26,6 @@ import com.intellij.ui.components.panels.NonOpaquePanel import com.intellij.ui.scale.JBUIScale import com.intellij.util.ui.JBInsets import com.intellij.util.ui.JBUI -import com.intellij.util.ui.StartupUiUtil import com.intellij.util.ui.UIUtil import com.smallcloud.refactai.RefactAIBundle import com.smallcloud.refactai.Resources @@ -313,7 +312,8 @@ class CustomSearchTextArea(val textArea: JTextArea) : JPanel(), PropertyChangeLi return if (SystemInfo.isMac) { JBInsets(3, 0, 2, 0) } else { - var bottom = if (StringUtil.getLineBreakCount(textArea.text) > 0) 2 else if (StartupUiUtil.isUnderDarcula()) 1 else 0 + var bottom = if (StringUtil.getLineBreakCount(textArea.text) > 0) 2 else + if (UIManager.getLookAndFeel().name.contains("Darcula")) 1 else 0 var top = if (textArea.getFontMetrics(textArea.font).height <= 16) 2 else 1 if (JBUIScale.isHiDPI(JBUIScale.scale(1f).toDouble())) { bottom = 0 diff --git a/src/main/kotlin/com/smallcloud/refactai/privacy/RefactAIPrivacyGroupAction.kt b/src/main/kotlin/com/smallcloud/refactai/privacy/RefactAIPrivacyGroupAction.kt index 7f012d0f..cfbb6db4 100644 --- a/src/main/kotlin/com/smallcloud/refactai/privacy/RefactAIPrivacyGroupAction.kt +++ b/src/main/kotlin/com/smallcloud/refactai/privacy/RefactAIPrivacyGroupAction.kt @@ -7,7 +7,7 @@ import com.intellij.openapi.ui.Messages import com.intellij.openapi.vfs.VirtualFile import com.smallcloud.refactai.RefactAIBundle import com.smallcloud.refactai.Resources -import com.smallcloud.refactai.settings.AppRootConfigurable +import com.smallcloud.refactai.Resources.refactAIRootSettingsID import com.smallcloud.refactai.io.InferenceGlobalContext.Companion.instance as InferenceGlobalContext @@ -53,7 +53,7 @@ class RefactAIPrivacyGroupAction : ActionGroup() { Separator(), object : DumbAwareAction() { override fun actionPerformed(e: AnActionEvent) { - ShowSettingsUtilImpl.getInstance().showSettingsDialog(e.project, AppRootConfigurable::class.java) + ShowSettingsUtilImpl.showSettingsDialog(e.project, refactAIRootSettingsID, null) } override fun update(e: AnActionEvent) { e.presentation.text = RefactAIBundle.message("privacy.privacyRules") diff --git a/src/main/kotlin/com/smallcloud/refactai/status_bar/StatusBarWidget.kt b/src/main/kotlin/com/smallcloud/refactai/status_bar/StatusBarWidget.kt index 2e26fc00..e2f447e6 100644 --- a/src/main/kotlin/com/smallcloud/refactai/status_bar/StatusBarWidget.kt +++ b/src/main/kotlin/com/smallcloud/refactai/status_bar/StatusBarWidget.kt @@ -5,7 +5,6 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ModalityState import com.intellij.openapi.editor.Editor import com.intellij.openapi.fileEditor.FileDocumentManager -import com.intellij.openapi.fileEditor.FileEditorManagerEvent import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.wm.CustomStatusBarWidget @@ -28,6 +27,7 @@ import com.smallcloud.refactai.account.LoginStateService import com.smallcloud.refactai.io.ConnectionChangedNotifier import com.smallcloud.refactai.io.ConnectionStatus import com.smallcloud.refactai.io.InferenceGlobalContextChangedNotifier +import com.smallcloud.refactai.listeners.SelectionChangedNotifier import com.smallcloud.refactai.notifications.emitLogin import com.smallcloud.refactai.notifications.emitRegular import com.smallcloud.refactai.privacy.Privacy @@ -118,12 +118,21 @@ class SMCStatusBarWidget(project: Project) : EditorBasedWidget(project), CustomS update(newMsg) } }) - } + ApplicationManager.getApplication() + .messageBus + .connect(this) + .subscribe(SelectionChangedNotifier.TOPIC, object : SelectionChangedNotifier { + override fun isEditorChanged(editor: Editor?) { + update(null) + } - override fun selectionChanged(event: FileEditorManagerEvent) { - update(null) + }) } +// override fun selectionChanged(event: FileEditorManagerEvent) { +// update(null) +// } + override fun ID(): String { return javaClass.name } @@ -169,7 +178,7 @@ class SMCStatusBarWidget(project: Project) : EditorBasedWidget(project), CustomS } private fun isPrivacyEnabled(): Boolean { - return PrivacyService.instance.getPrivacy(editor?.let { getVirtualFile(it) }) != Privacy.DISABLED + return PrivacyService.instance.getPrivacy(getEditor()?.let { getVirtualFile(it) }) != Privacy.DISABLED } // Compatability implementation. DO NOT ADD @Override. @@ -221,7 +230,7 @@ class SMCStatusBarWidget(project: Project) : EditorBasedWidget(project), CustomS if (!AccountManager.isLoggedIn && InferenceGlobalContext.isCloud) emitLogin(project) else - editor?.let { emitRegular(project, it) } + getEditor()?.let { emitRegular(project, it) } } } }