mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: Convert "AbstractCommonCheckinAction" to kotlin
This commit is contained in:
+79
-94
@@ -1,140 +1,125 @@
|
||||
// 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 com.intellij.openapi.vcs.actions;
|
||||
package com.intellij.openapi.vcs.actions
|
||||
|
||||
import com.intellij.configurationStore.StoreUtil;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.actionSystem.UpdateInBackground;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsBundle;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vcs.changes.ui.CommitChangeListDialog;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.intellij.configurationStore.saveDocumentsAndProjectSettings
|
||||
import com.intellij.openapi.actionSystem.Presentation
|
||||
import com.intellij.openapi.actionSystem.UpdateInBackground
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vcs.FilePath
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager
|
||||
import com.intellij.openapi.vcs.VcsBundle
|
||||
import com.intellij.openapi.vcs.changes.*
|
||||
import com.intellij.openapi.vcs.changes.ui.CommitChangeListDialog
|
||||
import com.intellij.util.ArrayUtil.isEmpty
|
||||
import com.intellij.util.ObjectUtils
|
||||
import com.intellij.util.containers.ContainerUtil.*
|
||||
import com.intellij.util.containers.stream
|
||||
import java.util.Arrays.asList
|
||||
import java.util.stream.Collectors.toSet
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.util.ArrayUtil.isEmpty;
|
||||
import static com.intellij.util.containers.ContainerUtil.concat;
|
||||
import static com.intellij.util.containers.ContainerUtil.emptyList;
|
||||
import static com.intellij.util.containers.ContainerUtil.isEmpty;
|
||||
import static com.intellij.util.containers.UtilKt.stream;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
public abstract class AbstractCommonCheckinAction extends AbstractVcsAction implements UpdateInBackground {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(AbstractCommonCheckinAction.class);
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull VcsContext context) {
|
||||
LOG.debug("actionPerformed. ");
|
||||
Project project = ObjectUtils.notNull(context.getProject());
|
||||
abstract class AbstractCommonCheckinAction : AbstractVcsAction(), UpdateInBackground {
|
||||
public override fun actionPerformed(context: VcsContext) {
|
||||
LOG.debug("actionPerformed. ")
|
||||
val project = ObjectUtils.notNull(context.project)
|
||||
|
||||
if (ChangeListManager.getInstance(project).isFreezedWithNotification("Can not " + getMnemonicsFreeActionName(context) + " now")) {
|
||||
LOG.debug("ChangeListManager is freezed. returning.");
|
||||
LOG.debug("ChangeListManager is freezed. returning.")
|
||||
}
|
||||
else if (ProjectLevelVcsManager.getInstance(project).isBackgroundVcsOperationRunning()) {
|
||||
LOG.debug("Background operation is running. returning.");
|
||||
else if (ProjectLevelVcsManager.getInstance(project).isBackgroundVcsOperationRunning) {
|
||||
LOG.debug("Background operation is running. returning.")
|
||||
}
|
||||
else {
|
||||
FilePath[] roots = prepareRootsForCommit(getRoots(context), project);
|
||||
val roots = prepareRootsForCommit(getRoots(context), project)
|
||||
ChangeListManager.getInstance(project)
|
||||
.invokeAfterUpdate(() -> performCheckIn(context, project, roots), InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE,
|
||||
VcsBundle.message("waiting.changelists.update.for.show.commit.dialog.message"), ModalityState.current());
|
||||
.invokeAfterUpdate({ performCheckIn(context, project, roots) }, InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE,
|
||||
VcsBundle.message("waiting.changelists.update.for.show.commit.dialog.message"), ModalityState.current())
|
||||
}
|
||||
}
|
||||
|
||||
protected void performCheckIn(@NotNull VcsContext context, @NotNull Project project, @NotNull FilePath[] roots) {
|
||||
LOG.debug("invoking commit dialog after update");
|
||||
LocalChangeList initialSelection = getInitiallySelectedChangeList(context, project);
|
||||
Change[] selectedChanges = context.getSelectedChanges();
|
||||
List<Change> selectedChangesList = isEmpty(selectedChanges) ? emptyList() : asList(selectedChanges);
|
||||
List<VirtualFile> selectedUnversioned = context.getSelectedUnversionedFiles();
|
||||
Collection<Change> changesToCommit;
|
||||
Collection<?> included;
|
||||
protected open fun performCheckIn(context: VcsContext, project: Project, roots: Array<FilePath>) {
|
||||
LOG.debug("invoking commit dialog after update")
|
||||
val initialSelection = getInitiallySelectedChangeList(context, project)
|
||||
val selectedChanges = context.selectedChanges
|
||||
val selectedChangesList = if (isEmpty(selectedChanges)) emptyList() else asList(*selectedChanges!!)
|
||||
val selectedUnversioned = context.selectedUnversionedFiles
|
||||
val changesToCommit: Collection<Change>
|
||||
val included: Collection<*>
|
||||
if (!isEmpty(selectedChangesList) || !isEmpty(selectedUnversioned)) {
|
||||
changesToCommit = selectedChangesList;
|
||||
included = concat(selectedChangesList, selectedUnversioned);
|
||||
changesToCommit = selectedChangesList
|
||||
included = concat(selectedChangesList, selectedUnversioned)
|
||||
}
|
||||
else {
|
||||
changesToCommit = getChangesIn(project, roots);
|
||||
included = changesToCommit;
|
||||
changesToCommit = getChangesIn(project, roots)
|
||||
included = changesToCommit
|
||||
}
|
||||
|
||||
CommitChangeListDialog.commitChanges(project, changesToCommit, included, initialSelection, getExecutor(project), null);
|
||||
CommitChangeListDialog.commitChanges(project, changesToCommit, included, initialSelection, getExecutor(project), null)
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<Change> getChangesIn(@NotNull Project project, @NotNull FilePath[] roots) {
|
||||
ChangeListManager manager = ChangeListManager.getInstance(project);
|
||||
return stream(roots)
|
||||
.flatMap(path -> manager.getChangesIn(path).stream())
|
||||
.collect(toSet());
|
||||
protected open fun prepareRootsForCommit(roots: Array<FilePath>, project: Project): Array<FilePath> {
|
||||
project.saveDocumentsAndProjectSettings()
|
||||
|
||||
return DescindingFilesFilter.filterDescindingFiles(roots, project)
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected FilePath[] prepareRootsForCommit(@NotNull FilePath[] roots, @NotNull Project project) {
|
||||
StoreUtil.saveDocumentsAndProjectSettings(project);
|
||||
|
||||
return DescindingFilesFilter.filterDescindingFiles(roots, project);
|
||||
protected open fun getMnemonicsFreeActionName(context: VcsContext): String? {
|
||||
return getActionName(context)
|
||||
}
|
||||
|
||||
protected String getMnemonicsFreeActionName(@NotNull VcsContext context) {
|
||||
return getActionName(context);
|
||||
protected open fun getExecutor(project: Project): CommitExecutor? {
|
||||
return null
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected CommitExecutor getExecutor(@NotNull Project project) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected LocalChangeList getInitiallySelectedChangeList(@NotNull VcsContext context, @NotNull Project project) {
|
||||
LocalChangeList result;
|
||||
ChangeListManager manager = ChangeListManager.getInstance(project);
|
||||
ChangeList[] changeLists = context.getSelectedChangeLists();
|
||||
protected open fun getInitiallySelectedChangeList(context: VcsContext, project: Project): LocalChangeList? {
|
||||
val result: LocalChangeList?
|
||||
val manager = ChangeListManager.getInstance(project)
|
||||
val changeLists = context.selectedChangeLists
|
||||
|
||||
if (!isEmpty(changeLists)) {
|
||||
// convert copy to real
|
||||
result = manager.findChangeList(changeLists[0].getName());
|
||||
result = manager.findChangeList(changeLists!![0].name)
|
||||
}
|
||||
else {
|
||||
Change[] changes = context.getSelectedChanges();
|
||||
result = !isEmpty(changes) ? manager.getChangeList(changes[0]) : manager.getDefaultChangeList();
|
||||
val changes = context.selectedChanges
|
||||
result = if (!isEmpty(changes)) manager.getChangeList(changes!![0]) else manager.defaultChangeList
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
protected abstract String getActionName(@NotNull VcsContext dataContext);
|
||||
protected abstract fun getActionName(dataContext: VcsContext): String?
|
||||
|
||||
@NotNull
|
||||
protected abstract FilePath[] getRoots(@NotNull VcsContext dataContext);
|
||||
protected abstract fun getRoots(dataContext: VcsContext): Array<FilePath>
|
||||
|
||||
protected abstract boolean approximatelyHasRoots(@NotNull VcsContext dataContext);
|
||||
protected abstract fun approximatelyHasRoots(dataContext: VcsContext): Boolean
|
||||
|
||||
@Override
|
||||
protected void update(@NotNull VcsContext vcsContext, @NotNull Presentation presentation) {
|
||||
Project project = vcsContext.getProject();
|
||||
override fun update(vcsContext: VcsContext, presentation: Presentation) {
|
||||
val project = vcsContext.project
|
||||
|
||||
if (project == null || !ProjectLevelVcsManager.getInstance(project).hasActiveVcss()) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
presentation.isEnabledAndVisible = false
|
||||
}
|
||||
else if (!approximatelyHasRoots(vcsContext)) {
|
||||
presentation.setEnabled(false);
|
||||
presentation.isEnabled = false
|
||||
}
|
||||
else {
|
||||
presentation.setText(getActionName(vcsContext) + "...");
|
||||
presentation.setEnabled(!ProjectLevelVcsManager.getInstance(project).isBackgroundVcsOperationRunning());
|
||||
presentation.setVisible(true);
|
||||
presentation.text = getActionName(vcsContext) + "..."
|
||||
presentation.isEnabled = !ProjectLevelVcsManager.getInstance(project).isBackgroundVcsOperationRunning
|
||||
presentation.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val LOG = Logger.getInstance(AbstractCommonCheckinAction::class.java)
|
||||
|
||||
private fun getChangesIn(project: Project, roots: Array<FilePath>): Set<Change> {
|
||||
val manager = ChangeListManager.getInstance(project)
|
||||
return roots.stream()
|
||||
.flatMap { path -> manager.getChangesIn(path).stream() }
|
||||
.collect(toSet())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user