【问题标题】:Eclipse Plugin Development : How to change file attributes of selected files?Eclipse 插件开发:如何更改选定文件的文件属性?
【发布时间】:2011-06-25 11:56:47
【问题描述】:

我正在尝试创建一个 Eclipse 插件来将选定的文件更改为只读。创建了弹出菜单示例插件项目,执行时显示消息“新操作已执行”

我卡在下一步了。

如何获取选定文件列表,并更改文件属性?

【问题讨论】:

    标签: file-io eclipse-plugin


    【解决方案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;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 2016-02-25
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多