首页 > 解决方案 > 如何覆盖应用和恢复默认值

问题描述

我想为一种文件配置一些外观设置。所以我在General->Appearance->Colors and Fonts.

我的plugin.xml样子是这样的:

<extension point="org.eclipse.ui.themes">
    <themeElementCategory
        id="com.example.themeElementCategory"
        label="My specific settings">
        <description>
            Control the appearance of .example files
        </description>
    </themeElementCategory>
    <colorDefinition
        categoryId="com.example.themeElementCategory"
        id="com.example.colorDefinition"
        label="Some Color"
        value="COLOR_DARK_BLUE">
        <description>
            Your description goes here
        </description>
    </colorDefinition>
    <fontDefinition
        categoryId="com.example.themeElementCategory"
        id="com.example.fontDefinition"
        label="Some Font"
        value="Lucida Sans-italic-18">
        <description>
            Description for this font
        </description>
    </fontDefinition>
</extension>

现在Colors and Fonts我有一个新条目,我可以设置颜色和字体。

如何扩展首选项窗口以便覆盖和Restore defaults按钮?ApplyApply and Close

  1. 在我的<themeElementCategory>我将不得不添加一个class=MyHandlingClass将覆盖的performApply(),但是该类应该扩展/实现什么?

  2. 与 1 相同,但添加一个PropertyChangeEvent,仍然不知道应该扩展/实现什么

  3. 不太可能,创建一个新的首选项页面,该页面扩展PreferencePage并实现IWorkbenchPreferencePage

我怎样才能实现前两个选项之一?

更新澄清
目前特定文件扩展名的颜色和字体在类中硬编码(我知道)。当文件在编辑器中打开时,信息将从该静态类中读取并在编辑器中可见。

我想做的事:

  1. 在一个static{}块中,读取首选项中配置的设置并更新我班级的静态字段。
  2. 如果用户从首选项中更改了这些设置,则在应用时,我想更新类中的静态字段并“重新绘制”编辑器。

标签: eclipseeclipse-plugin

解决方案


如果您只想知道主题项何时更改值,请使用添加监听器的addPropertyChangeListener方法IThemeManager进行更改:

IThemeManager manager = PlatformUI.getWorkbench().getThemeManager();

manager.addPropertyChangeListener(listener);

PropertyChangeEvent传递给 的方法propertyChanged包含IPropertyChangeListener更改的主题项的 id、旧值和新值。


推荐阅读