~ubuntu-branches/ubuntu/lucid/sawfish/lucid-updates

« back to all changes in this revision

Viewing changes to scripts/sawfish-menu.jl

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2002-01-20 17:42:28 UTC
  • Revision ID: james.westby@ubuntu.com-20020120174228-4q1ydztbkvfq1ht2
Tags: upstream-1.0.1.20020116
ImportĀ upstreamĀ versionĀ 1.0.1.20020116

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
exec rep "$0" "$@"
 
3
!#
 
4
 
 
5
;; sawmill-menu -- subprocess to handle menus
 
6
;; $Id: sawfish-menu.jl,v 1.6 2000/12/19 23:05:43 jsh Exp $
 
7
 
 
8
;; Copyright (C) 1999 John Harper <john@dcs.warwick.ac.uk>
 
9
 
 
10
;; This file is part of sawmill.
 
11
 
 
12
;; sawmill is free software; you can redistribute it and/or modify it
 
13
;; under the terms of the GNU General Public License as published by
 
14
;; the Free Software Foundation; either version 2, or (at your option)
 
15
;; any later version.
 
16
 
 
17
;; sawmill is distributed in the hope that it will be useful, but
 
18
;; WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
;; GNU General Public License for more details.
 
21
 
 
22
;; You should have received a copy of the GNU General Public License
 
23
;; along with sawmill; see the file COPYING.  If not, write to
 
24
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
25
 
 
26
(require 'gui.gtk)
 
27
(require 'rep.data.tables)
 
28
 
 
29
 
 
30
;; menus
 
31
 
 
32
(define menu-selected nil)
 
33
 
 
34
;; map radio-group ids to the last widget
 
35
(define group-table (make-fluid))
 
36
 
 
37
(define (make-group-table) (make-table symbol-hash eq))
 
38
(define (group-id-set id w) (table-set (fluid group-table) id w))
 
39
(define (group-id-ref id) (table-ref (fluid group-table) id))
 
40
 
 
41
(define (create-menu spec #!optional bar)
 
42
  (let* ((menu (if bar (gtk-menu-bar-new) (gtk-menu-new)))
 
43
         (accels (gtk-menu-ensure-uline-accel-group menu)))
 
44
 
 
45
    ;; Set the label of the menu item, handling underlined accelerators
 
46
    (define (label-menu-item item label-text #!optional shortcut)
 
47
      (let* ((label (gtk-label-new label-text))
 
48
             (hbox (gtk-hbox-new nil 16))
 
49
             (hkey (gtk-label-parse-uline label label-text)))
 
50
        (gtk-box-pack-start hbox label nil nil t 0)
 
51
        (when shortcut
 
52
          (let ((accel (gtk-label-new shortcut)))
 
53
            (gtk-box-pack-end hbox accel nil nil 0)))
 
54
        (gtk-widget-add-accelerator item "activate_item" accels hkey 0 0)
 
55
        (gtk-widget-show-all hbox)
 
56
        (gtk-container-add item hbox)))
 
57
 
 
58
    (mapc (lambda (cell)
 
59
            (let (label item)
 
60
              (when (and cell (symbolp (car cell)))
 
61
                (setq cell (symbol-value (car cell))))
 
62
              (if (null cell)
 
63
                  ;; A separator
 
64
                  (setq item (gtk-menu-item-new))
 
65
 
 
66
                (setq label (car cell))
 
67
                (setq cell (cdr cell))
 
68
                (if (and (consp (car cell)) (stringp (car (car cell))))
 
69
                    ;; A sub-menu
 
70
                    (let ((sub (create-menu cell)))
 
71
                      (setq item (gtk-menu-item-new))
 
72
                      (label-menu-item item label)
 
73
                      (gtk-menu-item-set-submenu item sub))
 
74
 
 
75
                  ;; A single menu item
 
76
                  (let ((options (cdr cell)))
 
77
                    (let* ((check (assq 'check options))
 
78
                           (group (cdr (assq 'group options)))
 
79
                           (insensitive (cdr (assq 'insensitive options)))
 
80
                           (shortcut (cdr (assq 'shortcut options)))
 
81
                           (last-widget (and group (group-id-ref group))))
 
82
                      (cond (group
 
83
                             (setq item (gtk-radio-menu-item-new-from-widget
 
84
                                         last-widget))
 
85
                             (group-id-set group item))
 
86
                            (check
 
87
                             (setq item (gtk-check-menu-item-new))
 
88
                             (gtk-check-menu-item-set-show-toggle item t))
 
89
                            (t (setq item (gtk-menu-item-new))))
 
90
                      (label-menu-item item label shortcut)
 
91
                      (when check
 
92
                        (gtk-check-menu-item-set-state item (cdr check)))
 
93
                      (when insensitive
 
94
                        (gtk-widget-set-sensitive item nil))))
 
95
 
 
96
                  (gtk-signal-connect
 
97
                   item "activate" (lambda ()
 
98
                                     (setq menu-selected (car cell))))))
 
99
              (when item
 
100
                (gtk-widget-lock-accelerators item)
 
101
                ((if bar gtk-menu-bar-append gtk-menu-append) menu item)
 
102
                (gtk-widget-show item))))
 
103
          spec)
 
104
    menu))
 
105
 
 
106
(define (popup-menu spec #!optional timestamp position)
 
107
  (let ((menu (let-fluids ((group-table (make-group-table)))
 
108
                (create-menu spec))))
 
109
    (gtk-signal-connect menu "deactivate" gtk-main-quit)
 
110
    (setq menu-selected nil)
 
111
    (gtk-menu-popup-interp menu nil nil 0 (or timestamp 0) position)
 
112
    (gtk-main)
 
113
    menu-selected))
 
114
 
 
115
 
 
116
;; entry point, loop reading command forms, sending back results
 
117
 
 
118
(condition-case nil
 
119
    (while t
 
120
      (let ((input (read standard-input)))
 
121
        (format standard-output "%S\n"
 
122
                (apply (symbol-value (car input)) (cdr input)))
 
123
        (when (filep standard-output)
 
124
          (flush-file standard-output))))
 
125
  (end-of-stream))
 
126
 
 
127
 
 
128
;; Local Variables:
 
129
;; major-mode: lisp-mode
 
130
;; End: