Commit Graph

109 Commits

Author SHA1 Message Date
Timm Bäder
7789d0e23f builder: Make object names a const array
We don't take ownership.
2020-03-07 15:30:38 +01:00
Benjamin Otte
e356d59a92 build: Add -Wnull-dereference
Sprinkle various g_assert() around the code where gcc cannot figure out
on its own that a variable is not NULL and too much refactoring would be
needed to make it do that.

Also fix usage of g_assert_nonnull(x) to use g_assert(x) because the
first is not marked as G_GNUC_NORETURN because of course GTester
supports not aborting on aborts.
2020-03-05 08:14:37 +01:00
Alexander Larsson
e134eef505 builder: Don't add profiler marks for short parses
There are a lot of thes (since we're recursing), so don't spew the
output with uninteresting ones.
2020-02-12 12:42:29 +01:00
Alexander Larsson
2890cd849f profiler: Add _end_mark() version of _add_mark()
These don't take a duration, instead they call g_get_monotonic_time() to
and subtract the start time for it.

Almost all our calls are like this, and this makes the callsites clearer
and avoids inlining the clock call into the call site.
2020-02-12 11:25:34 +01:00
Alexander Larsson
cc643df88b Convert all profiler times from nsec to usec
usec is the scale of the monotonic timer which is where we get almost
all the times from. The only actual source of nsec is the opengl
GPU time (but who knows what the actual resulution of that is).

Changing this to usec allows us to get rid of " * 1000" in a *lot* of
places all over the codebase, which are ugly and confusing.
2020-02-12 10:44:17 +01:00
Matthias Clasen
cb60c1b83d builder: Add profiler marks for parsing
This is useful to understand what ui files take
long to load.
2020-01-30 10:04:38 +01:00
Benjamin Otte
5015730212 builder: Turn last dlsym() function into a scope API
Looking up a get_type function by its name is now also part of
GtkBuilderScope.
2019-12-12 19:39:36 +01:00
Benjamin Otte
512c4c13a6 builder: Add gtk_builder_lookup_object()
... and use it. This function looks up an object like
gtk_builder_get_object() but generates an error on failure.

Unlike the evil function _gtk_builder_lookup_object() which also
generates an error but hides it for later lookup.

Use this to avoid continuing applying properties when an error was
encountered.
2019-12-12 19:12:11 +01:00
Benjamin Otte
33bd8f322c builder: Improve error message 2019-12-03 18:12:25 +01:00
Benjamin Otte
420169d5cd builder: Improve signal connecting
- Propagate the error back to the parser, so we get a proper GError
  instead of a g_warning().
- Connect closures by id, don't construct a name from the ids so that
  glib can take it apart again.
2019-11-22 17:42:31 +01:00
Rico Tzschichholz
97231ca231 gtk: Fix some g-i annotation warnings 2019-09-15 17:57:28 +02:00
Rico Tzschichholz
67bd28eaaf gtk: Fix parameter annotations for gtk_buildable_parse_context_get_position 2019-09-15 17:57:28 +02:00
Alexander Larsson
ff23397701 GtkBuilder: Add support for precompiling builder xml 2019-09-10 12:08:20 -04:00
Alexander Larsson
96b37f4eb8 Use the new GtkBuildableParser type in GtkBuildable interfaces 2019-09-10 12:08:20 -04:00
Alexander Larsson
135cea76fb GtkBuildableParser: Add a wrapper for GMarkupParser
This currenly just wraps GMarkupParser, but the plan is to expose this
instead of GMarkup in the GtkBuildable interfaces, allowing us to
replace the parser with something that handles pre-parsed input
instead.

Note that we duplicate some of the features of GMarkup to implement
the APIs rather then call down to GMarkup, as we need to support these
in the pre-parsed case anyway.
2019-09-10 12:07:15 -04:00
Mohammed Sadiq
c1bb699151 builderparser: Allow bind-source without bind-property
This allow users to bind same property of two objects with only
specifing “name” and “bind-source” in UI file.

Fixes https://gitlab.gnome.org/GNOME/gtk/issues/2080
2019-08-10 19:01:36 +05:30
Matthias Clasen
54e7a94d70 builder: Fix signedness issues in apis
Whenever we take a length argument that can
be -1 for 'nul-terminated', it should be
gssize, not gsize.

Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1555
2019-05-01 03:21:29 +00:00
Matthias Clasen
ed3b9669b3 builder: Allow specifying objects inline
In addition to <property name="foo">bar</property> referring
to an object with ID bar, we now also parse
<property name="foo"><object>...
to specify a property 'inline'.
2019-02-08 00:09:44 -05:00
Debarshi Ray
60cee7339f GtkBuilder: Enforce "class" as a mandatory attribute for <object>
https://bugzilla.gnome.org/show_bug.cgi?id=786931
2017-09-25 15:26:34 +02:00
Debarshi Ray
fd9aec27fc GtkBuilder: Prefer "type-func" over "class" when looking for the GType
https://bugzilla.gnome.org/show_bug.cgi?id=786932
2017-08-29 15:41:01 +02:00
Timm Bäder
0333602809 builderparser: Remove pointless TagType struct 2017-03-21 19:04:58 +01:00
Timm Bäder
de56947e86 gtkbuilder: Remove unused struct 2017-01-30 18:11:00 +01:00
Timm Bäder
c392f41bb2 builderparser: Shuffle if-statements around once more
The previous reordering broke the builderparser test case.
2017-01-08 13:07:12 +01:00
Timm Bäder
212f8a6c7b builderparser: Order string comparisons after frequency
The typical UI file has a lot more <property> tags than it has
<requested> or <interface> tags, etc. so order the string comparisons
according to this expected case.
2016-10-31 19:29:36 +01:00
Timm Bäder
938598032c builderparser: Save tag type instead of tag name
So we can save a few string comparisons
2016-10-31 19:29:36 +01:00
Timm Bäder
e3a3a66370 builderparser: Don't needlessly copy requested object names 2016-10-31 19:29:36 +01:00
Timm Bäder
f415a8bc84 builderparser: stack-allocate ParserData
No reason for it to be heap-allocated, it won't survive this function
call anyway.
2016-10-31 19:29:36 +01:00
Matthias Clasen
9c0e4c174a builder: Allow 'primary' as a modifier value
Support aliases for flags values in GtkBuilder, and use this
to support the special value 'primary' for GdkModifierType
values.

https://bugzilla.gnome.org/show_bug.cgi?id=699891
2016-03-05 23:44:03 -05:00
Matthias Clasen
2ee7fb1818 Don't use g_print for debug output
The g_print documentation explicitly says not to do this, since
g_print is meant to be redirected by applications. Instead use
g_message for logging that can be triggered via GTK_DEBUG.
2016-02-28 21:40:23 -05:00
Matthias Clasen
eec75ee9d6 Cosmetic changes
Line up struct-filling code with the order in the declaration.
2015-10-20 06:14:57 -04:00
Matthias Clasen
019078364e builder: Avoid some unnecessary overhead
Only get the class once per object, not once per property.
And don't canonicalize the property name, g_object_class_find_property
does that already.
2015-10-20 06:14:57 -04:00
Matthias Clasen
3526b08e01 Clean up debug features
Introduce a GTK_DEBUG_CHECK() macro and use it to check for
GTK_DEBUG flags everywhere. Also guard all such places by
2015-09-09 06:32:46 -04:00
Matthias Clasen
3d01f29bd9 builder: Move a function
Move _gtk_builder_boolean_from_string in the same source file
as the other _from_functions.
2015-09-07 12:43:19 -04:00
Matthias Clasen
20079a9960 builder: Minor refactoring
Keep the GString in PropertyInfo around, instead of throwing it
away and just keeping the char*.
2015-09-07 12:25:29 -04:00
Matthias Clasen
9f24b54786 Code cleanup
Use g_slist_free_full more consistently. This commit just converts
the obvious cases where g_slist_forall is directly followed by
g_slist_free.
2015-07-31 22:23:35 -04:00
Matthias Clasen
91b147622b gtkbuilderparser: Add some assertions
Add some assertions that things are non-NULL when we know they
are, so that coverity gets it.
2015-07-17 16:11:16 -04:00
Matthias Clasen
6535276c3e GtkBuilder: Emit a more detailed error for templates
Add the class and parent class name to the error message.
gtk-builder-tool will parse the error message and use the
class names for trying again to parse the file as a template.
2015-04-30 06:19:10 -04:00
Matthias Clasen
287ba6b94b Convert more GtkBuilder to g_markup_collect_attributes
The core parser itself was left, so handle it as well.
2015-04-30 06:19:10 -04:00
Matthias Clasen
10860d229e Formatting fixes 2015-04-30 06:19:10 -04:00
Matthias Clasen
d58500b318 GtkBuilder: Report more lookup failures as GError
Report failures to lookup objects for property values
and bindings via GError too, and provide location information
while doing so.

https://bugzilla.gnome.org/show_bug.cgi?id=748234
2015-04-29 15:19:31 -04:00
Matthias Clasen
5bd0ec6381 GtkBuilder: Report 'invalid ID' errors
Look for a stashed GError after calling custom_tag_end,
custom_finished or parser_finished vfuncs, and report
them up.
2015-04-27 22:56:53 -04:00
Matthias Clasen
44bf00d5da GtkBuilder: Unify builder error messages
Don't use <%s> for an attribute.
2015-04-26 15:03:48 -04:00
Matthias Clasen
0d57d21192 Fix a misleading condition
gcc5 rightfully complains about this condition being unclear.
2015-02-15 22:00:49 -05:00
Matthias Clasen
e356841957 GtkBuilder: Improve error messages
No `' looks just terrible. For quoting in non-UI contexts, we
prefer either '' or "".

https://bugzilla.gnome.org/show_bug.cgi?id=735192
2014-09-29 23:05:21 -04:00
Juan Pablo Ugarte
b059098c71 GtkBuilder: added template parent type check. 2014-05-02 14:38:05 -03:00
Juan Pablo Ugarte
49fa04212b GtkBuilder: improved parsing error report for invalid properties and signals.
Added GTK_BUILDER_ERROR_INVALID_PROPERTY and GTK_BUILDER_ERROR_INVALID_SIGNAL
error codes

ObjectInfo: Use a GType instead of a char * for the class name.
PropertyInfo: Use a GParamSpec instead of a char * for the property name.
SignalInfo: Use signal id and detail quark instead of a detailed signal name string.

This not only save us a few malloc in each case but lets us simplify the code
and report unknown properties and signals as a parsing error instead of just
printing a warning.
2014-05-01 17:59:53 -03:00
Juan Pablo Ugarte
c4afca906c GtkBuilder: fixed a few minor memory leaks.
Fixed memory leaks in parse_object(), parse_template() and parse_signal() functions.
Parameters value where strduped before the last posible return and not freed.
2014-05-01 17:59:53 -03:00
Juan Pablo Ugarte
887fc60cce Added bindings support to GtkBuilder by introducing 3 new <property> attributes "bind-source" to specify the source object of the binding "bind-property" to specify the source property and "bind-flags" to specify the binding flags (optional)
Binding an object sensitive property with a check button active property will look like this:

<object class="GtkButton" id="button">
  <property name="sensitive" bind-source="checkbutton" bind-property="active"/>
</object>

This is based on the original work done by Denis Washington for his GSoC project

This closes Bug 654417 "[GSoC] Add <binding> element to GtkBuilder syntax"
2014-04-18 18:59:14 -03:00
John Lindgren
451692d432 Fix typo (GTK_ENABLE_DEBUG vs. G_ENABLE_DEBUG).
https://bugzilla.gnome.org/show_bug.cgi?id=726858
2014-03-21 22:55:03 -04:00
Matthias Clasen
df455db2e3 GtkBuilder: Make IDs optional
One requirement of .ui files is that each object must have an ID,
even if it is never referred to or directly loaded from the code.
This makes editing .ui files much more onerous than it has to be,
due to the frequent need to invent new IDs, while avoiding
clashes.

This commit makes IDs optional in the XML. They only need to
be provided for objects which are referred to or explictly loaded
from the code. Since GtkBuilder needs IDs for its own internal
accounting, we create IDs of the form ___object_N___ if not
specified in the XML.

https://bugzilla.gnome.org/show_bug.cgi?id=712553
2013-11-18 06:00:02 -05:00