[gtk+/key-themes: 2/8] Add @binding-set rules to the CSS parser



commit 5acd30e6da9f88a2e735aeaffb0423081e50a93b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jan 28 01:52:03 2011 +0100

    Add @binding-set rules to the CSS parser
    
    these custom rules can be used to define key themes
    as in the RC files, a series of bind/unbind rules
    may be added then:
    
    @binding foo-bar {
      bind "<alt>1" { "move-cursor" (visual-positions, 1, 0) };
      unbind "<ctl>d"
    }

 gtk/gtkcssprovider.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 56 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 61972f9..78c4fe2 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -33,6 +33,7 @@
 #include "gtkthemingengine.h"
 #include "gtkstyleprovider.h"
 #include "gtkstylecontextprivate.h"
+#include "gtkbindings.h"
 #include "gtkprivate.h"
 
 /**
@@ -1475,7 +1476,7 @@ scanner_apply_scope (GScanner    *scanner,
   if (scope == SCOPE_VALUE)
     {
       scanner->config->cset_identifier_first = G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "@#-_";
-      scanner->config->cset_identifier_nth = G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "@#-_ +(),.%\t\n'/\"";
+      scanner->config->cset_identifier_nth = G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS "@#-_ +(){}<>,.%\t\n'/\"";
       scanner->config->scan_identifier_1char = TRUE;
     }
   else if (scope == SCOPE_SELECTOR)
@@ -3233,6 +3234,60 @@ parse_rule (GtkCssProvider  *css_provider,
           else
             return G_TOKEN_NONE;
         }
+      else if (strcmp (directive, "binding-set") == 0)
+        {
+          GtkBindingSet *binding_set;
+          gchar *binding_set_name;
+
+          g_scanner_get_next_token (scanner);
+
+          if (scanner->token != G_TOKEN_IDENTIFIER)
+            {
+              scanner->user_data = "Binding name";
+              return G_TOKEN_IDENTIFIER;
+            }
+
+          binding_set_name = scanner->value.v_identifier;
+          binding_set = gtk_binding_set_find (scanner->value.v_identifier);
+
+          if (!binding_set)
+            {
+              binding_set = gtk_binding_set_new (scanner->value.v_identifier);
+              binding_set->parsed = TRUE;
+            }
+
+          g_scanner_get_next_token (scanner);
+
+          if (scanner->token != G_TOKEN_LEFT_CURLY)
+            return G_TOKEN_LEFT_CURLY;
+
+          css_provider_push_scope (css_provider, SCOPE_VALUE);
+          g_scanner_get_next_token (scanner);
+
+          do
+            {
+              if (scanner->token != G_TOKEN_IDENTIFIER)
+                {
+                  scanner->user_data = "Binding definition";
+                  return G_TOKEN_IDENTIFIER;
+                }
+
+              gtk_binding_entry_add_signal_from_string (binding_set,
+                                                        scanner->value.v_identifier);
+              g_scanner_get_next_token (scanner);
+
+              if (scanner->token != ';')
+                return ';';
+
+              g_scanner_get_next_token (scanner);
+            }
+          while (scanner->token != G_TOKEN_RIGHT_CURLY);
+
+          css_provider_pop_scope (css_provider);
+          g_scanner_get_next_token (scanner);
+
+          return G_TOKEN_NONE;
+        }
       else
         {
           scanner->user_data = "Directive";



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]