Module: Clipboard::Gtk

Extended by:
Gtk
Includes:
Implementation
Included in:
Gtk
Defined in:
lib/clipboard/gtk.rb

Overview

Ruby-Gnome2 based implementation Requires either the gtk3 or the gtk2 gem

Constant Summary collapse

CLIPBOARDS =
%w[clipboard primary secondary].freeze

Instance Method Summary collapse

Instance Method Details

#clear(clipboard: "all") ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/clipboard/gtk.rb', line 46

def clear(clipboard: "all")
  selections = clipboard.to_s == "all" ? CLIPBOARDS : [clipboard]
  selections.each{ |selection|
    raise ArgumentError, "unknown clipboard selection" unless CLIPBOARDS.include?(selection)

    ::Gtk::Clipboard.get(Gdk::Selection.const_get(selection.to_s.upcase)).clear
  }

  true
end

#copy(data, clipboard: "all") ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/clipboard/gtk.rb', line 35

def copy(data, clipboard: "all")
  selections = clipboard.to_s == "all" ? CLIPBOARDS : [clipboard]
  selections.each{ |selection|
    raise ArgumentError, "unknown clipboard selection" unless CLIPBOARDS.include?(selection)

    ::Gtk::Clipboard.get(Gdk::Selection.const_get(selection.to_s.upcase)).set_text(data).store
  }

  true
end

#paste(which = nil, clipboard: "clipboard") ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
# File 'lib/clipboard/gtk.rb', line 26

def paste(which = nil, clipboard: "clipboard")
  selection = which || clipboard
  raise ArgumentError, "unknown clipboard selection" unless CLIPBOARDS.include?(selection)

  ::Gtk::Clipboard.get(
    Gdk::Selection.const_get(selection.to_s.upcase)
  ).wait_for_text || ""
end