簡體   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