Installs a tray icon (Windows only) and collects small text snippets.
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.
When | Version | What | Who |
---|---|---|---|
11-Feb-2006 | 1.1.0 | History start | |
28-Feb-2006 | 1.2.0 | Added edit mode, comments | |
3-Mar-2006 | 1.3.0 | Converted to RLP format |
This program implements a little utility for Windows users. It installs an icon in the system tray, and keeps track of text snippets from your clipboard (showing the last 5 items that you copied). It also allows you to add small notes.
The code is divided into three main sections: 〈3. Globals〉, defining a few global values, 〈4. Functions〉, defining the functions (actually, just one), and 〈5. System port setup〉, that sets up the system port (used to get Windows messages from the tray icon).
After that, the program consists of calling the set-tray function, that installs the systray icon and attaches a menu to it, and looping forever (see the 〈2.1 Forever loop〉 section for the reason we do this).
〈Main〉 ≡
〈3. Globals〉
〈4. Functions〉
〈5. System port setup〉
set-tray
forever [
〈2.1 Forever loop〉
]
Every 5 seconds, we check che clipboard. If a new clip is present, we add it to the clipboard history.
We conclude that there is a new clip if all the following conditions are met:
If it is so, we add it to the list (the title for the snippet is generated from the clip text); then if the list is longer than 5 items, we remove the older items (so only 5 are retained). (Note that we are actually only moving the block position; on saving only values from this position onward are saved (since we are not using save/all) and when generating the menu only these are considered.) Then we save the clips and recreate the menu by calling the set-tray function.
〈2.1 Forever loop〉 ≡
wait 5
if all [clip: attempt [read clipboard://] not empty? clip any [empty? clips/2 clip ≠ second last clips/2]] [
; add clip to the list (title generated from clip text)
insert/only tail clips/2 reduce [trim/lines copy/part clip 20 clip]
; show only the last 5 items in the history
clips/2: skip tail clips/2 −5
; save and recreate menu
attempt [save %clips.txt clips]
set-tray
]