mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (code compression)
This commit is contained in:
@@ -20,70 +20,38 @@ import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class CopyPathsAction extends AnAction implements DumbAware {
|
||||
|
||||
public CopyPathsAction() {
|
||||
setEnabledInModalContext(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final Collection<VirtualFile> files = getFiles(e);
|
||||
if (files.isEmpty()) {
|
||||
return;
|
||||
VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(e.getDataContext());
|
||||
if (files != null && files.length > 0) {
|
||||
CopyPasteManager.getInstance().setContents(new StringSelection(getPaths(files)));
|
||||
}
|
||||
CopyPasteManager.getInstance().setContents(new StringSelection(getPaths(files)));
|
||||
}
|
||||
|
||||
private static String getPaths(Collection<VirtualFile> files) {
|
||||
final StringBuilder buf = new StringBuilder(files.size() * 64);
|
||||
boolean first = true;
|
||||
private static String getPaths(VirtualFile[] files) {
|
||||
StringBuilder buf = new StringBuilder(files.length * 64);
|
||||
for (VirtualFile file : files) {
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
buf.append("\n");
|
||||
}
|
||||
if (buf.length() > 0) buf.append('\n');
|
||||
buf.append(file.getPresentableUrl());
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent event) {
|
||||
final Collection<VirtualFile> files = getFiles(event);
|
||||
final Presentation presentation = event.getPresentation();
|
||||
final boolean enabled = !files.isEmpty();
|
||||
presentation.setEnabled(enabled);
|
||||
if (ActionPlaces.isPopupPlace(event.getPlace())) {
|
||||
presentation.setVisible(enabled);
|
||||
}
|
||||
else {
|
||||
presentation.setVisible(true);
|
||||
}
|
||||
presentation.setText((files.size() == 1)
|
||||
? IdeBundle.message("action.copy.path")
|
||||
: IdeBundle.message("action.copy.paths"));
|
||||
VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(event.getDataContext());
|
||||
int num = files != null ? files.length : 0;
|
||||
Presentation presentation = event.getPresentation();
|
||||
presentation.setEnabled(num > 0);
|
||||
presentation.setVisible(num > 0 || !ActionPlaces.isPopupPlace(event.getPlace()));
|
||||
presentation.setText(IdeBundle.message(num == 1 ? "action.copy.path" : "action.copy.paths"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<VirtualFile> getFiles(AnActionEvent e) {
|
||||
final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(e.getDataContext());
|
||||
if (files == null || files.length == 0) return Collections.emptyList();
|
||||
final ArrayList<VirtualFile> result = new ArrayList<VirtualFile>(files.length);
|
||||
for (VirtualFile file : files) {
|
||||
if (!(file instanceof LightVirtualFile)) {
|
||||
result.add(file);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user