【发布时间】:2014-11-12 08:57:56
【问题描述】:
我正在尝试在我的 Eclipse RCP 应用程序中嵌入单词。如果在单词 application 内按下 CTRL+S,保存打开的编辑器会出现问题。
我尝试了以下截图,但即使在这个(从 Eclipse 中分离)截图中,我也没有收到 DocumentBeforeSaveEvent 事件:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleEvent;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.OleListener;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class WordMain {
final static int DocumentBeforeSaveEvent = 0x00000008;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell, SWT.NONE);
shell.setLayout(new GridLayout());
frame.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
OleControlSite site = new OleControlSite(frame, SWT.NONE, "Word.Document");
OleAutomation doc = new OleAutomation(site);
int[] dispInfo = doc.getIDsOfNames(new String[] { "Application" });
Variant variant = doc.getProperty(dispInfo[0]);
OleAutomation app = variant.getAutomation();
variant.dispose();
OleListener listener = new OleListener() {
@Override
public void handleEvent(OleEvent event) {
System.out.println("DocumentBeforeSave Event, no. params:" + event.arguments.length);
}
};
site.addEventListener(app, DocumentBeforeSaveEvent, listener);
site.doVerb(OLE.OLEIVERB_OPEN);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
app.dispose();
}
}
片段来源:http://www.eclipse.org/forums/index.php/t/139593/
也许DocumentBeforeSaveEvent 是错误的eventId,我需要某种按键监听器,监听 CTRL+S?
这是所有 eventIds 的列表,DocumentBeforeSave 似乎是我唯一可以使用的:
0x2 退出
0x3 文档更改
0x4 文档打开
0x6 DocumentBeforeClose
0x7 打印前文档
0x8 DocumentBeforeSave
0x9 新文档
0xa 窗口激活
0xb 窗口停用
0xc 窗口选择更改
0xd WindowBeforeRightClick
0xe WindowBeforeDoubleClick
0xf EPostagePropertyDialog
0x10 电子邮资插入
0x11 邮件合并后合并
0x12 MailMergeAfterRecordMerge
0x13 邮件合并前合并
0x14 MailMergeBeforeRecordMerge
0x15 MailMergeDataSourceLoad
0x16 MailMergeDataSourceValidate
0x17 MailMergeWizardSendToCustom
0x18 MailMergeWizardStateChange
0x19 窗口大小
0x1a XMLSelectionChange
0x1b XMLValidationError
0x1c 文档同步
0x1d EPostageInsertEx
0x1e MailMergeDataSourceValidate2
0x1f ProtectedViewWindowOpen
0x20 ProtectedViewWindowBeforeEdit
0x21 ProtectedViewWindowBeforeClose
0x22 ProtectedViewWindowSize
0x23 ProtectedViewWindowActivate
0x24 ProtectedViewWindowDeactivate
我注意到,嵌入的单词有它自己的“保存”按钮(左上角),即使单词被修改并且应该是“脏的”,它也始终处于停用状态。所以也许激活保存按钮(或保存功能)也会触发DocumentBeforeSaveEvent 事件。
使用 MS Word 2010、Java 7。
【问题讨论】:
标签: eclipse swt eclipse-rcp rcp ole