From 68dcb79af3e383da397f46942ce939ad0c908eca Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Fri, 1 Mar 2019 18:01:52 +0300 Subject: [PATCH] svn: Refactor "MarkTreeConflictResolvedAction" --- .../jetbrains/idea/svn/SvnBundle.properties | 2 +- ...ocallyDeletedTreeConflictResolvedAction.kt | 3 +- .../actions/MarkTreeConflictResolvedAction.kt | 102 ++++++------------ 3 files changed, 35 insertions(+), 72 deletions(-) diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties index acb8c11fee75..ee9166e0985b 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties @@ -633,7 +633,7 @@ Select 'svn:ignore' patterns to be deleted. detect.nested.working.copies=Detect nested working copies svn.changeview.item.in.conflict.text=File has {0} conflict(s) and can not be committed svn.changeview.locally.deleted.item.in.conflict.text=File has {0} conflict(s) -action.mark.tree.conflict.resolved.text=Mark Tree Conflict Resolved... +action.Subversion.MarkTreeResolved.text=Mark Tree Conflict Resolved... action.mark.tree.conflict.resolved.confirmation.text=Do you want to mark tree conflict as resolved? action.mark.tree.conflict.resolved.confirmation.title=Mark Tree Conflict Resolved svn.integrate.changelist.warning.unresolved.conflicts.text=Integration interrupted. There are unresolved conflicts or skipped items. diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/MarkLocallyDeletedTreeConflictResolvedAction.kt b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/MarkLocallyDeletedTreeConflictResolvedAction.kt index c228a02738c4..4839ab0c424e 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/MarkLocallyDeletedTreeConflictResolvedAction.kt +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/MarkLocallyDeletedTreeConflictResolvedAction.kt @@ -23,7 +23,7 @@ import org.jetbrains.idea.svn.api.Depth /** * @author irengrig */ -class MarkLocallyDeletedTreeConflictResolvedAction : DumbAwareAction(SvnBundle.message("action.mark.tree.conflict.resolved.text")) { +class MarkLocallyDeletedTreeConflictResolvedAction : DumbAwareAction(SvnBundle.message("action.Subversion.MarkTreeResolved.text")) { override fun actionPerformed(e: AnActionEvent) { val locallyDeletedChecker = MyLocallyDeletedChecker(e) @@ -51,7 +51,6 @@ class MarkLocallyDeletedTreeConflictResolvedAction : DumbAwareAction(SvnBundle.m val locallyDeletedChecker = MyLocallyDeletedChecker(e) e.presentation.isVisible = locallyDeletedChecker.isEnabled e.presentation.isEnabled = locallyDeletedChecker.isEnabled - //e.getPresentation().setText(SvnBundle.message("action.mark.tree.conflict.resolved.text")); } private fun resolveLocallyDeletedTextConflict(checker: MyLocallyDeletedChecker, exception: Ref) { diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/MarkTreeConflictResolvedAction.kt b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/MarkTreeConflictResolvedAction.kt index 0271f029d2a1..24f67c863a59 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/MarkTreeConflictResolvedAction.kt +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/MarkTreeConflictResolvedAction.kt @@ -1,110 +1,74 @@ // 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. package org.jetbrains.idea.svn.actions -import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.progress.ProgressIndicator -import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.progress.Task -import com.intellij.openapi.project.DumbAware -import com.intellij.openapi.project.Project +import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.ui.Messages -import com.intellij.openapi.util.Ref import com.intellij.openapi.vcs.AbstractVcsHelper import com.intellij.openapi.vcs.FilePath import com.intellij.openapi.vcs.VcsDataKeys import com.intellij.openapi.vcs.VcsException import com.intellij.openapi.vcs.changes.Change +import com.intellij.openapi.vcs.changes.ChangesUtil.getAfterPath +import com.intellij.openapi.vcs.changes.ChangesUtil.getBeforePath import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager import org.jetbrains.idea.svn.ConflictedSvnChange import org.jetbrains.idea.svn.SvnBundle import org.jetbrains.idea.svn.SvnVcs import org.jetbrains.idea.svn.api.Depth -import java.util.* -class MarkTreeConflictResolvedAction : AnAction(myText), DumbAware { +private fun getConflictedChange(e: AnActionEvent) = e.getData(VcsDataKeys.CHANGE_LEAD_SELECTION)?.singleOrNull() as? ConflictedSvnChange +private fun getDistinctFiles(change: Change): Collection { + val beforePath = getBeforePath(change) + val afterPath = getAfterPath(change) + val isAddMoveRename = beforePath == null || change.isMoved || change.isRenamed + + return listOfNotNull(beforePath, if (isAddMoveRename) afterPath else null) +} + +class MarkTreeConflictResolvedAction : DumbAwareAction() { override fun update(e: AnActionEvent) { - val checker = MyChecker(e) - e.presentation.isVisible = checker.isEnabled - e.presentation.isEnabled = checker.isEnabled - e.presentation.text = myText - } + val project = e.project + val conflictedChange = getConflictedChange(e) + val enabled = project != null && conflictedChange?.conflictState?.isTree == true - private class MyChecker internal constructor(e: AnActionEvent) { - var isEnabled: Boolean - val change: ConflictedSvnChange? - val project: Project? - - init { - val dc = e.dataContext - project = CommonDataKeys.PROJECT.getData(dc) - val changes = VcsDataKeys.CHANGE_LEAD_SELECTION.getData(dc) - - if (project == null || changes == null || changes.size != 1) { - isEnabled = false - change = null - } - else { - val change = changes[0] - isEnabled = change is ConflictedSvnChange && change.conflictState.isTree - if (isEnabled) { - this.change = change as ConflictedSvnChange - } - else { - this.change = null - } - } - } + e.presentation.isEnabledAndVisible = enabled } override fun actionPerformed(e: AnActionEvent) { - val checker = MyChecker(e) - if (!checker.isEnabled) return + val project = e.project!! + val conflictedChange = getConflictedChange(e)!! val markText = SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.title") - val result = Messages.showYesNoDialog(checker.project, - SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.text"), markText, + val result = Messages.showYesNoDialog(project, SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.text"), markText, Messages.getQuestionIcon()) if (result == Messages.YES) { - val exception = Ref() - ProgressManager.getInstance().run(object : Task.Backgroundable(checker.project, markText, true) { + object : Task.Backgroundable(project, markText, true) { + private var exception: VcsException? = null + override fun run(indicator: ProgressIndicator) { - val change = checker.change - val path = change!!.treeConflictMarkHolder - val vcs = SvnVcs.getInstance(checker.project!!) + val path = conflictedChange.treeConflictMarkHolder + val vcs = SvnVcs.getInstance(project) try { vcs.getFactory(path.ioFile).createConflictClient().resolve(path.ioFile, Depth.EMPTY, false, false, true) } catch (e: VcsException) { - exception.set(e) + exception = e } - VcsDirtyScopeManager.getInstance(checker.project).filePathsDirty(getDistinctFiles(change), null) + VcsDirtyScopeManager.getInstance(project).filePathsDirty(getDistinctFiles(conflictedChange), null) } - }) - if (!exception.isNull) { - AbstractVcsHelper.getInstance(checker.project).showError(exception.get(), markText) - } - } - } - private fun getDistinctFiles(change: Change): Collection { - val result = ArrayList(2) - if (change.beforeRevision != null) { - result.add(change.beforeRevision!!.file) + override fun onSuccess() { + if (exception != null) { + AbstractVcsHelper.getInstance(project).showError(exception, markText) + } + } + }.queue() } - if (change.afterRevision != null) { - if (change.beforeRevision == null || change.beforeRevision != null && (change.isMoved || change.isRenamed)) { - result.add(change.afterRevision!!.file) - } - } - return result - } - - companion object { - private val myText = SvnBundle.message("action.mark.tree.conflict.resolved.text") } }