Writing Eclipse plugin to modify Editor Preferences

后端 未结 3 1594
梦毁少年i
梦毁少年i 2020-12-22 11:56

I\'d like to develop a plugin (tool bar buttons) for Eclipse CDT where users can easily switch between 8 and 4 spaces tabs and turn on/off soft tabs. (Why bother you asked?

相关标签:
3条回答
  • 2020-12-22 12:11

    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!

    0 讨论(0)
  • 2020-12-22 12:14

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

    0 讨论(0)
  • 2020-12-22 12:19

    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);
    
    0 讨论(0)
提交回复
热议问题