()
| 620 | } |
| 621 | |
| 622 | func (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{} |
no test coverage detected