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

2023-08-23Java开发问题
3

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

The End

相关推荐

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

Eclipse 在尝试启动 Android 应用程序时卡住了
Eclipse gets stuck when trying to launch Android app(Eclipse 在尝试启动 Android 应用程序时卡住了)...
2024-08-25 Java开发问题
14

Eclipse:无法初始化监视器线程:无法建立环回连接
Eclipse: Failed to initialize Monitor Thread: Unable to establish loopback connection(Eclipse:无法初始化监视器线程:无法建立环回连接)...
2024-08-25 Java开发问题
4

Eclipse-找不到JDK
Eclipse- JDK not found(Eclipse-找不到JDK)...
2024-08-25 Java开发问题
6

Java 首选项存储在 Windows 7 中的什么位置?
Where are the Java preferences stored in Windows 7?(Java 首选项存储在 Windows 7 中的什么位置?)...
2024-08-25 Java开发问题
9

如何让 Eclipse 在 Windows 7 任务栏中表现良好?
How to make Eclipse behave well in the Windows 7 taskbar?(如何让 Eclipse 在 Windows 7 任务栏中表现良好?)...
2024-08-25 Java开发问题
9