如何将键绑定添加到gtk3应用程序?

luk*_*sen 5 css c gtk3

我正在尝试通过css将键绑定添加到gtk3应用程序中.这是我到目前为止:

// add style provider
GtkCssProvider *css = gtk_css_provider_new();                               
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),         
        GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);         
gtk_css_provider_load_from_path(css, "bindings.css", NULL);
Run Code Online (Sandbox Code Playgroud)

这是在前一个代码段中加载的'bindings.css':

@binding-set tree-view-bindings {
    bind "j" { "move-cursor" (display-lines, 1) };
    bind "k" { "move-cursor" (display-lines, -1) };
    bind "slash" { "start-interactive-search" () };
}

GtkTreeView {
    color: #F00;
    gtk-key-bindings: tree-view-bindings;
}
Run Code Online (Sandbox Code Playgroud)

颜色设置有效,因此不能完全破碎.但没有一个键绑定工作.我错过了什么?

小智 0

如果我错了,请原谅我,但我相信你把分号放在了错误的地方:)

@binding-set tree-view-bindings { bind "j" { "move-cursor" (display-lines, 1); } bind "k" { "move-cursor" (display-lines, -1); } bind "slash" { "start-interactive-search" (); } }