【发布时间】:2021-05-18 21:04:48
【问题描述】:
我的目标很简单 - 将当前 HTML 文件保存在 NetBeans 编辑器中,并在文件的顶部和底部增加一行,并以“.h”为扩展名。
这是我对 NetBeans 模块的第一次尝试,但经过一些教程和研究,当您在编辑器中右键单击 HTML 文件时,我在弹出菜单中添加了一个条目。它目前只显示一条“Hello World”消息:
执行此操作的代码在这里:
package ksmiller99.savehtmlasarduinoresource;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;
@ActionID(
category = "Edit",
id = "ksmiller99.savehtmlasarduinoresource.SaveHtmlAsArduinoResource"
)
@ActionRegistration(
displayName = "#CTL_SaveHtmlAsArduinoResource"
)
@ActionReference(path = "Editors/text/html/Popup")
@Messages("CTL_SaveHtmlAsArduinoResource=Save as Arduino Resource")
public final class SaveHtmlAsArduinoResource implements ActionListener {
@Override
public void actionPerformed(ActionEvent ev) {
//todo add a line to top and bottom of current file and save with .h extension
JOptionPane.showMessageDialog(null, "Hello Save As World");
}
}
如何访问当前编辑器的内容?不同的方法会更有意义吗?
我使用的是 NetBeans 12.0、JDK 13、Windows 10。
【问题讨论】:
标签: netbeans netbeans-12 openide