forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add paste support to entry widget (fyne-io#89)
* Add initial paste support to entry * Add Clipboard interface, implement for Gl driver * Add Shortcut interface and default handler * Allow adding of shortcuts to canvas
- Loading branch information
1 parent
0570f9b
commit 728a60a
Showing
18 changed files
with
686 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package fyne | ||
|
||
// Clipboard represents the system clipboard interface | ||
type Clipboard interface { | ||
// Content returns the clipboard content | ||
Content() string | ||
// SetContent sets the clipboard content | ||
SetContent(content string) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package desktop | ||
|
||
import ( | ||
"strings" | ||
|
||
"fyne.io/fyne" | ||
) | ||
|
||
// CustomShortcut describes a shortcut desktop event. | ||
type CustomShortcut struct { | ||
fyne.KeyName | ||
Modifier | ||
} | ||
|
||
// ShortcutName returns the shortcut name associated to the event | ||
func (cs *CustomShortcut) ShortcutName() string { | ||
id := &strings.Builder{} | ||
id.WriteString("CustomDesktop:") | ||
id.WriteString(modifierToString(cs.Modifier)) | ||
id.WriteString("+") | ||
id.WriteString(string(cs.KeyName)) | ||
return id.String() | ||
} | ||
|
||
func modifierToString(mods Modifier) string { | ||
s := []string{} | ||
if (mods & ShiftModifier) != 0 { | ||
s = append(s, string(KeyShift)) | ||
} | ||
if (mods & ControlModifier) != 0 { | ||
s = append(s, string(KeyControl)) | ||
} | ||
if (mods & AltModifier) != 0 { | ||
s = append(s, string(KeyAlt)) | ||
} | ||
if (mods & SuperModifier) != 0 { | ||
s = append(s, string(KeySuper)) | ||
} | ||
return strings.Join(s, "+") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package desktop | ||
|
||
import ( | ||
"testing" | ||
|
||
"fyne.io/fyne" | ||
) | ||
|
||
func TestCustomShortcut_Shortcut(t *testing.T) { | ||
type fields struct { | ||
KeyName fyne.KeyName | ||
Modifier Modifier | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want string | ||
}{ | ||
{ | ||
name: "Ctrl+C", | ||
fields: fields{ | ||
KeyName: fyne.KeyC, | ||
Modifier: ControlModifier, | ||
}, | ||
want: "CustomDesktop:Control+C", | ||
}, | ||
{ | ||
name: "Ctrl+Alt+Esc", | ||
fields: fields{ | ||
KeyName: fyne.KeyEscape, | ||
Modifier: ControlModifier + AltModifier, | ||
}, | ||
want: "CustomDesktop:Control+Alt+Escape", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cs := &CustomShortcut{ | ||
KeyName: tt.fields.KeyName, | ||
Modifier: tt.fields.Modifier, | ||
} | ||
if got := cs.ShortcutName(); got != tt.want { | ||
t.Errorf("CustomShortcut.ShortcutName() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_modifierToString(t *testing.T) { | ||
type args struct { | ||
} | ||
tests := []struct { | ||
name string | ||
mods Modifier | ||
want string | ||
}{ | ||
{ | ||
name: "None", | ||
mods: 0, | ||
want: "", | ||
}, | ||
{ | ||
name: "Ctrl", | ||
mods: ControlModifier, | ||
want: "Control", | ||
}, | ||
{ | ||
name: "Shift+Ctrl", | ||
mods: ShiftModifier + ControlModifier, | ||
want: "Shift+Control", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := modifierToString(tt.mods); got != tt.want { | ||
t.Errorf("modifierToString() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package gl | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/go-gl/glfw/v3.2/glfw" | ||
) | ||
|
||
// clipboard represents the system clipboard | ||
type clipboard struct { | ||
window *glfw.Window | ||
} | ||
|
||
// Content returns the clipboard content | ||
func (c *clipboard) Content() string { | ||
content, err := c.window.GetClipboardString() | ||
if err != nil { | ||
log.Printf("unable to get clipboard string: %v", err) | ||
return "" | ||
} | ||
return content | ||
} | ||
|
||
// SetContent sets the clipboard content | ||
func (c *clipboard) SetContent(content string) { | ||
c.window.SetClipboardString(content) | ||
} |
Oops, something went wrong.