REBOL [ Title: "Clips" Purpose: { Installs a tray icon (Windows only) and collects small text snippets. } Author: "Gabriele Santilli" EMail: giesse@rebol.it File: %clips.r License: { Copyright (C) 2006 Gabriele Santilli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. http://www.gnu.org/copyleft/gpl.html } Date: 11-Feb-2006 Version: 1.1.0 ; majorv.minorv.status ; status: 0: unfinished; 1: testing; 2: stable History: [ 11-Feb-2006 1.1.0 "History start" ] ] clips: any [ attempt [load %clips.txt] [ [["Persistent clips" "Here you get persistent clips."]] [["Your clipboard" "Here you see the last five items from your clipboard."]] ] ] keys: [] system/ports/system/awake: func [port /local msg] [ while [msg: pick port 1] [ if find/match msg [tray main menu] [ msg: last msg switch/default msg [ save [ inform layout [ across text 70 right "Title:" title: field return text 70 right "Note:" note: area any [attempt [read clipboard://] ""] return btn-enter "Add" [hide-popup] ] insert/only tail clips/1 reduce [title/text note/text] attempt [save %clips.txt clips] set-tray ] edit [ alert "Not yet implemented. Feel free to implement it." ] quit [ set-modes port [tray: [remove main]] quit ] ] [ if msg: find keys msg [ msg: index? msg msg: any [pick clips/1 msg pick clips/2 msg - length? clips/1] write clipboard:// msg/2 ] ] ] ] false ] insert tail system/ports/wait-list system/ports/system set-tray: has [menu w] [ menu: copy [ save: "Add note..." edit: "Edit..." quit: "Quit" bar ] keys: make block! add length? clips/1 length? clips/2 foreach pclip first clips [ w: to word! join "clip" index? tail keys append keys w insert insert tail menu to set-word! w pclip/1 ] append menu 'bar foreach clip second clips [ w: to word! join "clip" index? tail keys append keys w insert insert tail menu to set-word! w clip/1 ] set-modes system/ports/system compose/deep/only [ tray: [ add main [ help: "Clips" menu: (menu) ] ] ] ] set-tray alert "I will sit in your system tray and keep track of your clips." forever [ wait 5 if all [clip: attempt [read clipboard://] not empty? clip any [empty? clips/2 clip <> second last clips/2]] [ insert/only tail clips/2 reduce [trim/lines copy/part clip 20 clip] clips/2: skip tail clips/2 -5 attempt [save %clips.txt clips] set-tray ] ]