【问题标题】:How to override apply and restore defaults如何覆盖应用和恢复默认值
【发布时间】:2018-06-05 16:10:54
【问题描述】:

我想为一种文件配置一些外观设置。所以我在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. 在我的&lt;themeElementCategory&gt; 中,我必须添加一个class=MyHandlingClass,它将覆盖performApply(),但是该类应该扩展/实现什么?

  2. 同1,不过加了PropertyChangeEvent,还是不知道应该扩展/实现什么

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

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

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

我想做的事:

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

【问题讨论】:

  • 您不能覆盖首选项页面中的按钮。为什么你认为你需要?
  • @greg-449 哦,这是个坏消息……我更新了问题,提供了更多信息,说明我为什么要这样做

标签: eclipse eclipse-plugin


【解决方案1】:

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

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

manager.addPropertyChangeListener(listener);

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多