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

Method HandleExternalPaste

page.go:622–816  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

620}
621
622func (page *Page) HandleExternalPaste() {
623
624 if clipboardImg := clipboard.Read(clipboard.FmtImage); clipboardImg != nil {
625
626 if filePath, err := WriteImageToTemp(clipboardImg); err != nil {
627 globals.EventLog.Log(err.Error(), false)
628 } else {
629
630 globals.Resources.Get(filePath).TempFile = true
631 globals.Resources.Get(filePath).SaveFile = true
632
633 card := page.CreateNewCard(ContentTypeImage)
634 contents := card.Contents.(*ImageContents)
635 contents.LoadFileFrom(filePath)
636 card.Properties.Get("saveimage").Set(true)
637
638 }
639
640 } else if txt := clipboard.Read(clipboard.FmtText); txt != nil {
641
642 text := string(txt)
643
644 if res := globals.Resources.Get(text); res != nil && res.MimeType != "" {
645
646 if strings.Contains(res.MimeType, "image") || res.Extension == ".tga" || res.Extension == ".svg" {
647
648 card := page.CreateNewCard(ContentTypeImage)
649 card.Contents.(*ImageContents).LoadFileFrom(text)
650
651 } else if strings.Contains(res.MimeType, "audio") {
652
653 card := page.CreateNewCard(ContentTypeSound)
654 card.Contents.(*SoundContents).LoadFileFrom(text)
655
656 } else if strings.Contains(res.MimeType, "text") {
657
658 card := page.CreateNewCard(ContentTypeNote)
659 noteContents := card.Contents.(*NoteContents)
660 // noteContents.Label.Editing = true
661
662 // TODO: Fix this
663 noteContents.Label.SetText([]rune(text))
664 // noteContents.Label.Editing = false
665 // card.Properties.Get("description").Set(text)
666
667 } else {
668 globals.EventLog.Log("WARNING: Unsure of type of file at pasted link:\n%s\nNo card was created for this link.", true, text)
669 }
670
671 } else {
672
673 text = strings.ReplaceAll(text, "\r\n", "\n")
674
675 textLines := strings.Split(text, "\n")
676
677 // Get rid of empty starting and ending
678
679 tl := []string{}

Callers 1

GlobalShortcutsMethod · 0.80

Calls 15

CreateNewCardMethod · 0.95
LockPositionMethod · 0.95
RecreateMethod · 0.95
WriteImageToTempFunction · 0.85
LogMethod · 0.80
SetTextMethod · 0.80
LockToGridMethod · 0.80
WorldPositionMethod · 0.80
MeasureTextMethod · 0.80
MeasureTextAutowrapMethod · 0.80
DefaultSizeMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected