MCPcopy
hub / github.com/wavetermdev/waveterm / CreateTab

Function CreateTab

pkg/wcore/workspace.go:223–268  ·  view source on GitHub ↗

returns tabid

(ctx context.Context, workspaceId string, tabName string, activateTab bool, isInitialLaunch bool)

Source from the content-addressed store, hash-verified

221
222// returns tabid
223func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, isInitialLaunch bool) (string, error) {
224 if tabName == "" {
225 ws, err := GetWorkspace(ctx, workspaceId)
226 if err != nil {
227 return "", fmt.Errorf("workspace %s not found: %w", workspaceId, err)
228 }
229 tabNames := make([]string, 0, len(ws.TabIds))
230 for _, tabId := range ws.TabIds {
231 tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, tabId)
232 if err != nil || tab == nil {
233 continue
234 }
235 tabNames = append(tabNames, tab.Name)
236 }
237 tabName = getNextTabName(tabNames)
238 }
239
240 tab, err := createTabObj(ctx, workspaceId, tabName, nil)
241 if err != nil {
242 return "", fmt.Errorf("error creating tab: %w", err)
243 }
244 if activateTab {
245 err = SetActiveTab(ctx, workspaceId, tab.OID)
246 if err != nil {
247 return "", fmt.Errorf("error setting active tab: %w", err)
248 }
249 }
250
251 // No need to apply an initial layout for the initial launch, since the starter layout will get applied after onboarding modal dismissal
252 if !isInitialLaunch {
253 err = ApplyPortableLayout(ctx, tab.OID, GetNewTabLayout(), true)
254 if err != nil {
255 return tab.OID, fmt.Errorf("error applying new tab layout: %w", err)
256 }
257 tabBg := getTabBackground()
258 if tabBg != "" {
259 tabORef := waveobj.ORefFromWaveObj(tab)
260 wstore.UpdateObjectMeta(ctx, *tabORef, waveobj.MetaMapType{waveobj.MetaKey_TabBackground: tabBg}, false)
261 }
262 }
263 telemetry.GoUpdateActivityWrap(wshrpc.ActivityUpdate{NewTab: 1}, "createtab")
264 telemetry.GoRecordTEventWrap(&telemetrydata.TEvent{
265 Event: "action:createtab",
266 })
267 return tab.OID, nil
268}
269
270func createTabObj(ctx context.Context, workspaceId string, name string, meta waveobj.MetaMapType) (*waveobj.Tab, error) {
271 ws, err := GetWorkspace(ctx, workspaceId)

Callers 3

CreateTabMethod · 0.92
CreateWorkspaceFunction · 0.85
CheckAndFixWindowFunction · 0.85

Calls 12

DBMustGetFunction · 0.92
ORefFromWaveObjFunction · 0.92
UpdateObjectMetaFunction · 0.92
GoUpdateActivityWrapFunction · 0.92
GoRecordTEventWrapFunction · 0.92
GetWorkspaceFunction · 0.85
getNextTabNameFunction · 0.85
createTabObjFunction · 0.85
SetActiveTabFunction · 0.85
ApplyPortableLayoutFunction · 0.85
GetNewTabLayoutFunction · 0.85
getTabBackgroundFunction · 0.85

Tested by

no test coverage detected