annotate tests/Dnd/droptest.el @ 288:e11d67e05968 r21-0b42

Import from CVS: tag r21-0b42
author cvs
date Mon, 13 Aug 2007 10:35:54 +0200
parents 558f606b08ae
children c9fe270a4101
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
1 ;; a short example how to use the new Drag'n'Drop API in
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
2 ;; combination with extents.
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
3 ;;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
4
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
5 (defun dnd-drop-message (event object text)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
6 (message "Dropped %s with :%s" text object)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
7 ;; signal that we have done something with the data
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
8 t)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
9
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
10 (defun do-nothing (event object)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
11 ;; signal that the data is still unprocessed
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
12 nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
13
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
14 (defun start-drag (event what &optional typ)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
15 ;; short drag interface, until the real one is implemented
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
16 (cond ((featurep 'offix)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
17 (if (numberp typ)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
18 (offix-start-drag event what typ)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
19 (offix-start-drag event what)))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
20 ((featurep 'cde)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
21 (if (not typ)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
22 (funcall (intern "cde-start-drag-internal") event nil (list what))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
23 (funcall (intern "cde-start-drag-internal") event t what)))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
24 (t display-message 'error "no valid drag protocols implemented")))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
25
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
26 (defun make-drop-targets ()
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
27 (let ((buf (get-buffer-create "*DND misc-user extent test buffer*"))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
28 (s nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
29 (e nil))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
30 (set-buffer buf)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
31 (pop-to-buffer buf)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
32 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
33 (insert "[ DROP TARGET 1]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
34 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
35 (setq ext (make-extent s e))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
36 (set-extent-property ext
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
37 'dragdrop-drop-functions
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
38 '((do-nothing t t)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
39 (dnd-drop-message t t "on target 1")))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
40 (set-extent-property ext 'mouse-face 'highlight)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
41 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
42 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
43 (insert "[ DROP TARGET 2]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
44 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
45 (setq ext (make-extent s e))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
46 (set-extent-property ext
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
47 'dragdrop-drop-functions
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
48 '((dnd-drop-message t t "on target 2")))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
49 (set-extent-property ext 'mouse-face 'highlight)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
50 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
51 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
52 (insert "[ DROP TARGET 3]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
53 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
54 (setq ext (make-extent s e))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
55 (set-extent-property ext
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
56 'dragdrop-drop-functions
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
57 '((dnd-drop-message t t "on target 3")))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
58 (set-extent-property ext 'mouse-face 'highlight)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
59 (newline 2)))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
60
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
61 (defun make-drag-starters ()
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
62 (let ((buf (get-buffer-create "*DND misc-user extent test buffer*"))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
63 (s nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
64 (e nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
65 (ext nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
66 (kmap nil))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
67 (set-buffer buf)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
68 (pop-to-buffer buf)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
69 (erase-buffer buf)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
70 (insert "Try to drag data from one of the upper extents to one\nof the lower extents. Make sure that your minibuffer is big\ncause it is used to display the data.\n\nYou may also try to select some of this text and drag it with button2.\n\nTo ")
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
71 (setq s (point))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
72 (insert "EXIT")
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
73 (setq e (point))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
74 (insert " this demo, press 'q'.")
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
75 (setq ext (make-extent s e))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
76 (setq kmap (make-keymap))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
77 (define-key kmap [button1] 'end-dnd-demo)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
78 (set-extent-property ext 'keymap kmap)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
79 (set-extent-property ext 'mouse-face 'highlight)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
80 (newline 2)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
81 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
82 (insert "[ TEXT DRAG TEST ]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
83 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
84 (setq ext (make-extent s e))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
85 (set-extent-property ext 'mouse-face 'isearch)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
86 (setq kmap (make-keymap))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
87 (define-key kmap [button1] 'text-drag)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
88 (set-extent-property ext 'keymap kmap)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
89 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
90 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
91 (insert "[ FILE DRAG TEST ]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
92 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
93 (setq ext (make-extent s e))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
94 (set-extent-property ext 'mouse-face 'isearch)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
95 (setq kmap (make-keymap))
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
96 (if (featurep 'cde)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
97 (define-key kmap [button1] 'cde-file-drag)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
98 (define-key kmap [button1] 'file-drag))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
99 (set-extent-property ext 'keymap kmap)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
100 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
101 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
102 (insert "[ FILES DRAG TEST ]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
103 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
104 (setq ext (make-extent s e))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
105 (set-extent-property ext 'mouse-face 'isearch)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
106 (setq kmap (make-keymap))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
107 (define-key kmap [button1] 'files-drag)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
108 (set-extent-property ext 'keymap kmap)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
109 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
110 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
111 (insert "[ URL DRAG TEST ]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
112 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
113 (setq ext (make-extent s e))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
114 (set-extent-property ext 'mouse-face 'isearch)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
115 (setq kmap (make-keymap))
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
116 (if (featurep 'cde)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
117 (define-key kmap [button1] 'cde-file-drag)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
118 (define-key kmap [button1] 'url-drag))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
119 (set-extent-property ext 'keymap kmap)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
120 (newline 3)))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
121
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
122 (defun text-drag (event)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
123 (interactive "@e")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
124 (start-drag event "That's a test"))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
125
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
126 (defun file-drag (event)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
127 (interactive "@e")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
128 (start-drag event "/tmp/printcap" 2))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
129
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
130 (defun cde-file-drag (event)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
131 (interactive "@e")
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
132 (start-drag event '("/tmp/printcap") t))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
133
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
134 (defun url-drag (event)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
135 (interactive "@e")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
136 (start-drag event "http://www.xemacs.org/" 8))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
137
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
138 (defun files-drag (event)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
139 (interactive "@e")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
140 (start-drag event '("/tmp/dragtest" "/tmp/droptest" "/tmp/printcap") 3))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
141
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
142 (setq dragdrop-drop-functions '((do-nothing t t)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
143 ;; CDE does not have any button info...
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
144 (dnd-drop-message 0 t "cde-drop somewhere else")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
145 (dnd-drop-message 2 t "region somewhere else")
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
146 (dnd-drop-message 1 t "drag-source somewhere else")
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
147 (do-nothing t t)))
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
148
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
149 (make-drag-starters)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
150 (make-drop-targets)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
151
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
152 (defun end-dnd-demo ()
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
153 (interactive)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
154 (global-set-key [button2] button2-func)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
155 (bury-buffer))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
156
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
157 (setq lmap (make-keymap))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
158 (use-local-map lmap)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
159 (local-set-key [q] 'end-dnd-demo)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
160 (setq button2-func (lookup-key global-map [button2]))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
161 (global-unset-key [button2])