|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import appContext, { type EventData } from "../../components/app_context.js";
|
|
|
|
|
import type FNote from "../../entities/fnote.js";
|
|
|
|
|
import type { NoteType } from "../../entities/fnote.js";
|
|
|
|
|
import { t } from "../../services/i18n.js";
|
|
|
|
|
import type { ViewScope } from "../../services/link.js";
|
|
|
|
|
@ -39,47 +40,28 @@ const byBookType: Record<ViewTypeOptions, string | null> = {
|
|
|
|
|
|
|
|
|
|
export default class ContextualHelpButton extends NoteContextAwareWidget {
|
|
|
|
|
|
|
|
|
|
private helpNoteIdToOpen?: string | null;
|
|
|
|
|
|
|
|
|
|
isEnabled() {
|
|
|
|
|
this.helpNoteIdToOpen = null;
|
|
|
|
|
|
|
|
|
|
if (!super.isEnabled()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.note && this.note.type !== "book" && byNoteType[this.note.type]) {
|
|
|
|
|
this.helpNoteIdToOpen = byNoteType[this.note.type];
|
|
|
|
|
} else if (this.note && this.note.type === "book") {
|
|
|
|
|
this.helpNoteIdToOpen = byBookType[this.note.getAttributeValue("label", "viewType") as ViewTypeOptions ?? ""]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !!this.helpNoteIdToOpen;
|
|
|
|
|
return !!ContextualHelpButton.#getUrlToOpen(this.note);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
|
this.$widget = $(TPL);
|
|
|
|
|
this.$widget.on("click", () => {
|
|
|
|
|
const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
|
|
|
|
|
const targetNote = `_help_${this.helpNoteIdToOpen}`;
|
|
|
|
|
const helpSubcontext = subContexts.find((s) => s.viewScope?.viewMode === "contextual-help");
|
|
|
|
|
const viewScope: ViewScope = {
|
|
|
|
|
viewMode: "contextual-help",
|
|
|
|
|
};
|
|
|
|
|
if (!helpSubcontext) {
|
|
|
|
|
// The help is not already open, open a new split with it.
|
|
|
|
|
const { ntxId } = subContexts[subContexts.length - 1];
|
|
|
|
|
this.triggerCommand("openNewNoteSplit", {
|
|
|
|
|
ntxId,
|
|
|
|
|
notePath: targetNote,
|
|
|
|
|
hoistedNoteId: "_help",
|
|
|
|
|
viewScope
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// There is already a help window open, make sure it opens on the right note.
|
|
|
|
|
helpSubcontext.setNote(targetNote, { viewScope });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static #getUrlToOpen(note: FNote | null | undefined) {
|
|
|
|
|
if (note && note.type !== "book" && byNoteType[note.type]) {
|
|
|
|
|
return byNoteType[note.type];
|
|
|
|
|
} else if (note && note.type === "book") {
|
|
|
|
|
return byBookType[note.getAttributeValue("label", "viewType") as ViewTypeOptions ?? ""]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async refreshWithNote(note: FNote | null | undefined): Promise<void> {
|
|
|
|
|
this.$widget.attr("data-in-app-help", ContextualHelpButton.#getUrlToOpen(this.note) ?? "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
|
|
|
|
|