繁体   English   中英

Netbeans API:如何保存当前项目中的文件或所有文件?

[英]Netbeans API: How to save a file, or all files in the current project?

我正在使用提供的API为Netbeans开发一个插件模块,以便为新的编程语言提供支持。

我在Context菜单中使用文件类型中定义的MIME类型创建了一个Action。

我正在寻找一种方法来保存被选中的文件。 优选仅在其改变时。

还可以保存项目所有文件中的所有更改吗?

我在Action Listener类中的部分代码:

    @Override
    public void actionPerformed(ActionEvent ev) {
        FileObject f = context.getPrimaryFile();
        String path = f.getPath();     
        String name = f.getName();

        //Save file here

        ExecutionDescriptor descriptor = new ExecutionDescriptor()
                .controllable(true)
                .frontWindow(true)
                .preExecution(before)
                .postExecution(after);
        ExecutionService exeService = ExecutionService.newService(
                new ProcessLaunch(cmdLine),
                descriptor, "Run " + name);
        Future<Integer> exitCode = exeService.run();

    } 

LifecycleManager.getDefault().saveAll();

这将保存项目中的所有对象。

试试这个:

FileObject f = ...
DataObject data = DataObject.find(f);
EditorCookie cookie = data.getLookup().lookup(EditorCookie.class);
cookie.saveDocument();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM