Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Extensions/Gtk-4.0.Integration/Compiler/Blueprint.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project>
<PropertyGroup>
<BlueprintCompiler>blueprint-compiler</BlueprintCompiler>
</PropertyGroup>

<ItemDefinitionGroup>
<BlueprintEmbeddedResource>
<Link>%(Filename).blp.ui</Link>
<CompiledOutput>$(IntermediateOutputPath)%(Filename).blp.ui</CompiledOutput>
</BlueprintEmbeddedResource>
</ItemDefinitionGroup>

<ItemGroup>
<None Remove="**\*.blp.ui" />
<EmbeddedResource Include="**\*.blp.ui">
<LogicalName>%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<Project>
<UsingTask TaskName="CompileBlueprint" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<BlueprintFile ParameterType="System.String" Required="true" />
<OutputFile ParameterType="System.String" Required="true" />
<CompilerPath ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var process = new Process();
process.StartInfo.FileName = CompilerPath;
process.StartInfo.Arguments = $"compile --output {OutputFile} \"{BlueprintFile}\"";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;

if (!process.Start())
{
Log.LogError($"Failed to start blueprint compiler");
return false;
}

string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();

if (process.ExitCode != 0)
{
Log.LogError($"Blueprint compilation failed: {error}");
return false;
}

Log.LogMessage(MessageImportance.High, $"Compiled blueprint: {BlueprintFile} to {OutputFile}");
return true;
]]>
</Code>
</Task>
</UsingTask>

<Target Name="CompileBlueprints"
BeforeTargets="CoreCompile"
Inputs="@(BlueprintEmbeddedResource)"
Outputs="@(BlueprintEmbeddedResource->'%(CompiledOutput)')">
<ItemGroup>
<_BlueprintFilesToCompile Include="@(BlueprintEmbeddedResource)" />
</ItemGroup>

<Message Importance="high" Text="Compiling blueprint %(_BlueprintFilesToCompile.Identity)" />
<Exec WorkingDirectory="$(MSBuildProjectDirectory)" Command="$(BlueprintCompiler) compile --output %(_BlueprintFilesToCompile.CompiledOutput) %(_BlueprintFilesToCompile.Identity)" />
</Target>

<Target Name="CleanBlueprintOutput" BeforeTargets="CoreClean">
<ItemGroup>
<_BlueprintOutputFiles Include="$(IntermediateOutputPath)*.ui" />
</ItemGroup>
<Delete Files="@(_BlueprintOutputFiles)" />
</Target>
</Project>
14 changes: 14 additions & 0 deletions src/Extensions/Gtk-4.0.Integration/Compiler/Template.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<ItemDefinitionGroup>
<EmbeddedTemplateResource>
<Link>%(Filename).ui</Link>
</EmbeddedTemplateResource>
</ItemDefinitionGroup>

<ItemGroup>
<None Remove="@(EmbeddedTemplateResource)"/>
<EmbeddedResource Include="@(EmbeddedTemplateResource)">
<LogicalName>%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Project>
<Import Project="Compiler/Blueprint.Build.props" />
<Import Project="Compiler/Template.Build.props" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="Compiler/Blueprint.Build.targets" />
</Project>
8 changes: 8 additions & 0 deletions src/Extensions/Gtk-4.0.Integration/Gtk-4.0.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@
<RootNamespace>Gtk.Integration</RootNamespace>
<Description>Source Generator to make it easy to integrate C# with Gtk.</Description>
</PropertyGroup>

