mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[patch]: cleanUp and small fixes
* use ChangelistChooser as a default focused component; * do not choose default changelist as best variant, return null instead; * update changelist text only if name was not preselected manually; * apply from clipboard to default changelist instead of newly create with strange name; * cleanUp lambdas;
This commit is contained in:
@@ -16,13 +16,11 @@
|
||||
package com.intellij.openapi.vcs.changes;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeListUtil {
|
||||
@@ -31,25 +29,16 @@ public class ChangeListUtil {
|
||||
public static LocalChangeList getPredefinedChangeList(@NotNull String defaultName, @NotNull ChangeListManager changeListManager) {
|
||||
final LocalChangeList sameNamedList = changeListManager.findChangeList(defaultName);
|
||||
if (sameNamedList != null) return sameNamedList;
|
||||
LocalChangeList list = tryToMatchWithExistingChangelist(changeListManager, defaultName);
|
||||
return list == null ? changeListManager.getDefaultChangeList() : list;
|
||||
return tryToMatchWithExistingChangelist(changeListManager, defaultName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static LocalChangeList tryToMatchWithExistingChangelist(@NotNull ChangeListManager changeListManager,
|
||||
@NotNull final String defaultName) {
|
||||
List<LocalChangeList> matched = ContainerUtil.findAll(changeListManager.getChangeListsCopy(), new Condition<LocalChangeList>() {
|
||||
@Override
|
||||
public boolean value(LocalChangeList list) {
|
||||
return defaultName.contains(list.getName().trim());
|
||||
}
|
||||
});
|
||||
List<LocalChangeList> matched = ContainerUtil.findAll(changeListManager.getChangeListsCopy(),
|
||||
list -> defaultName.contains(list.getName().trim()));
|
||||
|
||||
return matched.isEmpty() ? null : Collections.max(matched, new Comparator<LocalChangeList>() {
|
||||
@Override
|
||||
public int compare(LocalChangeList o1, LocalChangeList o2) {
|
||||
return Ints.compare(o1.getName().trim().length(), o2.getName().trim().length());
|
||||
}
|
||||
});
|
||||
return matched.isEmpty() ? null : Collections.max(matched,
|
||||
(o1, o2) -> Ints.compare(o1.getName().trim().length(), o2.getName().trim().length()));
|
||||
}
|
||||
}
|
||||
|
||||
+17
-6
@@ -110,7 +110,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
|
||||
private VirtualFileAdapter myListener;
|
||||
private final boolean myCanChangePatchFile;
|
||||
private String myHelpId = "reference.dialogs.vcs.patch.apply";
|
||||
private final String myCommitMessage; //may be provided externally; todo: parse with Additional Info Reader from patch meta information
|
||||
private final boolean myShouldUpdateChangeListName;
|
||||
|
||||
public ApplyPatchDifferentiatedDialog(final Project project, final ApplyPatchExecutor callback, final List<ApplyPatchExecutor> executors,
|
||||
@NotNull final ApplyPatchMode applyPatchMode, @NotNull final VirtualFile patchFile) {
|
||||
@@ -178,7 +178,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
|
||||
}
|
||||
new MyShowDiff().showDiff();
|
||||
});
|
||||
|
||||
myShouldUpdateChangeListName = defaultList == null && externalCommitMessage == null;
|
||||
myUpdater = new MyUpdater();
|
||||
myPatchFile = new TextFieldWithBrowseButton();
|
||||
myPatchFile.addBrowseFolderListener(VcsBundle.message("patch.apply.select.title"), "", project, descriptor);
|
||||
@@ -189,7 +189,6 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
|
||||
}
|
||||
});
|
||||
|
||||
myCommitMessage = externalCommitMessage;
|
||||
myLoadQueue = new ZipperUpdater(500, Alarm.ThreadToUse.POOLED_THREAD, getDisposable());
|
||||
myCanChangePatchFile = applyPatchMode.isCanChangePatchFile();
|
||||
myReset = myCanChangePatchFile ? this::reset : EmptyRunnable.getInstance();
|
||||
@@ -200,7 +199,12 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
|
||||
});
|
||||
ChangeListManager changeListManager = ChangeListManager.getInstance(project);
|
||||
myChangeListChooser.setChangeLists(changeListManager.getChangeListsCopy());
|
||||
myChangeListChooser.setDefaultSelection(defaultList != null ? defaultList : changeListManager.getDefaultChangeList());
|
||||
if (defaultList != null) {
|
||||
myChangeListChooser.setDefaultSelection(defaultList);
|
||||
}
|
||||
else if (externalCommitMessage != null) {
|
||||
myChangeListChooser.setDefaultName(externalCommitMessage);
|
||||
}
|
||||
myChangeListChooser.init();
|
||||
|
||||
myInfoCalculator = new ChangesLegendCalculator();
|
||||
@@ -340,6 +344,12 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
|
||||
return myHelpId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myChangeListChooser.getPreferredFocusedComponent();
|
||||
}
|
||||
|
||||
private void setPathFileChangeDefault() {
|
||||
myRecentPathFileChange.set(new FilePresentationModel(myPatchFile.getText()));
|
||||
}
|
||||
@@ -371,8 +381,9 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
|
||||
new MatchPatchPaths(myProject).execute(filePatches, myUseProjectRootAsPredefinedBase);
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
myChangeListChooser
|
||||
.setDefaultName(myCommitMessage != null ? myCommitMessage : file.getNameWithoutExtension().replace('_', ' ').trim());
|
||||
if (myShouldUpdateChangeListName) {
|
||||
myChangeListChooser.setDefaultName(file.getNameWithoutExtension().replace('_', ' ').trim());
|
||||
}
|
||||
myPatches.clear();
|
||||
myPatches.addAll(matchedPatches);
|
||||
myReader = patchReader;
|
||||
|
||||
+2
-1
@@ -43,7 +43,8 @@ public class ApplyPatchFromClipboardAction extends DumbAwareAction {
|
||||
|
||||
public MyApplyPatchFromClipboardDialog(@NotNull Project project, @NotNull String clipboardText) {
|
||||
super(project, new ApplyPatchDefaultExecutor(project), Collections.emptyList(), ApplyPatchMode.APPLY_PATCH_IN_MEMORY,
|
||||
new LightVirtualFile("clipboardPatchFile", clipboardText));
|
||||
new LightVirtualFile("clipboardPatchFile", clipboardText), null, ChangeListManager.getInstance(project).getDefaultChangeList(),
|
||||
null, null, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user