mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
IDEA-307112 Search Everywhere: show info about selected item
GitOrigin-RevId: cc06536beb3b03de089faf3cbb13c092d88efee7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
193013fd5d
commit
e682601aa1
@@ -54,7 +54,7 @@ import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.components.fields.ExtendableTextComponent;
|
||||
import com.intellij.ui.components.fields.ExtendableTextField;
|
||||
import com.intellij.ui.popup.PopupUpdateProcessor;
|
||||
import com.intellij.ui.popup.PopupUpdateProcessorBase;
|
||||
import com.intellij.ui.scale.JBUIScale;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewBundle;
|
||||
@@ -103,6 +103,8 @@ public final class SearchEverywhereUI extends BigPopupUI implements DataProvider
|
||||
|
||||
public static final String SEARCH_EVERYWHERE_SEARCH_FILED_KEY = "search-everywhere-textfield"; //only for testing purposes
|
||||
|
||||
static final DataKey<SearchEverywhereFoundElementInfo> SELECTED_ITEM_INFO = DataKey.create("selectedItemInfo");
|
||||
|
||||
public static final int SINGLE_CONTRIBUTOR_ELEMENTS_LIMIT = 30;
|
||||
public static final int MULTIPLE_CONTRIBUTORS_ELEMENTS_LIMIT = 15;
|
||||
|
||||
@@ -332,6 +334,9 @@ public final class SearchEverywhereUI extends BigPopupUI implements DataProvider
|
||||
if (CommonDataKeys.PROJECT.is(dataId)) {
|
||||
return myProject;
|
||||
}
|
||||
if (SELECTED_ITEM_INFO.is(dataId)) {
|
||||
return ContainerUtil.getOnlyItem(getSelectedInfos());
|
||||
}
|
||||
if (PlatformCoreDataKeys.SELECTED_ITEM.is(dataId)) {
|
||||
SearchEverywhereFoundElementInfo info = ContainerUtil.getOnlyItem(getSelectedInfos());
|
||||
return info == null ? null : info.getElement();
|
||||
@@ -411,7 +416,7 @@ public final class SearchEverywhereUI extends BigPopupUI implements DataProvider
|
||||
|
||||
private void updateHint(Object element) {
|
||||
if (myHint == null || !myHint.isVisible()) return;
|
||||
final PopupUpdateProcessor updateProcessor = myHint.getUserData(PopupUpdateProcessor.class);
|
||||
final PopupUpdateProcessorBase updateProcessor = myHint.getUserData(PopupUpdateProcessorBase.class);
|
||||
if (updateProcessor != null) {
|
||||
updateProcessor.updatePopup(element);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.actions.searcheverywhere
|
||||
|
||||
import com.intellij.codeWithMe.ClientId.Companion.current
|
||||
import com.intellij.ide.DataManager
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.ui.popup.AbstractPopup
|
||||
import com.intellij.ui.popup.PopupPositionManager
|
||||
import com.intellij.ui.popup.PopupUpdateProcessorBase
|
||||
import com.intellij.util.ui.JBDimension
|
||||
import java.awt.Component
|
||||
import javax.swing.JEditorPane
|
||||
|
||||
class ShowElementInfoAction : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val ui = getSEUI(e.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT)) ?: return
|
||||
val infoManager = ElementInfoManager.getInstance(ui)
|
||||
e.getData(SearchEverywhereUI.SELECTED_ITEM_INFO)?.let { infoManager.showElementInfo(it, e.project) }
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
e.presentation.isEnabled = getSEUI(e.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT)) != null
|
||||
}
|
||||
|
||||
override fun getActionUpdateThread() = ActionUpdateThread.EDT
|
||||
|
||||
override fun isDumbAware() = true
|
||||
|
||||
private fun getSEUI(component: Component?): SearchEverywhereUI? {
|
||||
var current = component
|
||||
while (current != null) {
|
||||
if (current is SearchEverywhereUI) return current
|
||||
current = current.parent
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private const val POPUP_DIMENSION_KEY = "search.everywhere.element.info.popup"
|
||||
private const val ELEMENT_INFO_MANAGER_KEY = "SEElementInfoManager"
|
||||
|
||||
@Suppress("HardCodedStringLiteral")
|
||||
private class ElementInfoManager(private val seUI: SearchEverywhereUI) {
|
||||
|
||||
companion object {
|
||||
fun getInstance(ui : SearchEverywhereUI): ElementInfoManager {
|
||||
var manager = ui.getClientProperty(ELEMENT_INFO_MANAGER_KEY)
|
||||
if (manager != null) return manager as ElementInfoManager
|
||||
|
||||
manager = ElementInfoManager(ui)
|
||||
ui.putClientProperty(ELEMENT_INFO_MANAGER_KEY, manager)
|
||||
return manager
|
||||
}
|
||||
}
|
||||
|
||||
private var myPopup: AbstractPopup? = null
|
||||
|
||||
fun showElementInfo(info: SearchEverywhereFoundElementInfo, project: Project?) {
|
||||
val popup = myPopup
|
||||
if (popup?.isVisible == true) {
|
||||
fillContent(popup.component as JEditorPane, info)
|
||||
}
|
||||
else {
|
||||
val content = JEditorPane()
|
||||
content.preferredSize = JBDimension(250, 150)
|
||||
fillContent(content, info)
|
||||
showPopup(content, project)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showPopup(content: JEditorPane, project: Project?) {
|
||||
|
||||
val updater = object : PopupUpdateProcessorBase() {
|
||||
override fun updatePopup(element: Any?) {
|
||||
val popup = myPopup
|
||||
if (popup?.isVisible == true) {
|
||||
seUI.getData(SearchEverywhereUI.SELECTED_ITEM_INFO.name)?.let { fillContent(popup.component as JEditorPane, it as SearchEverywhereFoundElementInfo) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val popup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, content)
|
||||
.setProject(project)
|
||||
.addUserData(updater)
|
||||
.addUserData(current)
|
||||
.setResizable(true)
|
||||
.setMovable(true)
|
||||
.setFocusable(false)
|
||||
.setRequestFocus(false)
|
||||
.setCancelOnClickOutside(false)
|
||||
.setModalContext(false)
|
||||
.setCancelCallback { true }
|
||||
.setDimensionServiceKey(project, POPUP_DIMENSION_KEY, false)
|
||||
.createPopup() as AbstractPopup
|
||||
|
||||
seUI.registerHint(popup)
|
||||
Disposer.register(popup) { seUI.unregisterHint() }
|
||||
PopupPositionManager.positionPopupInBestPosition(popup, null, DataManager.getInstance().getDataContext(seUI))
|
||||
|
||||
myPopup = popup
|
||||
}
|
||||
|
||||
private fun fillContent(content: JEditorPane, info: SearchEverywhereFoundElementInfo) {
|
||||
if (info.element == SearchListModel.MORE_ELEMENT) {
|
||||
content.text = "'More...' element"
|
||||
return
|
||||
}
|
||||
|
||||
val sb = StringBuilder()
|
||||
sb.appendLine("contributor: ${info.contributor.searchProviderId}")
|
||||
sb.appendLine("weight: ${info.priority}")
|
||||
|
||||
content.text = sb.toString()
|
||||
}
|
||||
}
|
||||
@@ -2101,6 +2101,7 @@ action.FocusTracer.text=Start Focus Tracing
|
||||
action.KeymapToCsv.text=Export Keymap to CSV...
|
||||
action.CompareKeymaps.text=Compare Keymaps...
|
||||
action.BrowseWeb.text=Browse Web...
|
||||
action.ShowSearchEverywhereItemInfo.text=Show Search Everywhere Item Info
|
||||
action.PerformGC.text=Perform GC
|
||||
action.LogFocusRequests.text=Log Focus Requests
|
||||
action.UiInspector.text=UI &Inspector
|
||||
|
||||
@@ -1286,6 +1286,8 @@
|
||||
<action id="CompareKeymaps" internal="true" class="com.intellij.internal.CompareKeymapsAction"/>
|
||||
<action id="BrowseWeb" internal="true" class="com.intellij.internal.BrowseWebAction"/>
|
||||
|
||||
<action id="ShowSearchEverywhereItemInfo" class="com.intellij.ide.actions.searcheverywhere.ShowElementInfoAction" internal="true"/>
|
||||
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</group>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user