[gnome-builder/wip/slaf/xml-pack] xml-pack: automatic gtkbuilder.rng association for ui files
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/slaf/xml-pack] xml-pack: automatic gtkbuilder.rng association for ui files
- Date: Wed, 12 Jul 2017 16:48:01 +0000 (UTC)
commit af791871aaf64caf1ee8b652a5d8cd2e3500a8c3
Author: Sebastien Lafargue <slafargue gnome org>
Date: Wed Jul 12 18:45:26 2017 +0200
xml-pack: automatic gtkbuilder.rng association for ui files
If the file is recognized as a gtk builder file,
the corresponding gtkbuilder.rng file from gresources
is automatically added.
plugins/xml-pack/Makefile.am | 14 ++++++++++++++
plugins/xml-pack/ide-xml-parser-private.h | 1 +
plugins/xml-pack/ide-xml-parser.c | 19 +++++++++++++++++--
3 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/plugins/xml-pack/Makefile.am b/plugins/xml-pack/Makefile.am
index 5d5b520..0deeec1 100644
--- a/plugins/xml-pack/Makefile.am
+++ b/plugins/xml-pack/Makefile.am
@@ -1,5 +1,8 @@
if ENABLE_XML_PACK_PLUGIN
+CLEANFILES =
+DISTCLEANFILES =
+BUILT_SOURCES =
EXTRA_DIST = $(plugin_DATA)
plugindir = $(libdir)/gnome-builder/plugins
@@ -68,9 +71,20 @@ libxml_pack_plugin_la_SOURCES = \
xml-pack-plugin.c \
$(NULL)
+nodist_libxml_pack_plugin_la_SOURCES = \
+ ide-xml-resources.c \
+ ide-xml-resources.h \
+ $(NULL)
+
libxml_pack_plugin_la_CFLAGS = $(PLUGIN_CFLAGS)
libxml_pack_plugin_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+glib_resources_c = ide-xml-resources.c
+glib_resources_h = ide-xml-resources.h
+glib_resources_xml = ide-xml.gresource.xml
+glib_resources_namespace = ide_xml_pack
+include $(top_srcdir)/build/autotools/Makefile.am.gresources
+
include $(top_srcdir)/plugins/Makefile.plugin
endif
diff --git a/plugins/xml-pack/ide-xml-parser-private.h b/plugins/xml-pack/ide-xml-parser-private.h
index d48589a..13e6649 100644
--- a/plugins/xml-pack/ide-xml-parser-private.h
+++ b/plugins/xml-pack/ide-xml-parser-private.h
@@ -78,6 +78,7 @@ typedef struct _ParserState
gint64 sequence;
guint error_missing_tag_end : 1;
+ guint file_is_ui : 1;
} ParserState;
void ide_xml_parser_set_post_processing_callback (IdeXmlParser *self,
diff --git a/plugins/xml-pack/ide-xml-parser.c b/plugins/xml-pack/ide-xml-parser.c
index 11c8f7b..c0310f5 100644
--- a/plugins/xml-pack/ide-xml-parser.c
+++ b/plugins/xml-pack/ide-xml-parser.c
@@ -523,7 +523,11 @@ ide_xml_parser_processing_instruction_sax_cb (ParserState *state,
entry->kind = kind;
ide_xml_sax_get_location (self->sax_parser, &entry->line, &entry->col, NULL, NULL, NULL, NULL);
- entry->file = get_absolute_schema_file (state->file, schema_url);
+ /* We skip adding gtkbuilder.rng here and add it from gresources after the parsing */
+ if (g_str_has_suffix (schema_url, "gtkbuilder.rng"))
+ return;
+ else
+ entry->file = get_absolute_schema_file (state->file, schema_url);
/* Needed to pass the kind to the service schema fetcher */
g_object_set_data (G_OBJECT (entry->file), "kind", GUINT_TO_POINTER (entry->kind));
@@ -568,6 +572,7 @@ ide_xml_parser_get_analysis_worker (GTask *task,
IdeXmlParser *self = (IdeXmlParser *)source_object;
ParserState *state = (ParserState *)task_data;
IdeXmlAnalysis *analysis;
+ IdeXmlSchemaCacheEntry *entry;
g_autoptr(IdeDiagnostics) diagnostics = NULL;
g_autofree gchar *uri = NULL;
const gchar *doc_data;
@@ -583,7 +588,8 @@ ide_xml_parser_get_analysis_worker (GTask *task,
doc_data = g_bytes_get_data (state->content, &doc_size);
- if (ide_xml_parser_file_is_ui (state->file, doc_data, doc_size))
+ state->file_is_ui = ide_xml_parser_file_is_ui (state->file, doc_data, doc_size);
+ if (state->file_is_ui)
ide_xml_parser_ui_setup (self, state);
else
ide_xml_parser_generic_setup (self, state);
@@ -607,6 +613,15 @@ ide_xml_parser_get_analysis_worker (GTask *task,
diagnostics = ide_diagnostics_new (g_steal_pointer (&state->diagnostics_array));
ide_xml_analysis_set_diagnostics (analysis, diagnostics);
+ if (state->file_is_ui)
+ {
+ entry = ide_xml_schema_cache_entry_new ();
+ entry->kind = SCHEMA_KIND_RNG;
+ entry->file = g_file_new_for_uri
("resource:///org/gnome/builder/plugins/xml-pack-plugin/schemas/gtkbuilder.rng");
+ g_object_set_data (G_OBJECT (entry->file), "kind", GUINT_TO_POINTER (entry->kind));
+ g_ptr_array_add (state->schemas, entry);
+ }
+
if (state->schemas != NULL && state->schemas->len > 0)
ide_xml_analysis_set_schemas (analysis, g_steal_pointer (&state->schemas));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]