Writing an Eclipse Plugin to Change Editor Settings

I would like to develop a plugin (toolbar button) for the Eclipse CDT, where users can easily switch between 8 and 4 space tabs and enable / disable soft tabs. (Why worry what you asked? Thanks to the coding guide in my organization for distinguishing tabs between C / C ++ legacy and new codes)

I managed to create buttons on the toolbar, but I could not find information for changing the editor settings (those that you usually find in the settings of the General โ†’ Editors-> Text editors workspace).

Question 4587572 seems to cover a bit, but I'm still very new to the plugin, so I really don't get it.

I think I want to change the properties EDITOR_TAB_WIDTH and EDITOR_SPACES_FOR_TABS org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants for an executable text editor.

Not only a modification, I could not even read the properties with the following code. Just returns the default value: 30 I provided.

int width = Platform.getPreferencesService().getInt(
    "org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants",
    "EDITOR_TAB_WIDTH", 30, null);

My question is this: how do I change the tab settings of a working editor from my plugin?

Thank you very much for your help.

0
source share
3 answers

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

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

AnyEdit Tools, - eclipse.

0

@nonty . . , CDT.

    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);
    }
}

, , , "" "" . ... doh!

0

Source: https://habr.com/ru/post/1723874/


All Articles