我正在尝试创建一个eclipse插件,将所选文件更改为只读。创建弹出菜单示例插件项目,该项目在执行时显示消息“已执行新操作”
我被困在下一步。
如何获取所选文件列表并更改文件属性?
答案 0 :(得分:1)
我没有时间正确测试以下内容,但这可能是一个很好的起点:
public class SetFileToROHandler extends AbstractHandler implements IHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection s = HandlerUtil.getCurrentSelectionChecked(event);
if (!(s instanceof IStructuredSelection))
return null;
final IStructuredSelection ss = (IStructuredSelection) s;
for (final Object o : ss.toArray()) {
if (!(o instanceof IFile)) {
continue;
}
IFile f = (IFile) o;
f.setReadOnly(true);
}
return null;
}
}