Class: Teek::Clipboard
- Inherits:
-
Object
- Object
- Teek::Clipboard
- Defined in:
- lib/teek/clipboard.rb
Overview
Thin, typed wrapper around Tk's clipboard command family, reached
via App#clipboard.
Doesn't touch text widgets' own copy/cut/paste at all - ttk::entry/
text already bind <<Copy>>/<<Cut>>/<<Paste>> to the expected
platform keys (Control-c/x/v, plus their Command-key equivalents on
macOS) via Tk's own built-in class bindings, with nothing for teek to
wire up. This class is purely for reading/writing the clipboard
directly from app code (e.g. a "Copy to Clipboard" button that isn't
itself a text widget's own selection).
Instance Method Summary collapse
-
#clear ⇒ void
Clear the clipboard without setting new contents.
-
#get ⇒ String?
The clipboard's current text, or
nilif it's empty/has no owner (Tk raises a TclError for this rather than returning an empty string). -
#initialize(app) ⇒ Clipboard
constructor
private
A new instance of Clipboard.
-
#set(text) ⇒ void
Replace the clipboard's contents outright - Tk's own
clipboard clearfollowed byclipboard appendtwo-step, done as one call.
Constructor Details
#initialize(app) ⇒ Clipboard
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Clipboard.
18 19 20 |
# File 'lib/teek/clipboard.rb', line 18 def initialize(app) @app = app end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
Clear the clipboard without setting new contents.
43 44 45 46 |
# File 'lib/teek/clipboard.rb', line 43 def clear @app.tcl_invoke('clipboard', 'clear') nil end |
#get ⇒ String?
Returns the clipboard's current text, or nil if
it's empty/has no owner (Tk raises a TclError for this rather
than returning an empty string).
35 36 37 38 39 |
# File 'lib/teek/clipboard.rb', line 35 def get @app.tcl_invoke('clipboard', 'get') rescue Teek::TclError nil end |
#set(text) ⇒ void
This method returns an undefined value.
Replace the clipboard's contents outright - Tk's own clipboard clear followed by clipboard append two-step, done as one call.
26 27 28 29 30 |
# File 'lib/teek/clipboard.rb', line 26 def set(text) @app.tcl_invoke('clipboard', 'clear') @app.tcl_invoke('clipboard', 'append', '--', text.to_s) nil end |