-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Goto Script" tab to the "Find Action" window
- Loading branch information
1 parent
5962f6c
commit b6c340f
Showing
10 changed files
with
257 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/io/runescript/plugin/ide/icons/RsIconProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.runescript.plugin.ide.icons | ||
|
||
import com.intellij.ide.FileIconProvider | ||
import com.intellij.ide.IconProvider | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.psi.PsiElement | ||
import io.runescript.plugin.ide.RsIcons | ||
import io.runescript.plugin.ide.neptune.isNeptuneBuildFile | ||
import io.runescript.plugin.lang.psi.RsScript | ||
import io.runescript.plugin.lang.psi.mixin.getIconForTriggerName | ||
import io.runescript.plugin.lang.psi.triggerName | ||
import javax.swing.Icon | ||
|
||
class RsIconProvider : IconProvider() { | ||
override fun getIcon(element: PsiElement, flags: Int): Icon? { | ||
if (element is RsScript) { | ||
return getIconForTriggerName(element.triggerName) | ||
} | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/kotlin/io/runescript/plugin/ide/searchEverywhere/RsGotoScriptModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.runescript.plugin.ide.searchEverywhere | ||
|
||
import com.intellij.ide.IdeBundle | ||
import com.intellij.ide.util.gotoByName.FilteringGotoByModel | ||
import com.intellij.navigation.ChooseByNameContributor | ||
import com.intellij.navigation.NavigationItem | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.ui.IdeUICustomization | ||
import io.runescript.plugin.lang.psi.RsScript | ||
import io.runescript.plugin.lang.psi.qualifiedName | ||
|
||
class RsGotoScriptModel(project: Project) : | ||
FilteringGotoByModel<RsTriggerRef>(project, emptyArray()) { | ||
|
||
private val contributor = RsChooseByNameContributor() | ||
private val separators = emptyArray<String>() | ||
|
||
override fun getPromptText(): String { | ||
return "Enter script name" | ||
} | ||
|
||
override fun getNotInMessage(): String { | ||
return IdeUICustomization.getInstance().projectMessage("label.no.matches.found.in.project") | ||
} | ||
|
||
override fun getNotFoundMessage(): String { | ||
return IdeBundle.message("label.no.matches.found"); | ||
} | ||
|
||
override fun getCheckBoxName(): String? { | ||
return null | ||
} | ||
|
||
override fun loadInitialCheckBoxState(): Boolean { | ||
return false | ||
} | ||
|
||
override fun saveInitialCheckBoxState(state: Boolean) { | ||
} | ||
|
||
override fun getSeparators(): Array<String> { | ||
return separators | ||
} | ||
|
||
override fun getFullName(item: Any): String? { | ||
return (item as? RsScript)?.qualifiedName | ||
} | ||
|
||
override fun willOpenEditor(): Boolean { | ||
return true | ||
} | ||
|
||
override fun filterValueFor(item: NavigationItem): RsTriggerRef? { | ||
return RsTriggerRef.forNavigationItem(item) | ||
} | ||
|
||
override fun getContributorList(): MutableList<ChooseByNameContributor> { | ||
return mutableListOf(contributor) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/io/runescript/plugin/ide/searchEverywhere/RsGotoScriptSymbolConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.runescript.plugin.ide.searchEverywhere | ||
|
||
import com.intellij.ide.util.gotoByName.ChooseByNameFilterConfiguration | ||
import com.intellij.openapi.components.* | ||
import com.intellij.openapi.project.Project | ||
|
||
@Service(Service.Level.PROJECT) | ||
@State(name = "GotoScriptSymbolConfiguration", storages = [Storage(StoragePathMacros.WORKSPACE_FILE)]) | ||
class RsGotoScriptSymbolConfiguration : ChooseByNameFilterConfiguration<RsTriggerRef>() { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun getInstance(project: Project): RsGotoScriptSymbolConfiguration = project.service() | ||
} | ||
|
||
override fun nameForElement(type: RsTriggerRef): String { | ||
return type.displayName | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/io/runescript/plugin/ide/searchEverywhere/RsSearchEverywhereContributor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.runescript.plugin.ide.searchEverywhere | ||
|
||
import com.intellij.ide.actions.searcheverywhere.* | ||
import com.intellij.ide.actions.searcheverywhere.footer.createPsiExtendedInfo | ||
import com.intellij.ide.util.gotoByName.FilteringGotoByModel | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.actionSystem.CommonDataKeys | ||
import com.intellij.openapi.project.Project | ||
|
||
class RsSearchEverywhereContributor(event: AnActionEvent) : AbstractGotoSEContributor(event), | ||
SearchFieldActionsContributor { | ||
|
||
private val filter = createTriggerFilter(event.getRequiredData(CommonDataKeys.PROJECT)) | ||
|
||
override fun getGroupName(): String { | ||
return "Scripts" | ||
} | ||
|
||
override fun getFullGroupName(): String { | ||
return "Scripts" | ||
} | ||
|
||
override fun getSortWeight(): Int { | ||
return 400 | ||
} | ||
|
||
override fun createModel(project: Project): FilteringGotoByModel<RsTriggerRef> { | ||
val model = RsGotoScriptModel(project) | ||
model.setFilterItems(filter.selectedElements) | ||
return model | ||
} | ||
|
||
override fun getActions(onChanged: Runnable): List<AnAction> { | ||
return doGetActions(filter, RsTriggerFilterCollector(), onChanged) | ||
} | ||
|
||
override fun isEmptyPatternSupported(): Boolean { | ||
return true | ||
} | ||
|
||
@Suppress("OVERRIDE_DEPRECATION") | ||
override fun getElementPriority(element: Any, searchPattern: String): Int { | ||
return super.getElementPriority(element, searchPattern) + 5 | ||
} | ||
|
||
override fun createExtendedInfo(): ExtendedInfo { | ||
return createPsiExtendedInfo() | ||
} | ||
|
||
class Factory : SearchEverywhereContributorFactory<Any> { | ||
override fun createContributor(initEvent: AnActionEvent): SearchEverywhereContributor<Any> { | ||
return PSIPresentationBgRendererWrapper.wrapIfNecessary(RsSearchEverywhereContributor(initEvent)) | ||
} | ||
|
||
override fun isAvailable(project: Project): Boolean { | ||
return true | ||
} | ||
} | ||
|
||
companion object { | ||
fun createTriggerFilter(project: Project): PersistentSearchEverywhereContributorFilter<RsTriggerRef> { | ||
val items = RsTriggerRef.forAllTriggers() | ||
val persistentConfig = RsGotoScriptSymbolConfiguration.getInstance(project) | ||
return PersistentSearchEverywhereContributorFilter( | ||
items, | ||
persistentConfig, | ||
RsTriggerRef::displayName, | ||
RsTriggerRef::icon | ||
) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/io/runescript/plugin/ide/searchEverywhere/RsTriggerFilterCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.runescript.plugin.ide.searchEverywhere; | ||
|
||
import com.intellij.ide.actions.searcheverywhere.SearchEverywhereFiltersStatisticsCollector; | ||
|
||
public class RsTriggerFilterCollector extends SearchEverywhereFiltersStatisticsCollector.BaseFilterStatisticsCollector<RsTriggerRef> { | ||
|
||
@Override | ||
public void elementMarkChanged(RsTriggerRef element, boolean isMarked) { | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/kotlin/io/runescript/plugin/ide/searchEverywhere/RsTriggerRef.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.runescript.plugin.ide.searchEverywhere | ||
|
||
import com.intellij.navigation.NavigationItem | ||
import com.intellij.openapi.util.text.StringUtil | ||
import io.runescript.plugin.ide.RsIcons | ||
import io.runescript.plugin.lang.psi.RsScript | ||
import io.runescript.plugin.lang.psi.triggerName | ||
import io.runescript.plugin.lang.psi.type.trigger.RsTriggerType | ||
import javax.swing.Icon | ||
|
||
data class RsTriggerRef(val displayName: String, val icon: Icon?) { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun forTrigger(trigger: RsTriggerType): RsTriggerRef = RsTriggerRef( | ||
trigger.literal, | ||
when (trigger) { | ||
RsTriggerType.PROC -> RsIcons.GutterProc | ||
RsTriggerType.CLIENTSCRIPT -> RsIcons.GutterClientScript | ||
RsTriggerType.COMMAND -> RsIcons.GutterCommand | ||
else -> RsIcons.GutterOther | ||
} | ||
) | ||
|
||
@JvmStatic | ||
fun forNavigationItem(item: NavigationItem): RsTriggerRef? { | ||
val trigger = RsTriggerType.lookup((item as RsScript).triggerName) ?: return null | ||
return forTrigger(trigger) | ||
} | ||
|
||
@JvmStatic | ||
fun forAllTriggers(): List<RsTriggerRef> { | ||
return RsTriggerType.values() | ||
.sortedWith { a, b -> StringUtil.naturalCompare(a.literal, b.literal) } | ||
.map { forTrigger(it) } | ||
} | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as RsTriggerRef | ||
|
||
return displayName == other.displayName | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return displayName.hashCode() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters