如何覆盖应用和恢复默认值

时间:2018-06-05 06:44:37

标签: eclipse eclipse-plugin

我想为一种文件配置一些外观设置。所以我在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 defaultsApplyApply and Close按钮?

  1. 在我的<themeElementCategory>中,我必须添加一个覆盖class=MyHandlingClass的{​​{1}},但该类应该扩展/实现什么?

  2. 与1相同,但添加performApply(),仍然不知道应该扩展/实施什么

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

  4. 如何实现前两个选项之一?

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

    我想做什么:

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

1 个答案:

答案 0 :(得分:1)

如果您只是想知道主题项何时更改值,请使用addPropertyChangeListener的{​​{1}}方法为更改添加侦听器:

IThemeManager

传递给IThemeManager manager = PlatformUI.getWorkbench().getThemeManager(); manager.addPropertyChangeListener(listener); PropertyChangeEvent方法的propertyChanged包含已更改主题项的ID,旧值和新值。

相关问题