mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[push] Show proposed targets in the order defined by plugins
* Let PushSupport return the sorted List. * Use the order of items in the list in the completion items comparator.
This commit is contained in:
@@ -23,7 +23,7 @@ import com.intellij.ui.SimpleColoredText;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Base class to provide vcs-specific info
|
||||
@@ -50,10 +50,11 @@ public abstract class PushSupport<Repo extends Repository, Source extends PushSo
|
||||
public abstract Target getDefaultTarget(@NotNull Repo repository);
|
||||
|
||||
/**
|
||||
* @return All remembered remote destinations used for completion
|
||||
* @return All remote destinations which will be proposed to user in the target field completion.
|
||||
* They will be shown in the same order as they appear in the returned list.
|
||||
*/
|
||||
@NotNull
|
||||
public abstract Collection<String> getTargetNames(@NotNull Repo repository);
|
||||
public abstract List<String> getTargetNames(@NotNull Repo repository);
|
||||
|
||||
/**
|
||||
* @return current source(branch) for repository
|
||||
|
||||
@@ -36,7 +36,6 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class RepositoryWithBranchPanel extends NonOpaquePanel implements TreeCellRenderer {
|
||||
@@ -51,7 +50,7 @@ public class RepositoryWithBranchPanel extends NonOpaquePanel implements TreeCel
|
||||
private String myOldDestination;
|
||||
|
||||
public RepositoryWithBranchPanel(Project project, @NotNull String repoName,
|
||||
@NotNull String sourceName, String targetName, @NotNull Collection<String> targetVariants) {
|
||||
@NotNull String sourceName, String targetName, @NotNull final List<String> targetVariants) {
|
||||
super();
|
||||
setLayout(new BorderLayout());
|
||||
myRepositoryCheckbox = new JBCheckBox();
|
||||
@@ -68,7 +67,12 @@ public class RepositoryWithBranchPanel extends NonOpaquePanel implements TreeCel
|
||||
myArrowLabel = new JLabel(" -> ");
|
||||
myOldDestination = targetName;
|
||||
TextFieldWithAutoCompletionListProvider<String> provider =
|
||||
new TextFieldWithAutoCompletion.StringsCompletionProvider(targetVariants, null);
|
||||
new TextFieldWithAutoCompletion.StringsCompletionProvider(targetVariants, null) {
|
||||
@Override
|
||||
public int compare(String item1, String item2) {
|
||||
return Integer.valueOf(ContainerUtil.indexOf(targetVariants, item1)).compareTo(ContainerUtil.indexOf(targetVariants, item2));
|
||||
}
|
||||
};
|
||||
myDestBranchTextField = new TextFieldWithAutoCompletion<String>(project, provider, true, targetName) {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1430,6 +1430,16 @@ public class ContainerUtil extends ContainerUtilRt {
|
||||
return sorted;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends Comparable> List<T> sorted(@NotNull Collection<T> list) {
|
||||
return sorted(list, new Comparator<T>() {
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> void sort(@NotNull T[] a, @NotNull Comparator<T> comparator) {
|
||||
int size = a.length;
|
||||
|
||||
@@ -1928,6 +1938,15 @@ public class ContainerUtil extends ContainerUtilRt {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static <T> int indexOf(@NotNull List<T> list, @NotNull final T object) {
|
||||
return indexOf(list, new Condition<T>() {
|
||||
@Override
|
||||
public boolean value(T t) {
|
||||
return t.equals(object);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <A,B> Map<B,A> reverseMap(@NotNull Map<A,B> map) {
|
||||
final Map<B,A> result = newHashMap();
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.zmlx.hg4idea.HgVcs;
|
||||
import org.zmlx.hg4idea.repo.HgRepository;
|
||||
import org.zmlx.hg4idea.util.HgUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class HgPushSupport extends PushSupport<HgRepository, HgPushSource, HgTarget> {
|
||||
|
||||
@@ -71,13 +71,13 @@ public class HgPushSupport extends PushSupport<HgRepository, HgPushSource, HgTar
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<String> getTargetNames(@NotNull HgRepository repository) {
|
||||
return ContainerUtil.map(repository.getRepositoryConfig().getPaths(), new Function<String, String>() {
|
||||
public List<String> getTargetNames(@NotNull HgRepository repository) {
|
||||
return ContainerUtil.sorted(ContainerUtil.map(repository.getRepositoryConfig().getPaths(), new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return HgUtil.removePasswordIfNeeded(s);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user