Skip to content

Commit

Permalink
Add a notifier for the remodder plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Garethp committed May 10, 2024
1 parent 5f3042b commit 5ce1910
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package RimworldDev.Rider.HarmonyPluginNotifier

import com.intellij.ide.IdeBundle
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.ide.plugins.advertiser.PluginData
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.FUSEventSource
import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.installAndEnable
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotificationProvider
import java.util.function.Function
import javax.swing.JComponent
import javax.swing.JLabel

class HarmonyPluginNotifier : EditorNotificationProvider {
override fun collectNotificationData(p0: Project, p1: VirtualFile): Function<in FileEditor, out JComponent?>? {


return Function { editor ->
val descriptorsById = PluginManagerCore.buildPluginIdMap()
val hasPlugin = descriptorsById.containsKey(
PluginId.getId("com.zetrith.remodder")
)

apply(editor, p0)
}
}

fun apply(editor: FileEditor, project: Project): EditorNotificationPanel? {
if (editor.file.extension != "cs") return null
if (!editor.file.contentsToByteArray().toString(Charsets.UTF_8).contains(Regex("using\\s+HarmonyLib;"))) return null

lateinit var label: JLabel
val panel = object : EditorNotificationPanel(editor, EditorNotificationPanel.Status.Info) {
init {
label = myLabel
}
}

panel.text = IdeBundle.message("plugins.advertiser.plugins.found", "harmony")

fun createInstallActionLabel() {
val labelText =
IdeBundle.message("plugins.advertiser.action.install.plugin.name", "Remodder")

panel.createActionLabel(labelText) {
FUSEventSource.EDITOR.logInstallPlugins(listOf("com.zetrith.remodder"))
installAndEnable(project, setOf(PluginId.getId("com.zetrith.remodder")), true) {
// pluginAdvertiserExtensionsState.addEnabledExtensionOrFileNameAndInvalidateCache(extensionOrFileName)
// updateAllNotifications(project)
}
}

panel.createActionLabel(IdeBundle.message("plugins.advertiser.action.ignore.extension")) {
// FUSEventSource.EDITOR.logIgnoreExtension(project)
// pluginAdvertiserExtensionsState.ignoreExtensionOrFileNameAndInvalidateCache(extensionOrFileName)
// updateAllNotifications(project)
}
}

createInstallActionLabel()

return panel
}
}
3 changes: 3 additions & 0 deletions src/rider/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ in your mods!</p>
<backend.markup.adapterFactory language="XML" implementationClass="com.jetbrains.rider.daemon.RiderCacheAwareMarkupAdapterFactory" />

<spellchecker.bundledDictionaryProvider implementation="RimworldDev.Rider.spellchecker.DictionaryProvider" />

<editorNotificationProvider
implementation="RimworldDev.Rider.HarmonyPluginNotifier.HarmonyPluginNotifier"/>
</extensions>

</idea-plugin>

0 comments on commit 5ce1910

Please sign in to comment.