1
#| nokogiri-widgets/match-window.jl -- match-window widget
3
$Id: match-window.jl,v 1.9 2001/08/24 02:43:40 jsh Exp $
5
Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
7
This file is part of sawfish.
9
sawfish is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2, or (at your option)
14
sawfish is distributed in the hope that it will be useful, but
15
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.
19
You should have received a copy of the GNU General Public License
20
along with sawfish; see the file COPYING. If not, write to
21
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
(define-structure sawfish.ui.widgets.match-window ()
33
(defconst matcher-count 3)
36
;;; the widget representing the `matchers' frame
38
;; (match-window:matchers x-properties)
40
(define (make-match-window:matchers changed-callback x-properties)
41
(declare (unused changed-callback))
43
(let ((frame (gtk-frame-new (_ "Matchers")))
44
(table (gtk-table-new matcher-count 3 nil))
45
(l10n-x-properties (mapcar (lambda (x)
46
(cons (car x) (_ (cdr x))))
52
(let ((combo (gtk-combo-new))
53
(entry (gtk-entry-new))
54
(button (gtk-button-new-with-label (_ "Grab..."))))
55
(gtk-combo-set-popdown-strings
56
combo (cons "" (mapcar cdr l10n-x-properties)))
57
(gtk-table-attach-defaults table combo 0 1 i (1+ i))
58
(gtk-table-attach-defaults table entry 1 2 i (1+ i))
59
(gtk-table-attach-defaults table button 2 3 i (1+ i))
60
(gtk-signal-connect button "clicked"
62
(let* ((string (gtk-entry-get-text (gtk-combo-entry combo)))
63
(x-prop (and string (car (rassoc string
64
l10n-x-properties)))))
66
(let ((prop (wm-grab-x-property (or x-prop (intern string)))))
67
(gtk-entry-set-text entry (if (stringp prop)
70
(setq widgets (nconc widgets (list (cons combo entry))))))
71
(gtk-container-add frame table)
72
(gtk-container-border-width table box-border)
73
(gtk-table-set-row-spacings table box-spacing)
74
(gtk-table-set-col-spacings table box-spacing)
75
(gtk-widget-show-all frame)
83
(gtk-entry-set-text (gtk-combo-entry (car cell)) "")
84
(gtk-entry-set-text (cdr cell) "")) widgets)))
87
(do ((cells widgets (cdr cells))
89
((or (null cells) (null rest)))
91
(gtk-combo-entry (caar cells))
92
(or (cdr (assq (caar rest) l10n-x-properties)) (caar rest)))
93
(gtk-entry-set-text (cdar cells) (cdar rest)))))
96
(let loop ((cells widgets)
100
(let ((name (gtk-entry-get-text
101
(gtk-combo-entry (caar cells))))
102
(value (gtk-entry-get-text (cdar cells))))
103
(if (or (string= name "") (string= value ""))
104
(loop (cdr cells) out)
105
(let ((prop (rassoc name l10n-x-properties)))
107
(setq name (car prop))
108
(setq name (intern name))))
110
(cons (cons name value) out))))))))
113
(define-widget-type 'match-window:matchers make-match-window:matchers)
116
;;; the widget representing the `Actions' frame
118
(define (make-match-window:actions changed-callback properties)
119
(declare (unused changed-callback))
121
(let ((frame (gtk-frame-new (_ "Actions")))
122
(book (gtk-notebook-new))
127
(let ((title (car sub))
128
(table (gtk-table-new (length (cdr sub)) 2 nil))
129
(vbox (gtk-vbox-new nil box-spacing)))
131
(props (cdr sub) (cdr props)))
133
(let* ((prop (car props))
134
(is-boolean (eq (cadr prop) 'boolean))
137
`(boolean ,(beautify-symbol-name (car prop)))
138
`(optional ,(cadr prop))))))
140
(gtk-table-attach-defaults
141
table (make-left-label (beautify-symbol-name (car prop)))
143
(gtk-table-attach-defaults
144
table (widget-gtk-widget widget) 1 2 i (1+ i))
145
(setq widgets (cons (cons (car prop) widget) widgets))))
146
(gtk-table-set-row-spacings table box-spacing)
147
(gtk-table-set-col-spacings table box-spacing)
148
(gtk-box-pack-start vbox table)
149
(gtk-notebook-append-page book vbox (gtk-label-new title))))
152
(setq widgets (nreverse widgets))
153
(gtk-container-border-width book box-border)
154
(gtk-container-add frame book)
155
(gtk-widget-show-all frame)
161
(mapc (lambda (x) (widget-clear (cdr x))) widgets)))
165
(let ((widget (cdr (assq (car cell) widgets))))
167
(widget-set widget (cdr cell))))) x)))
170
(let loop ((rest widgets)
174
(let ((value (widget-ref (cdar rest))))
176
(loop (cdr rest) (cons (cons (caar rest) value) out))
177
(loop (cdr rest) out)))))))))))
179
(define-widget-type 'match-window:actions make-match-window:actions)
181
(define (make-left-label string)
182
(let ((hbox (gtk-hbox-new nil 0)))
183
(gtk-box-pack-end hbox (gtk-label-new string))
186
;; also in sawfish-xgettext
187
(define (beautify-symbol-name symbol)
188
(cond ((stringp symbol) symbol)
189
((not (symbolp symbol)) (format "%s" symbol))
191
(let ((name (copy-sequence (symbol-name symbol))))
192
(while (string-match "[-:]" name)
193
(setq name (concat (substring name 0 (match-start))
194
? (substring name (match-end)))))
195
(aset name 0 (char-upcase (aref name 0)))
201
;; (match-window ...)
203
(define (make-match-window-item changed-callback properties x-properties)
205
(define (print-matcher match)
206
(if (stringp (cdr match)) (cdr match) "?"))
208
(define (print-action action)
209
(if (eq (cdr action) t)
210
(format nil "%s" (car action))
211
(format nil "%s=%s" (car action) (cdr action))))
214
(list (mapconcat print-matcher (car x) ", ")
215
(mapconcat print-action (cdr x) ", ")))
217
(define (dialog title callback #!key for value)
218
(declare (unused title))
219
(let ((vbox (gtk-vbox-new nil box-spacing))
220
(matcher-widget (make-widget
221
`(match-window:matchers ,x-properties)))
222
(action-widget (make-widget
223
`(match-window:actions ,properties))))
224
(gtk-container-add vbox (widget-gtk-widget matcher-widget))
225
(gtk-container-add vbox (widget-gtk-widget action-widget))
227
(widget-set matcher-widget (car value))
228
(widget-set action-widget (cdr value)))
229
(gtk-widget-show vbox)
231
(simple-dialog (_ "Match window properties") vbox
233
(callback (cons (widget-ref matcher-widget)
234
(widget-ref action-widget))))
237
(define (validp x) (and (consp x) (listp (car x)) (listp (cdr x))))
245
(make-widget `(list ,type (,(_ "Matchers") ,(_ "Actions")))
248
(define-widget-type 'match-window make-match-window-item))