GTW-8778 [rdct] fix UiNotifyConnector not initializing diff previews in RemDev

GitOrigin-RevId: 91e21a5274abc706fe240e673535a4cfc805e719
This commit is contained in:
Aleksey Pivovarov
2024-05-24 20:15:41 +02:00
committed by intellij-monorepo-bot
parent ead4484e59
commit ccf038d771
9 changed files with 57 additions and 28 deletions

View File

@@ -2802,6 +2802,8 @@ f:com.intellij.diff.util.DiffUtil
- s:installLineConvertor(com.intellij.openapi.editor.ex.EditorEx,com.intellij.diff.contents.DocumentContent):V
- s:installLineConvertor(com.intellij.openapi.editor.ex.EditorEx,com.intellij.diff.contents.DocumentContent,com.intellij.diff.tools.util.FoldingModelSupport,I):V
- s:installLineConvertor(com.intellij.openapi.editor.ex.EditorEx,com.intellij.diff.tools.util.FoldingModelSupport):V
- s:installShowNotifyListener(javax.swing.JComponent,com.intellij.util.ui.update.Activatable):V
- s:installShowNotifyListener(javax.swing.JComponent,java.lang.Runnable):V
- s:invertIndexes(I[]):I[]
- s:isDiffEditor(com.intellij.openapi.editor.Editor):Z
- s:isEditable(com.intellij.openapi.editor.Editor):Z
@@ -2830,6 +2832,7 @@ f:com.intellij.diff.util.DiffUtil
- s:requestFocus(com.intellij.openapi.project.Project,java.awt.Component):V
- s:requestFocusInWindow(java.awt.Component):V
- s:runPreservingFocus(com.intellij.diff.FocusableContext,java.lang.Runnable):V
- s:runWhenFirstShown(javax.swing.JComponent,java.lang.Runnable):V
- s:scrollEditor(com.intellij.openapi.editor.Editor,I,I,Z):V
- s:scrollEditor(com.intellij.openapi.editor.Editor,I,Z):V
- s:scrollToCaret(com.intellij.openapi.editor.Editor,Z):V

View File

@@ -65,9 +65,7 @@ import com.intellij.util.concurrency.annotations.RequiresEdt;
import com.intellij.util.concurrency.annotations.RequiresWriteLock;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.update.Activatable;
import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.UiNotifyConnector;
import com.intellij.util.ui.update.Update;
import com.intellij.xml.breadcrumbs.NavigatableCrumb;
import org.jetbrains.annotations.Nls;
@@ -159,12 +157,7 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase implements EditorD
myPanel.setPersistentNotifications(DiffUtil.createCustomNotifications(this, myContext, myRequest));
DiffTitleHandler.createHandler(() -> createTitles(), myContentPanel, myRequest, this);
UiNotifyConnector.installOn(getComponent(), new Activatable() {
@Override
public void showNotify() {
myMarkupUpdater.scheduleUpdate();
}
});
DiffUtil.installShowNotifyListener(getComponent(), () -> myMarkupUpdater.scheduleUpdate());
}
@Override

View File

