[vcs] Merge DiffEditorTitleCustomizer getters to one which returns single class

Solution with 3 methods doesn't allow to calculate common data one time (like conflict type or current HEAD etc.)

GitOrigin-RevId: bbd2f61fdae1f5d0c7eba30ba359de8bf675a3d8
This commit is contained in:
Nikolay Rykunov
2019-11-07 02:40:58 +00:00
committed by intellij-monorepo-bot
parent 2e3a23877b
commit 80b36e43f5
3 changed files with 32 additions and 37 deletions
@@ -15,6 +15,10 @@ import org.jetbrains.annotations.ApiStatus
*/
@ApiStatus.OverrideOnly
open class MergeDialogCustomizer {
companion object {
val DEFAULT_CUSTOMIZER_LIST = DiffEditorTitleCustomizerList(null, null, null)
}
/**
* Returns the description that is shown above the list of conflicted files.
*
@@ -34,7 +38,7 @@ open class MergeDialogCustomizer {
* Returns the title that is shown above the left panel in the 3-way merge dialog.
*
* @param file the file that is being merged.
* @see getLeftTitleCustomizer
* @see getTitleCustomizerList
*/
open fun getLeftPanelTitle(file: VirtualFile): String = DiffBundle.message("merge.version.title.our")
@@ -42,7 +46,7 @@ open class MergeDialogCustomizer {
* Returns the title that is shown above the center panel in the 3-way merge dialog.
*
* @param file the file that is being merged.
* @see getCenterTitleCustomizer
* @see getTitleCustomizerList
*/
open fun getCenterPanelTitle(file: VirtualFile): String = DiffBundle.message("merge.version.title.base")
@@ -50,8 +54,8 @@ open class MergeDialogCustomizer {
* Returns the title that is shown above the right panel in the 3-way merge dialog.
*
* @param file the file that is being merged.
* @param revisionNumber the revision number of the file at the right. Can be `null` if unknown.
* @see getRightTitleCustomizer
* @param revisionNumber the revision number of the file at the right. Can be null if unknown.
* @see getTitleCustomizerList
*/
open fun getRightPanelTitle(file: VirtualFile, revisionNumber: VcsRevisionNumber?): String =
if (revisionNumber != null)
@@ -75,26 +79,16 @@ open class MergeDialogCustomizer {
open fun getColumnNames(): List<String>? = null
/**
* Allows to customize the left diff editor title in the 3-way merge dialog using [DiffEditorTitleCustomizer].
*
* This method takes precedence over [getLeftPanelTitle], which is used as a fallback only if this method returns `null`.
* Allows to customize diff editor titles in the 3-way merge dialog using [DiffEditorTitleCustomizer] for each editor.
* This method takes precedence over methods like [getLeftPanelTitle].
* If [DiffEditorTitleCustomizer] is null for the side, get(side)PanelTitle will be used as a fallback.
*/
@ApiStatus.Experimental
open fun getLeftTitleCustomizer(file: FilePath): DiffEditorTitleCustomizer? = null
open fun getTitleCustomizerList(file: FilePath): DiffEditorTitleCustomizerList = DEFAULT_CUSTOMIZER_LIST
/**
* Allows to customize the center diff editor title in the 3-way merge dialog using [DiffEditorTitleCustomizer].
*
* This method takes precedence over [getCenterPanelTitle], which is used as a fallback only if this method returns `null`.
*/
@ApiStatus.Experimental
open fun getCenterTitleCustomizer(file: FilePath): DiffEditorTitleCustomizer? = null
/**
* Allows to customize the right diff editor title in the 3-way merge dialog using [DiffEditorTitleCustomizer].
*
* This method takes precedence over [getRightPanelTitle], which is used as a fallback only if this method returns `null`.
*/
@ApiStatus.Experimental
open fun getRightTitleCustomizer(file: FilePath): DiffEditorTitleCustomizer? = null
data class DiffEditorTitleCustomizerList(
val leftTitleCustomizer: DiffEditorTitleCustomizer?,
val centerTitleCustomizer: DiffEditorTitleCustomizer?,
val rightTitleCustomizer: DiffEditorTitleCustomizer?
)
}
@@ -3,7 +3,6 @@ package com.intellij.openapi.vcs.merge
import com.intellij.CommonBundle
import com.intellij.configurationStore.StoreReloadManager
import com.intellij.diff.DiffEditorTitleCustomizer
import com.intellij.diff.DiffManager
import com.intellij.diff.DiffRequestFactory
import com.intellij.diff.InvalidDiffRequestException
@@ -388,15 +387,7 @@ open class MultipleFileMergeDialog(
}
val filePath = VcsUtil.getFilePath(file)
val mergeTitleCustomizers = mergeDialogCustomizer.run {
listOf(
getLeftTitleCustomizer(filePath),
getCenterTitleCustomizer(filePath),
getRightTitleCustomizer(filePath)
)
}
ConflictData(mergeData, title, conflictTitles, mergeTitleCustomizers)
ConflictData(mergeData, title, conflictTitles, mergeDialogCustomizer.getTitleCustomizerList(filePath))
}, "Loading Revisions...", true, project)
}
catch (ex: VcsException) {
@@ -442,7 +433,9 @@ open class MultipleFileMergeDialog(
}
break
}
request.putUserData(EDITORS_TITLE_CUSTOMIZER, conflictData.contentTitleCustomizers)
conflictData.contentTitleCustomizers.run {
request.putUserData(EDITORS_TITLE_CUSTOMIZER, listOf(leftTitleCustomizer, centerTitleCustomizer, rightTitleCustomizer))
}
DiffManager.getInstance().showMerge(project, request)
}
updateModelFromFiles()
@@ -470,6 +463,6 @@ open class MultipleFileMergeDialog(
val mergeData: MergeData,
val title: String,
val contentTitles: List<String>,
val contentTitleCustomizers: List<DiffEditorTitleCustomizer?>
val contentTitleCustomizers: MergeDialogCustomizer.DiffEditorTitleCustomizerList
)
}
@@ -521,8 +521,17 @@ public class GitRebaseProcess {
GitMergeProvider.calcColumnName(true, myBasePresentable));
}
@Nullable
@NotNull
@Override
public DiffEditorTitleCustomizerList getTitleCustomizerList(@NotNull FilePath file) {
return new DiffEditorTitleCustomizerList(
getLeftTitleCustomizer(file),
null,
getRightTitleCustomizer(file)
);
}
@Nullable
public DiffEditorTitleCustomizer getLeftTitleCustomizer(@NotNull FilePath file) {
if (myIngoingCommit == null) {
return null;
@@ -550,7 +559,6 @@ public class GitRebaseProcess {
}
@Nullable
@Override
public DiffEditorTitleCustomizer getRightTitleCustomizer(@NotNull FilePath file) {
if (myHead == null || myMergeBase == null || myUpstreamHash == null) {
return null;