Writing Eclipse plugin to modify Editor Preferences

我与影子孤独终老i 提交于 2019-11-29 17:41:40

You can use code similar to the following to get and set preferences in any plugin.

IPreferenceStore s = new ScopedPreferenceStore(new InstanceScope(), "org.eclipse.ui");
ss.setValue("SHOW_MEMORY_MONITOR", true);

You should try installing and using the AnyEdit Tools which does the job -- one of the most popular eclipse plugins.

Thanks @nonty for suggestion. It works well. For benefits of others, here's my full code to change tab settings in CDT editor.

    public void run(IAction action) {
    if(action.isChecked())
    {
        IPreferenceStore ps = new ScopedPreferenceStore(new InstanceScope(), "org.eclipse.cdt.core");
        ps.setValue("org.eclipse.cdt.core.formatter.tabulation.size",  8);
        ps.setValue("org.eclipse.cdt.core.formatter.indentation.size", 8);
        ps.setValue("org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations", true);
        ps.setValue("org.eclipse.cdt.core.formatter.tabulation.char", "tab"); //=mixed/space/tab

        // To check if the value
        // int tabWidth = ps.getInt("org.eclipse.cdt.core.formatter.tabulation.size");
        // String tabFormat = ps.getString("org.eclipse.cdt.core.formatter.tabulation.char");
        // MessageDialog.openInformation(null, "CDT Tab Width", "CDT tab width: " + tabWidth + " format: " + tabFormat);
    }
}

Now all I need to do is make sure each Editor tab remembers it's Tab settings and automatically switch back when tab changes. Where do I start... doh!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!