MCPcopy Create free account
hub / github.com/SolarLune/masterplan / Save

Method Save

project.go:366–521  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

364}
365
366func (project *Project) Save() {
367
368 project.SendMessage(NewMessage(MessageProjectSaveInitiated, nil, nil))
369
370 if globals.ReleaseMode == ReleaseModeDemo {
371 globals.EventLog.Log("Cannot save in demo mode of MasterPlan.", true)
372 return
373 }
374
375 saveData, _ := sjson.Set("{}", "version", globals.Version.String())
376
377 saveData, _ = sjson.Set(saveData, "pan", project.Camera.TargetPosition)
378 saveData, _ = sjson.Set(saveData, "zoom", project.Camera.TargetZoom)
379 saveData, _ = sjson.Set(saveData, "currentPage", project.CurrentPage.ID)
380
381 if cache := project.Properties.Get(ProjectCacheDirectory); cache.AsString() != "" {
382 cache.Set(project.PathToRelative(cache.AsString(), true))
383 }
384
385 saveData, _ = sjson.SetRaw(saveData, "properties", project.Properties.Serialize(true))
386
387 if cache := project.Properties.Get(ProjectCacheDirectory); cache.AsString() != "" {
388 cache.Set(project.PathToAbsolute(cache.AsString(), true))
389 }
390
391 savedImages := map[string]string{}
392
393 pageData := "["
394
395 pagesToSave := []*Page{project.Pages[0]}
396
397 if len(project.Pages) > 1 {
398
399 for _, page := range project.Pages[1:] {
400 // If a page is an orphan, then we can just skip saving it as long as it doesn't have any cards
401 if page.Valid() {
402 pagesToSave = append(pagesToSave, page)
403 } else if project.HasOrphanPages {
404
405 valid := false
406
407 // Orphan
408
409 for _, card := range page.Cards {
410 if card.Valid {
411 valid = true
412 break
413 }
414 }
415
416 // else, page.PointingSubpageCard points to a card that has been deleted; if it hadn't been deleted, then the page would be valid
417 if !valid {
418 continue
419 }
420
421 pagesToSave = append(pagesToSave, page)
422
423 }

Callers 4

AutoBackupMethod · 0.95
SaveAsMethod · 0.95
GlobalShortcutsMethod · 0.95
ConstructMenusFunction · 0.80

Calls 15

SendMessageMethod · 0.95
PathToRelativeMethod · 0.95
PathToAbsoluteMethod · 0.95
NewMessageFunction · 0.85
FileExistsFunction · 0.85
AddFileToRecentFilesListFunction · 0.85
LogMethod · 0.80
AsStringMethod · 0.80
SetRawMethod · 0.80
GetIfExistsMethod · 0.80
CloseMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected