mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
[vcs-log] remove selected list from structure chooser
This commit is contained in:
@@ -38,6 +38,7 @@ import com.intellij.openapi.vcs.changes.ui.VirtualFileListCellRenderer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.components.JBPanel;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
@@ -70,22 +71,24 @@ import java.util.List;
|
||||
public class VcsStructureChooser extends DialogWrapper {
|
||||
private final static int MAX_FOLDERS = 100;
|
||||
public static final Border BORDER = IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.LEFT);
|
||||
public static final String DEFAULT_TEXT = "<html>Selected:</html>";
|
||||
public static final String CAN_NOT_ADD_TEXT = "<html>Selected: <font color=red>(You have added " + MAX_FOLDERS + " elements. No more is allowed.)</font></html>";
|
||||
|
||||
@NotNull private final Project myProject;
|
||||
|
||||
private Set<VirtualFile> myRoots;
|
||||
private Map<VirtualFile, String> myModulesSet;
|
||||
private SelectionManager mySelectionManager;
|
||||
private DefaultMutableTreeNode myRoot;
|
||||
private JBList mySelectedList;
|
||||
private JLabel mySelectedLabel;
|
||||
private Tree myTree;
|
||||
private final Set<VirtualFile> mySelectedFiles = new java.util.HashSet<VirtualFile>();
|
||||
private final List<VirtualFile> myInitialRoots;
|
||||
|
||||
private JLabel mySelectedLabel;
|
||||
private final SelectionManager mySelectionManager;
|
||||
private DefaultMutableTreeNode myRoot;
|
||||
private Tree myTree;
|
||||
|
||||
public VcsStructureChooser(@NotNull Project project,
|
||||
final String title,
|
||||
final Collection<VirtualFile> initialSelection,
|
||||
List<VirtualFile> initialRoots) {
|
||||
String title,
|
||||
Collection<VirtualFile> initialSelection,
|
||||
@NotNull List<VirtualFile> initialRoots) {
|
||||
super(project, true);
|
||||
myInitialRoots = initialRoots;
|
||||
setTitle(title);
|
||||
@@ -128,11 +131,11 @@ public class VcsStructureChooser extends DialogWrapper {
|
||||
|
||||
@NotNull
|
||||
public Collection<VirtualFile> getSelectedFiles() {
|
||||
return ((CollectionListModel) mySelectedList.getModel()).getItems();
|
||||
return mySelectedFiles;
|
||||
}
|
||||
|
||||
private void checkEmptyness() {
|
||||
setOKActionEnabled(mySelectedList.getModel().getSize() > 0);
|
||||
setOKActionEnabled(!mySelectedFiles.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -240,37 +243,23 @@ public class VcsStructureChooser extends DialogWrapper {
|
||||
}
|
||||
});
|
||||
|
||||
final Splitter splitter = new Splitter(true, 0.7f);
|
||||
Disposer.register(this.getDisposable(), new Disposable() {
|
||||
public void dispose() {
|
||||
splitter.dispose();
|
||||
}
|
||||
});
|
||||
splitter.setFirstComponent(new JBScrollPane(fileSystemTree.getTree()));
|
||||
final JPanel wrapper = new JPanel(new BorderLayout());
|
||||
mySelectedLabel = new JLabel(DEFAULT_TEXT);
|
||||
JBPanel panel = new JBPanel(new BorderLayout());
|
||||
panel.add(new JBScrollPane(fileSystemTree.getTree()), BorderLayout.CENTER);
|
||||
mySelectedLabel = new JLabel("");
|
||||
mySelectedLabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
|
||||
wrapper.add(mySelectedLabel, BorderLayout.NORTH);
|
||||
mySelectedList = new JBList(new CollectionListModel(new ArrayList<VirtualFile>()));
|
||||
mySelectedList.setCellRenderer(new WithModulesListCellRenderer(myProject, myModulesSet));
|
||||
wrapper.add(ScrollPaneFactory.createScrollPane(mySelectedList), BorderLayout.CENTER);
|
||||
splitter.setSecondComponent(wrapper);
|
||||
panel.add(mySelectedLabel, BorderLayout.SOUTH);
|
||||
|
||||
mySelectionManager.setSelectionChangeListener(new PlusMinus<VirtualFile>() {
|
||||
@Override
|
||||
public void plus(VirtualFile virtualFile) {
|
||||
final CollectionListModel model = (CollectionListModel)mySelectedList.getModel();
|
||||
model.add(virtualFile);
|
||||
model.sort(FilePathComparator.getInstance());
|
||||
mySelectedFiles.add(virtualFile);
|
||||
recalculateErrorText();
|
||||
mySelectedList.revalidate();
|
||||
mySelectedList.repaint();
|
||||
}
|
||||
|
||||
private void recalculateErrorText() {
|
||||
checkEmptyness();
|
||||
if (mySelectionManager.canAddSelection()) {
|
||||
mySelectedLabel.setText(DEFAULT_TEXT);
|
||||
mySelectedLabel.setText("");
|
||||
} else {
|
||||
mySelectedLabel.setText(CAN_NOT_ADD_TEXT);
|
||||
}
|
||||
@@ -279,43 +268,11 @@ public class VcsStructureChooser extends DialogWrapper {
|
||||
|
||||
@Override
|
||||
public void minus(VirtualFile virtualFile) {
|
||||
final CollectionListModel defaultListModel = (CollectionListModel)mySelectedList.getModel();
|
||||
for (int i = 0; i < defaultListModel.getSize(); i++) {
|
||||
final VirtualFile elementAt = (VirtualFile)defaultListModel.getElementAt(i);
|
||||
if (virtualFile.equals(elementAt)) {
|
||||
defaultListModel.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
defaultListModel.sort(FilePathComparator.getInstance());
|
||||
mySelectedFiles.remove(virtualFile);
|
||||
recalculateErrorText();
|
||||
mySelectedList.revalidate();
|
||||
mySelectedList.repaint();
|
||||
}
|
||||
});
|
||||
mySelectedList.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getModifiers() == 0 && e.getKeyCode() == KeyEvent.VK_DELETE) {
|
||||
final int[] idx = mySelectedList.getSelectedIndices();
|
||||
if (idx != null && idx.length > 0) {
|
||||
final int answer = Messages
|
||||
.showYesNoDialog(myProject, "Remove selected paths from filter?", "Remove from filter", Messages.getQuestionIcon());
|
||||
if (Messages.YES == answer) {
|
||||
Arrays.sort(idx);
|
||||
for (int i = idx.length - 1; i >= 0; --i) {
|
||||
int i1 = idx[i];
|
||||
mySelectionManager.removeSelection((VirtualFile)((CollectionListModel) mySelectedList.getModel()).getElementAt(i1));
|
||||
myTree.revalidate();
|
||||
myTree.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return splitter;
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user