diff-preview: add show diff in editor tab "GotIt" tooltip
authorDmitry Zhuravlev <dmitry.zhuravlev@jetbrains.com>
Tue, 17 Nov 2020 15:08:25 +0000 (18:08 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 15 Dec 2020 15:45:21 +0000 (15:45 +0000)
GitOrigin-RevId: ff765c42099de2d7c6a82e4a16f24128d1ae91f0

platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java
platform/platform-resources/src/META-INF/PlatformExtensions.xml
platform/vcs-api/vcs-api-core/resources/messages/VcsBundle.properties
platform/vcs-impl/resources/META-INF/VcsExtensions.xml
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ShowDiffInEditorTooltipInstaller.kt [new file with mode: 0644]

index ae63067ad0a6c46858927227e229b4b05d61ee1d..1dc0a7da3cf700beda21969cc9d63f2f7d7d61a7 100644 (file)
@@ -509,6 +509,16 @@ public abstract class DiffRequestProcessor implements Disposable {
     ActionUtil.recursiveRegisterShortcutSet(myToolbarGroup, myMainPanel, null);
   }
 
+  @NotNull
+  public ActionToolbar getToolbar() {
+    return myToolbar;
+  }
+
+  @NotNull
+  public Wrapper getContentPanel() {
+    return myContentPanel;
+  }
+
   protected void buildActionPopup(@Nullable List<? extends AnAction> viewerActions) {
     collectPopupActions(viewerActions);
 
index 7e4dd51a1c1aae0957bcd71ecd9aacf54bcf50e3..68ee75c8757871143666b8d2903e51e066413975 100644 (file)
     <statistics.gotItTooltipAllowlist prefix="extract.method.gotit.navigate"/>
     <statistics.gotItTooltipAllowlist prefix="extract.method.signature.change"/>
     <statistics.gotItTooltipAllowlist prefix="changes.view.toolwindow"/>
+    <statistics.gotItTooltipAllowlist prefix="show.diff.in.editor"/>
     <statistics.gotItTooltipAllowlist prefix="reader.mode.got.it"/>
     <statistics.gotItTooltipAllowlist prefix="fragment.hidden"/>
 
index eeb462df99401ed4293bddbbb18a21a834ebd67f..42f85bf7e876b5e404b3308875e69865bca62e94 100644 (file)
@@ -1142,3 +1142,4 @@ todo.tab.title.changelist.suffix=Changelist
 get.from.vcs.extension.list.accessible.name=Repository Location
 vcs.dnd.image.text.n.files={0} {0, choice, 1#file|2#files}
 checking.recent.changes=Checking recent changes...
+show.diff.in.editor.tab.got.it.tooltip=To show diff in an editor tab again, use this menu.
index 8f0b243ec591e8715437c609040ceab6bf357584..3ccfca6d3bb6a479022ed8cffa1558bba38a1785 100644 (file)
     <statistics.projectUsagesCollector implementation="com.intellij.openapi.vcs.statistics.VcsOptionsUsagesCollector"/>
     <statistics.projectUsagesCollector implementation="com.intellij.openapi.vcs.statistics.VcsUsagesCollector"/>
     <statistics.notificationIdsHolder implementation="com.intellij.openapi.vcs.VcsNotificationIdsHolder"/>
+
+    <diff.editor.diffRequestProcessorEditorCustomizer implementation="com.intellij.openapi.vcs.changes.ShowDiffInEditorTooltipInstaller"/>
   </extensions>
 
   <extensions defaultExtensionNs="org.jetbrains">
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ShowDiffInEditorTooltipInstaller.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ShowDiffInEditorTooltipInstaller.kt
new file mode 100644 (file)
index 0000000..e56fcf5
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.openapi.vcs.changes
+
+import com.intellij.diff.editor.DiffRequestProcessorEditor
+import com.intellij.diff.editor.DiffRequestProcessorEditorCustomizer
+import com.intellij.diff.impl.DiffRequestProcessor
+import com.intellij.openapi.Disposable
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.util.Disposer
+import com.intellij.openapi.vcs.VcsBundle
+import com.intellij.openapi.vcs.changes.ui.ActionToolbarGotItTooltip
+import com.intellij.openapi.vcs.changes.ui.gearButton
+import com.intellij.util.ui.update.DisposableUpdate
+import com.intellij.util.ui.update.MergingUpdateQueue
+
+class ShowDiffInEditorTooltipInstaller : DiffRequestProcessorEditorCustomizer {
+
+  override fun customize(editor: DiffRequestProcessorEditor) {
+    val diffProcessor = editor.processor
+    val project = diffProcessor.project ?: return
+    ShowDiffInEditorTabTooltipHolder(project, editor, diffProcessor)
+  }
+}
+
+private class ShowDiffInEditorTabTooltipHolder(project: Project,
+                                               disposable: Disposable,
+                                               private val diffProcessor: DiffRequestProcessor) :
+  EditorDiffPreviewFilesListener, Disposable {
+
+  companion object {
+    const val TOOLTIP_ID = "show.diff.in.editor"
+  }
+
+  /**
+   * In case of multiple show tooltip request coming from different listeners, [MergingUpdateQueue] will help here to ensure that only one tooltip will be shown
+   */
+  private val notificationQueue = MergingUpdateQueue("DiffRequestNotificationQueue", 500, true, null, this)
+
+  init {
+    Disposer.register(disposable, this)
+    project.messageBus.connect(this).subscribe(EditorDiffPreviewFilesListener.TOPIC, this)
+  }
+
+  override fun shouldOpenInNewWindowChanged(shouldOpenInNewWindow: Boolean) {
+    if (shouldOpenInNewWindow) {
+      showGotItTooltip()
+    }
+  }
+
+  private fun showGotItTooltip() = notificationQueue.queue(DisposableUpdate.createDisposable(this, TOOLTIP_ID, {
+    val targetComponent = diffProcessor.contentPanel.targetComponent
+    ActionToolbarGotItTooltip(TOOLTIP_ID, VcsBundle.message("show.diff.in.editor.tab.got.it.tooltip"),
+                              this, diffProcessor.toolbar, gearButton, targetComponent)
+  }))
+
+  override fun dispose() {}
+}