action.ChangesView.NewChangeList.text=New Changelist...
action.ChangesView.NewChangeList.description=Create new changelist
action.ChangesView.Revert.text=_Rollback\u2026
+action.ChangesView.RevertFiles.text=_Rollback File\u2026
action.ChangesView.RemoveChangeList.text=Delete Changelist
action.ChangesView.RemoveChangeList.description=Remove changelist and move all changes to another
action.ChangesView.RemoveChangeList.text.template=Delete {0,choice,0#Changelist|2#Changelists}
message.title.annotate=Annotate
action.name.checkin.directory={0} {1,choice,1#Directory|2#Directories}
action.name.checkin.file={0} {1,choice,1#File|2#Files}
+action.for.file.with.dialog.text={0} {1,choice,1#File|2#Files}\u2026
column.name.revision.list.author=Author
column.name.revisions.list.filter=Date
column.name.revisions.list.branch=Branch
<action id="ChangesView.Revert" class="com.intellij.openapi.vcs.changes.actions.RollbackAction"
icon="AllIcons.Actions.Rollback"/>
+ <action id="ChangesView.RevertFiles" class="com.intellij.openapi.vcs.changes.actions.RollbackFilesAction"/>
<group id="ChangesView.ViewOptions"/>
<group id="ChangesViewPopupMenu">
<reference ref="CheckinFiles"/>
<reference ref="ChangesView.Revert"/>
+ <reference ref="ChangesView.RevertFiles"/>
<reference ref="ChangesView.Move"/>
<reference ref="Diff.ShowDiff"/>
<reference ref="EditSource"/>
<reference ref="ChangesView.ApplyPatch"/>
<reference ref="ChangesView.ApplyPatchFromClipboard"/>
<reference ref="ChangesView.Revert"/>
+ <reference ref="ChangesView.RevertFiles"/>
<reference ref="ChangesView.Refresh"/>
<reference ref="ChangesView.NewChangeList"/>
<reference ref="ChangesView.RemoveChangeList"/>
-// 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-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.
package com.intellij.openapi.vcs.actions;
import com.intellij.ide.ActionsTopHitProvider;
{"comm", "commit ", "ChangesView.ToggleCommitUi"},
{"reve", "revert ", "ChangesView.Revert"},
{"roll", "rollback ", "ChangesView.Revert"},
+ {"reve", "revert ", "ChangesView.RevertFiles"},
+ {"roll", "rollback ", "ChangesView.RevertFiles"},
{"compare", "compare ", "Compare.SameVersion"},
{"create p", "create patch ", "ChangesView.CreatePatch"},
{"pat", "patch ", "ChangesView.CreatePatch"},
package com.intellij.openapi.vcs.changes.actions;
-import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.CommonDataKeys;
+import com.intellij.openapi.actionSystem.UpdateInBackground;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import java.util.*;
+import static com.intellij.openapi.actionSystem.ActionPlaces.CHANGES_VIEW_POPUP;
import static com.intellij.openapi.ui.Messages.getQuestionIcon;
import static com.intellij.openapi.ui.Messages.showYesNoDialog;
import static com.intellij.openapi.util.text.StringUtil.ELLIPSIS;
-import static com.intellij.openapi.util.text.StringUtil.removeEllipsisSuffix;
+import static com.intellij.openapi.vcs.actions.AbstractCommonCheckinActionKt.isProjectUsesNonModalCommit;
import static com.intellij.util.containers.ContainerUtil.*;
import static com.intellij.util.containers.UtilKt.notNullize;
import static com.intellij.util.ui.UIUtil.removeMnemonic;
public class RollbackAction extends AnAction implements DumbAware, UpdateInBackground {
@Override
public void update(@NotNull AnActionEvent e) {
- Project project = e.getData(CommonDataKeys.PROJECT);
- boolean visible = project != null && ProjectLevelVcsManager.getInstance(project).hasActiveVcss();
- e.getPresentation().setEnabledAndVisible(visible);
- if (!visible) return;
+ e.getPresentation().setEnabledAndVisible(false);
+
+ Project project = e.getProject();
+ if (project == null || !ProjectLevelVcsManager.getInstance(project).hasActiveVcss()) return;
+ if (isProjectUsesNonModalCommit(e) && CHANGES_VIEW_POPUP.equals(e.getPlace())) return;
Change[] leadSelection = e.getData(VcsDataKeys.CHANGE_LEAD_SELECTION);
- boolean isEnabled =
+ boolean hasDataToRollback =
!ArrayUtil.isEmpty(leadSelection) ||
Boolean.TRUE.equals(e.getData(VcsDataKeys.HAVE_LOCALLY_DELETED)) ||
Boolean.TRUE.equals(e.getData(VcsDataKeys.HAVE_MODIFIED_WITHOUT_EDITING)) ||
hasReversibleFiles(e) ||
currentChangelistNotEmpty(project);
- e.getPresentation().setEnabled(isEnabled);
+ e.getPresentation().setVisible(true);
+ e.getPresentation().setEnabled(hasDataToRollback);
e.getPresentation().setText(getRollbackOperationName(project) + ELLIPSIS);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
- Project project = e.getData(CommonDataKeys.PROJECT);
- if (project == null) {
- return;
- }
- final String title = ActionPlaces.CHANGES_VIEW_TOOLBAR.equals(e.getPlace())
- ? null
- : VcsBundle.message("error.cant.perform.operation.now",
- removeEllipsisSuffix(removeMnemonic(getRollbackOperationName(project))));
- if (ChangeListManager.getInstance(project).isFreezedWithNotification(title)) return;
+ if (!RollbackFilesAction.checkClmActive(e)) return;
+ Project project = requireNonNull(e.getProject());
List<FilePath> missingFiles = e.getData(ChangesListView.MISSING_FILES_DATA_KEY);
Collection<Change> changes = getChanges(e);
LinkedHashSet<VirtualFile> modifiedWithoutEditing = getModifiedWithoutEditing(e, project);
--- /dev/null
+// 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.
+package com.intellij.openapi.vcs.changes.actions
+
+import com.intellij.openapi.actionSystem.ActionPlaces.CHANGES_VIEW_TOOLBAR
+import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.openapi.fileEditor.FileDocumentManager
+import com.intellij.openapi.project.DumbAwareAction
+import com.intellij.openapi.util.text.StringUtil.removeEllipsisSuffix
+import com.intellij.openapi.vcs.VcsBundle.message
+import com.intellij.openapi.vcs.VcsDataKeys
+import com.intellij.openapi.vcs.actions.isProjectUsesNonModalCommit
+import com.intellij.openapi.vcs.changes.ChangeListManager
+import com.intellij.openapi.vcs.changes.ui.ChangesListView
+import com.intellij.openapi.vcs.changes.ui.RollbackChangesDialog
+import com.intellij.util.ui.UIUtil.removeMnemonic
+import com.intellij.vcsUtil.RollbackUtil.getRollbackOperationName
+import kotlin.streams.toList
+
+class RollbackFilesAction : DumbAwareAction() {
+ override fun update(e: AnActionEvent) {
+ e.presentation.isEnabledAndVisible = false
+
+ if (!e.isProjectUsesNonModalCommit()) return
+ val project = e.project ?: return
+ val changesView = e.getData(ChangesListView.DATA_KEY) ?: return
+ val changes = changesView.selectedChanges.limit(2).toList()
+
+ with(e.presentation) {
+ isVisible = true
+ isEnabled = changes.isNotEmpty()
+ text = message("action.for.file.with.dialog.text", getRollbackOperationName(project), changes.size)
+ }
+ }
+
+ override fun actionPerformed(e: AnActionEvent) {
+ if (!checkClmActive(e)) return
+
+ val project = e.project!!
+ val changes = e.getData(VcsDataKeys.CHANGES)!!.toList()
+
+ FileDocumentManager.getInstance().saveAllDocuments()
+ RollbackChangesDialog.rollbackChanges(project, changes)
+ }
+
+ companion object {
+ @JvmStatic
+ fun checkClmActive(e: AnActionEvent): Boolean {
+ val project = e.project ?: return false
+ val title =
+ if (CHANGES_VIEW_TOOLBAR == e.place) null
+ else message("error.cant.perform.operation.now", removeEllipsisSuffix(removeMnemonic(getRollbackOperationName(project))))
+
+ return !ChangeListManager.getInstance(project).isFreezedWithNotification(title)
+ }
+ }
+}
\ No newline at end of file
<reference ref="Git.FileActions"/>
<reference ref="Show.Current.Revision"/>
<reference ref="ChangesView.Revert" />
+ <reference ref="ChangesView.RevertFiles" />
<separator/>
<reference ref="Git.ResolveConflicts" />
<separator/>
<action id="hg4idea.add" class="com.intellij.openapi.vcs.changes.actions.ScheduleForAdditionWithIgnoredFilesConfirmationAction"
icon="AllIcons.General.Add" use-shortcut-of="ChangesView.AddUnversioned"/>
<reference ref="ChangesView.Revert"/>
+ <reference ref="ChangesView.RevertFiles"/>
<separator/>
<reference ref="Compare.SameVersion"/>