如何通过代码启用和设置优先自动保存的时间间隔

How to enable and set the time interval of autosave in preference through code

如何以编程方式启用“编辑器”->“自动保存”首选项按钮和时间间隔。

没有官方的API。

查看处理此首选项的 org.eclipse.ui.internal.ide.dialogs.AutoSavePreferencePage,值存储在 org.eclipse.ui.workbench 插件的首选项中。

所以像这样:

IPreferenceStore prefs = 
    new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.workbench");

prefs.setValue("SAVE_AUTOMATICALLY", true);

prefs.setValue("SAVE_AUTOMATICALLY_INTERVAL", interval (as a string));

org.eclipse.ui.internal.IPreferenceConstants 包含首选项键的常量,但由于这是内部 class,不应使用它。

注意:由于这不是官方的API,它可能随时更改。