简体   繁体   English

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

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

I'm developing a plugin module for Netbeans using the provided API in order to provide support for a new programming language. 我正在使用提供的API为Netbeans开发一个插件模块,以便为新的编程语言提供支持。

I've created an Action in the Context Menu, using the MIME-type defined in a File Type. 我在Context菜单中使用文件类型中定义的MIME类型创建了一个Action。

I looking for a method to save the file that's being selected. 我正在寻找一种方法来保存被选中的文件。 Preferably only if it's changed. 优选仅在其改变时。

Also is it possible to save all the changes in all the files of the project? 还可以保存项目所有文件中的所有更改吗?

Part of my code from the Action Listener class: 我在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();

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

try this: 试试这个:

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