2
// Copyright (C) 2010-2011 Robert Dyer
4
// This file is part of Plank.
6
// Plank is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
11
// Plank is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program. If not, see <http://www.gnu.org/licenses/>.
24
public class ClippyDockItem : DockletItem
26
Gtk.Clipboard clipboard;
27
Gee.ArrayList<string> clips = new Gee.ArrayList<string> ();
34
public ClippyDockItem.with_dockitem_file (GLib.File file)
36
GLib.Object (Prefs: new ClippyPreferences.with_file (file));
41
unowned ClippyPreferences prefs = (ClippyPreferences) Prefs;
45
if (prefs.TrackMouseSelections)
46
clipboard = Gtk.Clipboard.get (Gdk.Atom.intern ("PRIMARY", true));
48
clipboard = Gtk.Clipboard.get (Gdk.Atom.intern ("CLIPBOARD", true));
50
timer_id = Gdk.threads_add_timeout (prefs.TimerDelay, check_clipboard);
58
GLib.Source.remove (timer_id);
61
bool check_clipboard ()
63
clipboard.request_text ((Gtk.ClipboardTextReceivedFunc) clipboard_text_received);
68
[CCode (instance_pos = -1)]
69
void clipboard_text_received (Gtk.Clipboard clipboard, string text)
71
if (text == null || text == "")
74
unowned ClippyPreferences prefs = (ClippyPreferences) Prefs;
78
while (clips.size > prefs.MaxEntries)
81
cur_position = clips.size;
89
Text = _("Clipboard is currently empty.");
90
else if (cur_position == 0 || cur_position > clips.size)
91
Text = get_entry_at (clips.size);
93
Text = get_entry_at (cur_position);
96
string get_entry_at (int pos)
98
return clips.get (pos - 1).replace ("\n", "").replace ("\t", "");
101
void copy_entry_at (int pos)
103
if (pos < 1 || pos > clips.size)
106
var str = clips.get (pos - 1);
107
clipboard.set_text (str, (int) str.length);
114
if (cur_position == 0)
115
copy_entry_at (clips.size);
117
copy_entry_at (cur_position);
129
protected override Animation on_scrolled (Gdk.ScrollDirection direction, Gdk.ModifierType mod, uint32 event_time)
131
if (direction == Gdk.ScrollDirection.UP)
136
if (cur_position < 1)
137
cur_position = clips.size;
138
else if (cur_position > clips.size)
143
return Animation.NONE;
146
protected override Animation on_clicked (PopupButton button, Gdk.ModifierType mod, uint32 event_time)
148
if (button == PopupButton.LEFT && clips.size > 0) {
150
return Animation.BOUNCE;
153
return Animation.NONE;
156
public override Gee.ArrayList<Gtk.MenuItem> get_menu_items ()
158
var items = new Gee.ArrayList<Gtk.MenuItem> ();
160
for (var i = clips.size ; i > 0; i--) {
161
var item = create_menu_item (clips.get (i - 1), "edit-cut");
162
item.activate.connect (() => {
168
if (clips.size > 0) {
169
var item = create_menu_item (_("_Clear"), "edit-clear-all", true);
170
item.activate.connect (clear);