[SE] IDEA-344651 Preview in Search Everywhere experiment in EAP

GitOrigin-RevId: c865c47c2593aa1a68435e1356e7bfbf650292cc
This commit is contained in:
Dmitry Krasilschikov
2024-01-31 13:55:04 +02:00
committed by intellij-monorepo-bot
parent f3221958e3
commit 69a2c27a1d
8 changed files with 82 additions and 9 deletions

View File

@@ -5,13 +5,21 @@ import com.intellij.icons.ExpUiIcons
import com.intellij.ide.IdeBundle
import com.intellij.ide.actions.searcheverywhere.SEHeaderActionListener.Companion.SE_HEADER_ACTION_TOPIC
import com.intellij.ide.actions.searcheverywhere.SearchEverywhereUI.isPreviewEnabled
import com.intellij.ide.actions.searcheverywhere.statistics.SearchEverywhereUsageTriggerCollector.*
import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.toolbar.floating.AbstractFloatingToolbarProvider
import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent
import com.intellij.openapi.project.DumbAwareToggleAction
import com.intellij.openapi.project.Project
import com.intellij.usages.impl.UsagePreviewPanel.Companion.PREVIEW_EDITOR_FLAG
import com.intellij.util.containers.DisposableWrapperList
import java.util.function.Supplier
const val PREVIEW_ACTION_ID = "Search.Everywhere.Preview"
class PreviewAction : DumbAwareToggleAction(Supplier { IdeBundle.message("search.everywhere.preview.action.text") },
Supplier { IdeBundle.message("search.everywhere.preview.action.description") },
ExpUiIcons.General.PreviewHorizontally) {
@@ -26,8 +34,43 @@ class PreviewAction : DumbAwareToggleAction(Supplier { IdeBundle.message("search
PropertiesComponent.getInstance().isTrueValue(SearchEverywhereUI.PREVIEW_PROPERTY_KEY)
override fun setSelected(e: AnActionEvent, state: Boolean) {
PropertiesComponent.getInstance().updateValue(SearchEverywhereUI.PREVIEW_PROPERTY_KEY, state)
ApplicationManager.getApplication().messageBus.syncPublisher<SEHeaderActionListener>(SE_HEADER_ACTION_TOPIC)
.performed(SEHeaderActionListener.SearchEverywhereActionEvent(e.presentation.text))
PREVIEW_SWITCHED.log(e.project, PREVIEW_STATE.with(state))
togglePreview(state)
}
companion object {
fun togglePreview(state: Boolean) {
PropertiesComponent.getInstance().updateValue(SearchEverywhereUI.PREVIEW_PROPERTY_KEY, state)
ApplicationManager.getApplication().messageBus.syncPublisher<SEHeaderActionListener>(SE_HEADER_ACTION_TOPIC)
.performed(SEHeaderActionListener.SearchEverywhereActionEvent(PREVIEW_ACTION_ID))
}
}
}
class CloseSearchEverywherePreview : AnAction() {
override fun getActionUpdateThread() = ActionUpdateThread.BGT
override fun actionPerformed(e: AnActionEvent) {
PREVIEW_CLOSED.log(e.project, PREVIEW_CLOSED_STATE.with(true))
PreviewAction.togglePreview(false)
}
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = PreviewExperiment.isExperimentEnabled
}
}
class CloseSearchEverywherePreviewToolbar : AbstractFloatingToolbarProvider("Search.Everywhere.Preview.Close") {
override val autoHideable = false
private val toolbarComponents = DisposableWrapperList<Pair<Project, FloatingToolbarComponent>>()
override fun isApplicable(dataContext: DataContext): Boolean {
return isPreviewEnabled() && dataContext.getData(PlatformDataKeys.EDITOR)?.getUserData(PREVIEW_EDITOR_FLAG) != null
}
override fun register(dataContext: DataContext, component: FloatingToolbarComponent, parentDisposable: Disposable) {
val project = dataContext.getData(CommonDataKeys.PROJECT) ?: return
toolbarComponents.add(project to component, parentDisposable)
component.scheduleShow()
}
}

View File

@@ -0,0 +1,12 @@
// Copyright 2000-2024 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.internal.statistic.eventLog.EventLogConfiguration
import com.intellij.internal.statistic.utils.StatisticsUploadAssistant
import com.intellij.openapi.application.ApplicationManager
object PreviewExperiment {
val isExperimentEnabled = StatisticsUploadAssistant.isSendAllowed()
&& ApplicationManager.getApplication().isEAP
&& EventLogConfiguration.getInstance().bucket < 128
}

View File

@@ -693,7 +693,7 @@ public final class SearchEverywhereUI extends BigPopupUI implements DataProvider
SEHeaderActionListener.Companion.getSE_HEADER_ACTION_TOPIC(), new SEHeaderActionListener() {
@Override
public void performed(@NotNull SEHeaderActionListener.SearchEverywhereActionEvent event) {
if (event.getActionID().equals("Preview")) {
if (event.getActionID().equals(PreviewActionKt.PREVIEW_ACTION_ID)) {
updatePreviewVisibility();
}
}
@@ -1068,7 +1068,7 @@ public final class SearchEverywhereUI extends BigPopupUI implements DataProvider
}
static boolean isPreviewEnabled() {
return Registry.is("search.everywhere.preview");
return PreviewExperiment.INSTANCE.isExperimentEnabled() || Registry.is("search.everywhere.preview");
}
private static boolean isPreviewActive() {

View File

@@ -81,6 +81,10 @@ public final class SearchEverywhereUsageTriggerCollector extends CounterUsagesCo
TIME_TO_FIRST_RESULT, FIRST_TAB_ID, TIME_TO_FIRST_RESULT_LAST_QUERY, LAST_TAB_ID, DURATION_MS,
ML_EXPERIMENT_GROUP, ML_EXPERIMENT_VERSION
);
public static final BooleanEventField PREVIEW_STATE = EventFields.Boolean("previewState");
public static final VarargEventId PREVIEW_SWITCHED = GROUP.registerVarargEvent("previewSwitched", PREVIEW_STATE);
public static final BooleanEventField PREVIEW_CLOSED_STATE = EventFields.Boolean("previewClosed");
public static final VarargEventId PREVIEW_CLOSED = GROUP.registerVarargEvent("previewClosed", PREVIEW_CLOSED_STATE);
@Override
public EventLogGroup getGroup() {

View File

@@ -2843,4 +2843,7 @@ action.GuestForceOldReconnect.text=Guest Drop Wire (Internal)
action.RestoreProtocolHandler.text=Register Gateway Protocol
action.GatewayPluginsAction.text=Manage Providers
action.DSOpenConsole.text=Open Python Console
action.DSOpenConsole.text=Open Python Console
action.search.everywhere.preview.close.text=Close Preview
action.search.everywhere.preview.close.description=Close search everywhere preview

View File

@@ -1708,6 +1708,11 @@
defaultValue="false"
description="Turn on the highlighting passes preload experiment"/>
<editorFloatingToolbarProvider
id="CloseSearchEverywherePreviewToolbar"
order="after DefaultFloatingToolbarProvider"
implementation="com.intellij.ide.actions.searcheverywhere.CloseSearchEverywherePreviewToolbar"/>
<actionConfigurationCustomizer implementation="com.intellij.openapi.project.impl.SeparateProcessActionsCustomizer"/>
<projectService serviceImplementation="com.intellij.openapi.updateSettings.impl.CustomPluginRepositoriesConfigurationComponent"

View File

@@ -1658,5 +1658,11 @@
</group>
<action id="RemoveMainToolbarActionsAction" class="com.intellij.openapi.wm.impl.headertoolbar.RemoveMainToolbarActionsAction" internal="true"/>
<group id="Search.Everywhere.Preview.Close">
<action id="search.everywhere.preview.close"
class="com.intellij.ide.actions.searcheverywhere.CloseSearchEverywherePreview"
icon="AllIcons.Actions.CloseDarkGrey"/>
</group>
</actions>
</idea-plugin>

View File

@@ -504,7 +504,7 @@ open class UsagePreviewPanel @JvmOverloads constructor(project: Project,
return stub
}
private val PREVIEW_EDITOR_FLAG = Key.create<UsagePreviewPanel>("PREVIEW_EDITOR_FLAG")
val PREVIEW_EDITOR_FLAG = Key.create<UsagePreviewPanel>("PREVIEW_EDITOR_FLAG")
@Contract("null -> !null")
private fun cannotPreviewMessage(infos: List<UsageInfo>?): @NlsContexts.StatusText String? {
if (infos == null) {