1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-05 18:34:03 +02:00

[VIM-3784] Store the information about the first version of IdeaVim for the user.

This commit is contained in:
Alex Plate 2025-01-27 11:09:47 +02:00
parent 1d77b0b059
commit ee548b52db
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
5 changed files with 57 additions and 3 deletions
src/main/java/com/maddyhome/idea/vim
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api

View File

@ -22,6 +22,7 @@ import com.intellij.openapi.updateSettings.impl.UpdateSettings
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.IjVimEnabler
import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.initInjector
import com.maddyhome.idea.vim.ui.JoinEap
@ -49,6 +50,8 @@ internal class PluginStartup : ProjectActivity/*, LightEditCompatible*/ {
// This code should be executed once
VimPlugin.getInstance().initialize()
(injector.enabler as IjVimEnabler).ideOpened()
// Uninstall survey. Should be registered once for all projects
PluginStateManager.addStateListener(object : PluginStateListener {
override fun install(p0: IdeaPluginDescriptor) {/*Nothing*/

View File

@ -20,6 +20,11 @@ internal class VimState {
var isIdeaPutNotified by StateProperty("idea-put")
var wasSubscribedToEAPAutomatically by StateProperty("was-automatically-subscribed-to-eap")
/**
* First logged version of IdeaVim, or "-1" if no version logged
*/
var firstIdeaVimVersion: String by StringProperty("first-ideavim-version", "-1")
fun readData(element: Element) {
val notifications = element.getChild("notifications")
map.keys.forEach { name ->
@ -27,6 +32,11 @@ internal class VimState {
map[name] = it.toBoolean()
}
}
stringMap.keys.forEach { name ->
notifications?.getChild(name)?.getAttributeValue("value")?.let {
stringMap[name] = it
}
}
}
fun saveData(element: Element) {
@ -38,10 +48,16 @@ internal class VimState {
child.setAttribute("enabled", value.toString())
notifications.addContent(child)
}
stringMap.forEach { (name, value) ->
val child = Element(name)
child.setAttribute("value", value)
notifications.addContent(child)
}
}
}
private val map by lazy { mutableMapOf<String, Boolean>() }
private val stringMap by lazy { mutableMapOf<String, String>() }
private class StateProperty(val xmlName: String) : ReadWriteProperty<VimState, Boolean> {
@ -55,3 +71,17 @@ private class StateProperty(val xmlName: String) : ReadWriteProperty<VimState, B
map[xmlName] = value
}
}
private class StringProperty(val propertyName: String, val defaultValue: String) : ReadWriteProperty<VimState, String> {
init {
stringMap[propertyName] = defaultValue
}
override fun getValue(thisRef: VimState, property: KProperty<*>): String =
stringMap.getOrPut(propertyName) { defaultValue }
override fun setValue(thisRef: VimState, property: KProperty<*>, value: String) {
stringMap[propertyName] = value
}
}

View File

@ -14,7 +14,19 @@ import com.maddyhome.idea.vim.api.VimEnabler
@Service
internal class IjVimEnabler : VimEnabler {
private var isNewUser = false
override fun isEnabled(): Boolean {
return VimPlugin.isEnabled()
}
override fun isNewIdeaVimUser(): Boolean = isNewUser
fun ideOpened() {
val myFirstVersion = VimPlugin.getVimState().firstIdeaVimVersion
if (myFirstVersion == "-1") {
VimPlugin.getVimState().firstIdeaVimVersion = VimPlugin.getVersion()
this.isNewUser = true
}
}
}

View File

@ -14,4 +14,13 @@ package com.maddyhome.idea.vim.api
*/
interface VimEnabler {
fun isEnabled(): Boolean
/**
* Returns true if probably the current IDE session has an IdeaVim plugin just installed.
* A session is a time between IDE open and close.
*
* There is no guarantee that the user actually never tried the IdeaVim before, or the plugin was just installed,
* so no important functionality should depend on this.
*/
fun isNewIdeaVimUser(): Boolean
}

View File

@ -16,7 +16,7 @@ class VimEnablerStub : VimEnabler {
vimLogger<ExecutionContextManagerStub>().warn("VimEnablerStub is used. Please replace it with your own implementation of VimEnabler.")
}
override fun isEnabled(): Boolean {
TODO("Not yet implemented")
}
override fun isEnabled(): Boolean = throw NotImplementedError()
override fun isNewIdeaVimUser(): Boolean = throw NotImplementedError()
}