[Dart] How to refresh the LineMarkerProvider icon through code

Answered

Hi,

When a user selects'Collect plugin' in the operation menu, data will be saved in sqlite. How can I update the icon on the left to display it through code?

 

 

my code 




class PluginDartIconLineMark : LineMarkerProvider {

override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<PsiElement>? {
if (element.isDartPluginElement() && element is YAMLKeyValueImpl) {
val isExits = FlutterCollectService.exits(element.getPluginName()) //是否已经收藏了
return LineMarkerInfo(
element.firstChild, element.firstChild.textRange,
if(isExits) MyIcons.collect else MyIcons.dartPackageIcon, { element.text }, PluginDartIconLineMarkNavHandler(element),
GutterIconRenderer.Alignment.LEFT
) { "111" }
}
return null
}
}

///处理点击
class PluginDartIconLineMarkNavHandler(val element: PsiElement) : GutterIconNavigationHandler<PsiElement> {
override fun navigate(e: MouseEvent?, elt: PsiElement?) {
if ((e != null) && (e.clickCount == 1)) {
JBPopupFactory.getInstance().createListPopup(PluginDartIconActioinMenuList(element = element))
.show(RelativePoint(e.locationOnScreen))
}
}
}

data class PluginDartIconActionMenuItem(val title: String, val type: String, val icon: Icon)
class PluginDartIconActioinMenuList(val element: PsiElement) : BaseListPopupStep<PluginDartIconActionMenuItem>() {

private val isExites = FlutterCollectService.exits(element.getPluginName()) //是否已经收藏

private val menus
get() = listOf(
PluginDartIconActionMenuItem(
title = "${PluginBundle.get("nav.to")} pub.dev",
type = "navToPub",
icon = AllIcons.Toolwindows.WebToolWindow
),
PluginDartIconActionMenuItem(
PluginBundle.get("plugin.collect"),
"collect",
if (isExites) MyIcons.collect else MyIcons.collectUn
)
)

init {
super.init(element.text, menus, menus.map { it.icon })
}


override fun getTextFor(value: PluginDartIconActionMenuItem?): String {
return value?.title ?: "未知选项"
}

override fun onChosen(selectedValue: PluginDartIconActionMenuItem?, finalChoice: Boolean): PopupStep<*>? {
when (selectedValue?.type) {
menus[0].type -> {
BrowserUtil.browse("$PUB_URL${element.getPluginName()}")
}

menus[1].type -> {
addToCollect()
}
}
return super.onChosen(selectedValue, finalChoice)
}


///添加收藏
private fun addToCollect() {
if (isExites) {
removeCollect()
return
}
SqliteConnectManager.createFlutterPluginTable()
FlutterCollectService.add(element.getPluginName(), element.project)
/// TODO update the icon
}


///移除收藏
private fun removeCollect() {
val success = FlutterCollectService.remove(element.getPluginName())
if (success) {
element.project.toast("Delete succeeded")

/// TODO update the icon
} else {
element.project.toast("Delete failed")
}



}
}
0
1 comment

Hi,

Try to call DaemonCodeAnalyzer.restart().

0

Please sign in to leave a comment.