diff --git a/src/Library/demos/Source View/main.blp b/src/Library/demos/Source View/main.blp new file mode 100644 index 000000000..5d9bf1f14 --- /dev/null +++ b/src/Library/demos/Source View/main.blp @@ -0,0 +1,24 @@ +using Gtk 4.0; +using Adw 1; +using GtkSource 5; + +Adw.StatusPage { + title: "Source View"; + description: _("Widget that enables text-editing with advanced features like syntax highlighting"); + + Box { + orientation: vertical; + halign: center; + + ScrolledWindow source_view { + height-request: 180; + width-request: 600; + has-frame: true; + } + + LinkButton { + label: "API Reference"; + uri: "https://gnome.pages.gitlab.gnome.org/gtksourceview/gtksourceview5/class.View.html"; + } + } +} diff --git a/src/Library/demos/Source View/main.js b/src/Library/demos/Source View/main.js new file mode 100644 index 000000000..46a309abe --- /dev/null +++ b/src/Library/demos/Source View/main.js @@ -0,0 +1,25 @@ +import GtkSource from "gi://GtkSource"; + +// Strictly speaking we don't _have_ to do this here since WorkBench does this for us. +// However, you _have_ to call this once during the startup in your application - e.g. in GApplication::startup +GtkSource.init(); + +// Get the language we want to use +const language_manager = GtkSource.LanguageManager.get_default(); +const language = language_manager.get_language("js"); + +// Create the buffer - this holds the text that's used in the SourceView +const buffer = GtkSource.Buffer.new_with_language(language); +buffer.set_text('console.log("Hello World!");', -1); + +// Create the SourceView which displays the buffer's display +const source_view = GtkSource.View.new({ + auto_indent: true, + indent_width: 4, + buffer, + show_line_numbers: true, +}); + +// Add the SourceView to our ScrolledView so its displayed +const scrolled_window = workbench.builder.get_object("scrolled_window"); +scrolled_window.set_child(source_view); diff --git a/src/Library/demos/Source View/main.json b/src/Library/demos/Source View/main.json new file mode 100644 index 000000000..5a88c92e3 --- /dev/null +++ b/src/Library/demos/Source View/main.json @@ -0,0 +1,7 @@ +{ + "name": "Source View", + "category": "controls", + "description": "Widget that enables text-editing with advanced features like syntax highlighting", + "panels": ["code", "preview"], + "autorun": true +} diff --git a/src/Library/demos/Source View/main.vala b/src/Library/demos/Source View/main.vala new file mode 100644 index 000000000..6e96f474b --- /dev/null +++ b/src/Library/demos/Source View/main.vala @@ -0,0 +1,23 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 --pkg gtksourceview-5 + +public void main () { + Gtk.init (); + GtkSource.init (); + + // Get the language we want to use + var language_manager = GtkSource.LanguageManager.get_default(); + var language = language_manager.get_language("js"); + // Create the buffer - this holds the text that's used in the SourceView + var buffer = new GtkSource.Buffer.with_language(language); + buffer.set_text("console.log(\"Hello World!\");"); + + // Create the SourceView which displays the buffer's display + var source_view = new GtkSource.View.with_buffer(buffer); + source_view.auto_indent = true; + source_view.indent_width = 4; + source_view.show_line_numbers = true; + + // Add the SourceView to our ScrolledView so its displayed + var scrolled_window = workbench.builder.get_object ("scrolled_window") as Gtk.ScrolledWindow; + scrolled_window.child = source_view; +} diff --git a/src/about.js b/src/about.js index 102641cef..2ed842ce9 100644 --- a/src/about.js +++ b/src/about.js @@ -70,6 +70,7 @@ ${getBlueprintVersion()} "JCWasmx86 https://github.com/JCWasmx86", "Alex (PaladinDev) https://github.com/SpikedPaladin", "Diego Iván M.E https://github.com/Diego-Ivan", + "Rasmus Thomsen ", "Marvin W https://github.com/mar-v-in", // Add yourself as // "John Doe",