1 Star 0 Fork 21

interesting-goods/Fyne

forked from Gitee 极速下载/Fyne 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
shortcut.go 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
package fyne
import (
"sync"
)
// ShortcutHandler is a default implementation of the shortcut handler
// for the canvasObject
type ShortcutHandler struct {
mu sync.RWMutex
entry map[string]func(Shortcut)
}
// TypedShortcut handle the registered shortcut
func (sh *ShortcutHandler) TypedShortcut(shortcut Shortcut) {
if _, ok := sh.entry[shortcut.ShortcutName()]; !ok {
return
}
sh.entry[shortcut.ShortcutName()](shortcut)
}
// AddShortcut register an handler to be executed when the shortcut action is triggered
func (sh *ShortcutHandler) AddShortcut(shortcut Shortcut, handler func(shortcut Shortcut)) {
sh.mu.Lock()
defer sh.mu.Unlock()
if sh.entry == nil {
sh.entry = make(map[string]func(Shortcut))
}
sh.entry[shortcut.ShortcutName()] = handler
}
// Shortcut is the interface used to describe a shortcut action
type Shortcut interface {
ShortcutName() string
}
// ShortcutPaste describes a shortcut paste action.
type ShortcutPaste struct {
Clipboard Clipboard
}
// ShortcutName returns the shortcut name
func (se *ShortcutPaste) ShortcutName() string {
return "Paste"
}
// ShortcutCopy describes a shortcut copy action.
type ShortcutCopy struct {
Clipboard Clipboard
}
// ShortcutName returns the shortcut name
func (se *ShortcutCopy) ShortcutName() string {
return "Copy"
}
// ShortcutCut describes a shortcut cut action.
type ShortcutCut struct {
Clipboard Clipboard
}
// ShortcutName returns the shortcut name
func (se *ShortcutCut) ShortcutName() string {
return "Cut"
}
// ShortcutSelectAll describes a shortcut selectAll action.
type ShortcutSelectAll struct{}
// ShortcutName returns the shortcut name
func (se *ShortcutSelectAll) ShortcutName() string {
return "SelectAll"
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/interesting-goods/Fyne.git
[email protected]:interesting-goods/Fyne.git
interesting-goods
Fyne
Fyne
master

搜索帮助