diff options
| author | David Ponce | 2006-03-07 06:41:45 +0000 |
|---|---|---|
| committer | David Ponce | 2006-03-07 06:41:45 +0000 |
| commit | f35262f952977bf0837f0fd8d55522494a3fec94 (patch) | |
| tree | 92dd5396778a241d70127cd34952ebfa3512d844 | |
| parent | 3070196c58ddc7b202bc93753238699ab9e0de49 (diff) | |
| download | emacs-f35262f952977bf0837f0fd8d55522494a3fec94.tar.gz emacs-f35262f952977bf0837f0fd8d55522494a3fec94.zip | |
Update Commentary header.
(tree-widget-theme-name): Ignore parent themes.
(tree-widget-set-parent-theme): New function.
(tree-widget-set-theme): Use it.
(tree-widget-set-image-properties): Move definition. Does nothing
if image properties have already been set.
(tree-widget-image-properties): Move definition. Receive an image
name. Set the :pointer property.
(tree-widget-lookup-image): Doc fix. Search in parent themes.
Don't set the :pointer image property.
(tree-widget-convert-widget): New function. Handle :dynargs
compatibility here.
(tree-widget): Use it to :convert-widget. Add the :expander-p
predicate to control when the :expander function is entered.
Thanks to Ken Manheimer <ken.manheimer@gmail.com> for the idea.
(tree-widget-value-create): Handle :expander-p. widget-apply
:expander.
(tree-widget-expander-p): New function. Default value of the
:expander-p property.
| -rw-r--r-- | lisp/tree-widget.el | 178 |
1 files changed, 92 insertions, 86 deletions
diff --git a/lisp/tree-widget.el b/lisp/tree-widget.el index 55385d42e95..b868369fc4a 100644 --- a/lisp/tree-widget.el +++ b/lisp/tree-widget.el | |||
| @@ -50,14 +50,16 @@ | |||
| 50 | ;; Specify a function to be called to dynamically provide the | 50 | ;; Specify a function to be called to dynamically provide the |
| 51 | ;; tree's children in response to an expand request. This function | 51 | ;; tree's children in response to an expand request. This function |
| 52 | ;; will be passed the tree widget and must return a list of child | 52 | ;; will be passed the tree widget and must return a list of child |
| 53 | ;; widgets. | 53 | ;; widgets. Child widgets returned by the :expander function are |
| 54 | ;; stored in the :args property of the tree widget. | ||
| 54 | ;; | 55 | ;; |
| 55 | ;; *Please note:* Child widgets returned by the :expander function | 56 | ;; :expander-p |
| 56 | ;; are stored in the :args property of the tree widget. To speed | 57 | ;; Specify a predicate which must return non-nil to indicate that |
| 57 | ;; up successive expand requests, the :expander function is not | 58 | ;; the :expander function above has to be called. By default, to |
| 58 | ;; called again when the :args value is non-nil. To refresh child | 59 | ;; speed up successive expand requests, the :expander-p predicate |
| 59 | ;; values, it is necessary to set the :args property to nil, then | 60 | ;; return non-nil when the :args value is nil. So, by default, to |
| 60 | ;; redraw the tree. | 61 | ;; refresh child values, it is necessary to set the :args property |
| 62 | ;; to nil, then redraw the tree. | ||
| 61 | ;; | 63 | ;; |
| 62 | ;; :open-icon (default `tree-widget-open-icon') | 64 | ;; :open-icon (default `tree-widget-open-icon') |
| 63 | ;; :close-icon (default `tree-widget-close-icon') | 65 | ;; :close-icon (default `tree-widget-close-icon') |
| @@ -265,19 +267,42 @@ See also the option `widget-image-conversion'." | |||
| 265 | 267 | ||
| 266 | (defsubst tree-widget-theme-name () | 268 | (defsubst tree-widget-theme-name () |
| 267 | "Return the current theme name, or nil if no theme is active." | 269 | "Return the current theme name, or nil if no theme is active." |
| 268 | (and tree-widget--theme (aref tree-widget--theme 0))) | 270 | (and tree-widget--theme (car (aref tree-widget--theme 0)))) |
| 269 | 271 | ||
| 270 | (defsubst tree-widget-set-theme (&optional name) | 272 | (defsubst tree-widget-set-parent-theme (name) |
| 273 | "Set to NAME the parent theme of the current theme. | ||
| 274 | The default parent theme is the \"default\" theme." | ||
| 275 | (unless (member name (aref tree-widget--theme 0)) | ||
| 276 | (aset tree-widget--theme 0 | ||
| 277 | (append (aref tree-widget--theme 0) (list name))) | ||
| 278 | ;; Load the theme setup | ||
| 279 | (let ((default-directory (tree-widget-themes-directory))) | ||
| 280 | (when default-directory | ||
| 281 | (load (expand-file-name "tree-widget-theme-setup" name) t))))) | ||
| 282 | |||
| 283 | (defun tree-widget-set-theme (&optional name) | ||
| 271 | "In the current buffer, set the theme to use for images. | 284 | "In the current buffer, set the theme to use for images. |
| 272 | The current buffer must be where the tree widget is drawn. | 285 | The current buffer must be where the tree widget is drawn. |
| 273 | Optional argument NAME is the name of the theme to use. It defaults | 286 | Optional argument NAME is the name of the theme to use. It defaults |
| 274 | to the value of the variable `tree-widget-theme'. | 287 | to the value of the variable `tree-widget-theme'. |
| 275 | Does nothing if NAME is already the current theme." | 288 | Does nothing if NAME is already the current theme. |
| 289 | |||
| 290 | If there is a \"tree-widget-theme-setup\" library in the theme | ||
| 291 | directory, load it to setup a parent theme or the images properties. | ||
| 292 | Typically it should contain something like this: | ||
| 293 | |||
| 294 | (tree-widget-set-parent-theme \"my-parent-theme\") | ||
| 295 | (tree-widget-set-image-properties | ||
| 296 | (if (featurep 'xemacs) | ||
| 297 | '(:ascent center) | ||
| 298 | '(:ascent center :mask (heuristic t)) | ||
| 299 | ))" | ||
| 276 | (or name (setq name (or tree-widget-theme "default"))) | 300 | (or name (setq name (or tree-widget-theme "default"))) |
| 277 | (unless (string-equal name (tree-widget-theme-name)) | 301 | (unless (string-equal name (tree-widget-theme-name)) |
| 278 | (set (make-local-variable 'tree-widget--theme) | 302 | (set (make-local-variable 'tree-widget--theme) |
| 279 | (make-vector 4 nil)) | 303 | (make-vector 4 nil)) |
| 280 | (aset tree-widget--theme 0 name))) | 304 | (tree-widget-set-parent-theme name) |
| 305 | (tree-widget-set-parent-theme "default"))) | ||
| 281 | 306 | ||
| 282 | (defun tree-widget--locate-sub-directory (name path) | 307 | (defun tree-widget--locate-sub-directory (name path) |
| 283 | "Locate the sub-directory NAME in PATH. | 308 | "Locate the sub-directory NAME in PATH. |
| @@ -328,50 +353,6 @@ specified directory is not accessible." | |||
| 328 | (aset tree-widget--theme 1 (or found 'void)) | 353 | (aset tree-widget--theme 1 (or found 'void)) |
| 329 | found)) | 354 | found)) |
| 330 | 355 | ||
| 331 | (defsubst tree-widget-set-image-properties (props) | ||
| 332 | "In current theme, set images properties to PROPS." | ||
| 333 | (aset tree-widget--theme 2 props)) | ||
| 334 | |||
| 335 | (defun tree-widget-image-properties (file) | ||
| 336 | "Return the properties of an image in current theme. | ||
| 337 | FILE is the absolute file name of an image. | ||
| 338 | |||
| 339 | If there is a \"tree-widget-theme-setup\" library in the theme | ||
| 340 | directory, where is located FILE, load it to setup theme images | ||
| 341 | properties. Typically it should contain something like this: | ||
| 342 | |||
| 343 | (tree-widget-set-image-properties | ||
| 344 | (if (featurep 'xemacs) | ||
| 345 | '(:ascent center) | ||
| 346 | '(:ascent center :mask (heuristic t)) | ||
| 347 | )) | ||
| 348 | |||
| 349 | When there is no \"tree-widget-theme-setup\" library in the current | ||
| 350 | theme directory, load the one from the default theme, if available. | ||
| 351 | Default global properties are provided for respectively Emacs and | ||
| 352 | XEmacs in the variables `tree-widget-image-properties-emacs', and | ||
| 353 | `tree-widget-image-properties-xemacs'." | ||
| 354 | ;; If properties are in the cache, use them. | ||
| 355 | (let ((plist (aref tree-widget--theme 2))) | ||
| 356 | (unless plist | ||
| 357 | ;; Load tree-widget-theme-setup if available. | ||
| 358 | (load (expand-file-name "tree-widget-theme-setup" | ||
| 359 | (file-name-directory file)) t t) | ||
| 360 | ;; If properties have been setup, use them. | ||
| 361 | (unless (setq plist (aref tree-widget--theme 2)) | ||
| 362 | ;; Try from the default theme. | ||
| 363 | (load (expand-file-name "../default/tree-widget-theme-setup" | ||
| 364 | (file-name-directory file)) t t) | ||
| 365 | ;; If properties have been setup, use them. | ||
| 366 | (unless (setq plist (aref tree-widget--theme 2)) | ||
| 367 | ;; By default, use supplied global properties. | ||
| 368 | (setq plist (if (featurep 'xemacs) | ||
| 369 | tree-widget-image-properties-xemacs | ||
| 370 | tree-widget-image-properties-emacs)) | ||
| 371 | ;; Setup the cache. | ||
| 372 | (tree-widget-set-image-properties plist)))) | ||
| 373 | plist)) | ||
| 374 | |||
| 375 | (defconst tree-widget--cursors | 356 | (defconst tree-widget--cursors |
| 376 | ;; Pointer shapes when the mouse pointer is over inactive | 357 | ;; Pointer shapes when the mouse pointer is over inactive |
| 377 | ;; tree-widget images. This feature works since Emacs 22, and | 358 | ;; tree-widget images. This feature works since Emacs 22, and |
| @@ -384,35 +365,46 @@ XEmacs in the variables `tree-widget-image-properties-emacs', and | |||
| 384 | ("no-handle" . arrow) | 365 | ("no-handle" . arrow) |
| 385 | )) | 366 | )) |
| 386 | 367 | ||
| 368 | (defsubst tree-widget-set-image-properties (props) | ||
| 369 | "In current theme, set images properties to PROPS. | ||
| 370 | Does nothing if images properties have already been set for that | ||
| 371 | theme." | ||
| 372 | (or (aref tree-widget--theme 2) | ||
| 373 | (aset tree-widget--theme 2 props))) | ||
| 374 | |||
| 375 | (defsubst tree-widget-image-properties (name) | ||
| 376 | "Return the properties of image NAME in current theme. | ||
| 377 | Default global properties are provided for respectively Emacs and | ||
| 378 | XEmacs in the variables `tree-widget-image-properties-emacs', and | ||
| 379 | `tree-widget-image-properties-xemacs'." | ||
| 380 | ;; Add the pointer shape | ||
| 381 | (cons :pointer | ||
| 382 | (cons (or (cdr (assoc name tree-widget--cursors)) 'hand) | ||
| 383 | (tree-widget-set-image-properties | ||
| 384 | (if (featurep 'xemacs) | ||
| 385 | tree-widget-image-properties-xemacs | ||
| 386 | tree-widget-image-properties-emacs))))) | ||
| 387 | |||
| 387 | (defun tree-widget-lookup-image (name) | 388 | (defun tree-widget-lookup-image (name) |
| 388 | "Look up in current theme for an image with NAME. | 389 | "Look up in current theme for an image with NAME. |
| 389 | Search first in current theme, then in default theme (see also the | 390 | Search first in current theme, then in parent themes (see also the |
| 390 | variable `tree-widget-theme'). | 391 | function `tree-widget-set-parent-theme'). |
| 391 | Return the first image found having a supported format, or nil if not | 392 | Return the first image found having a supported format, or nil if not |
| 392 | found." | 393 | found." |
| 393 | (let ((default-directory (tree-widget-themes-directory))) | 394 | (let ((default-directory (tree-widget-themes-directory)) file) |
| 394 | (when default-directory | 395 | (when default-directory |
| 395 | (let (file (theme (tree-widget-theme-name))) | 396 | (catch 'found |
| 396 | (catch 'found | 397 | (dolist (dir (aref tree-widget--theme 0)) |
| 397 | (dolist (dir (if (string-equal theme "default") | 398 | (dolist (fmt (tree-widget-image-formats)) |
| 398 | '("default") (list theme "default"))) | 399 | (dolist (ext (cdr fmt)) |
| 399 | (dolist (fmt (tree-widget-image-formats)) | 400 | (setq file (expand-file-name (concat name ext) dir)) |
| 400 | (dolist (ext (cdr fmt)) | 401 | (and (file-readable-p file) |
| 401 | (setq file (expand-file-name (concat name ext) dir)) | 402 | (file-regular-p file) |
| 402 | (and | 403 | (throw 'found |
| 403 | (file-readable-p file) | 404 | (tree-widget-create-image |
| 404 | (file-regular-p file) | 405 | (car fmt) file |
| 405 | (throw | 406 | (tree-widget-image-properties name))))))) |
| 406 | 'found | 407 | nil)))) |
| 407 | (tree-widget-create-image | ||
| 408 | (car fmt) file | ||
| 409 | ;; Add the pointer shape | ||
| 410 | (cons :pointer | ||
| 411 | (cons | ||
| 412 | (or (cdr (assoc name tree-widget--cursors)) | ||
| 413 | 'hand) | ||
| 414 | (tree-widget-image-properties file))))))))) | ||
| 415 | nil))))) | ||
| 416 | 408 | ||
| 417 | (defun tree-widget-find-image (name) | 409 | (defun tree-widget-find-image (name) |
| 418 | "Find the image with NAME in current theme. | 410 | "Find the image with NAME in current theme. |
| @@ -530,12 +522,13 @@ Handle mouse button 1 click on buttons.") | |||
| 530 | (define-widget 'tree-widget 'default | 522 | (define-widget 'tree-widget 'default |
| 531 | "Tree widget." | 523 | "Tree widget." |
| 532 | :format "%v" | 524 | :format "%v" |
| 533 | :convert-widget 'widget-types-convert-widget | 525 | :convert-widget 'tree-widget-convert-widget |
| 534 | :value-get 'widget-value-value-get | 526 | :value-get 'widget-value-value-get |
| 535 | :value-delete 'widget-children-value-delete | 527 | :value-delete 'widget-children-value-delete |
| 536 | :value-create 'tree-widget-value-create | 528 | :value-create 'tree-widget-value-create |
| 537 | :action 'tree-widget-action | 529 | :action 'tree-widget-action |
| 538 | :help-echo 'tree-widget-help-echo | 530 | :help-echo 'tree-widget-help-echo |
| 531 | :expander-p 'tree-widget-expander-p | ||
| 539 | :open-icon 'tree-widget-open-icon | 532 | :open-icon 'tree-widget-open-icon |
| 540 | :close-icon 'tree-widget-close-icon | 533 | :close-icon 'tree-widget-close-icon |
| 541 | :empty-icon 'tree-widget-empty-icon | 534 | :empty-icon 'tree-widget-empty-icon |
| @@ -646,6 +639,14 @@ This hook should be local in the buffer setup to display widgets.") | |||
| 646 | (1- (point)) (point) | 639 | (1- (point)) (point) |
| 647 | 'display (list 'space :width tree-widget-space-width))) | 640 | 'display (list 'space :width tree-widget-space-width))) |
| 648 | 641 | ||
| 642 | (defun tree-widget-convert-widget (widget) | ||
| 643 | "Convert :args as widget types in WIDGET." | ||
| 644 | (let ((tree (widget-types-convert-widget widget))) | ||
| 645 | ;; Compatibility | ||
| 646 | (widget-put tree :expander (or (widget-get tree :expander) | ||
| 647 | (widget-get tree :dynargs))) | ||
| 648 | tree)) | ||
| 649 | |||
| 649 | (defun tree-widget-value-create (tree) | 650 | (defun tree-widget-value-create (tree) |
| 650 | "Create the TREE tree-widget." | 651 | "Create the TREE tree-widget." |
| 651 | (let* ((node (tree-widget-node tree)) | 652 | (let* ((node (tree-widget-node tree)) |
| @@ -662,8 +663,6 @@ This hook should be local in the buffer setup to display widgets.") | |||
| 662 | (if (widget-get tree :open) | 663 | (if (widget-get tree :open) |
| 663 | ;;;; Expanded node. | 664 | ;;;; Expanded node. |
| 664 | (let ((args (widget-get tree :args)) | 665 | (let ((args (widget-get tree :args)) |
| 665 | (xpandr (or (widget-get tree :expander) | ||
| 666 | (widget-get tree :dynargs))) | ||
| 667 | (guide (widget-get tree :guide)) | 666 | (guide (widget-get tree :guide)) |
| 668 | (noguide (widget-get tree :no-guide)) | 667 | (noguide (widget-get tree :no-guide)) |
| 669 | (endguide (widget-get tree :end-guide)) | 668 | (endguide (widget-get tree :end-guide)) |
| @@ -674,9 +673,11 @@ This hook should be local in the buffer setup to display widgets.") | |||
| 674 | (endguidi (tree-widget-find-image "end-guide")) | 673 | (endguidi (tree-widget-find-image "end-guide")) |
| 675 | (handli (tree-widget-find-image "handle")) | 674 | (handli (tree-widget-find-image "handle")) |
| 676 | (nohandli (tree-widget-find-image "no-handle"))) | 675 | (nohandli (tree-widget-find-image "no-handle"))) |
| 677 | ;; Request children at run time, when not already done. | 676 | ;; Request children at run time, when requested. |
| 678 | (when (and (not args) xpandr) | 677 | (when (and (widget-get tree :expander) |
| 679 | (setq args (mapcar 'widget-convert (funcall xpandr tree))) | 678 | (widget-apply tree :expander-p)) |
| 679 | (setq args (mapcar 'widget-convert | ||
| 680 | (widget-apply tree :expander))) | ||
| 680 | (widget-put tree :args args)) | 681 | (widget-put tree :args args)) |
| 681 | ;; Defer the node widget creation after icon creation. | 682 | ;; Defer the node widget creation after icon creation. |
| 682 | (widget-put tree :node (widget-convert node)) | 683 | (widget-put tree :node (widget-convert node)) |
| @@ -800,6 +801,11 @@ Ignore the EVENT argument." | |||
| 800 | "Collapse node" | 801 | "Collapse node" |
| 801 | "Expand node")) | 802 | "Expand node")) |
| 802 | 803 | ||
| 804 | (defun tree-widget-expander-p (tree) | ||
| 805 | "Return non-nil if the TREE tree-widget :expander has to be called. | ||
| 806 | That is, if TREE :args is nil." | ||
| 807 | (null (widget-get tree :args))) | ||
| 808 | |||
| 803 | (provide 'tree-widget) | 809 | (provide 'tree-widget) |
| 804 | 810 | ||
| 805 | ;; arch-tag: c3a1ada2-1663-41dc-9d16-2479ed8320e8 | 811 | ;; arch-tag: c3a1ada2-1663-41dc-9d16-2479ed8320e8 |