comparison lisp/tree-widget.el @ 65747:cfaa6269b03d

(tree-widget-themes-load-path): New variable. (tree-widget-themes-directory): Doc fix. (tree-widget-image-formats) [Emacs]: Doc fix. (tree-widget--locate-sub-directory): New function. (tree-widget-themes-directory): Use it.
author David Ponce <david@dponce.com>
date Fri, 30 Sep 2005 06:28:53 +0000
parents e2b8d96a5a4f
children 5955934355f2
comparison
equal deleted inserted replaced
65746:6f5a2198d5e4 65747:cfaa6269b03d
129 (not (or (featurep 'xemacs) (< emacs-major-version 21))) 129 (not (or (featurep 'xemacs) (< emacs-major-version 21)))
130 "*Non-nil means that tree-widget will try to use images." 130 "*Non-nil means that tree-widget will try to use images."
131 :type 'boolean 131 :type 'boolean
132 :group 'tree-widget) 132 :group 'tree-widget)
133 133
134 (defvar tree-widget-themes-load-path
135 '(load-path
136 (let ((dir (if (fboundp 'locate-data-directory)
137 (locate-data-directory "tree-widget") ;; XEmacs
138 data-directory)))
139 (and dir (list dir (expand-file-name "images" dir))))
140 )
141 "List of locations where to search for the themes sub-directory.
142 Each element is an expression that will be evaluated to return a
143 single directory or a list of directories to search.
144
145 The default is to search in the `load-path' first, then in the
146 \"images\" sub directory in the data directory, then in the data
147 directory.
148 The data directory is the value of the variable `data-directory' on
149 Emacs, and what `(locate-data-directory \"tree-widget\")' returns on
150 XEmacs.")
151
134 (defcustom tree-widget-themes-directory "tree-widget" 152 (defcustom tree-widget-themes-directory "tree-widget"
135 "*Name of the directory where to look up for image themes. 153 "*Name of the directory where to look up for image themes.
136 When nil use the directory where the tree-widget library is located. 154 When nil use the directory where the tree-widget library is located.
137 When a relative name is specified, try to locate that sub directory in 155 When a relative name is specified, try to locate that sub directory in
138 `load-path', then in the data directory, and use the first one found. 156 the locations specified in `tree-widget-themes-load-path'.
139 The data directory is the value of the variable `data-directory' on
140 Emacs, and what `(locate-data-directory \"tree-widget\")' returns on
141 XEmacs.
142 The default is to use the \"tree-widget\" relative name." 157 The default is to use the \"tree-widget\" relative name."
143 :type '(choice (const :tag "Default" "tree-widget") 158 :type '(choice (const :tag "Default" "tree-widget")
144 (const :tag "With the library" nil) 159 (const :tag "With the library" nil)
145 (directory :format "%{%t%}:\n%v")) 160 (directory :format "%{%t%}:\n%v"))
146 :group 'tree-widget) 161 :group 'tree-widget)
234 "Create an image of type TYPE from FILE, and return it. 249 "Create an image of type TYPE from FILE, and return it.
235 Give the image the specified properties PROPS." 250 Give the image the specified properties PROPS."
236 (apply 'create-image `(,file ,type nil ,@props))) 251 (apply 'create-image `(,file ,type nil ,@props)))
237 (defsubst tree-widget-image-formats () 252 (defsubst tree-widget-image-formats ()
238 "Return the alist of image formats/file name extensions. 253 "Return the alist of image formats/file name extensions.
239 See also the option `widget-image-file-name-suffixes'." 254 See also the option `widget-image-conversion'."
240 (delq nil 255 (delq nil
241 (mapcar 256 (mapcar
242 #'(lambda (fmt) 257 #'(lambda (fmt)
243 (and (image-type-available-p (car fmt)) fmt)) 258 (and (image-type-available-p (car fmt)) fmt))
244 widget-image-conversion))) 259 widget-image-conversion)))
262 (unless (string-equal name (tree-widget-theme-name)) 277 (unless (string-equal name (tree-widget-theme-name))
263 (set (make-local-variable 'tree-widget--theme) 278 (set (make-local-variable 'tree-widget--theme)
264 (make-vector 4 nil)) 279 (make-vector 4 nil))
265 (aset tree-widget--theme 0 name))) 280 (aset tree-widget--theme 0 name)))
266 281
282 (defun tree-widget--locate-sub-directory (name path)
283 "Locate the sub-directory NAME in PATH.
284 Return the absolute name of the directory found, or nil if not found."
285 (let (dir elt)
286 (while (and (not dir) (consp path))
287 (setq elt (condition-case nil (eval (car path)) (error nil))
288 path (cdr path))
289 (cond
290 ((stringp elt)
291 (setq dir (expand-file-name name elt))
292 (or (file-accessible-directory-p dir)
293 (setq dir nil)))
294 ((and elt (not (equal elt (car path))))
295 (setq dir (tree-widget--locate-sub-directory name elt)))))
296 dir))
297
267 (defun tree-widget-themes-directory () 298 (defun tree-widget-themes-directory ()
268 "Locate the directory where to search for a theme. 299 "Locate the directory where to search for a theme.
269 It is defined in variable `tree-widget-themes-directory'. 300 It is defined in variable `tree-widget-themes-directory'.
270 Return the absolute name of the directory found, or nil if the 301 Return the absolute name of the directory found, or nil if the
271 specified directory is not accessible." 302 specified directory is not accessible."
272 (let ((found (aref tree-widget--theme 1))) 303 (let ((found (aref tree-widget--theme 1)))
273 (if found 304 (cond
274 ;; The directory is available in the cache. 305 ;; The directory was not found.
275 (unless (eq found 'void) found) 306 ((eq found 'void)
276 (cond 307 (setq found nil))
277 ;; Use the directory where tree-widget is located. 308 ;; The directory is available in the cache.
278 ((null tree-widget-themes-directory) 309 (found)
279 (setq found (locate-library "tree-widget")) 310 ;; Use the directory where this library is located.
280 (when found 311 ((null tree-widget-themes-directory)
281 (setq found (file-name-directory found)) 312 (setq found (locate-library "tree-widget"))
282 (or (file-accessible-directory-p found) 313 (when found
283 (setq found nil)))) 314 (setq found (file-name-directory found))
284 ;; Check accessibility of absolute directory name.
285 ((file-name-absolute-p tree-widget-themes-directory)
286 (setq found (expand-file-name tree-widget-themes-directory))
287 (or (file-accessible-directory-p found) 315 (or (file-accessible-directory-p found)
288 (setq found nil))) 316 (setq found nil))))
289 ;; Locate a sub-directory in `load-path' and data directory. 317 ;; Check accessibility of absolute directory name.
290 (t 318 ((file-name-absolute-p tree-widget-themes-directory)
291 (let ((path 319 (setq found (expand-file-name tree-widget-themes-directory))
292 (append load-path 320 (or (file-accessible-directory-p found)
293 (list (if (fboundp 'locate-data-directory) 321 (setq found nil)))
294 ;; XEmacs 322 ;; Locate a sub-directory in `tree-widget-themes-load-path'.
295 (locate-data-directory "tree-widget") 323 (t
296 ;; Emacs 324 (setq found (tree-widget--locate-sub-directory
297 data-directory))))) 325 tree-widget-themes-directory
298 (while (and path (not found)) 326 tree-widget-themes-load-path))))
299 (when (car path) 327 ;; Store the result in the cache for later use.
300 (setq found (expand-file-name 328 (aset tree-widget--theme 1 (or found 'void))
301 tree-widget-themes-directory (car path))) 329 found))
302 (or (file-accessible-directory-p found)
303 (setq found nil)))
304 (setq path (cdr path))))))
305 ;; Store the result in the cache for later use.
306 (aset tree-widget--theme 1 (or found 'void))
307 found)))
308 330
309 (defsubst tree-widget-set-image-properties (props) 331 (defsubst tree-widget-set-image-properties (props)
310 "In current theme, set images properties to PROPS." 332 "In current theme, set images properties to PROPS."
311 (aset tree-widget--theme 2 props)) 333 (aset tree-widget--theme 2 props))
312 334
349 ;; Setup the cache. 371 ;; Setup the cache.
350 (tree-widget-set-image-properties plist)))) 372 (tree-widget-set-image-properties plist))))
351 plist)) 373 plist))
352 374
353 (defconst tree-widget--cursors 375 (defconst tree-widget--cursors
354 ;; Pointer shapes when the mouse pointer is over tree-widget images. 376 ;; Pointer shapes when the mouse pointer is over inactive
355 ;; This feature works since Emacs 22, and ignored on older versions, 377 ;; tree-widget images. This feature works since Emacs 22, and
356 ;; and XEmacs. 378 ;; ignored on older versions, and XEmacs.
357 '( 379 '(
358 ("guide" . arrow) 380 ("guide" . arrow)
359 ("no-guide" . arrow) 381 ("no-guide" . arrow)
360 ("end-guide" . arrow) 382 ("end-guide" . arrow)
361 ("handle" . arrow) 383 ("handle" . arrow)