Skip to content
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

Find Gtk doc index at build time #121

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
9 changes: 8 additions & 1 deletion build-aux/build-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ async function loadDocs() {
const [pkgdatadir] = ARGV;
GLib.mkdir_with_parents(pkgdatadir, 0o755);

const start_index = DOC_INDEX.findIndex((doc) => doc.name === "Gtk-4.0");

await Gio.File.new_for_path(pkgdatadir)
.get_child("doc-index.json")
.replace_contents_async(
new TextEncoder().encode(JSON.stringify(DOC_INDEX)),
new TextEncoder().encode(
JSON.stringify({
start_index,
docs: DOC_INDEX,
}),
),
null,
false,
Gio.FileCreateFlags.NONE,
Expand Down
1 change: 1 addition & 0 deletions src/sidebar/Sidebar.blp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ template $Sidebar : Adw.NavigationPage {
[top]
Box {
SearchEntry search_entry {
search-delay: 200;
AkshayWarrier marked this conversation as resolved.
Show resolved Hide resolved
hexpand: true;
placeholder-text: _("Search Biblioteca");
}
Expand Down
40 changes: 19 additions & 21 deletions src/sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import Template from "./Sidebar.blp" with { type: "uri" };

import "../icons/edit-find-symbolic.svg";

const GTK_INDEX = 19;
let doc_index;
AkshayWarrier marked this conversation as resolved.
Show resolved Hide resolved

class Sidebar extends Adw.NavigationPage {
constructor(...params) {
super(params);
this.uri_to_tree_path = {};
this.#initializeSidebar();
this.#connectSearchEntry();
this._search_entry.connect("search-changed", this.#onSearch);
}

resetSidebar() {
this.browse_view.collapseAllRows();
this.browse_view.selection_model.selected = GTK_INDEX;
this.browse_view.selection_model.selected = doc_index?.start_index ?? 0;
this._search_entry.text = "";
this._stack.visible_child = this.browse_view;
}
Expand All @@ -45,18 +45,18 @@ class Sidebar extends Adw.NavigationPage {
"doc-index.json",
);
const content = index_file.load_contents(null);
const doc_index = JSON.parse(decode(content[1]));
doc_index = JSON.parse(decode(content[1]));

let idx = 0;
const promises = [];
for (const item of doc_index) {
for (const item of doc_index.docs) {
promises.push(
this.#buildPage(this.browse_view.root_model, item, [idx++]),
);
}

Promise.all(promises).then(() => {
this.browse_view.selection_model.selected = GTK_INDEX;
this.browse_view.selection_model.selected = doc_index.start_index;
this.search_view.initializeModel(this.flattened_model);
});

Expand Down Expand Up @@ -107,21 +107,19 @@ class Sidebar extends Adw.NavigationPage {
return Gio.ListStore.new(DocumentationPage);
}

#connectSearchEntry() {
this._search_entry.connect("search-changed", () => {
if (this._search_entry.text) {
this._stack.visible_child = this.search_view;
this.search_view.search_term = this._search_entry.text;
if (!this.search_view.selection_model.n_items)
this._stack.visible_child = this._status_page;
} else {
const index = this.browse_view.selection_model.selected;
this._stack.visible_child = this.browse_view;
// Make sure the selection doesnt change when switching views
this.browse_view.selection_model.selected = index;
}
});
}
#onSearch = () => {
if (this._search_entry.text) {
this._stack.visible_child = this.search_view;
this.search_view.search_term = this._search_entry.text;
if (!this.search_view.selection_model.n_items)
this._stack.visible_child = this._status_page;
} else {
const index = this.browse_view.selection_model.selected;
this._stack.visible_child = this.browse_view;
// Make sure the selection doesnt change when switching views
this.browse_view.selection_model.selected = index;
}
};
}

export default GObject.registerClass(
Expand Down