Skip to content

Commit

Permalink
fix compilation on new version
Browse files Browse the repository at this point in the history
  • Loading branch information
reymondzzzz committed Sep 18, 2023
1 parent b294d94 commit 1db99a3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/com/smallcloud/refactai/Resources.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -57,21 +57,25 @@ object Resources {

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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ val LongthinkKey = Key.create<LongthinkFunctionVariation>("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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ 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(), null, null)
}
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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
Expand Down Expand Up @@ -116,7 +115,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, null, null)
notification.expire()
}).notify(project)
lastNotification = notification
Expand Down Expand Up @@ -145,7 +144,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, null, null)
notification.expire()
})

Expand Down Expand Up @@ -179,7 +178,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, null, null)
notification.expire()
})
notification.notify(project)
Expand All @@ -193,7 +192,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, null, null)
notification.expire()
})
notification.notify(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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.io.InferenceGlobalContext.Companion.instance as InferenceGlobalContext


Expand Down Expand Up @@ -53,7 +52,7 @@ class RefactAIPrivacyGroupAction : ActionGroup() {
Separator(),
object : DumbAwareAction() {
override fun actionPerformed(e: AnActionEvent) {
ShowSettingsUtilImpl.getInstance().showSettingsDialog(e.project, AppRootConfigurable::class.java)
ShowSettingsUtilImpl.showSettingsDialog(e.project, null, null)
}
override fun update(e: AnActionEvent) {
e.presentation.text = RefactAIBundle.message("privacy.privacyRules")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) }
}
}
}
Expand Down

0 comments on commit 1db99a3

Please sign in to comment.