vcs-log: fix hiding diff preview panel in FileHistory

FileHistoryDiffProcessor does not implement ChangeViewDiffRequestProcessor.
Instead, destroy and re-create the panel when needed.

Fix regression after 8c10354d243eb5e6d35682e1d1a848d0a0c1a41b

GitOrigin-RevId: 27dcec12d559e57c3b3072472faa6e1d95f751b4
This commit is contained in:
Aleksey Pivovarov
2024-02-15 14:30:46 +01:00
committed by intellij-monorepo-bot
parent d038506a05
commit 8470728a07
4 changed files with 85 additions and 47 deletions

View File

@@ -59,6 +59,11 @@ open class TreeHandlerChangesTreeTracker(
setRestartTimerOnAdd(true)
}
init {
assert(editorViewer is CombinedDiffComponentProcessor ||
editorViewer is ChangeViewDiffRequestProcessor)
}
open fun track() {
val disposable = editorViewer.disposable
@@ -124,7 +129,16 @@ open class TreeHandlerChangesTreeTracker(
}
private fun clearPreview() {
clearDiffViewer(editorViewer)
if (editorViewer.disposable.isDisposed) return
when (editorViewer) {
is CombinedDiffComponentProcessor -> {
editorViewer.cleanBlocks()
}
is ChangeViewDiffRequestProcessor -> {
editorViewer.clear()
}
else -> fail(editorViewer)
}
}
private inner class PreviewUpdate(val updateType: UpdateType) : Update(updateType) {
@@ -150,21 +164,6 @@ open class TreeHandlerChangesTreeTracker(
enum class UpdateType {
FULL, ON_SELECTION_CHANGE, ON_MODEL_CHANGE
}
companion object {
fun clearDiffViewer(editorViewer: DiffEditorViewer) {
if (editorViewer.disposable.isDisposed) return
when (editorViewer) {
is CombinedDiffComponentProcessor -> {
editorViewer.cleanBlocks()
}
is ChangeViewDiffRequestProcessor -> {
editorViewer.clear()
}
else -> fail(editorViewer)
}
}
}
}

View File

@@ -140,9 +140,15 @@ public class FileHistoryPanel extends JPanel implements DataProvider, Disposable
tablePanel.add(actionsToolbar, BorderLayout.WEST);
setLayout(new BorderLayout());
DiffEditorViewer diffPreview = createDiffPreview(false);
FrameDiffPreview frameDiffPreview = new FrameDiffPreview(diffPreview, myProperties, tablePanel,
"vcs.history.diff.splitter.proportion", false, 0.7f);
FrameDiffPreview frameDiffPreview = new FrameDiffPreview(myProperties, tablePanel,
"vcs.history.diff.splitter.proportion", false, 0.7f,
this) {
@NotNull
@Override
protected DiffEditorViewer createViewer() {
return createDiffPreview(false);
}
};
add(frameDiffPreview.getMainComponent(), BorderLayout.CENTER);
PopupHandler.installPopupMenu(myGraphTable, VcsLogActionIds.HISTORY_POPUP_ACTION_GROUP, ActionPlaces.VCS_HISTORY_PLACE);

View File

@@ -6,7 +6,7 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.ActionToolbar
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.ui.Splitter
import com.intellij.openapi.vcs.changes.ui.TreeHandlerChangesTreeTracker
import com.intellij.openapi.util.Disposer
import com.intellij.ui.OnePixelSplitter
import com.intellij.util.ui.JBUI
import com.intellij.vcs.log.impl.CommonUiProperties
@@ -16,35 +16,62 @@ import org.jetbrains.annotations.NonNls
import javax.swing.JComponent
import kotlin.math.roundToInt
class FrameDiffPreview(val previewDiff: DiffEditorViewer,
uiProperties: VcsLogUiProperties,
mainComponent: JComponent,
@NonNls splitterProportionKey: String,
vertical: Boolean = false,
defaultProportion: Float = 0.7f) {
abstract class FrameDiffPreview(uiProperties: VcsLogUiProperties,
mainComponent: JComponent,
@NonNls splitterProportionKey: String,
vertical: Boolean = false,
defaultProportion: Float = 0.7f,
parentDisposable: Disposable) : Disposable {
private val previewDiffSplitter: Splitter = OnePixelSplitter(vertical, splitterProportionKey, defaultProportion)
val mainComponent: JComponent
get() = previewDiffSplitter
val mainComponent: JComponent get() = previewDiffSplitter
private var isDisposed = false
private var diffViewer: DiffEditorViewer? = null
init {
previewDiffSplitter.firstComponent = mainComponent
toggleDiffPreviewOnPropertyChange(uiProperties, previewDiff.disposable, ::showDiffPreview)
toggleDiffPreviewOrientationOnPropertyChange(uiProperties, previewDiff.disposable, ::changeDiffPreviewOrientation)
toggleDiffPreviewOnPropertyChange(uiProperties, this, ::showDiffPreview)
toggleDiffPreviewOrientationOnPropertyChange(uiProperties, this, ::changeDiffPreviewOrientation)
invokeLater { showDiffPreview(uiProperties.get(CommonUiProperties.SHOW_DIFF_PREVIEW)) }
Disposer.register(parentDisposable, this)
}
override fun dispose() {
isDisposed = true
diffViewer?.let { Disposer.dispose(it.disposable) }
diffViewer = null
}
protected abstract fun createViewer(): DiffEditorViewer
fun getPreferredFocusedComponent(): JComponent? {
return diffViewer?.preferredFocusedComponent
}
private fun showDiffPreview(state: Boolean) {
previewDiffSplitter.secondComponent = if (state) previewDiff.component else null
previewDiffSplitter.secondComponent?.let {
val defaultMinimumSize = it.minimumSize
if (isDisposed) return
val isShown = diffViewer != null
if (state == isShown) return
if (state) {
val newDiffViewer = createViewer()
val component = newDiffViewer.component
previewDiffSplitter.secondComponent = component
val defaultMinimumSize = component.minimumSize
val actionButtonSize = ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE
it.minimumSize = JBUI.size(defaultMinimumSize.width.coerceAtMost((actionButtonSize.width * 1.5f).roundToInt()),
defaultMinimumSize.height.coerceAtMost((actionButtonSize.height * 1.5f).roundToInt()))
component.minimumSize = JBUI.size(defaultMinimumSize.width.coerceAtMost((actionButtonSize.width * 1.5f).roundToInt()),
defaultMinimumSize.height.coerceAtMost((actionButtonSize.height * 1.5f).roundToInt()))
diffViewer = newDiffViewer
}
if (!state) {
TreeHandlerChangesTreeTracker.clearDiffViewer(previewDiff)
else {
previewDiffSplitter.secondComponent = null
Disposer.dispose(diffViewer!!.disposable)
diffViewer = null
}
}

View File

@@ -170,13 +170,17 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
myChangesBrowserSplitter.setSecondComponent(myDetailsSplitter);
setLayout(new BorderLayout());
DiffEditorViewer processor = myChangesBrowser.createChangeProcessor(false);
Disposer.register(this, processor.getDisposable());
processor.setToolbarVerticalSizeReferent(getToolbar());
myDiffPreview = new FrameDiffPreview(processor,
myUiProperties, myChangesBrowserSplitter, DIFF_SPLITTER_PROPORTION,
myDiffPreview = new FrameDiffPreview(myUiProperties, myChangesBrowserSplitter, DIFF_SPLITTER_PROPORTION,
myUiProperties.get(MainVcsLogUiProperties.DIFF_PREVIEW_VERTICAL_SPLIT),
0.7f);
0.7f, this) {
@NotNull
@Override
protected DiffEditorViewer createViewer() {
DiffEditorViewer processor = myChangesBrowser.createChangeProcessor(false);
processor.setToolbarVerticalSizeReferent(getToolbar());
return processor;
}
};
add(myDiffPreview.getMainComponent());
myHistory = VcsLogUiUtil.installNavigationHistory(logUi, myGraphTable);
@@ -416,10 +420,12 @@ public class MainFrame extends JPanel implements DataProvider, Disposable {
private class MyFocusPolicy extends ComponentsListFocusTraversalPolicy {
@Override
protected @NotNull List<Component> getOrderedComponents() {
return List.of(myGraphTable,
myChangesBrowser.getPreferredFocusedComponent(),
myDiffPreview.getPreviewDiff().getPreferredFocusedComponent(),
myFilterUi.getTextFilterComponent().getFocusedComponent());
return ContainerUtil.skipNulls(
Arrays.asList(myGraphTable,
myChangesBrowser.getPreferredFocusedComponent(),
myDiffPreview.getPreferredFocusedComponent(),
myFilterUi.getTextFilterComponent().getFocusedComponent())
);
}
}