Add bottom panel support (#1294)

* Add bottom panel

* Bottom panel store

* Extract ExtensionSlot component

* Tab rendering

* Add toggle button on top menu bar

* nit

* Add toggle button tooltip

* Add command
This commit is contained in:
Chenlei Hu
2024-10-24 21:15:19 +02:00
committed by GitHub
parent 957a767ed0
commit d142893244
11 changed files with 240 additions and 58 deletions

View File

@@ -0,0 +1,59 @@
import type { BottomPanelExtension } from '@/types/extensionTypes'
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { useCommandStore } from '@/stores/commandStore'
export const useBottomPanelStore = defineStore('bottomPanel', () => {
const bottomPanelVisible = ref(false)
const toggleBottomPanel = () => {
// If there are no tabs, don't show the bottom panel
if (bottomPanelTabs.value.length === 0) {
return
}
bottomPanelVisible.value = !bottomPanelVisible.value
}
const bottomPanelTabs = ref<BottomPanelExtension[]>([])
const activeBottomPanelTabId = ref<string | null>(null)
const activeBottomPanelTab = computed<BottomPanelExtension | null>(() => {
return (
bottomPanelTabs.value.find(
(tab) => tab.id === activeBottomPanelTabId.value
) ?? null
)
})
const setActiveTab = (tabId: string) => {
activeBottomPanelTabId.value = tabId
}
const toggleBottomPanelTab = (tabId: string) => {
if (activeBottomPanelTabId.value === tabId) {
bottomPanelVisible.value = false
} else {
activeBottomPanelTabId.value = tabId
bottomPanelVisible.value = true
}
}
const registerBottomPanelTab = (tab: BottomPanelExtension) => {
bottomPanelTabs.value = [...bottomPanelTabs.value, tab]
if (bottomPanelTabs.value.length === 1) {
activeBottomPanelTabId.value = tab.id
}
useCommandStore().registerCommand({
id: `Workspace.ToggleBottomPanelTab.${tab.id}`,
icon: 'pi pi-list',
label: tab.title,
function: () => toggleBottomPanelTab(tab.id)
})
}
return {
bottomPanelVisible,
toggleBottomPanel,
bottomPanelTabs,
activeBottomPanelTab,
activeBottomPanelTabId,
setActiveTab,
toggleBottomPanelTab,
registerBottomPanelTab
}
})