mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
4070abadde
Only create new tab in `CheckAndFixWindow` if no tabs or pinned tabs exist Update `resolvers.resolveTabNum` to account for pinned tabs Remove obsolete and unused `wstore.DeleteTab` Only show accelerators for first 9 workspaces in workspace app menu to be consistent with other keybindings Fix tabbar spacing to remove min size for drag right spacer, account for workspace switcher button size Fix updatebanner size calculations
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
// Copyright 2024, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package wstore
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
|
|
"github.com/wavetermdev/waveterm/pkg/waveobj"
|
|
)
|
|
|
|
func init() {
|
|
for _, rtype := range waveobj.AllWaveObjTypes() {
|
|
waveobj.RegisterType(rtype)
|
|
}
|
|
}
|
|
|
|
func UpdateTabName(ctx context.Context, tabId, name string) error {
|
|
return WithTx(ctx, func(tx *TxWrap) error {
|
|
tab, _ := DBGet[*waveobj.Tab](tx.Context(), tabId)
|
|
if tab == nil {
|
|
return fmt.Errorf("tab not found: %q", tabId)
|
|
}
|
|
if tabId != "" {
|
|
tab.Name = name
|
|
DBUpdate(tx.Context(), tab)
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func UpdateObjectMeta(ctx context.Context, oref waveobj.ORef, meta waveobj.MetaMapType, mergeSpecial bool) error {
|
|
return WithTx(ctx, func(tx *TxWrap) error {
|
|
if oref.IsEmpty() {
|
|
return fmt.Errorf("empty object reference")
|
|
}
|
|
obj, _ := DBGetORef(tx.Context(), oref)
|
|
if obj == nil {
|
|
return ErrNotFound
|
|
}
|
|
objMeta := waveobj.GetMeta(obj)
|
|
if objMeta == nil {
|
|
objMeta = make(map[string]any)
|
|
}
|
|
newMeta := waveobj.MergeMeta(objMeta, meta, mergeSpecial)
|
|
waveobj.SetMeta(obj, newMeta)
|
|
DBUpdate(tx.Context(), obj)
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func MoveBlockToTab(ctx context.Context, currentTabId string, newTabId string, blockId string) error {
|
|
return WithTx(ctx, func(tx *TxWrap) error {
|
|
block, _ := DBGet[*waveobj.Block](tx.Context(), blockId)
|
|
if block == nil {
|
|
return fmt.Errorf("block not found: %q", blockId)
|
|
}
|
|
currentTab, _ := DBGet[*waveobj.Tab](tx.Context(), currentTabId)
|
|
if currentTab == nil {
|
|
return fmt.Errorf("current tab not found: %q", currentTabId)
|
|
}
|
|
newTab, _ := DBGet[*waveobj.Tab](tx.Context(), newTabId)
|
|
if newTab == nil {
|
|
return fmt.Errorf("new tab not found: %q", newTabId)
|
|
}
|
|
blockIdx := utilfn.FindStringInSlice(currentTab.BlockIds, blockId)
|
|
if blockIdx == -1 {
|
|
return fmt.Errorf("block not found in current tab: %q", blockId)
|
|
}
|
|
currentTab.BlockIds = utilfn.RemoveElemFromSlice(currentTab.BlockIds, blockId)
|
|
newTab.BlockIds = append(newTab.BlockIds, blockId)
|
|
block.ParentORef = waveobj.MakeORef(waveobj.OType_Tab, newTabId).String()
|
|
DBUpdate(tx.Context(), block)
|
|
DBUpdate(tx.Context(), currentTab)
|
|
DBUpdate(tx.Context(), newTab)
|
|
return nil
|
|
})
|
|
}
|