1 // 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.
2 package org.jetbrains.plugins.github.pullrequest
4 import com.intellij.collaboration.ui.codereview.diff.MutableDiffRequestChainProcessor
5 import com.intellij.diff.util.FileEditorBase
6 import com.intellij.openapi.project.Project
7 import com.intellij.openapi.util.Disposer
8 import com.intellij.util.ui.update.MergingUpdateQueue
9 import com.intellij.util.ui.update.Update
10 import org.jetbrains.plugins.github.i18n.GithubBundle
12 internal class GHPRDiffFileEditor(project: Project,
13 private val diffRequestModel: GHPRDiffRequestModel,
14 private val file: GHRepoVirtualFile)
17 internal val diffProcessor = MutableDiffRequestChainProcessor(project, null)
19 private val diffChainUpdateQueue =
20 MergingUpdateQueue("updateDiffChainQueue", 100, true, null, this).apply {
21 setRestartTimerOnAdd(true)
24 override fun isValid() = !Disposer.isDisposed(diffProcessor)
27 diffRequestModel.addAndInvokeRequestChainListener(diffChainUpdateQueue) {
28 val chain = diffRequestModel.requestChain
29 diffChainUpdateQueue.run(Update.create(diffRequestModel) {
30 diffProcessor.chain = chain
35 override fun getName(): String = GithubBundle.message("pull.request.editor.diff")
37 override fun getComponent() = diffProcessor.component
38 override fun getPreferredFocusedComponent() = diffProcessor.preferredFocusedComponent
40 override fun selectNotify() = diffProcessor.updateRequest()
42 override fun getFile() = file