@@ -21,6 +21,7 @@ import com.intellij.diff.FrameDiffTool.DiffViewer;
import com.intellij.diff.requests.ContentDiffRequest;
import com.intellij.diff.tools.util.DiffDataKeys;
import com.intellij.diff.util.DiffTaskQueue;
import com.intellij.diff.util.DiffUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -36,7 +37,6 @@ import com.intellij.util.concurrency.annotations.RequiresBackgroundThread;
import com.intellij.util.concurrency.annotations.RequiresEdt;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.update.Activatable;
import com.intellij.util.ui.update.UiNotifyConnector;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -82,7 +82,7 @@ public abstract class DiffViewerBase implements DiffViewer, DataProvider {
fireEvent(EventType.INIT);
UiNotifyConnector.installOn(getComponent(), new Activatable() {
DiffUtil.installShowNotifyListener(getComponent(), new Activatable() {
private boolean wasNotShownYet = true;
@Override

View File

@@ -101,6 +101,8 @@ import com.intellij.util.ui.JBValue;
import com.intellij.util.ui.SingleComponentCenteringLayout;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.components.BorderLayoutPanel;
import com.intellij.util.ui.update.Activatable;
import com.intellij.util.ui.update.UiNotifyConnector;
import icons.PlatformDiffImplIcons;
import org.jetbrains.annotations.*;
@@ -559,6 +561,43 @@ public final class DiffUtil {
return result.wrapWithHtmlBody().toString();
}
/**
* RemDev-friendly UI listener
* <p>
* {@link UIUtil#markAsShowing} is not firing the events, so the components with delayed intitialization will not function correctly.
*/
public static void runWhenFirstShown(@NotNull JComponent component, @NotNull Runnable runnable) {
if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
runnable.run();
}
else {
UiNotifyConnector.doWhenFirstShown(component, runnable);
}
}
public static void installShowNotifyListener(@NotNull JComponent component, @NotNull Runnable runnable) {
installShowNotifyListener(component, new Activatable() {
@Override
public void showNotify() {
runnable.run();
}
});
}
/**
* RemDev-friendly UI listener
* <p>
* {@link UIUtil#markAsShowing} is not firing the events, so the components with delayed intitialization will not function correctly.
*/
public static void installShowNotifyListener(@NotNull JComponent component, @NotNull Activatable activatable) {
if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
activatable.showNotify();
}
else {
UiNotifyConnector.installOn(component, activatable);
}
}
//
// Titles
//

View File

@@ -5,6 +5,7 @@ import com.intellij.diff.chains.DiffRequestProducer
import com.intellij.diff.impl.DiffEditorViewer
import com.intellij.diff.impl.DiffRequestProcessor
import com.intellij.diff.impl.DiffRequestProcessorListener
import com.intellij.diff.util.DiffUtil
import com.intellij.history.integration.LocalHistoryBundle
import com.intellij.openapi.Disposable
import com.intellij.openapi.ListSelection
@@ -20,7 +21,6 @@ import com.intellij.platform.lvcs.impl.filePath
import com.intellij.platform.lvcs.impl.statistics.LocalHistoryCounter
import com.intellij.util.EventDispatcher
import com.intellij.util.ui.update.Activatable
import com.intellij.util.ui.update.UiNotifyConnector
import org.jetbrains.annotations.Nls
internal class SingleFileActivityDiffPreview(project: Project, private val model: ActivityViewModel, disposable: Disposable) : EditorTabDiffPreview(project) {
@@ -69,9 +69,7 @@ internal class SingleFileActivityDiffPreview(project: Project, private val model
model.addListener(object : ActivityModelListener {
override fun onSelectionChanged(selection: ActivitySelection?) = processor.updatePreview()
}, processor)
UiNotifyConnector.installOn(processor.component, object : Activatable {
override fun showNotify() = processor.updatePreview()
})
DiffUtil.installShowNotifyListener(processor.component) { processor.updatePreview() }
return processor
}
}

View File

@@ -4,11 +4,12 @@ package com.intellij.openapi.vcs.changes;
import com.intellij.diff.impl.CacheDiffRequestProcessor
import com.intellij.diff.requests.NoDiffRequest
import com.intellij.openapi.project.Project;
import com.intellij.util.ui.UIUtil
abstract class SingleFileDiffPreviewProcessor(project: Project, place: String) : CacheDiffRequestProcessor.Simple(project, place), DiffPreviewUpdateProcessor {
fun updatePreview() {
val state = component.isShowing
val state = UIUtil.isShowing(component)
if (state) {
refresh(false)
}

View File

@@ -2,6 +2,7 @@
package com.intellij.openapi.vcs.changes.actions.diff;
import com.intellij.diff.actions.impl.GoToChangePopupBuilder;
import com.intellij.diff.util.DiffUtil;
import com.intellij.openapi.ListSelection;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -20,7 +21,6 @@ import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.ui.tree.TreeUtil;
import com.intellij.util.ui.update.UiNotifyConnector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -140,7 +140,7 @@ public abstract class PresentableGoToChangePopupAction<T> extends GoToChangePopu
viewer.requestRefresh();
if (myChanges.getSelectedIndex() != -1) {
UiNotifyConnector.doWhenFirstShown(this, () -> {
DiffUtil.runWhenFirstShown(this, () -> {
viewer.invokeAfterRefresh(() -> {
DefaultMutableTreeNode toSelect = TreeUtil.findNode(myViewer.getRoot(), node -> {
return node instanceof GenericChangesBrowserNode &&

View File

@@ -5,6 +5,7 @@ import com.intellij.diagnostic.Checks.fail
import com.intellij.diff.chains.DiffRequestProducer
import com.intellij.diff.impl.DiffEditorViewer
import com.intellij.diff.tools.combined.*
import com.intellij.diff.util.DiffUtil
import com.intellij.openapi.ListSelection
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vcs.changes.Change
@@ -17,7 +18,6 @@ import com.intellij.util.ui.UIUtil
import com.intellij.util.ui.tree.TreeUtil
import com.intellij.util.ui.update.Activatable
import com.intellij.util.ui.update.MergingUpdateQueue
import com.intellij.util.ui.update.UiNotifyConnector
import com.intellij.util.ui.update.Update
import java.awt.event.FocusAdapter
import java.awt.event.FocusEvent
@@ -96,7 +96,7 @@ open class TreeHandlerChangesTreeTracker(
}
if (updateWhileShown) {
UiNotifyConnector.installOn(editorViewer.component, object : Activatable {
DiffUtil.installShowNotifyListener(editorViewer.component, object : Activatable {
override fun showNotify() {
updatePreview(UpdateType.FULL)
updatePreviewQueue.cancelAllUpdates()

View File

@@ -2,6 +2,7 @@
package com.intellij.vcs.log.history;
import com.intellij.diff.impl.DiffEditorViewer;
import com.intellij.diff.util.DiffUtil;
import com.intellij.ide.ui.customization.CustomActionsSchema;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
@@ -25,8 +26,6 @@ import com.intellij.ui.switcher.QuickActionProvider;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.components.BorderLayoutPanel;
import com.intellij.util.ui.table.ComponentsListFocusTraversalPolicy;
import com.intellij.util.ui.update.Activatable;
import com.intellij.util.ui.update.UiNotifyConnector;
import com.intellij.vcs.log.UnsupportedHistoryFiltersException;
import com.intellij.vcs.log.VcsCommitMetadata;
import com.intellij.vcs.log.VcsLogBundle;
@@ -236,6 +235,7 @@ class FileHistoryPanel extends JPanel implements UiDataProvider, Disposable {
@NotNull
FileHistoryDiffProcessor createDiffPreview(boolean isInEditor) {
FileHistoryDiffProcessor diffPreview = new FileHistoryDiffProcessor(myProject, () -> getSelectedChange(), isInEditor, this);
ListSelectionListener selectionListener = e -> {
int[] selection = myGraphTable.getSelectedRows();
ApplicationManager.getApplication().invokeLater(() -> diffPreview.updatePreview(),
@@ -251,16 +251,11 @@ class FileHistoryPanel extends JPanel implements UiDataProvider, Disposable {
o -> Disposer.isDisposed(diffPreview));
}
};
UiNotifyConnector.installOn(diffPreview.getComponent(), new Activatable() {
@Override
public void showNotify() {
diffPreview.updatePreview();
}
});
myGraphTable.getModel().addTableModelListener(modelListener);
Disposer.register(diffPreview, () -> myGraphTable.getModel().removeTableModelListener(modelListener));
DiffUtil.installShowNotifyListener(diffPreview.getComponent(), () -> diffPreview.updatePreview());
return diffPreview;
}