gtk4-macros-0.9.5/.cargo_vcs_info.json0000644000000001510000000000100131770ustar { "git": { "sha1": "46796d32a80c38003469ced94559310a80bc1d5f" }, "path_in_vcs": "gtk4-macros" }gtk4-macros-0.9.5/COPYRIGHT000064400000000000000000000012131046102023000132620ustar 00000000000000The gtk-rs Project is licensed under the MIT license, see the LICENSE file or . Copyrights in the gtk-rs Project project are retained by their contributors. No copyright assignment is required to contribute to the gtk-rs Project project. For full authorship information, see the version control history. This project provides interoperability with various GNOME libraries but doesn't distribute any parts of them. Distributing compiled libraries and executables that link to those libraries may be subject to terms of the GNU LGPL or other licenses. For more information check the license of each GNOME library. gtk4-macros-0.9.5/Cargo.toml0000644000000033620000000000100112040ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.70" name = "gtk4-macros" version = "0.9.5" authors = ["The gtk-rs Project Developers"] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Macros helpers for GTK 4 bindings" homepage = "https://gtk-rs.org/gtk4-rs" documentation = "https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4_macros" readme = "README.md" keywords = [ "gtk", "gtk4", "gtk-rs", "gnome", "GUI", ] categories = [ "api-bindings", "gui", ] license = "MIT" repository = "https://github.com/gtk-rs/gtk4-rs" [lib] name = "gtk4_macros" path = "src/lib.rs" proc-macro = true [[test]] name = "compile" path = "tests/compile.rs" [[test]] name = "templates" path = "tests/templates.rs" [dependencies.proc-macro-crate] version = "3.0" [dependencies.proc-macro2] version = "1.0" [dependencies.quick-xml] version = "0.37" optional = true [dependencies.quote] version = "1.0" [dependencies.syn] version = "2.0" features = ["full"] [dev-dependencies.futures-channel] version = "0.3" [dev-dependencies.futures-util] version = "0.3" [dev-dependencies.gtk] version = "0.9" package = "gtk4" [dev-dependencies.trybuild2] version = "1.0" [features] blueprint = [] default = [] xml_validation = ["quick-xml"] gtk4-macros-0.9.5/Cargo.toml.orig000064400000000000000000000014251046102023000146630ustar 00000000000000[package] description = "Macros helpers for GTK 4 bindings" documentation = "https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4_macros" keywords = ["gtk", "gtk4", "gtk-rs", "gnome", "GUI"] name = "gtk4-macros" authors.workspace = true categories.workspace = true edition.workspace = true homepage.workspace = true license.workspace = true repository.workspace = true rust-version.workspace = true version.workspace = true [lib] proc-macro = true [features] default = [] xml_validation = ["quick-xml"] blueprint = [] [dependencies] quick-xml = {version = "0.37", optional = true} proc-macro-crate = "3.0" proc-macro2 = "1.0" quote = "1.0" syn = {version = "2.0", features = ["full"]} [dev-dependencies] futures-channel = "0.3" futures-util = "0.3" gtk.workspace = true trybuild2 = "1.0"gtk4-macros-0.9.5/LICENSE000064400000000000000000000020001046102023000127670ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gtk4-macros-0.9.5/README.md000064400000000000000000000020201046102023000132430ustar 00000000000000# gtk4-macros [Project site](https://gtk-rs.org/) Macro helpers for GTK 4 bindings, part of [gtk4-rs](https://github.com/gtk-rs/gtk4-rs/). ## Minimum supported Rust version Currently, the minimum supported Rust version is `1.70`. ## Documentation - The Rust API [Stable](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4_macros)/[Development](https://gtk-rs.org/gtk4-rs/git/docs/gtk4_macros/) ## Available Macros - `CompositeTemplate` ### Features | Feature | Description | | --- | ----------- | | `xml_validation` | Check the existence of `#[template_child]` fields in the UI file. Only works with `#[template(string = "")]` | | `blueprint` | Adds blueprint usage support in `#[template(string = "")]` | ### See Also - [glib](https://crates.io/crates/glib) - [gio](https://crates.io/crates/gio) - [gtk4](https://crates.io/crates/gdk4) - [gdk4](https://crates.io/crates/gdk4) - [gtk4](https://crates.io/crates/gtk4) ## License The Rust bindings of __gtk4-macros__ are available under the MIT License, please refer to it. gtk4-macros-0.9.5/src/attribute_parser.rs000064400000000000000000000260041046102023000165100ustar 00000000000000// Take a look at the license at the top of the repository in the LICENSE file. use proc_macro2::Span; use quote::ToTokens; use syn::{ parse::{Parse, ParseStream}, punctuated::Punctuated, Attribute, DeriveInput, Error, Field, Fields, Ident, LitBool, LitStr, Meta, Result, Token, Type, }; /// Custom meta keywords. mod kw { // `template` attribute. syn::custom_keyword!(file); syn::custom_keyword!(resource); syn::custom_keyword!(string); syn::custom_keyword!(allow_template_child_without_attribute); // `template_child` attribute. syn::custom_keyword!(id); syn::custom_keyword!(internal); } /// The parsed `template` attribute. pub struct Template { pub source: TemplateSource, pub allow_template_child_without_attribute: bool, } impl Parse for Template { fn parse(input: ParseStream) -> Result { let mut source = None; let mut allow_template_child_without_attribute = false; while !input.is_empty() { let lookahead = input.lookahead1(); if lookahead.peek(kw::file) { let keyword: kw::file = input.parse()?; let _: Token![=] = input.parse()?; let value: LitStr = input.parse()?; if source.is_some() { return Err(Error::new_spanned( keyword, "Specify only one of 'file', 'resource', or 'string'", )); } source = Some(TemplateSource::File(value.value())); } else if lookahead.peek(kw::resource) { let keyword: kw::resource = input.parse()?; let _: Token![=] = input.parse()?; let value: LitStr = input.parse()?; if source.is_some() { return Err(Error::new_spanned( keyword, "Specify only one of 'file', 'resource', or 'string'", )); } source = Some(TemplateSource::Resource(value.value())); } else if lookahead.peek(kw::string) { let keyword: kw::string = input.parse()?; let _: Token![=] = input.parse()?; let value: LitStr = input.parse()?; if source.is_some() { return Err(Error::new_spanned( keyword, "Specify only one of 'file', 'resource', or 'string'", )); } source = Some( TemplateSource::from_string_source(value.value()) .ok_or_else(|| Error::new_spanned(value, "Unknown language"))?, ); } else if lookahead.peek(kw::allow_template_child_without_attribute) { let keyword: kw::allow_template_child_without_attribute = input.parse()?; if allow_template_child_without_attribute { return Err(Error::new_spanned( keyword, "Duplicate 'allow_template_child_without_attribute'", )); } allow_template_child_without_attribute = true; } else { return Err(lookahead.error()); } if !input.is_empty() { let _: Token![,] = input.parse()?; } } let Some(source) = source else { return Err(Error::new( Span::call_site(), "Invalid meta, specify one of 'file', 'resource', or 'string'", )); }; Ok(Template { source, allow_template_child_without_attribute, }) } } /// The source of a template. pub enum TemplateSource { File(String), Resource(String), Xml(String), #[cfg(feature = "blueprint")] Blueprint(String), } impl TemplateSource { fn from_string_source(value: String) -> Option { for c in value.chars() { #[cfg(feature = "blueprint")] if c.is_ascii_alphabetic() { // blueprint code starts with some alphabetic letters return Some(Self::Blueprint(value)); } else if c == '<' { // xml tags starts with '<' symbol return Some(Self::Xml(value)); } #[cfg(not(feature = "blueprint"))] if c == '<' { // xml tags starts with '<' symbol return Some(Self::Xml(value)); } } None } } pub fn parse_template_source(input: &DeriveInput) -> Result