16
|
1 ;;; ediff-tbar.el --- A toolbar for Ediff control buffer
|
|
2
|
|
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Marc Paquette <marcpa@cam.org>
|
|
6
|
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Code:
|
|
25
|
|
26 (provide 'ediff-tbar)
|
|
27
|
|
28 ;; compiler pacifier
|
|
29 (defvar toolbar-icon-directory)
|
|
30
|
|
31 (eval-when-compile
|
|
32 (let ((load-path (cons (expand-file-name ".") load-path)))
|
|
33 (or (featurep 'ediff-init)
|
|
34 (load "ediff-init.el" nil nil 'nosuffix))
|
|
35 (or (featurep 'ediff-util)
|
|
36 (load "ediff-util.el" nil nil 'nosuffix))
|
|
37 ))
|
|
38 ;; end pacifier
|
|
39
|
|
40 (require 'ediff-init)
|
|
41
|
|
42 (defvar ediff-use-toolbar-p nil
|
|
43 "If t, Ediff will use a toolbar for the control frame.
|
|
44 This has an effect only if your emacs supports Toolbars.
|
|
45 Currently, XEmacs does, but not Emacs.
|
|
46 Do not change the value of this variable interactively.
|
|
47 This should be done only via the menu bar or by executing
|
|
48 `ediff-toggle-use-toolbar'.")
|
|
49
|
|
50 (defvar ediff-toolbar-height 21
|
|
51 "The height of the Ediff toolbar.
|
|
52 The value must match the actual size of the toolbar icons.")
|
|
53
|
|
54 (defvar ediff-toolbar-width 200.0
|
|
55 "The width of the Ediff toolbar.
|
|
56 The value must match the actual width of the toolbar.
|
|
57 Here's an example:
|
|
58 There are 10 buttons, each 15 pixels large, and the shadows occupy 2
|
|
59 pixels each side, and the last button is right-justified (so we reserve
|
|
60 about 30 pixels for fill space) = 200 pixels.")
|
|
61
|
|
62 (defun ediff-has-toolbar-support-p ()
|
|
63 (and ediff-xemacs-p
|
|
64 (featurep 'toolbar)
|
|
65 (console-on-window-system-p)))
|
|
66
|
|
67 (defun ediff-use-toolbar-p ()
|
|
68 (and (ediff-has-toolbar-support-p) ;Can it do it ?
|
|
69 ediff-use-toolbar-p)) ;Does the user want it ?
|
|
70
|
|
71 ;; Here the toolbar width is not the same width talked about in XEmacs
|
|
72 ;; lispref info documentation : it is the minimal width needed by
|
|
73 ;; ediff's toolbar to display all buttons, for an horizontal toolbar.
|
|
74 ;; Ideally, we would query the toolbar for the width of each button
|
|
75 ;; and add them, but I didn't find query functions in the doc on
|
|
76 ;; toolbars. Therefore, I use a static number of pixels that should
|
|
77 ;; be adjusted if the toolbar gets more or loses some buttons. --marcpa
|
|
78 (defun ediff-compute-toolbar-width ()
|
|
79 (if (not (ediff-use-toolbar-p))
|
|
80 0
|
|
81 (ceiling (/ ediff-toolbar-width (font-instance-width (face-font-instance 'default))))))
|
|
82
|
|
83 (defvar ediff-toolbar-next-icon
|
|
84 (if (featurep 'toolbar)
|
|
85 (toolbar-make-button-list
|
|
86 (expand-file-name
|
|
87 (if (featurep 'xpm) "ediff-next.xpm" "ediff-next.xbm")
|
|
88 toolbar-icon-directory)))
|
|
89 "Next difference icon in toolbar.")
|
|
90
|
|
91 (defvar ediff-toolbar-previous-icon
|
|
92 (if (featurep 'toolbar)
|
|
93 (toolbar-make-button-list
|
|
94 (expand-file-name
|
|
95 (if (featurep 'xpm) "ediff-prev.xpm" "ediff-prev.xbm")
|
|
96 toolbar-icon-directory)))
|
|
97 "Previous difference icon in toolbar.")
|
|
98
|
|
99 (defvar ediff-toolbar-A-icon
|
|
100 (if (featurep 'toolbar)
|
|
101 (toolbar-make-button-list
|
|
102 (expand-file-name
|
|
103 ;; UP
|
|
104 (if (featurep 'xpm) "ediff-A-up.xpm" "ediff-A-up.xbm")
|
|
105 toolbar-icon-directory)
|
|
106 (expand-file-name
|
|
107 ;; DOWN
|
|
108 (if (featurep 'xpm) "ediff-A-up.xpm" "ediff-A-up.xbm")
|
|
109 toolbar-icon-directory)
|
|
110 (expand-file-name
|
|
111 ;; DISABLED
|
|
112 (if (featurep 'xpm) "ediff-A-xx.xpm" "ediff-A-up.xbm")
|
|
113 toolbar-icon-directory)
|
|
114 ))
|
|
115 "Select diff A icon in toolbar.")
|
|
116
|
|
117 (defvar ediff-toolbar-B-icon
|
|
118 (if (featurep 'toolbar)
|
|
119 (toolbar-make-button-list
|
|
120 (expand-file-name
|
|
121 ;; UP
|
|
122 (if (featurep 'xpm) "ediff-B-up.xpm" "ediff-B-up.xbm")
|
|
123 toolbar-icon-directory)
|
|
124 (expand-file-name
|
|
125 ;; DOWN
|
|
126 (if (featurep 'xpm) "ediff-B-up.xpm" "ediff-B-up.xbm")
|
|
127 toolbar-icon-directory)
|
|
128 (expand-file-name
|
|
129 ;; DISABLED
|
|
130 (if (featurep 'xpm) "ediff-B-xx.xpm" "ediff-B-up.xbm")
|
|
131 toolbar-icon-directory)
|
|
132 ))
|
|
133 "Select diff B icon in toolbar.")
|
|
134
|
|
135 (defvar ediff-toolbar-toggle-split-icon
|
|
136 (if (featurep 'toolbar)
|
|
137 (toolbar-make-button-list
|
|
138 (expand-file-name
|
|
139 ;; UP
|
|
140 (if (featurep 'xpm)
|
|
141 "ediff-toggle-split-up.xpm" "ediff-toggle-split-up.xbm")
|
|
142 toolbar-icon-directory)
|
|
143 ))
|
|
144 "Toggle split mode between side-to-side and one-on-top-of-another.")
|
|
145
|
|
146 (defvar ediff-toolbar-save-icon
|
|
147 (if (featurep 'toolbar)
|
|
148 (toolbar-make-button-list
|
|
149 (expand-file-name
|
|
150 ;; UP
|
|
151 (if (featurep 'xpm) "ediff-save.xpm" "ediff-save.xbm")
|
|
152 toolbar-icon-directory)
|
|
153 (expand-file-name
|
|
154 ;; DOWN
|
|
155 (if (featurep 'xpm) "ediff-save.xpm" "ediff-save.xbm")
|
|
156 toolbar-icon-directory)
|
|
157 (expand-file-name
|
|
158 ;; DISABLED
|
|
159 (if (featurep 'xpm) "ediff-save-xx.xpm" "ediff-save-xx.xbm")
|
|
160 toolbar-icon-directory)
|
|
161 ))
|
|
162 "Save merge buffer.")
|
|
163
|
|
164 (defvar ediff-toolbar-quit-icon
|
|
165 (if (featurep 'toolbar)
|
|
166 (toolbar-make-button-list
|
|
167 (expand-file-name
|
|
168 (if (featurep 'xpm) "ediff-quit.xpm" "ediff-quit.xbm")
|
|
169 toolbar-icon-directory)))
|
|
170 "Exit Ediff session.")
|
|
171
|
|
172 (defvar ediff-toolbar-help-icon
|
|
173 (if (featurep 'toolbar)
|
|
174 (toolbar-make-button-list
|
|
175 (expand-file-name
|
|
176 (if (featurep 'xpm) "ediff-help.xpm" "ediff-help.xbm")
|
|
177 toolbar-icon-directory)))
|
|
178 "Show Ediff help.")
|
|
179
|
|
180 (defvar ediff-toolbar-refresh-icon
|
|
181 (if (featurep 'toolbar)
|
|
182 (toolbar-make-button-list
|
|
183 (expand-file-name
|
|
184 (if (featurep 'xpm) "ediff-update.xpm" "ediff-update.xbm")
|
|
185 toolbar-icon-directory)))
|
|
186 "Refresh Ediff display (aka recenter).")
|
|
187
|
|
188 (defvar ediff-toolbar-refine-icon
|
|
189 (if (featurep 'toolbar)
|
|
190 (toolbar-make-button-list
|
|
191 (expand-file-name
|
|
192 ;; UP
|
|
193 (if (featurep 'xpm) "ediff-refine.xpm" "ediff-refine.xbm")
|
|
194 toolbar-icon-directory)
|
|
195 ))
|
|
196 "Refine current difference region by computing fine diffs.")
|
|
197
|
|
198 (defun ediff-toolbar-previous-difference ()
|
|
199 (interactive)
|
|
200 (let ((ediff-grab-mouse nil))
|
|
201 (ediff-previous-difference 1)))
|
|
202
|
|
203 (defun ediff-toolbar-next-difference ()
|
|
204 (interactive)
|
|
205 (let ((ediff-grab-mouse nil))
|
|
206 (ediff-next-difference 1)))
|
|
207
|
|
208 (defun ediff-toolbar-select/copy-A ()
|
|
209 (interactive)
|
|
210 (let ((ediff-grab-mouse nil))
|
|
211 (cond ((or (ediff-merge-job)
|
|
212 (ediff-merge-with-ancestor-job))
|
|
213 (ediff-copy-A-to-C nil))
|
|
214 (t
|
|
215 (ediff-copy-A-to-B nil)))))
|
|
216
|
|
217 (defun ediff-toolbar-select/copy-B ()
|
|
218 (interactive)
|
|
219 (let ((ediff-grab-mouse nil))
|
|
220 (cond ((or (ediff-merge-job)
|
|
221 (ediff-merge-with-ancestor-job))
|
|
222 (ediff-copy-B-to-C nil))
|
|
223 (t
|
|
224 (ediff-copy-B-to-A nil)))))
|
|
225
|
|
226 (defun ediff-toolbar-toggle-split ()
|
|
227 (interactive)
|
|
228 (let ((ediff-grab-mouse nil))
|
|
229 (ediff-toggle-split)))
|
|
230
|
|
231
|
|
232 (defun ediff-toolbar-save ()
|
|
233 (interactive)
|
|
234 (ediff-barf-if-not-control-buffer)
|
|
235 (if (ediff-merge-job)
|
|
236 (ediff-maybe-save-and-delete-merge 'save-and-continue)
|
|
237 ;; 2-way or 3-way compare: save modified buffers
|
|
238 (mapcar (function
|
|
239 (lambda (type)
|
|
240 (let ((ebuf (ediff-get-buffer type)))
|
|
241 (and (ediff-buffer-live-p ebuf)
|
|
242 (ediff-eval-in-buffer ebuf
|
|
243 (and (buffer-modified-p)
|
|
244 (save-buffer)))))))
|
|
245 '(A B C))))
|
|
246
|
|
247
|
|
248 (defun ediff-toolbar-quit ()
|
|
249 (interactive)
|
|
250 (let ((ediff-grab-mouse nil))
|
|
251 (ediff-quit nil)))
|
|
252
|
|
253 (defun ediff-toolbar-help ()
|
|
254 (interactive)
|
|
255 (ediff-toggle-help))
|
|
256
|
|
257 (defun ediff-toolbar-refresh ()
|
|
258 "Recenter"
|
|
259 (interactive)
|
|
260 (let ((ediff-grab-mouse nil))
|
|
261 (ediff-recenter)))
|
|
262
|
|
263 (defun ediff-toolbar-refine ()
|
|
264 "Refine current difference region by computing fine diffs."
|
|
265 (interactive)
|
|
266 (let ((ediff-grab-mouse nil))
|
|
267 (ediff-make-or-kill-fine-diffs 'make-them)))
|
|
268
|
|
269 (defun ediff-toolbar-refine-needed-p ()
|
|
270 (and (> ediff-current-difference 0)
|
|
271 (> ediff-auto-refine-limit
|
|
272 (- (ediff-get-diff-posn 'A 'end ediff-current-difference)
|
|
273 (ediff-get-diff-posn 'A 'beg ediff-current-difference)))))
|
|
274
|
|
275 (defvar ediff-toolbar
|
|
276 (if (featurep 'toolbar)
|
|
277 '([ediff-toolbar-refine-icon
|
|
278 ediff-toolbar-refine
|
|
279 t
|
|
280 ;;; The toolbar is not automatically refreshed (in 19.14)
|
|
281 ;;; when :activep changes state.
|
|
282 ;;(ediff-toolbar-refine-needed-p)
|
|
283 "Refine current difference region by computing fine diffs."]
|
|
284 [ediff-toolbar-previous-icon
|
|
285 ediff-toolbar-previous-difference
|
|
286 t
|
|
287 "Go to the previous difference."]
|
|
288 [ediff-toolbar-next-icon
|
|
289 ediff-toolbar-next-difference
|
|
290 t
|
|
291 "Advance to the next difference."]
|
|
292 [ediff-toolbar-A-icon
|
|
293 ediff-toolbar-select/copy-A
|
|
294 (not (ediff-3way-comparison-job))
|
|
295 "Select/Copy difference A."]
|
|
296 [ediff-toolbar-B-icon
|
|
297 ediff-toolbar-select/copy-B
|
|
298 (not (ediff-3way-comparison-job))
|
|
299 "Select/Copy difference B."]
|
|
300 [ediff-toolbar-save-icon
|
|
301 ediff-toolbar-save
|
|
302 t
|
|
303 "Save buffers modified in this session."]
|
|
304 [ediff-toolbar-refresh-icon
|
|
305 ediff-toolbar-refresh
|
|
306 t
|
|
307 "Refresh Ediff display (aka recenter)."]
|
|
308 [ediff-toolbar-toggle-split-icon
|
|
309 ediff-toolbar-toggle-split
|
|
310 t
|
|
311 "Toggle split mode between side-to-side and one-on-top-of-another."]
|
|
312 [ediff-toolbar-help-icon
|
|
313 ediff-toolbar-help
|
|
314 t
|
|
315 "Toggle short/long help."]
|
|
316 nil
|
|
317 [ediff-toolbar-quit-icon
|
|
318 ediff-toolbar-quit
|
|
319 t
|
|
320 "Quit this ediff session."]
|
|
321 )))
|
|
322
|
|
323 (defvar ediff-toolbar-3way
|
|
324 (if (featurep 'toolbar)
|
|
325 '([ediff-toolbar-refine-icon
|
|
326 ediff-toolbar-refine
|
|
327 t
|
|
328 ;;; The toolbar is not automatically refreshed (in 19.14)
|
|
329 ;;; when :activep changes state.
|
|
330 ;;(ediff-toolbar-refine-needed-p)
|
|
331 "Refine current difference region by computing fine diffs."]
|
|
332 [ediff-toolbar-previous-icon
|
|
333 ediff-toolbar-previous-difference
|
|
334 t
|
|
335 "Go to the previous difference."]
|
|
336 [ediff-toolbar-next-icon
|
|
337 ediff-toolbar-next-difference
|
|
338 t
|
|
339 "Advance to the next difference."]
|
|
340 [ediff-toolbar-save-icon
|
|
341 ediff-toolbar-save
|
|
342 t
|
|
343 "Save buffers modified in this session."]
|
|
344 [ediff-toolbar-refresh-icon
|
|
345 ediff-toolbar-refresh
|
|
346 t
|
|
347 "Refresh Ediff display (aka recenter)."]
|
|
348 [ediff-toolbar-toggle-split-icon
|
|
349 ediff-toolbar-toggle-split
|
|
350 t
|
|
351 "Toggle split mode between side-to-side and one-on-top-of-another."]
|
|
352 [ediff-toolbar-help-icon
|
|
353 ediff-toolbar-help
|
|
354 t
|
|
355 "Toggle short/long help."]
|
|
356 nil
|
|
357 [ediff-toolbar-quit-icon
|
|
358 ediff-toolbar-quit
|
|
359 t
|
|
360 "Quit this ediff session."]
|
|
361 )))
|
|
362
|
|
363
|
|
364
|
|
365 ;;; Local Variables:
|
|
366 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
|
|
367 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
|
|
368 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body))
|
|
369 ;;; End:
|
|
370
|
|
371 ;;; ediff-tbar.el ends here
|