| <template> |
| <ContextMenu :options="contextMenuItems" @onMenuItemClick="onContextMenuItemClick" |
| @onMenuItemRightClick="onContextMenuItemRightClick"> |
| <div :class="'title' + selectedclass(treeDatumID)" :style="indentStyle" :data-label="treeDatum.title" |
| @click="titleBarClick"> |
| |
| <IconSwitcher v-if="treeDatum.nodes" class="title-element clickable expand-icon" |
| :useFirst="treeDatum.treeExpanded" :iconID1="['fa', 'angle-down']" :iconID2="['fa', 'angle-right']" |
| :width="15" @click="toggleExpand(treeDatumID)" /> |
| <div v-else :style="flexFixedWidth(7)"></div> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <Tooltip :tip="selInstructions"> |
| <div class="title-text clickable" @click="titleClick(treeDatumID)" |
| :style="treeDatum.visible ? '' : 'color: lightgray;'"> |
| {{ title }} |
| <span v-if="treeDatum.nodes"> |
| {{ descendentCounts(treeDatum) }} |
| </span> |
| </div> |
| </Tooltip> |
| |
| <IconBar :width="24 * Object.keys(iconsToDisplay).length" extraClasses="me-2 selected" |
| style="margin-right: 8px"> |
| |
| <IconSwitcher class="title-element clickable" :useFirst="treeDatum.visible" :iconID1="visibleIconToUse" |
| :iconID2="visibleIconToUse" :icon2Style="{ color: 'lightgray' }" :width="22" |
| @click="toggleVisible(treeDatumID)" title="Visible" /> |
| <IconSwitcher v-if="iconsToDisplay.focused" class="title-element clickable" |
| :useFirst="treeDatum.focused" :iconID1="['fa', 'arrows-to-eye']" :iconID2="['fa', 'arrows-to-eye']" |
| :icon2Style="{ color: 'lightgray' }" :width="22" @click="toggleFocused(treeDatumID)" |
| title="Focus" /> |
| <IconSwitcher v-if="iconsToDisplay.delete" class="title-element clickable delete" :useFirst="true" |
| :iconID1="['far', 'rectangle-xmark']" :iconID2="['far', 'rectangle-xmark']" :width="22" |
| @click="deleteMol(treeDatumID)" title="Delete" /> |
| <IconSwitcher v-if="iconsToDisplay.cloneExtract" class="title-element clickable cloneextract" |
| :useFirst="true" :iconID1="['far', 'clone']" :iconID2="['far', 'clone']" :width="22" |
| @click="cloneMol(treeDatumID)" title="Clone" /> |
| <IconSwitcher v-if="iconsToDisplay.rename" class="title-element clickable rename" :useFirst="true" |
| :iconID1="['fa', 'pencil']" :iconID2="['fa', 'pencil']" :width="22" @click="renameMol(treeDatumID)" |
| title="Rename" /> |
| |
| |
| </IconBar> |
| </div> |
| </ContextMenu> |
| </template> |
| |
| <script lang="ts"> |
| import { Options, Vue } from "vue-class-component"; |
| import { Prop } from "vue-property-decorator"; |
| import Tooltip from "@/UI/MessageAlerts/Tooltip.vue"; |
| import * as LoadedPlugins from "@/Plugins/LoadedPlugins"; |
| import ContextMenu from "../ContextMenu/ContextMenu.vue"; |
| import { IContextMenuOption } from "../ContextMenu/ContextMenuInterfaces"; |
| import { getMoleculesFromStore } from "@/Store/StoreExternalAccess"; |
| import IconSwitcher from "@/UI/Navigation/TitleBar/IconBar/IconSwitcher.vue"; |
| import IconBar from "@/UI/Navigation/TitleBar/IconBar/IconBar.vue"; |
| import { TreeNodeType, SelectedType } from "../TreeView/TreeInterfaces"; |
| import { flexFixedWidthStyle } from "../TitleBar/IconBar/IconBarUtils"; |
| import * as api from "@/Api"; |
| import { doSelecting, selectInstructionsBrief } from "./MolSelecting"; |
| import { TreeNode } from "@/TreeNodes/TreeNode/TreeNode"; |
| import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList"; |
| import { IMenuItem, IMenuSubmenu } from "../Menu/Menu"; |
| import { toggleVisibilityWithConfirmation } from "../TreeView/TreeUtils"; |
| interface IIconsToDisplay { |
| visible?: boolean; |
| focused?: boolean; |
| rename?: boolean; |
| cloneExtract?: boolean; |
| delete?: boolean; |
| } |
| |
| |
| |
| |
| @Options({ |
| components: { |
| IconSwitcher, |
| IconBar, |
| Tooltip, |
| ContextMenu, |
| }, |
| }) |
| export default class TitleBar extends Vue { |
| @Prop({ required: true }) treeDatum!: TreeNode; |
| @Prop({ default: 0 }) depth!: number; |
| @Prop({ default: undefined }) treeData!: TreeNodeList; |
| @Prop({ default: "" }) filterStr!: string; |
| |
| |
| |
| |
| |
| |
| get visibleIconToUse(): string[] | string { |
| |
| const children = this.treeDatum.nodes?.flattened; |
| |
| if (!children) return ["far", "fa-eye"]; |
| |
| let someVisible = undefined as boolean | undefined; |
| let someInvisible = undefined as boolean | undefined; |
| |
| for (const child of children._nodes) { |
| if (child.visible) someVisible = true; |
| else someInvisible = true; |
| |
| if (someVisible && someInvisible) { |
| |
| return "half_visible.svg"; |
| } |
| } |
| |
| if (someVisible && !someInvisible) { |
| |
| this.treeDatum.visible = true; |
| return ["far", "fa-eye"]; |
| } |
| |
| |
| this.treeDatum.visible = false; |
| return ["far", "fa-eye-slash"]; |
| |
| |
| |
| |
| |
| |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| descendentCounts(node: TreeNode): string { |
| const numChildren = node.nodes?.length; |
| const numTerminals = node.nodes?.terminals.length; |
| |
| |
| const triggerId = node.nodes?.triggerId; |
| if (triggerId === "-234") return ""; |
| |
| let s = `(${numChildren}`; |
| if (numChildren !== numTerminals) { |
| s += ` / ${numTerminals}`; |
| } |
| s += ")"; |
| return s; |
| } |
| |
| |
| |
| |
| |
| |
| get treeDatumID(): TreeNodeType { |
| return this.treeDatum.id as TreeNodeType; |
| } |
| |
| |
| |
| |
| |
| |
| get indentStyle(): string { |
| let depthToUse = this.depth; |
| if (this.depth === 0 && this.treeDatum.parentId) { |
| |
| depthToUse = this.treeDatum.getAncestry(getMoleculesFromStore()).length - 1; |
| } |
| return `margin-left:${8 * depthToUse}px;`; |
| } |
| |
| |
| |
| |
| |
| get getLocalTreeData(): any { |
| if (!this.treeData) { |
| return this.$store.state["molecules"]; |
| } |
| return this.treeData; |
| } |
| |
| |
| |
| |
| |
| |
| get iconsToDisplay(): IIconsToDisplay { |
| let toDisplay: IIconsToDisplay = {}; |
| |
| |
| toDisplay.visible = true; |
| |
| |
| if (this.treeDatum.visible) { |
| toDisplay.focused = true; |
| } |
| |
| |
| if (this.isSelected(this.treeDatumID)) { |
| toDisplay.rename = true; |
| toDisplay.cloneExtract = true; |
| toDisplay.delete = true; |
| } |
| |
| return toDisplay; |
| } |
| |
| |
| |
| |
| |
| |
| get selInstructions(): string { |
| return selectInstructionsBrief; |
| } |
| |
| |
| |
| |
| |
| |
| |
| get title(): string { |
| let title = this.treeDatum.title; |
| |
| |
| |
| title = title.replace("(", ":"); |
| title = title.replace(")", ":"); |
| while (title.indexOf(" :") !== -1) { |
| title = title.replace(" :", ":"); |
| } |
| while (title.indexOf(": ") !== -1) { |
| title = title.replace(": ", ":"); |
| } |
| |
| |
| while (title.startsWith(":")) { |
| title = title.slice(1); |
| } |
| |
| title = title.trim(); |
| |
| while (title.indexOf("::") !== -1) { |
| title = title.replace("::", ":"); |
| } |
| |
| |
| if (title.endsWith(":")) { |
| title = title.slice(0, title.length - 1); |
| } |
| |
| return title; |
| } |
| |
| |
| |
| |
| |
| |
| |
| flexFixedWidth(width: number): string { |
| return flexFixedWidthStyle(width); |
| } |
| |
| |
| |
| |
| |
| |
| |
| selectedclass(id: string): string { |
| let node = this.getNode(id); |
| if (node === null) { |
| return ""; |
| } |
| return node.selected !== SelectedType.False ? " selected" : ""; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| isSelected(id: string): boolean { |
| let node = this.getNode(id); |
| if (node === null) { |
| return false; |
| } |
| return node.selected !== SelectedType.False; |
| } |
| |
| |
| |
| |
| |
| |
| |
| getNode(id: string): TreeNode | null { |
| return (this.getLocalTreeData as TreeNodeList).filters.onlyId(id); |
| } |
| |
| |
| |
| |
| |
| titleBarClick() { |
| |
| |
| |
| |
| } |
| |
| |
| |
| |
| |
| |
| toggleExpand(id: string) { |
| let node = this.getNode(id); |
| if (node !== null) { |
| node.treeExpanded = !node.treeExpanded; |
| |
| |
| |
| if (node.treeExpanded) { |
| let currentNode = node; |
| while (currentNode.nodes && currentNode.nodes.length === 1) { |
| const child = currentNode.nodes.get(0); |
| child.treeExpanded = true; |
| currentNode = child; |
| } |
| } |
| |
| |
| if (node.nodes?.terminals.length === 1) { |
| node.nodes.flattened.forEach((node2: TreeNode) => { |
| node2.treeExpanded = true; |
| }); |
| } |
| } |
| } |
| |
| |
| |
| |
| |
| |
| async toggleVisible(id: string) { |
| let node = this.getNode(id); |
| if (node === null) { |
| return; |
| } |
| |
| let nodesToToggle: TreeNodeList; |
| if (node.selected !== SelectedType.False) { |
| |
| nodesToToggle = getMoleculesFromStore().filters.keepSelected(true, true); |
| } else { |
| |
| nodesToToggle = new TreeNodeList([node]).flattened; |
| } |
| |
| await toggleVisibilityWithConfirmation(nodesToToggle); |
| } |
| |
| |
| |
| |
| |
| async toggleFocused(id: string) { |
| let allData = this.$store.state["molecules"] as TreeNodeList; |
| if (this.getNode(id)?.focused) { |
| |
| this.$store.commit("clearFocusedMolecule"); |
| } else { |
| |
| allData.flattened.forEach((node: TreeNode) => { |
| node.focused = node.id === id; |
| }); |
| } |
| const viewer = await api.visualization.viewer; |
| viewer.zoomOnFocused(); |
| } |
| |
| |
| |
| |
| |
| |
| renameMol(id: string) { |
| api.plugins.runPlugin("renamemol", id); |
| } |
| |
| |
| |
| |
| |
| |
| cloneMol(id: string) { |
| api.plugins.runPlugin("clonemol", id); |
| } |
| |
| |
| |
| |
| |
| |
| deleteMol(id: string) { |
| api.plugins.runPlugin("deletemol", id); |
| } |
| |
| |
| |
| |
| |
| |
| titleClick(id: string) { |
| doSelecting(id, this.getLocalTreeData, this.filterStr); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| get editMenuItems(): IMenuItem[] { |
| const editMenu = LoadedPlugins.allMenuData.filter( |
| (m) => m.text === "Edit" |
| )[0] as IMenuSubmenu; |
| |
| |
| const allEditItems: IMenuItem[] = []; |
| |
| editMenu.items.forEach((item) => { |
| const subItems = (item as IMenuSubmenu).items; |
| if (subItems === undefined) { |
| |
| |
| |
| |
| return; |
| } |
| |
| for (const subItem of subItems) { |
| |
| if (["Undo", "Redo"].includes(subItem.text as string)) { |
| continue; |
| } |
| allEditItems.push(subItem as IMenuItem); |
| } |
| allEditItems.push({ |
| path: "", |
| text: "separator", |
| } as IMenuItem); |
| }); |
| |
| |
| while (allEditItems[0].text === "separator") { |
| allEditItems.shift(); |
| } |
| while (allEditItems[allEditItems.length - 1].text === "separator") { |
| allEditItems.pop(); |
| } |
| |
| return allEditItems; |
| } |
| |
| |
| |
| |
| |
| |
| get contextMenuItems(): IContextMenuOption[] { |
| return this.editMenuItems.map((item) => { |
| const checkPluginAllowed = item.checkPluginAllowed; |
| const allowed = checkPluginAllowed |
| ? checkPluginAllowed(this.$store.state.molecules) === null |
| : true; |
| return { |
| text: item.text as string, |
| pluginId: item.pluginId as string, |
| enabled: allowed, |
| function: item.function, |
| } as IContextMenuOption; |
| }); |
| } |
| |
| |
| |
| |
| |
| onContextMenuItemRightClick() { |
| const id = this.treeDatumID; |
| const isSelected = this.isSelected(id); |
| |
| if (!isSelected) { |
| doSelecting(id, this.getLocalTreeData, this.filterStr); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| onContextMenuItemClick(menuItem: IContextMenuOption) { |
| if (menuItem && menuItem.function) { |
| menuItem.function(); |
| } |
| } |
| } |
| </script> |
| |
| <style lang="scss"></style> |
| |
| |
| <style lang="scss" scoped> |
| .title { |
| display: flex; |
| } |
| |
| .title-element { |
| margin-right: 2px; |
| display: block; |
| float: right; |
| } |
| |
| .title-text { |
| flex: auto; |
| white-space: nowrap; |
| overflow: hidden; |
| text-overflow: ellipsis; |
| } |
| |
| .clickable { |
| cursor: pointer; |
| } |
| |
| .title-text:hover { |
| text-decoration: underline; |
| } |
| |
| .btn-bar { |
| overflow: hidden; |
| right: 0; |
| position: absolute; |
| background-color: white; |
| padding-bottom: 1px; |
| } |
| |
| // See https://codepen.io/kdydesign/pen/VrQZqx |
| $transition-time: 0.2s; |
| |
| .slide-enter-active { |
| -moz-transition-duration: $transition-time; |
| -webkit-transition-duration: $transition-time; |
| -o-transition-duration: $transition-time; |
| transition-duration: $transition-time; |
| -moz-transition-timing-function: ease-in; |
| -webkit-transition-timing-function: ease-in; |
| -o-transition-timing-function: ease-in; |
| transition-timing-function: ease-in; |
| } |
| |
| .slide-leave-active { |
| -moz-transition-duration: $transition-time; |
| -webkit-transition-duration: $transition-time; |
| -o-transition-duration: $transition-time; |
| transition-duration: $transition-time; |
| -moz-transition-timing-function: cubic-bezier(0, 1, 0.5, 1); |
| -webkit-transition-timing-function: cubic-bezier(0, 1, 0.5, 1); |
| -o-transition-timing-function: cubic-bezier(0, 1, 0.5, 1); |
| transition-timing-function: cubic-bezier(0, 1, 0.5, 1); |
| } |
| |
| .slide-enter-to, |
| .slide-leave { |
| max-height: 100px; |
| overflow: hidden; |
| } |
| |
| .slide-enter, |
| .slide-leave-to { |
| overflow: hidden; |
| max-height: 0; |
| } |
| |
| .selected, |
| .selected * { |
| background-color: #f0f0f0; |
| } |
| </style> |
| |
| <style lang="scss"></style> |
| |