1 // 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.
2 package org.jetbrains.plugins.github.pullrequest
4 import com.intellij.diff.util.FileEditorBase
5 import com.intellij.openapi.fileEditor.FileEditor.PROP_VALID
6 import com.intellij.openapi.project.Project
7 import com.intellij.openapi.util.Disposer
8 import com.intellij.openapi.vfs.VirtualFile
9 import com.intellij.collaboration.ui.codereview.diff.MutableDiffRequestChainProcessor
10 import com.intellij.util.ui.update.MergingUpdateQueue
11 import com.intellij.util.ui.update.Update
12 import org.jetbrains.plugins.github.i18n.GithubBundle
13 import java.awt.event.KeyEvent
14 import javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW
15 import javax.swing.KeyStroke
17 internal class GHPRDiffFileEditor(project: Project,
18 private val diffRequestModel: GHPRDiffRequestModel,
19 private val file: GHRepoVirtualFile)
22 internal val diffProcessor = MutableDiffRequestChainProcessor(project, null)
24 private val diffChainUpdateQueue =
25 MergingUpdateQueue("updateDiffChainQueue", 100, true, null, this).apply {
26 setRestartTimerOnAdd(true)
29 override fun isValid() = !Disposer.isDisposed(diffProcessor)
32 Disposer.register(this, diffProcessor)
34 diffProcessor.component.registerKeyboardAction({
35 propertyChangeSupport.firePropertyChange(PROP_VALID, true, false)
37 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), WHEN_IN_FOCUSED_WINDOW)
39 diffRequestModel.addAndInvokeRequestChainListener(diffChainUpdateQueue) {
40 val chain = diffRequestModel.requestChain
41 diffChainUpdateQueue.run(Update.create(diffRequestModel) {
42 diffProcessor.chain = chain
47 override fun getName(): String = GithubBundle.message("pull.request.editor.diff")
49 override fun getComponent() = diffProcessor.component
50 override fun getPreferredFocusedComponent() = diffProcessor.preferredFocusedComponent
52 override fun selectNotify() = diffProcessor.updateRequest()
54 override fun getFile() = file