<ItemGroup>
<None Update="GirCore.Gtk-4.0.Integration.props" Pack="true" PackagePath="buildTransitive" />
<None Update="GirCore.Gtk-4.0.Integration.targets" Pack="true" PackagePath="buildTransitive" />
<None Update="Compiler\Blueprint.Build.props" Pack="true" PackagePath="buildTransitive" />
<None Update="Compiler\Blueprint.Build.targets" Pack="true" PackagePath="buildTransitive" />
<None Update="Compiler\Template.Build.props" Pack="true" PackagePath="buildTransitive" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions src/GirCore.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
</Folder>
<Folder Name="/Samples/">
<File Path="Samples/Directory.Build.props" />
<File Path="Samples\Directory.Build.targets" />
</Folder>
<Folder Name="/Samples/Adw-1/">
<Project Path="Samples/Adw-1/Window/Window.csproj" />
Expand All @@ -68,6 +69,7 @@
<Project Path="Samples/Gtk-4.0/AboutDialog/AboutDialog.csproj" />
<Project Path="Samples/Gtk-4.0/Builder/Builder.csproj" />
<Project Path="Samples/Gtk-4.0/CompositeTemplate/CompositeTemplate.csproj" />
<Project Path="Samples/Gtk-4.0/CompositeTemplateBlueprint/CompositeTemplateBlueprint.csproj" />
<Project Path="Samples/Gtk-4.0/DrawingArea/DrawingArea.csproj" />
<Project Path="Samples/Gtk-4.0/DropDown/DropDown.csproj" />
<Project Path="Samples/Gtk-4.0/FontDialog/FontDialog.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions src/Samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project>
<Import Project="../Extensions/Gtk-4.0.Integration/GirCore.Gtk-4.0.Integration.props" />

<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/Samples/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="../Extensions/Gtk-4.0.Integration/GirCore.Gtk-4.0.Integration.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<ProjectReference Include="..\..\..\Extensions\GObject-2.0.Integration\GObject-2.0.Integration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\..\Extensions\Gtk-4.0.Integration\Gtk-4.0.Integration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\..\Libs\Gtk-4.0\Gtk-4.0.csproj" />

<UiEmbeddedResource Include="**/*.ui" />
</ItemGroup>

<PropertyGroup>
Expand All @@ -12,12 +14,5 @@
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<None Remove="**\*.ui" />
<EmbeddedResource Include="**\*.ui">
<LogicalName>%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions src/Samples/Gtk-4.0/CompositeTemplate/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using System;
using System.Reflection;
using CompositeTemplate;

var application = Gtk.Application.New("org.gir.core", Gio.ApplicationFlags.FlagsNone);
application.OnActivate += (sender, args) =>
{
Console.WriteLine("Resources:");
var names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
foreach (var name in names)
Console.WriteLine(name);

var window = Gtk.ApplicationWindow.New((Gtk.Application) sender);
window.Title = "Gtk4 Window";
window.SetDefaultSize(300, 300);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Gtk 4.0;

template $CompositeBoxWidget: Box {
orientation: vertical;

Label {
label: "Welcome to CompositeTemplates!";
}

Label my_label {
label: "Nothing to see here.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace CompositeTemplate;

[GObject.Subclass<Gtk.Box>(qualifiedName: nameof(CompositeBoxWidget))]
[Gtk.Template<Gtk.AssemblyResource>("CompositeBoxWidget.blp.ui")]
public partial class CompositeBoxWidget
{
[Gtk.Connect("my_label")]
private Gtk.Label _label;

partial void Initialize()
{
_label.Label_ = "With support for connected members!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\..\Extensions\GObject-2.0.Integration\GObject-2.0.Integration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\..\Extensions\Gtk-4.0.Integration\Gtk-4.0.Integration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\..\Libs\Gtk-4.0\Gtk-4.0.csproj" />

<BlueprintEmbeddedResource Include="**/*.blp" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>
12 changes: 12 additions & 0 deletions src/Samples/Gtk-4.0/CompositeTemplateBlueprint/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CompositeTemplate;

var application = Gtk.Application.New("org.gir.core", Gio.ApplicationFlags.FlagsNone);
application.OnActivate += (sender, args) =>
{
var window = Gtk.ApplicationWindow.New((Gtk.Application) sender);
window.Title = "Gtk4 Window";
window.SetDefaultSize(300, 300);
window.Child = CompositeBoxWidget.NewWithProperties([]);
window.Show();
};
return application.RunWithSynchronizationContext(null);
Loading