Skip to content

Commit

Permalink
cmd/fyne_demo: set the clipboard for Copy/Cut/Paste shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrec committed Oct 2, 2024
1 parent 70576c8 commit 50b23bb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/fyne_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ func makeMenu(a fyne.App, w fyne.Window) *fyne.MainMenu {

cutShortcut := &fyne.ShortcutCut{Clipboard: a.Clipboard()}
cutItem := fyne.NewMenuItem("Cut", func() {
shortcutFocused(cutShortcut, w.Canvas().Focused())
shortcutFocused(cutShortcut, a.Clipboard(), w.Canvas().Focused())
})
cutItem.Shortcut = cutShortcut
copyShortcut := &fyne.ShortcutCopy{Clipboard: a.Clipboard()}
copyItem := fyne.NewMenuItem("Copy", func() {
shortcutFocused(copyShortcut, w.Canvas().Focused())
shortcutFocused(copyShortcut, a.Clipboard(), w.Canvas().Focused())
})
copyItem.Shortcut = copyShortcut
pasteShortcut := &fyne.ShortcutPaste{Clipboard: a.Clipboard()}
pasteItem := fyne.NewMenuItem("Paste", func() {
shortcutFocused(pasteShortcut, w.Canvas().Focused())
shortcutFocused(pasteShortcut, a.Clipboard(), w.Canvas().Focused())
})
pasteItem.Shortcut = pasteShortcut
performFind := func() { fmt.Println("Menu Find") }
Expand Down Expand Up @@ -251,7 +251,15 @@ func makeNav(setTutorial func(tutorial tutorials.Tutorial), loadPrevious bool) f
return container.NewBorder(nil, themes, nil, nil, tree)
}

func shortcutFocused(s fyne.Shortcut, f fyne.Focusable) {
func shortcutFocused(s fyne.Shortcut, cb fyne.Clipboard, f fyne.Focusable) {
switch sh := s.(type) {
case *fyne.ShortcutCopy:
sh.Clipboard = cb
case *fyne.ShortcutCut:
sh.Clipboard = cb
case *fyne.ShortcutPaste:
sh.Clipboard = cb
}
if focused, ok := f.(fyne.Shortcutable); ok {
focused.TypedShortcut(s)
}
Expand Down

0 comments on commit 50b23bb

Please sign in to comment.