From d7d8619363b2d46c905d31ed928e674a54ab7e3a Mon Sep 17 00:00:00 2001 From: PaladinDev Date: Sun, 2 Jul 2023 23:44:37 +0300 Subject: [PATCH] Added blueprint template --- templates/blueprint/.editorconfig | 41 +++++++++++++++++++ templates/blueprint/README.md | 1 + .../blueprint/data/${APP_NAME}.gresource.xml | 7 ++++ templates/blueprint/data/meson.build | 17 ++++++++ templates/blueprint/data/ui/window.blp | 28 +++++++++++++ templates/blueprint/meson.build | 14 +++++++ templates/blueprint/src/core/application.vala | 20 +++++++++ templates/blueprint/src/main.vala | 4 ++ templates/blueprint/src/meson.build | 21 ++++++++++ templates/blueprint/src/ui/main-window.vala | 10 +++++ templates/blueprint/template.json | 35 ++++++++++++++++ templates/meson.build | 1 + 12 files changed, 199 insertions(+) create mode 100644 templates/blueprint/.editorconfig create mode 100644 templates/blueprint/README.md create mode 100644 templates/blueprint/data/${APP_NAME}.gresource.xml create mode 100644 templates/blueprint/data/meson.build create mode 100644 templates/blueprint/data/ui/window.blp create mode 100644 templates/blueprint/meson.build create mode 100644 templates/blueprint/src/core/application.vala create mode 100644 templates/blueprint/src/main.vala create mode 100644 templates/blueprint/src/meson.build create mode 100644 templates/blueprint/src/ui/main-window.vala create mode 100644 templates/blueprint/template.json diff --git a/templates/blueprint/.editorconfig b/templates/blueprint/.editorconfig new file mode 100644 index 0000000..7a05aed --- /dev/null +++ b/templates/blueprint/.editorconfig @@ -0,0 +1,41 @@ +# taken from gitg +root = true + +[*] +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[*.vala] +indent_size = 4 +indent_style = tab +insert_final_newline = true +max_line_length = 100 + +[*.{c,h}] +indent_size = 2 +indent_style = space +insert_final_newline = true +max_line_length = 100 + +[*.css] +indent_size = 2 +indent_style = space + +[*.{ui,xml,xml.in}] +indent_size = 2 +indent_style = space + +[*.py] +indent_size = 4 +indent_style = space + +[*.json] +indent_style = space +indent_size = 4 + +[meson.build] +indent_size = 2 +indent_style = space + diff --git a/templates/blueprint/README.md b/templates/blueprint/README.md new file mode 100644 index 0000000..7d69c9c --- /dev/null +++ b/templates/blueprint/README.md @@ -0,0 +1 @@ +# ${APP_NAME} diff --git a/templates/blueprint/data/${APP_NAME}.gresource.xml b/templates/blueprint/data/${APP_NAME}.gresource.xml new file mode 100644 index 0000000..c8c1f12 --- /dev/null +++ b/templates/blueprint/data/${APP_NAME}.gresource.xml @@ -0,0 +1,7 @@ + + + + + ui/window.ui + + diff --git a/templates/blueprint/data/meson.build b/templates/blueprint/data/meson.build new file mode 100644 index 0000000..ff167eb --- /dev/null +++ b/templates/blueprint/data/meson.build @@ -0,0 +1,17 @@ +blueprints = files( + 'ui/window.blp', +) + +blp_target = custom_target( + 'blueprints', + + input: blueprints, + output: '.', + command: [ find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@' ], +) + +project_resources = gnome.compile_resources( + project_name + '-resources', + project_name + '.gresource.xml', + dependencies: blp_target +) diff --git a/templates/blueprint/data/ui/window.blp b/templates/blueprint/data/ui/window.blp new file mode 100644 index 0000000..5a020c8 --- /dev/null +++ b/templates/blueprint/data/ui/window.blp @@ -0,0 +1,28 @@ +using Gtk 4.0; +using Adw 1; + +template ${APP_NAMESPACE}MainWindow : Adw.ApplicationWindow { + title: "${PROJECT_NAME}"; + default-width: 400; + default-height: 350; + + Gtk.Box { + orientation: vertical; + + Adw.HeaderBar {} + + Gtk.Box { + orientation: vertical; + halign: center; + valign: center; + hexpand: true; + vexpand: true; + + Gtk.Label { + styles ["title-1"] + label: "Hello, world!"; + } + } + } +} + diff --git a/templates/blueprint/meson.build b/templates/blueprint/meson.build new file mode 100644 index 0000000..140e04f --- /dev/null +++ b/templates/blueprint/meson.build @@ -0,0 +1,14 @@ +project( + '${PROJECT_NAME}', + + ['c', 'vala'], + version: '${PROJECT_VERSION}' +) + +pkg = import('pkgconfig') +gnome = import('gnome') + +project_name = meson.project_name() + +subdir('data') +subdir('src') diff --git a/templates/blueprint/src/core/application.vala b/templates/blueprint/src/core/application.vala new file mode 100644 index 0000000..d7c62c1 --- /dev/null +++ b/templates/blueprint/src/core/application.vala @@ -0,0 +1,20 @@ +namespace ${APP_NAMESPACE} { + + public class Application : Adw.Application { + + public Application() { + Object( + application_id: "${APP_ID}", + flags: ApplicationFlags.FLAGS_NONE + ); + } + + public override void activate() { + base.activate(); + var win = active_window ?? new MainWindow(this); + + win.present(); + } + } +} + diff --git a/templates/blueprint/src/main.vala b/templates/blueprint/src/main.vala new file mode 100644 index 0000000..d138f4a --- /dev/null +++ b/templates/blueprint/src/main.vala @@ -0,0 +1,4 @@ +int main(string[] args) { + var app = new ${APP_NAMESPACE}.Application(); + return app.run(args); +} diff --git a/templates/blueprint/src/meson.build b/templates/blueprint/src/meson.build new file mode 100644 index 0000000..0348f37 --- /dev/null +++ b/templates/blueprint/src/meson.build @@ -0,0 +1,21 @@ +project_deps = [ + dependency('gtk4'), + dependency('libadwaita-1'), +] + +project_sources = files( + 'main.vala', + + 'core/application.vala', + 'ui/main-window.vala', +) + +executable( + project_name, + + project_resources, + project_sources, + vala_args: [ '--gresourcesdir=data/' ], + dependencies: project_deps, + install: true, +) diff --git a/templates/blueprint/src/ui/main-window.vala b/templates/blueprint/src/ui/main-window.vala new file mode 100644 index 0000000..6770b5f --- /dev/null +++ b/templates/blueprint/src/ui/main-window.vala @@ -0,0 +1,10 @@ +namespace ${APP_NAMESPACE} { + + [GtkTemplate (ui = "${APP_PATH}ui/window.ui")] + public class MainWindow : Adw.ApplicationWindow { + + public MainWindow(Gtk.Application app) { + Object(application: app); + } + } +} diff --git a/templates/blueprint/template.json b/templates/blueprint/template.json new file mode 100644 index 0000000..20c3ef0 --- /dev/null +++ b/templates/blueprint/template.json @@ -0,0 +1,35 @@ +{ + "description": "a starter libadwaita app with blueprint", + "variables": { + "APP_NAME": { + "auto": true, + "default": "/${PROJECT_NAME}/\\s+//" + }, + "APP_ID": { + "summary": "application ID", + "pattern": "^\\w+(\\.\\w+)*$", + "default": "io.github.${USERNAME}.${APP_NAME}" + }, + "APP_NAMESPACE": { + "summary": "application namespace", + "pattern": "[A-Z]\\w{2,}", + "default": "/${PROJECT_NAME}/\\s+//" + }, + "APP_PATH": { + "auto": true, + "default": "/${APP_ID}/(\\.|^|$)/\\//" + } + }, + "templates": [ + "data/ui/window.blp", + "data/${APP_NAME}.gresource.xml", + "data/meson.build", + "src/core/application.vala", + "src/ui/main-window.vala", + "src/main.vala", + "src/meson.build", + ".editorconfig", + "meson.build", + "README.md" + ] +} diff --git a/templates/meson.build b/templates/meson.build index 996b305..1f56fd2 100644 --- a/templates/meson.build +++ b/templates/meson.build @@ -1,3 +1,4 @@ +install_subdir('blueprint', install_dir: templates_dir) install_subdir('eos', install_dir: templates_dir) install_subdir('gnome', install_dir: templates_dir) install_subdir('gtk', install_dir: templates_dir)