Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse plugin 从SWT小部件正确使用GTK CSS选择器?_Eclipse Plugin_Gtk_Swt_Eclipse Rcp - Fatal编程技术网

Eclipse plugin 从SWT小部件正确使用GTK CSS选择器?

Eclipse plugin 从SWT小部件正确使用GTK CSS选择器?,eclipse-plugin,gtk,swt,eclipse-rcp,Eclipse Plugin,Gtk,Swt,Eclipse Rcp,我正在尝试将GTK+3 CSS规则应用于EclipseUI中使用的小部件,特别是现在的组合框。例如:假设我想将组合框中选定文本的背景色设置为红色。应用于combobox小部件的样式规则为 *.entry:selected { background-color: #FF0000; } 我已经在Ubuntu中使用Gtk+CSS Inspector工具证明了这条规则,并且在那里有效,但我没有找到在组合框代码中应用这条规则的方法 在SWT内部,有些地方在Linux上使用CSS,比如这个片段来设置背景色

我正在尝试将GTK+3 CSS规则应用于EclipseUI中使用的小部件,特别是现在的组合框。例如:假设我想将组合框中选定文本的背景色设置为红色。应用于combobox小部件的样式规则为

*.entry:selected { background-color: #FF0000; }
我已经在Ubuntu中使用Gtk+CSS Inspector工具证明了这条规则,并且在那里有效,但我没有找到在组合框代码中应用这条规则的方法

在SWT内部,有些地方在Linux上使用CSS,比如这个片段来设置背景色,但是,将上述规则添加到CSS覆盖中不会产生任何明显的影响(是的,背景色确实有效)

我尝试了各种选择器组合,但到目前为止还没有找到使文本的“选择”背景色生效的方法

这里有一个链接,指向SWT中处理CSS的相应ComboBox类——请参见setBackgroundColor方法

我已经证明了代码是可以运行的,并且通过改变css规则,成功地改变了整个组合框的背景。然而,如果我注入我的新规则,它就会被忽略


任何帮助都将不胜感激。谢谢

如果这是一个Eclipse4.xRCP,那么它有自己的CSS代码,这可能会覆盖基础SWT代码Hello@greg-449。虽然这是基于E4的,但E4 CSS似乎使用了SWT API,这些API最终映射到此代码中。我可以通过这个方法看到E4 CSS背景颜色的变化。如果这是一个Eclipse4.xRCP,它有自己的CSS代码,这可能会覆盖基本SWT代码Hello@greg-449。虽然这是基于E4的,但E4 CSS似乎使用了SWT API,这些API最终映射到此代码中。我可以通过这个方法看到E4 CSS背景颜色的变化。
@Override
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
    // CSS to be parsed for various widgets within Combo
    background = rgba;
    String css = "* {\n";
    if (rgba != null) {
        String color = display.gtk_rgba_to_css_string (rgba);
        css += "background: " + color + ";\n";
    }
    css += "}\n";
    // Cache background color
    cssBackground = css;
    String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND);

    //Injected code to make selected text red
    finalCss += "\n.*:selected {background-color: #FF0000}";
    if (entryHandle == 0 || (style & SWT.READ_ONLY) != 0) {
        // For read only Combos, we can just apply the background CSS to the GtkToggleButton.
        gtk_css_provider_load_from_css (OS.gtk_widget_get_style_context(buttonHandle), finalCss);
    } else {
        if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
            // For GTK3.16+, only the GtkEntry needs to be themed.
            gtk_css_provider_load_from_css (OS.gtk_widget_get_style_context(entryHandle), finalCss);
        } else {
            // Maintain GTK3.14- functionality
            setBackgroundColorGradient (OS.gtk_widget_get_style_context (entryHandle), handle, rgba);
            super.setBackgroundColor (OS.gtk_widget_get_style_context (entryHandle), entryHandle, rgba);
        }
    }
    // Set the background color of the text of the drop down menu.
    OS.g_object_set (textRenderer, OS.background_rgba, rgba, 0);
}