Initial Commit
[packages] / xemacs-packages / jde / lisp / jde-custom.el
1 ;;; jde-custom.el -- Integrated Development Environment for Java.
2 ;; $Revision: 1.1 $ $Date: 2007-11-26 15:16:45 $ 
3
4 ;; Author: Paul Kinnucan <paulk@mathworks.com>
5 ;; Maintainer: Paul Kinnucan
6 ;; Keywords: java, tools
7
8 ;; Copyright (C) 2004 Paul Kinnucan.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; This is one of a set of packages that make up the 
28 ;; Java Development Environment (JDE) for Emacs. See the
29 ;; JDE User's Guide for more information.
30
31 ;; The latest version of the JDE is available at
32 ;; <URL:http://jdee.sunsite.dk>.
33
34 ;; Please send any comments, bugs, or upgrade requests to
35 ;; Paul Kinnucan at paulk@mathworks.com.
36
37 ;;; Code:
38
39 (require 'jde-project-file)
40
41 (defun jde-custom-variable-set (widget)
42   "Set the current value for the variable being edited by WIDGET."
43   (let ((symbol (widget-value widget)))
44     (custom-variable-set widget)
45     (jde-save-project)
46     (add-to-list 'jde-dirty-variables symbol)))
47
48 (defun jde-custom-variable-reset-standard (widget)
49   "Restore the standard setting for the variable being edited by WIDGET.
50 This operation eliminates any saved setting for the variable,
51 restoring it to the state of a variable that has never been customized."
52   (custom-variable-reset-standard widget)
53   (jde-save-project))
54
55 (defvar jde-custom-variable-menu
56   '(("Save in JDEE Project File" jde-custom-variable-set
57      (lambda (widget)
58        (and
59         (eq (widget-get widget :custom-state) 'modified)
60         (string-match "^jde-" (symbol-name (widget-value widget))))))
61     ("Set for Current Session" custom-variable-set
62      (lambda (widget)
63        (eq (widget-get widget :custom-state) 'modified)))
64     ("Save for Future Sessions" custom-variable-save
65      (lambda (widget)
66        (memq (widget-get widget :custom-state) '(modified set changed rogue))))
67     ("Reset to Current" custom-redraw
68      (lambda (widget)
69        (and (default-boundp (widget-value widget))
70             (memq (widget-get widget :custom-state) '(modified changed)))))
71     ("Reset to Saved" custom-variable-reset-saved
72      (lambda (widget)
73        (and (or (get (widget-value widget) 'saved-value)
74                 (get (widget-value widget) 'saved-variable-comment))
75             (memq (widget-get widget :custom-state)
76                   '(modified set changed rogue)))))
77     ("Erase Customization" jde-custom-variable-reset-standard
78      (lambda (widget)
79        (and (get (widget-value widget) 'standard-value)
80             (memq (widget-get widget :custom-state)
81                   '(modified set changed saved rogue)))))
82     ("---" ignore ignore)
83     ("Add Comment" custom-comment-show custom-comment-invisible-p)
84     ("---" ignore ignore)
85     ("Don't show as Lisp expression" custom-variable-edit
86      (lambda (widget)
87        (eq (widget-get widget :custom-form) 'lisp)))
88     ("Show initial Lisp expression" custom-variable-edit-lisp
89      (lambda (widget)
90        (eq (widget-get widget :custom-form) 'edit))))
91   "Alist of actions for the `jde-custom-variable' widget.
92 Each entry has the form (NAME ACTION FILTER) where NAME is the name of
93 the menu entry, ACTION is the function to call on the widget when the
94 menu is selected, and FILTER is a predicate which takes a `jde-custom-variable'
95 widget as an argument, and returns non-nil if ACTION is valid on that
96 widget.  If FILTER is nil, ACTION is always valid.")
97
98
99 (defun jde-custom-variable-action (widget &optional event)
100   "Show the menu for `jde-custom-variable' WIDGET.
101 Optional EVENT is the location for the menu."
102   (if (eq (widget-get widget :custom-state) 'hidden)
103       (custom-toggle-hide widget)
104     (unless (eq (widget-get widget :custom-state) 'modified)
105       (custom-variable-state-set widget))
106     (custom-redraw-magic widget)
107     (let* ((completion-ignore-case t)
108            (answer (widget-choose (concat "Operation on "
109                                           (custom-unlispify-tag-name
110                                            (widget-get widget :value)))
111                                   (custom-menu-filter jde-custom-variable-menu
112                                                       widget)
113                                   event)))
114       (if answer
115           (funcall answer widget)))))
116
117
118 (define-widget 'jde-custom-variable 'custom
119   "Customize a JDEE variable."
120   :format "%v"
121   :help-echo "Set or reset this variable."
122   :documentation-property 'variable-documentation
123   :custom-category 'option
124   :custom-state nil
125   :custom-menu 'custom-variable-menu-create
126   :custom-form nil ; defaults to value of `custom-variable-default-form'
127   :value-create 'custom-variable-value-create
128   :action 'jde-custom-variable-action
129   :custom-set 'custom-variable-set
130   :custom-save 'custom-variable-save
131   :custom-reset-current 'custom-redraw
132   :custom-reset-saved 'custom-variable-reset-saved
133   :custom-reset-standard 'custom-variable-reset-standard)
134
135 ;;;###autoload
136 (defalias 'jde-customize-variable 'jde-customize-option)
137
138 ;;;###autoload
139 (defun jde-customize-option (symbol)
140   "Customize SYMBOL, which must be a JDEE option variable."
141   (interactive (custom-variable-prompt))
142   (unless (get symbol 'custom-type)
143     (error "Variable %s cannot be customized" symbol))
144   (custom-buffer-create (list (list symbol 'jde-custom-variable))
145                         (format "*Customize Option: %s*"
146                                 (custom-unlispify-tag-name symbol))))
147
148
149 (defun jde-custom-adjust-groups ()
150   "Change the symbol type in the symbol spec lists for all
151 JDEE groups from `custom-variable' to `jde-custom-variable'.
152 This causes the save-to-project-file menu item to appear
153 for JDEE variables in group customization buffers."
154   (flet ((adjust-group 
155           (group)
156           (let ((symbol-specs (get group 'custom-group)))
157             (dolist (spec symbol-specs)
158               (let ((symbol (nth 0 spec))
159                     (symbol-type (nth 1 spec)))
160                 (if (eq symbol-type 'custom-group)
161                     (adjust-group symbol)
162                   (setcdr spec (list 'jde-custom-variable))))))))
163     (adjust-group 'jde)))
164       
165
166 (provide 'jde-custom)
167
168 ;; Change History
169 ;;
170 ;; $Log: jde-custom.el,v $
171 ;; Revision 1.1  2007-11-26 15:16:45  michaels
172 ;; Update jde to author version 2.3.5.1.
173 ;;
174 ;; Revision 1.2  2004/03/21 03:08:45  paulk
175 ;; Get rid of DOS line endings.
176 ;;
177 ;; Revision 1.1  2004/02/24 05:43:11  paulk
178 ;; Initial revision.
179 ;;
180 ;;
181 ;;
182 ;;
183