diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000000..7740ffd7161 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Sources/GtkCodeGen/GirFiles"] + path = Sources/GtkCodeGen/GirFiles + url = https://github.com/moreSwift/gir-files diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 642ca3d25dd..8412d6c19fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,15 +27,25 @@ Due to limitations of Swift Package Manager and the way this project is structur 2. Make sure that you haven't introduced any new warnings 3. Make sure that the code builds, and the example works correctly 4. If you are adding a new feature, consider adding an example usage of it to the example -5. Run `format_and_lint.sh` (requires installing `swift-format` and `swiftlint`) +5. Run `./Scripts/format_and_lint.sh` (requires installing `swift-format` and `swiftlint`) ## While coding Here are a few things to keep in mind while working on the code. 1. Do not directly modify a file that has a corresponding `.gyb` template file (which will be in the - same directory). Instead, modify the template file and then run `./generate.sh` to build all of - the templates. To learn more about gyb [read this post](https://nshipster.com/swift-gyb/) + same directory). Instead, modify the template file and then run `./Scripts/generate_gyb.sh` + to build all of the templates. To learn more about gyb + [read this post](https://nshipster.com/swift-gyb/) +2. Do not directly modify files in `Sources/Gtk/Generated` or `Sources/Gtk3/Generated`. Update the + generator at `Sources/GtkCodeGen` instead and run `./Scripts/generate_gtk.sh` to regenerate the + Gtk 3 and Gtk 4 bindings. If the changes can not be made by updating the generator, pull the + target file out of `Sources/{Gtk,Gtk3}/Generated` and into `Sources/{Gtk,Gtk3}/Widgets` and + modify it however you want. Remember to remove the class from `allowListedClasses`, + `gtk3AllowListedClasses` or `gtk4AllowListedClasses` so that it doesn't get regenerated the + next time someone runs `./Scripts/generate_gtk.sh`. Alternatively, if possible, add + code to the generated classes via extensions outside of the Generated directories. I usually + name these extension files `ClassName+ManualAdditions.swift`. 3. Make sure to avoid massive monolithic commits where possible ## Codestyle diff --git a/Package.swift b/Package.swift index 7da07affdc8..1ee258ab98a 100644 --- a/Package.swift +++ b/Package.swift @@ -229,7 +229,8 @@ let package = Package( name: "GtkCodeGen", dependencies: [ "XMLCoder", .product(name: "SwiftSyntaxBuilder", package: "swift-syntax"), - ] + ], + exclude: ["GirFiles"] ), .systemLibrary( name: "CGtk3", diff --git a/Scripts/format.sh b/Scripts/format.sh new file mode 100755 index 00000000000..2ea0557cbed --- /dev/null +++ b/Scripts/format.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../ + +if [ -z "$1" ]; then + swift format format --in-place --recursive --configuration .swift-format Sources Examples/Sources +else + swift format format --in-place --recursive --configuration .swift-format $1 +fi diff --git a/Scripts/format_and_lint.sh b/Scripts/format_and_lint.sh new file mode 100755 index 00000000000..d88c538f360 --- /dev/null +++ b/Scripts/format_and_lint.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../ + +./Scripts/format.sh +swiftlint lint --quiet diff --git a/Scripts/generate.sh b/Scripts/generate.sh new file mode 100755 index 00000000000..8eab6519355 --- /dev/null +++ b/Scripts/generate.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd "$(dirname "$0")" + +./generate_gyb.sh + +./generate_gtk.sh diff --git a/Scripts/generate_gtk.sh b/Scripts/generate_gtk.sh new file mode 100755 index 00000000000..205e19215f6 --- /dev/null +++ b/Scripts/generate_gtk.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cd "$(dirname "$0")" + +./generate_gtk4.sh +./generate_gtk3.sh diff --git a/Scripts/generate_gtk3.sh b/Scripts/generate_gtk3.sh new file mode 100755 index 00000000000..3df94ef392d --- /dev/null +++ b/Scripts/generate_gtk3.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../ + +# Generate Gtk3 wrapper +swift run GtkCodeGen Sources/GtkCodeGen/GirFiles/Gtk-3.0.gir Sources/Gtk3/Generated CGtk3 +./Scripts/format.sh Sources/Gtk3/Generated diff --git a/Scripts/generate_gtk4.sh b/Scripts/generate_gtk4.sh new file mode 100755 index 00000000000..5b0fd6ab296 --- /dev/null +++ b/Scripts/generate_gtk4.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../ + +# Generate Gtk4 wrapper +swift run GtkCodeGen Sources/GtkCodeGen/GirFiles/Gtk-4.0.gir Sources/Gtk/Generated CGtk +./Scripts/format.sh Sources/Gtk/Generated diff --git a/Scripts/generate_gyb.sh b/Scripts/generate_gyb.sh new file mode 100755 index 00000000000..717feff8248 --- /dev/null +++ b/Scripts/generate_gyb.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../ + +# Find and compile all *.gyb files in the Sources directory +find Sources -name '*.gyb' | + while read file; do + ./gyb/gyb --line-directive '' -o "$PWD/${file%.gyb}" "$PWD/$file" + ./Scripts/format.sh $PWD/${file%.gyb} + done diff --git a/test.sh b/Scripts/test.sh similarity index 89% rename from test.sh rename to Scripts/test.sh index 89c1a5a8063..c9052678c95 100755 --- a/test.sh +++ b/Scripts/test.sh @@ -1,4 +1,7 @@ #!/bin/sh + +cd "$(dirname "$0")"/../ + # `swift test` builds all targets in the package (even those not depended upon # by any test targets), which leads to `swift test` on its own being broken # for SwiftCrossUI diff --git a/Sources/AppKitBackend/AppKitBackend.swift b/Sources/AppKitBackend/AppKitBackend.swift index 49e9eb250a3..e657f0130cb 100644 --- a/Sources/AppKitBackend/AppKitBackend.swift +++ b/Sources/AppKitBackend/AppKitBackend.swift @@ -158,7 +158,7 @@ public final class AppKitBackend: AppBackend { keyEquivalent: "" ) renderedItem.isOn = value - + let wrappedAction = Action { onChange(!renderedItem.isOn) } diff --git a/Sources/GtkCodeGen/GirFiles b/Sources/GtkCodeGen/GirFiles new file mode 160000 index 00000000000..a9bfeaf9cfb --- /dev/null +++ b/Sources/GtkCodeGen/GirFiles @@ -0,0 +1 @@ +Subproject commit a9bfeaf9cfb0e7e722a2efd7c3ad865e68acd2c1 diff --git a/Sources/SwiftCrossUI/Views/ForEach.swift b/Sources/SwiftCrossUI/Views/ForEach.swift index 020b14db7f7..051d7462a79 100644 --- a/Sources/SwiftCrossUI/Views/ForEach.swift +++ b/Sources/SwiftCrossUI/Views/ForEach.swift @@ -437,10 +437,13 @@ class ForEachViewChildren< } } - extension ForEach where ID == Int { /// Creates a view that creates child views on demand based on a collection of data. - @available(*, deprecated, renamed: "init(_:id:_:)", message: "ForEach requires an explicit 'id' parameter for non-Identifiable elements to correctly persist state across view updates") + @available( + *, deprecated, renamed: "init(_:id:_:)", + message: + "ForEach requires an explicit 'id' parameter for non-Identifiable elements to correctly persist state across view updates" + ) @_disfavoredOverload public init( _ elements: Items, @@ -457,7 +460,8 @@ extension ForEach where Child == [MenuItem], ID == Int { @available( *, deprecated, - message: "ForEach requires an explicit 'id' parameter for non-Identifiable elements to correctly persist state across view updates" + message: + "ForEach requires an explicit 'id' parameter for non-Identifiable elements to correctly persist state across view updates" ) @_disfavoredOverload public init( diff --git a/format_and_lint.sh b/format_and_lint.sh deleted file mode 100755 index da4b4a39b10..00000000000 --- a/format_and_lint.sh +++ /dev/null @@ -1,2 +0,0 @@ -swift format format --in-place --recursive --configuration .swift-format Sources Examples/Sources -swiftlint lint --quiet diff --git a/generate.sh b/generate.sh deleted file mode 100755 index 9756a58b682..00000000000 --- a/generate.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Find and compile all *.gyb files in the Sources directory -find Sources -name '*.gyb' | - while read file; do - ./gyb/gyb --line-directive '' -o "$PWD/${file%.gyb}" "$PWD/$file" - swiftlint --fix --config .swiftlint.yml $PWD/${file%.gyb} 1>/dev/null - done - -# Generate Gtk4 wrapper -swift run GtkCodeGen $(pkg-config --variable=includedir gtk4)/../share/gir-1.0/Gtk-4.0.gir Sources/Gtk/Generated CGtk - -# Generate Gtk3 wrapper -swift run GtkCodeGen $(pkg-config --variable=includedir gtk+-3.0)/../share/gir-1.0/Gtk-3.0.gir Sources/Gtk3/Generated CGtk3