编写 Eclipse 插件来修改编辑器首选项

Writing Eclipse plugin to modify Editor Preferences(编写 Eclipse 插件来修改编辑器首选项)

本文介绍了编写 Eclipse 插件来修改编辑器首选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 Eclipse CDT 开发一个插件(工具栏按钮),用户可以在其中轻松地在 8 和 4 个空格选项卡之间切换并打开/关闭软选项卡.(为什么要问这个问题?感谢我的组织中的编码指南,用于区分 C/C++ 旧代码和新代码)

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? Thanks to the coding guideline in my org for tabbing difference between C/C++ legacy and new codes)

我设法创建了工具栏按钮,但找不到修改编辑器首选项的信息(通常在工作区首选项 General->Editors->Text Editors 中找到的那些).

I managed to create toolbar buttons but I couldn't find information to modify Editor Preferences (The ones you normally find in Workspace preferences General->Editors->Text Editors).

问题 4587572 似乎涵盖了一点,但我对插件开发还是很陌生,所以我不真懂.

The question 4587572 seems to cover a bit but I'm still very new to Plug-in dev so I don't really understand.

我想我想修改 EDITOR_TAB_WIDTH 和 EDITOR_SPACES_FOR_TABS 的属性org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants用于正在运行的文本编辑器.

I guess I want to modify EDITOR_TAB_WIDTH and EDITOR_SPACES_FOR_TABS properties of org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants for the running text Editor.

不仅修改,我什至无法使用以下代码读取属性.只返回我提供的默认值:30.

Not only modifying, I couldn't even read the properties with following code. Just returns me default value:30 I provided.

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

我的问题总结是:如何从我的插件修改正在运行的编辑器的选项卡设置?

My question in summary is: How do I modify tab settings of a running Editor from my plugin?

非常感谢您的帮助.

推荐答案

您可以使用类似于以下的代码来获取和设置任何插件中的首选项.

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

这篇关于编写 Eclipse 插件来修改编辑器首选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:编写 Eclipse 插件来修改编辑器首选项

基础教程推荐