编写Eclipse插件以修改编辑器首选项 [英] Writing Eclipse plugin to modify Editor Preferences

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

问题描述

我想为Eclipse CDT开发一个插件(工具栏按钮),用户可以轻松地在8和4个空格标签之间切换,并打开/关闭软标签。 (为什么麻烦你问?感谢我的组织中的编码指南,以便在C / C ++遗产和新的代码之间进行区别)



我设法创建工具栏按钮,但我couldn找不到修改编辑器首选项的信息(通常在Workspace首选项中通常找到的 - >编辑器 - >文本编辑器)。



问题 4587572 似乎覆盖了一点,但我还是非常新的插件开发,所以我不太明白。



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



不仅修改,我甚至不能用以下代码来读取属性。只需返回我的默认值:30我提供了。

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

我的问题总结如下:如何从我的插件修改正在运行的编辑器的标签设置? / p>

非常感谢您的帮助。

解决方案

您可以使用类似的代码获取并设置任何插件的首选项。

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


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)

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

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

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.

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?

Much appreciate for your help.

解决方案

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插件以修改编辑器首选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