mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff-preview: extract Esc handler setup to common editor customizer
This will unify Esc handler setup for all components which customized by such editor customizer. GitOrigin-RevId: 2dd86a2389902fe9c1c84e64b4bb1562c9039abc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
70a13ff1ca
commit
8a20184961
+36
@@ -0,0 +1,36 @@
|
||||
// Copyright 2000-2021 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.diff.editor
|
||||
|
||||
import com.intellij.diff.impl.DiffRequestProcessor
|
||||
import com.intellij.diff.util.DiffUserDataKeysEx
|
||||
import com.intellij.diff.util.DiffUtil
|
||||
import com.intellij.diff.util.FileEditorBase
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.actionSystem.CommonShortcuts
|
||||
import com.intellij.openapi.fileEditor.FileEditor
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
class DiffFileEditorEscapeHandlerCustomizer : DiffRequestProcessorEditorCustomizer {
|
||||
|
||||
override fun customize(file: VirtualFile, editor: FileEditor, processor: DiffRequestProcessor) {
|
||||
if (editor !is FileEditorBase) return
|
||||
|
||||
if (!DiffUtil.isUserDataFlagSet(DiffUserDataKeysEx.DIFF_IN_EDITOR_WITH_EXPLICIT_DISPOSABLE, processor.context)) {
|
||||
Disposer.register(editor, Disposable {
|
||||
Disposer.dispose(processor)
|
||||
})
|
||||
}
|
||||
Disposer.register(processor, Disposable {
|
||||
editor.firePropertyChange(FileEditor.PROP_VALID, true, false)
|
||||
})
|
||||
|
||||
processor.component.registerKeyboardAction({ Disposer.dispose(editor) },
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
|
||||
file.getUserData(DiffVirtualFile.ESCAPE_HANDLER)?.registerCustomShortcutSet(CommonShortcuts.ESCAPE, editor.component, editor)
|
||||
}
|
||||
}
|
||||
@@ -2,25 +2,16 @@
|
||||
package com.intellij.diff.editor
|
||||
|
||||
import com.intellij.diff.impl.DiffRequestProcessor
|
||||
import com.intellij.diff.util.DiffUserDataKeysEx
|
||||
import com.intellij.diff.util.DiffUtil
|
||||
import com.intellij.diff.util.FileEditorBase
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.actionSystem.CommonShortcuts
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.diff.DiffBundle
|
||||
import com.intellij.openapi.fileEditor.FileEditor
|
||||
import com.intellij.openapi.fileEditor.impl.EditorWindow
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.event.ContainerAdapter
|
||||
import java.awt.event.ContainerEvent
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
open class DiffRequestProcessorEditor(
|
||||
private val file: DiffVirtualFile,
|
||||
@@ -36,19 +27,6 @@ open class DiffRequestProcessorEditor(
|
||||
|
||||
init {
|
||||
putUserData(EditorWindow.HIDE_TABS, true)
|
||||
if (!DiffUtil.isUserDataFlagSet(DiffUserDataKeysEx.DIFF_IN_EDITOR_WITH_EXPLICIT_DISPOSABLE, processor.context)) {
|
||||
Disposer.register(this, Disposable {
|
||||
Disposer.dispose(processor)
|
||||
})
|
||||
}
|
||||
Disposer.register(processor, Disposable {
|
||||
propertyChangeSupport.firePropertyChange(FileEditor.PROP_VALID, true, false)
|
||||
})
|
||||
|
||||
processor.component.registerKeyboardAction({ Disposer.dispose(this) },
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), WHEN_IN_FOCUSED_WINDOW)
|
||||
|
||||
file.getUserData(DiffVirtualFile.ESCAPE_HANDLER)?.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component, this)
|
||||
}
|
||||
|
||||
override fun getComponent(): JComponent = panel
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 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.
|
||||
// Copyright 2000-2021 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.diff.util
|
||||
|
||||
import com.intellij.codeHighlighting.BackgroundEditorHighlighter
|
||||
@@ -27,6 +27,10 @@ abstract class FileEditorBase : UserDataHolderBase(), FileEditor {
|
||||
override fun selectNotify() {}
|
||||
override fun deselectNotify() {}
|
||||
|
||||
fun firePropertyChange(propName: String, oldValue: Boolean, newValue: Boolean) {
|
||||
propertyChangeSupport.firePropertyChange(propName, oldValue, newValue)
|
||||
}
|
||||
|
||||
override fun addPropertyChangeListener(listener: PropertyChangeListener) {
|
||||
propertyChangeSupport.addPropertyChangeListener(listener)
|
||||
}
|
||||
|
||||
@@ -300,6 +300,7 @@
|
||||
<statistics.notificationIdsHolder implementation="com.intellij.openapi.vcs.VcsNotificationIdsHolder"/>
|
||||
|
||||
<diff.editor.diffRequestProcessorEditorCustomizer implementation="com.intellij.openapi.vcs.changes.ShowDiffInEditorTooltipInstaller"/>
|
||||
<diff.editor.diffRequestProcessorEditorCustomizer implementation="com.intellij.diff.editor.DiffFileEditorEscapeHandlerCustomizer"/>
|
||||
<registryKey key="patch.context.line.count" defaultValue="3" description="Number of context lines for creating patches"/>
|
||||
</extensions>
|
||||
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
// 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.
|
||||
// Copyright 2000-2021 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 org.jetbrains.plugins.github.pullrequest
|
||||
|
||||
import com.intellij.collaboration.ui.codereview.diff.MutableDiffRequestChainProcessor
|
||||
import com.intellij.diff.util.FileEditorBase
|
||||
import com.intellij.openapi.fileEditor.FileEditor.PROP_VALID
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.collaboration.ui.codereview.diff.MutableDiffRequestChainProcessor
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue
|
||||
import com.intellij.util.ui.update.Update
|
||||
import org.jetbrains.plugins.github.i18n.GithubBundle
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
internal class GHPRDiffFileEditor(project: Project,
|
||||
private val diffRequestModel: GHPRDiffRequestModel,
|
||||
@@ -29,13 +24,6 @@ internal class GHPRDiffFileEditor(project: Project,
|
||||
override fun isValid() = !Disposer.isDisposed(diffProcessor)
|
||||
|
||||
init {
|
||||
Disposer.register(this, diffProcessor)
|
||||
|
||||
diffProcessor.component.registerKeyboardAction({
|
||||
propertyChangeSupport.firePropertyChange(PROP_VALID, true, false)
|
||||
},
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), WHEN_IN_FOCUSED_WINDOW)
|
||||
|
||||
diffRequestModel.addAndInvokeRequestChainListener(diffChainUpdateQueue) {
|
||||
val chain = diffRequestModel.requestChain
|
||||
diffChainUpdateQueue.run(Update.create(diffRequestModel) {
|
||||
|
||||
Reference in New Issue
Block a user