|
| 1 | +<template> |
| 2 | + <!-- SpecialUrlAddToTabsetComponent --> |
| 3 | + <!-- {{ handler.actions(currentTabsetId, { tabset: props.tabset, level: props.level }) }}--> |
| 4 | + <template |
| 5 | + v-if="handler.actions(currentTabsetId, { tabset: props.tabset, level: 'root' }).length == 0 && defaultAction"> |
| 6 | + <q-btn |
| 7 | + padding="xs" |
| 8 | + fab-mini |
| 9 | + unelevated |
| 10 | + @click.stop="emits('buttonClicked', new ActionHandlerButtonClickedHolder(handler, defaultAction))" |
| 11 | + class="q-ma-none q-px-sm q-py-none" |
| 12 | + :icon="defaultAction.icon" |
| 13 | + :class="{ shakeWithColor: animateAddtabButton, 'cursor-pointer': !alreadyInTabset }" |
| 14 | + :color="alreadyInTabset ? 'grey-5' : containedInTsCount > 0 ? 'primary' : 'warning'" |
| 15 | + size="12px" |
| 16 | + data-testid="saveInTabsetBtn"> |
| 17 | + <!-- <div>{{ defaultAction.label }}</div>--> |
| 18 | + <!-- <q-icon right class="q-ma-none q-pa-none" size="2em" name="o_south" />--> |
| 19 | + </q-btn> |
| 20 | + <q-tooltip class="tooltip-small" v-if="alreadyInTabset"> Already in current tabset</q-tooltip> |
| 21 | + <q-tooltip class="tooltip-small" v-else-if="containedInTsCount > 0"> |
| 22 | + {{ tooltipAlreadyInOtherTabsets(props.tabset!.name) }} |
| 23 | + </q-tooltip> |
| 24 | + <q-tooltip class="tooltip-small" v-else> |
| 25 | + Add current Tab to '{{ tabsetNameOrChain(props.tabset as Tabset) }}'... |
| 26 | + </q-tooltip> |
| 27 | + </template> |
| 28 | + |
| 29 | + <!-- SpecialUrlAddToTabsetComponent handlerDefaultAction --> |
| 30 | + <template v-else-if="showExtraMenuItems()"> |
| 31 | + <!-- :disable="!handler.actions()[0]!.active(props.currentChromeTab)"--> |
| 32 | + <q-btn |
| 33 | + fab-mini |
| 34 | + glossy |
| 35 | + padding="xs" |
| 36 | + rounded |
| 37 | + @click.stop="emits('buttonClicked', new ActionHandlerButtonClickedHolder(handler, defaultAction))" |
| 38 | + class="q-ma-none q-pa-none" |
| 39 | + :icon="defaultAction?.icon" |
| 40 | + :class="{ shakeWithColor: animateAddtabButton, 'cursor-pointer': !alreadyInTabset }" |
| 41 | + :color="alreadyInTabset ? 'grey-5' : containedInTsCount > 0 ? 'primary' : 'warning'" |
| 42 | + data-testid="saveInTabsetBtn"> |
| 43 | + <!-- <div>{{ defaultAction.label }}</div>--> |
| 44 | + <!-- <q-icon right class="q-ma-none q-pa-none" size="2em" name="o_south" />--> |
| 45 | + <q-tooltip class="tooltip-small" v-if="alreadyInTabset"> Already in current tabset</q-tooltip> |
| 46 | + <q-tooltip class="tooltip-small" v-else-if="containedInTsCount > 0"> |
| 47 | + {{ tooltipAlreadyInOtherTabsets(props.tabset!.name) }} |
| 48 | + </q-tooltip> |
| 49 | + <q-tooltip class="tooltip-small" v-else> |
| 50 | + Add current Tab to '{{ tabsetNameOrChain(props.tabset as Tabset) }}'... |
| 51 | + </q-tooltip> |
| 52 | + </q-btn> |
| 53 | + |
| 54 | + <transition appear> |
| 55 | + <span> |
| 56 | + <q-btn flat icon="more_vert" text-color="primary" class="cursor-pointer q-ma-none q-pa-none" size="md" /> |
| 57 | + <q-menu :offset="[0, 0]" @click.stop=""> |
| 58 | + <q-list dense style="min-width: 200px"> |
| 59 | + <template v-for="l in handler.actions(currentTabsetId, { tabset: props.tabset, level: 'root' })"> |
| 60 | + <template v-if="'context' in l"> |
| 61 | + <component |
| 62 | + :key="l.component.name" |
| 63 | + :is="l.component" |
| 64 | + :tabset="props.tabset" |
| 65 | + :folder="props.folder" |
| 66 | + :level="'root'" |
| 67 | + :context="'context' in l ? l.context : {}" /> |
| 68 | + </template> |
| 69 | + <template v-else> |
| 70 | + <component :key="l.name" :is="l" :tabset="props.tabset" :folder="props.folder" :level="'root'" /> |
| 71 | + </template> |
| 72 | + </template> |
| 73 | + </q-list> |
| 74 | + </q-menu> |
| 75 | + </span> |
| 76 | + </transition> |
| 77 | + </template> |
| 78 | +</template> |
| 79 | + |
| 80 | +<script lang="ts" setup> |
| 81 | +import { useQuasar } from 'quasar' |
| 82 | +import { useActionHandlers } from 'src/tabsets/actionHandling/ActionHandlers' |
| 83 | +import { AddUrlToTabsetHandler } from 'src/tabsets/actionHandling/AddUrlToTabsetHandler' |
| 84 | +import { NoopAddUrlToTabsetHandler } from 'src/tabsets/actionHandling/handler/NoopAddUrlToTabsetHandler' |
| 85 | +import { ActionContext } from 'src/tabsets/actionHandling/model/ActionContext' |
| 86 | +import { ActionHandlerButtonClickedHolder } from 'src/tabsets/actionHandling/model/ActionHandlerButtonClickedHolder' |
| 87 | +import { useTabsetService } from 'src/tabsets/services/TabsetService2' |
| 88 | +import { useTabsetsStore } from 'src/tabsets/stores/tabsetsStore' |
| 89 | +import { useUiStore } from 'src/ui/stores/uiStore' |
| 90 | +import { ref, watchEffect } from 'vue' |
| 91 | +import { Tabset } from '../models/Tabset' |
| 92 | +
|
| 93 | +const props = defineProps<{ |
| 94 | + currentChromeTab: chrome.tabs.Tab |
| 95 | + tabset: Tabset |
| 96 | + folder?: Tabset |
| 97 | +}>() |
| 98 | +
|
| 99 | +const emits = defineEmits(['buttonClicked', 'asNewFile', 'extraSpaceNeeded']) |
| 100 | +
|
| 101 | +const $q = useQuasar() |
| 102 | +
|
| 103 | +const { getHandler } = useActionHandlers($q) |
| 104 | +
|
| 105 | +const handler = ref<AddUrlToTabsetHandler>(new NoopAddUrlToTabsetHandler()) |
| 106 | +const defaultAction = ref<ActionContext | undefined>(undefined) |
| 107 | +const containedInTsCount = ref(0) |
| 108 | +const animateAddtabButton = ref(false) |
| 109 | +const currentTabsetId = ref<string | undefined>(undefined) |
| 110 | +const alreadyInTabset = ref(false) |
| 111 | +//const extraMenuItems = ref(false) |
| 112 | +
|
| 113 | +watchEffect(() => { |
| 114 | + useTabsetsStore() |
| 115 | + .getCurrentTabsetId() |
| 116 | + .then((tsId: string | undefined) => (currentTabsetId.value = tsId)) |
| 117 | +}) |
| 118 | +
|
| 119 | +const showExtraMenuItems = () => { |
| 120 | + const res: boolean = |
| 121 | + handler.value.actions(currentTabsetId.value, { tabset: props.tabset, level: 'root' }).length > 0 && |
| 122 | + defaultAction.value !== undefined |
| 123 | + emits('extraSpaceNeeded', res) |
| 124 | + return res |
| 125 | +} |
| 126 | +
|
| 127 | +watchEffect(() => { |
| 128 | + handler.value = getHandler(props.currentChromeTab.url, props.folder) |
| 129 | + defaultAction.value = handler.value.defaultAction() |
| 130 | + showExtraMenuItems() |
| 131 | +}) |
| 132 | +
|
| 133 | +watchEffect(() => { |
| 134 | + containedInTsCount.value = useTabsetService().tabsetsFor(props.currentChromeTab.url!).length |
| 135 | +}) |
| 136 | +
|
| 137 | +watchEffect(() => { |
| 138 | + animateAddtabButton.value = useUiStore().animateAddtabButton |
| 139 | +}) |
| 140 | +
|
| 141 | +watchEffect(() => { |
| 142 | + alreadyInTabset.value = useTabsetService().urlExistsInCurrentTabset(props.currentChromeTab.url) |
| 143 | +}) |
| 144 | +
|
| 145 | +const activeFolderNameFor = (ts: Tabset, activeFolder: string) => { |
| 146 | + const folder = useTabsetsStore().getActiveFolder(ts, activeFolder) |
| 147 | + return folder ? folder.name : ts.name |
| 148 | +} |
| 149 | +
|
| 150 | +const tabsetNameOrChain = (tabset: Tabset) => { |
| 151 | + return tabset.folderActive ? activeFolderNameFor(tabset, tabset.folderActive) : tabset.name |
| 152 | +} |
| 153 | +
|
| 154 | +const tooltipAlreadyInOtherTabsets = (tabsetName: string) => |
| 155 | + `Already contained in ${containedInTsCount.value} other tabsets. Click to add here as well.` |
| 156 | +</script> |
| 157 | + |
| 158 | +<style> |
| 159 | +.q-btn-dropdown--simple * + .q-btn-dropdown__arrow { |
| 160 | + margin-left: 0; |
| 161 | + border: 1px solid red; |
| 162 | +} |
| 163 | +
|
| 164 | +.q-btn-dropdown--split .q-btn-dropdown__arrow-container { |
| 165 | + padding: 0; |
| 166 | +} |
| 167 | +</style> |
0 commit comments