【发布时间】:2020-11-02 01:09:56
【问题描述】:
您好,我正在使用 Eclipse ShowInSystemExplorerHandler API,如果我选择单个文件或文件夹,它工作正常。但它不适用于多选文件或文件夹。我在下面提供了代码 sn-p。请帮助我如何解决,以便我应该能够在特定于操作系统的资源管理器中打开多个文件夹/文件。顺便说一句,我正在使用structuredSelection.forEach,以便我可以打开所有文件和文件夹。
在代码下方查找。
@SuppressWarnings("restriction")
public class OpenExplorerHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
ISelectionService service = window.getSelectionService();
IStructuredSelection structuredSelection = (IStructuredSelection) service.getSelection();
structuredSelection.forEach( selctionElement -> {
if (selctionElement instanceof IAdaptable) {
IResource resource = (IResource) ((IAdaptable) selctionElement).getAdapter(IResource.class);
File selectedFileFolder = resource.getLocation().toFile();
String filePath = selectedFileFolder.getAbsolutePath();
ECommandService commandService = PlatformUI.getWorkbench().getService(ECommandService.class);
EHandlerService handlerService = PlatformUI.getWorkbench().getService(EHandlerService.class);
Command command = commandService.getCommand(ShowInSystemExplorerHandler.ID);
if (command.isDefined()) {
ParameterizedCommand parameterizedCommand = commandService
.createCommand(ShowInSystemExplorerHandler.ID, Collections.singletonMap(
ShowInSystemExplorerHandler.RESOURCE_PATH_PARAMETER, filePath));
if (handlerService.canExecute(parameterizedCommand)) {
handlerService.executeHandler(parameterizedCommand);
}
}
}
});
return null;
}
}
【问题讨论】:
-
发生了什么?我认为这会打开多个资源管理器窗口。 ShowInSystemExplorerHandler 命令处理程序仅支持打开单个路径。
-
先生,如果我选择一个文件或文件夹,它可以工作。但是如果我选择多个文件或文件夹,它不会打开。顺便说一句,我正在使用
structuredSelection.forEach( selctionElement -> { ...}进行迭代并尝试打开文件夹。
标签: eclipse eclipse-plugin swt eclipse-rcp jface