diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts index 67e4025b0..b06e19c6e 100644 --- a/apps/client/src/services/utils.ts +++ b/apps/client/src/services/utils.ts @@ -148,7 +148,7 @@ export function isElectron() { return !!(window && window.process && window.process.type); } -function isMac() { +export function isMac() { return navigator.platform.indexOf("Mac") > -1; } diff --git a/apps/client/src/widgets/buttons/note_actions.ts b/apps/client/src/widgets/buttons/note_actions.ts index 05b60230a..44e7a244d 100644 --- a/apps/client/src/widgets/buttons/note_actions.ts +++ b/apps/client/src/widgets/buttons/note_actions.ts @@ -37,88 +37,3 @@ const TPL = /*html*/` `; - -export default class NoteActionsWidget extends NoteContextAwareWidget { - - private $convertNoteIntoAttachmentButton!: JQuery; - private $findInTextButton!: JQuery; - private $printActiveNoteButton!: JQuery; - private $exportAsPdfButton!: JQuery; - private $showSourceButton!: JQuery; - private $showAttachmentsButton!: JQuery; - private $renderNoteButton!: JQuery; - private $saveRevisionButton!: JQuery; - private $exportNoteButton!: JQuery; - private $importNoteButton!: JQuery; - private $openNoteExternallyButton!: JQuery; - private $openNoteCustomButton!: JQuery; - private $deleteNoteButton!: JQuery; - - isEnabled() { - return this.note?.type !== "launcher"; - } - - doRender() { - this.$widget = $(TPL); - this.$widget.on("show.bs.dropdown", () => { - if (this.note) { - this.refreshVisibility(this.note); - } - }); - - this.$convertNoteIntoAttachmentButton = this.$widget.find("[data-trigger-command='convertNoteIntoAttachment']"); - this.$findInTextButton = this.$widget.find(".find-in-text-button"); - this.$printActiveNoteButton = this.$widget.find(".print-active-note-button"); - this.$exportAsPdfButton = this.$widget.find(".export-as-pdf-button"); - this.$showSourceButton = this.$widget.find(".show-source-button"); - this.$showAttachmentsButton = this.$widget.find(".show-attachments-button"); - this.$renderNoteButton = this.$widget.find(".render-note-button"); - this.$saveRevisionButton = this.$widget.find(".save-revision-button"); - - this.$widget.on("click", ".dropdown-item", () => this.$widget.find("[data-bs-toggle='dropdown']").dropdown("toggle")); - - this.$openNoteExternallyButton = this.$widget.find(".open-note-externally-button"); - this.$openNoteCustomButton = this.$widget.find(".open-note-custom-button"); - } - - async refreshVisibility(note: FNote) { - this.$convertNoteIntoAttachmentButton.toggle(note.isEligibleForConversionToAttachment()); - - this.toggleDisabled(this.$showAttachmentsButton, !isInOptions); - this.toggleDisabled(this.$showSourceButton, ["text", "code", "relationMap", "mermaid", "canvas", "mindMap"].includes(note.type)); - - - this.toggleDisabled(this.$printActiveNoteButton, canPrint); - this.toggleDisabled(this.$exportAsPdfButton, canPrint); - this.$exportAsPdfButton.toggleClass("hidden-ext", !utils.isElectron()); - - this.toggleDisabled(this.$openNoteExternallyButton, utils.isElectron() && !["search", "book"].includes(note.type)); - this.toggleDisabled( - this.$openNoteCustomButton, - utils.isElectron() && - !utils.isMac() && // no implementation for Mac yet - !["search", "book"].includes(note.type) - ); - - // I don't want to handle all special notes like this, but intuitively user might want to export content of backend log - this.toggleDisabled(this.$exportNoteButton, !["_backendLog"].includes(note.noteId) && !isInOptions); - - this.toggleDisabled(this.$importNoteButton, !["search"].includes(note.type) && !isInOptions); - this.toggleDisabled(this.$deleteNoteButton, !isInOptions); - this.toggleDisabled(this.$saveRevisionButton, !isInOptions); - } - - toggleDisabled($el: JQuery, enable: boolean) { - if (enable) { - $el.removeAttr("disabled"); - } else { - $el.attr("disabled", "disabled"); - } - } - - entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { - if (loadResults.isNoteReloaded(this.noteId)) { - this.refresh(); - } - } -} diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx index f5587dbbf..ec9835936 100644 --- a/apps/client/src/widgets/ribbon/NoteActions.tsx +++ b/apps/client/src/widgets/ribbon/NoteActions.tsx @@ -9,7 +9,7 @@ import ws from "../../services/ws"; import ActionButton from "../react/ActionButton" import Dropdown from "../react/Dropdown"; import { FormDropdownDivider, FormListItem } from "../react/FormList"; -import { isElectron as getIsElectron } from "../../services/utils"; +import { isElectron as getIsElectron, isMac as getIsMac } from "../../services/utils"; import { ParentComponent } from "../react/react_utils"; import { useContext } from "preact/hooks"; import NoteContext from "../../components/note_context"; @@ -44,15 +44,19 @@ function RevisionsButton({ note }: NoteActionsProps) { function NoteContextMenu(props: NoteActionsProps) { const { note, noteContext } = props; - if (!note) { + if (!note || note.type === "launcher") { return <>; } const parentComponent = useContext(ParentComponent); + const canBeConvertedToAttachment = note?.isEligibleForConversionToAttachment(); const isSearchable = ["text", "code", "book", "mindMap", "doc"].includes(note.type); const isInOptions = note.noteId.startsWith("_options"); const isPrintable = ["text", "code"].includes(note.type); const isElectron = getIsElectron(); + const isMac = getIsMac(); + const hasSource = ["text", "code", "relationMap", "mermaid", "canvas", "mindMap"].includes(note.type); + const isSearchOrBook = ["search", "book"].includes(note.type); return ( - + {canBeConvertedToAttachment && } {note.type === "render" && } - {isElectron && } + {isElectron && } parentComponent?.triggerCommand("showImportDialog", { noteId: note.noteId })} /> noteContext?.notePath && parentComponent?.triggerCommand("showExportDialog", { notePath: noteContext.notePath, defaultType: "single" })} /> - - - + + + - + branches.deleteNotes([note.getParentBranches()[0].branchId])} /> - + ); } @@ -103,7 +110,7 @@ function CommandItem({ icon, text, title, command, disabled }: { icon: string, t } function ConvertToAttachment({ note }: NoteActionsProps) { - return (note?.isEligibleForConversionToAttachment() && + return ( {