代码之家  ›  专栏  ›  技术社区  ›  John Doe

如何覆盖应用和还原默认值

  •  0
  • John Doe  · 技术社区  · 7 年前

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

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

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

    3. 不太可能,创建一个扩展 PreferencePage 和工具 IWorkbenchPreferencePage

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

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

    我想做的是:

    1. 在一个 static{} 块,读取在首选项中配置的设置,并从我的类中更新静态字段。
    2. 如果用户从首选项更改这些设置,则在应用时,我希望更新类中的静态字段并“重新绘制”编辑器。
    1 回复  |  直到 7 年前
        1
  •  1
  •   greg-449    7 年前

    如果只想知道主题项何时更改值,请使用 addPropertyChangeListener 方法 IThemeManager 要为更改添加侦听器,请执行以下操作:

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

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