-
-
Notifications
You must be signed in to change notification settings - Fork 90
library: Show which languages are available in each entry #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de2b0e3
c9a8868
47b5a59
c1dc107
9b00ce4
77c2928
a52b422
f6413ac
d1a14b7
a4ee37d
eca12d6
0f55da3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using Gtk 4.0; | ||
| using Adw 1; | ||
|
|
||
| template $EntryRow : Adw.PreferencesRow { | ||
| accessibility { | ||
| labelled-by: title_label; | ||
| described-by: description_label; | ||
| } | ||
| title: bind title_label.label; | ||
|
|
||
| Box contents { | ||
| orientation: horizontal; | ||
|
|
||
| Box labels_box { | ||
| margin-top: 6; | ||
| margin-start: 12; | ||
| margin-bottom: 6; | ||
| spacing: 3; | ||
| orientation: vertical; | ||
|
|
||
| Label title_label { | ||
| xalign: 0; | ||
| wrap: true; | ||
| wrap-mode: word_char; | ||
| } | ||
| Label description_label { | ||
| styles ["dim-label", "caption"] | ||
| xalign: 0; | ||
| wrap: true; | ||
| wrap-mode: word_char; | ||
| natural-wrap-mode: none; | ||
| } | ||
|
|
||
| Box languages_box { | ||
| orientation: horizontal; | ||
| spacing: 3; | ||
| margin-top: 3; | ||
| } | ||
| } | ||
|
|
||
| Image { | ||
| icon-name: "go-next-symbolic"; | ||
| margin-end: 12; | ||
| margin-start: 6; | ||
| hexpand: true; | ||
| halign: end; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import Adw from "gi://Adw"; | ||
| import Gtk from "gi://Gtk"; | ||
| import Gio from "gi://Gio"; | ||
| import GObject from "gi://GObject"; | ||
|
|
||
| import { demoSupportsLanguage, getLanguage } from "../util.js"; | ||
| import Template from "./EntryRow.blp" with { type: "uri" }; | ||
|
|
||
| class EntryRow extends Adw.PreferencesRow { | ||
| constructor({ demo, ...params } = {}) { | ||
| super(params); | ||
|
|
||
| this._title_label.label = demo.name; | ||
| this._description_label.label = demo.description; | ||
|
|
||
| this.#createLanguageTags(demo); | ||
|
|
||
| const action_group = new Gio.SimpleActionGroup(); | ||
| const activate_action = new Gio.SimpleAction({ | ||
| name: "activate", | ||
| parameter_type: null, | ||
| }); | ||
|
|
||
| activate_action.connect("activate", () => { | ||
| this.emit("activated", null); | ||
| }); | ||
| action_group.add_action(activate_action); | ||
|
|
||
| this.insert_action_group("demo-row", action_group); | ||
| this.action_name = "demo-row.activate"; | ||
| } | ||
|
|
||
| #createLanguageTags(demo) { | ||
| const language = getLanguage("javascript"); | ||
| const language_tag = this.#createLanguageTag(language); | ||
| this._languages_box.append(language_tag); | ||
|
|
||
| ["vala", "rust"].forEach((id) => { | ||
| const language = getLanguage(id); | ||
| if (!demoSupportsLanguage(demo, language.id)) return; | ||
| const language_tag = this.#createLanguageTag(language); | ||
| this._languages_box.append(language_tag); | ||
| }); | ||
| } | ||
|
|
||
| #createLanguageTag(language) { | ||
| const button = new Gtk.Button({ | ||
| label: language.name, | ||
| valign: Gtk.Align.CENTER, | ||
| css_classes: ["pill", "small"], | ||
| }); | ||
|
|
||
| button.connect("clicked", () => { | ||
| this.emit("activated", language.id); | ||
| }); | ||
|
|
||
| return button; | ||
| } | ||
| } | ||
|
|
||
| export default GObject.registerClass( | ||
| { | ||
| GTypeName: "EntryRow", | ||
| Template, | ||
| Properties: { | ||
| demo: GObject.ParamSpec.jsobject( | ||
| "demo", | ||
| "", | ||
| "", | ||
| GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY, | ||
| null, | ||
| ), | ||
| }, | ||
| Signals: { | ||
| activated: { | ||
| param_types: [GObject.TYPE_STRING], | ||
| }, | ||
| }, | ||
| InternalChildren: ["title_label", "description_label", "languages_box"], | ||
| }, | ||
| EntryRow, | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ export const languages = [ | |
| extensions: [".js", ".mjs"], | ||
| types: ["text/javascript", "application/javascript"], | ||
| document: null, | ||
| default_file: "main.js", | ||
| }, | ||
| { | ||
| id: "css", | ||
|
|
@@ -78,6 +79,7 @@ export const languages = [ | |
| types: ["text/x-vala"], | ||
| document: null, | ||
| placeholder: "// Sorry, this demo is not available in Vala yet.", | ||
| default_file: "main.vala", | ||
| }, | ||
| { | ||
| id: "rust", | ||
|
|
@@ -87,6 +89,7 @@ export const languages = [ | |
| types: ["text/x-rust"], | ||
| document: null, | ||
| placeholder: "// Sorry, this demo is not available in Rust yet.", | ||
| default_file: "code.rs", | ||
| }, | ||
| ]; | ||
|
|
||
|
|
@@ -186,6 +189,12 @@ export function getDemo(name) { | |
| return demo; | ||
| } | ||
|
|
||
| export function demoSupportsLanguage(demo, id) { | ||
| const language = getLanguage(id); | ||
| const demo_dir = demos_dir.get_child(demo.name); | ||
| return demo_dir.get_child(language.default_file).query_exists(null); | ||
| } | ||
|
Comment on lines
+192
to
+196
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For each demo (> 100) this checks twice if a file exist It's not ideal. The Library should already open faster. What I have in mind is to build a Library index at build time so there is no need to query file system to build the Library window.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was also worried about all the I/O, and although it did not seem to slow it down that much, with a hundred more demos it will likely be a problem. I thought about adding the languages available in each |
||
|
|
||
| export function getNowForFilename() { | ||
| return new GLib.DateTime().format("%Y-%m-%d %H-%M-%S"); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well done 👍