Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a notifier for the remodder plugin #46

Open
wants to merge 2 commits into
base: 2024.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 2024.2
* Adds support for [Parent=""] attributes
* When opening a file with Harmony Patches, adds a notifier to the user that they might want to install the Remodder plugin

## 2024.1
* Built for 2024.1
Expand Down
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
}
}
4 changes: 4 additions & 0 deletions src/rider/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ in your mods!</p>
<![CDATA[
<p><ul>
<li>Add support for Parent="" referencesin XML defs</li>
<li>When opening a file with Harmony Patches, adds a notifier to the user that they might want to install the Remodder plugin</li>
</ul></p>
]]>
</change-notes>
Expand All @@ -35,6 +36,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>