编写 Eclipse 插件来修改编辑器首选项
我想为 Eclipse CDT 开发一个插件(工具栏按钮),用户可以轻松地在 8 和 4 个空格选项卡之间切换并打开/关闭软选项卡。 (你为什么要问这个问题?感谢我的组织中的编码指南,用于区分 C/C++ 旧代码和新代码之间的差异)
我设法创建工具栏按钮,但找不到修改编辑器首选项的信息(您通常在工作区首选项常规 -> 编辑器 -> 文本编辑器)。
问题 4587572 似乎涵盖了一些内容,但我对插件开发仍然很陌生,所以我不太明白。
我想我想修改 EDITOR_TAB_WIDTH 和 EDITOR_SPACES_FOR_TABS 属性 org.eclipse.ui.texteditor.AbstractDecolatedTextEditorPreferenceConstants 对于正在运行的文本编辑器。
不仅修改,我什至无法使用以下代码读取属性。只是返回我提供的默认值:30。
int width = Platform.getPreferencesService().getInt(
"org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants",
"EDITOR_TAB_WIDTH", 30, null);
我的问题总结是:如何从我的插件修改正在运行的编辑器的选项卡设置?
非常感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用类似于以下的代码来获取和设置任何插件中的首选项。
You can use code similar to the following to get and set preferences in any plugin.
您应该尝试安装并使用 AnyEdit Tools 来完成这项工作——最流行的 Eclipse 插件之一。
You should try installing and using the AnyEdit Tools which does the job -- one of the most popular eclipse plugins.
感谢@nonty 的建议。效果很好。为了其他人的利益,这里是我在 CDT 编辑器中更改选项卡设置的完整代码。
现在我需要做的就是确保每个编辑器选项卡记住它的选项卡设置,并在选项卡更改时自动切换回来。我该从哪里开始……啊!
Thanks @nonty for suggestion. It works well. For benefits of others, here's my full code to change tab settings in CDT editor.
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!