Ejemplo n.º 1
0
        private void ensure_gresource_to_file_map()
        {
            // map gresource paths to real file names
            if (gresource_to_file_map != null)
            {
                return;
            }
            gresource_to_file_map = new Dictionary <string, string>();
            foreach (var gresource in context.gresources)
            {
                if (!File.Exists(gresource))
                {
                    Report.error(null, "GResources file `%s' does not exist".printf(gresource));
                    continue;
                }

                MarkupReader reader = new MarkupReader(gresource);

                int    state  = 0;
                string prefix = null;
                string alias  = null;

                MarkupTokenType current_token = reader.read_token();
                while (current_token != MarkupTokenType.EOF)
                {
                    if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "gresource")
                    {
                        prefix = reader.get_attribute("prefix");
                    }
                    else if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "file")
                    {
                        alias = reader.get_attribute("alias");
                        state = 1;
                    }
                    else if (state == 1 && current_token == MarkupTokenType.TEXT)
                    {
                        var name     = reader.content;
                        var filename = context.get_gresource_path(gresource, name);
                        if (alias != null)
                        {
                            gresource_to_file_map[Path.build_filename(prefix, alias)] = filename;
                        }
                        gresource_to_file_map[Path.build_filename(prefix, name)] = filename;
                        state = 0;
                    }

                    current_token = reader.read_token();
                }
            }
        }
Ejemplo n.º 2
0
        private void process_current_ui_resource(string ui_resource, CodeNode node)
        {
            /* Scan a single gtkbuilder file for signal handlers in <object> elements,
             * and save an handler string -> Vala.Signal mapping for each of them */
            ensure_cclass_to_vala_map();
            ensure_gresource_to_file_map();

            current_handler_to_signal_map = null;
            current_child_to_class_map    = null;
            var ui_file = gresource_to_file_map[ui_resource];

            if (ui_file == null || !File.Exists(ui_file))
            {
                node.error = true;
                Report.error(node.source_reference, "UI resource not found: `%s'. Please make sure to specify the proper GResources xml files with --gresources and alternative search locations with --gresourcesdir.".printf(ui_resource));
                return;
            }
            current_handler_to_signal_map = new Dictionary <string, Signal>();
            current_child_to_class_map    = new Dictionary <string, Class>();

            MarkupReader reader        = new MarkupReader(ui_file);
            Class        current_class = null;

            bool            template_tag_found = false;
            MarkupTokenType current_token      = reader.read_token();

            while (current_token != MarkupTokenType.EOF)
            {
                if (current_token == MarkupTokenType.START_ELEMENT && (reader.name == "template" || reader.name == "object"))
                {
                    if (reader.name == "template")
                    {
                        template_tag_found = true;
                    }
                    var class_name = reader.get_attribute("class");
                    if (class_name != null)
                    {
                        current_class = cclass_to_vala_map[class_name];

                        var child_name = reader.get_attribute("id");
                        if (child_name != null)
                        {
                            current_child_to_class_map[child_name] = current_class;
                        }
                    }
                }
                else if (current_class != null && current_token == MarkupTokenType.START_ELEMENT && reader.name == "signal")
                {
                    var signal_name  = reader.get_attribute("name");
                    var handler_name = reader.get_attribute("handler");

                    if (current_class != null)
                    {
                        if (signal_name == null || handler_name == null)
                        {
                            Report.error(node.source_reference, "Invalid signal in ui file `%s'".printf(ui_file));
                            current_token = reader.read_token();
                            continue;
                        }
                        var sep_idx = signal_name.IndexOf("::");
                        if (sep_idx >= 0)
                        {
                            // detailed signal, we don't care about the detail
                            signal_name = signal_name.Substring(0, sep_idx);
                        }

                        var sig = SemanticAnalyzer.symbol_lookup_inherited(current_class, signal_name.Replace("-", "_")) as Signal;
                        if (sig != null)
                        {
                            current_handler_to_signal_map[handler_name] = sig;
                        }
                    }
                }
                current_token = reader.read_token();
            }

            if (!template_tag_found)
            {
                Report.error(node.source_reference, "ui resource `%s' does not describe a valid composite template".printf(ui_resource));
            }
        }