~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to doc/CUSTOM

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2006-11-23 15:10:53 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061123151053-q42sk1lvks41xpfx
Tags: 1:1.2.1-9
uim-gtk2.0.postinst: Don't call update-gtk-immodules on purge.
(closes: Bug#398530)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
This document describes usage of the uim-custom API and facility for
 
2
developers.
 
3
 
 
4
 
 
5
* Abstract
 
6
 
 
7
* Design basics and decisions
 
8
 
 
9
* How to define your own customs
 
10
 
 
11
* How to reflect defined customs into your IM code
 
12
 
 
13
  To acquire a defined custom in your IM, describe as following in the
 
14
  your IM file.
 
15
 
 
16
    (require-custom "your-custom.scm")
 
17
 
 
18
  Don't use ordinary 'require' to load a custom file. The
 
19
  require-custom performs per-user configuration loading and reload
 
20
  management, but ordinary 'require' does not.
 
21
 
 
22
  "-custom" suffix of the filename is only a convention and not
 
23
  required. But we recommend the naming convention to manage the files
 
24
  easily.
 
25
 
 
26
 
 
27
* Invoke an arbitrary procedure when a custom variable has been set
 
28
 
 
29
  The feature is usable via the hook named 'custom-set-hooks'. See
 
30
  following example.
 
31
 
 
32
  (custom-add-hook 'anthy-input-mode-actions
 
33
                   'custom-set-hooks
 
34
                   (lambda ()
 
35
                     (puts "anthy-input-mode-actions has been set\n")
 
36
                     (anthy-configure-widgets)))
 
37
 
 
38
  Any procedure that takes no argument can be placed into the third
 
39
  argument to custom-add-hook. The procedure will be invoked when the
 
40
  custom variable anthy-input-mode-actions has been set. Interprocess
 
41
  custom variable update via uim-helper-server also triggers this
 
42
  hook. So some variables edited on uim-pref will be propagated to any
 
43
  processes and invokes the hook on the fly.
 
44
 
 
45
  For example, dynamic file switching can be triggered by uim-pref
 
46
  using following hook.
 
47
 
 
48
  (custom-add-hook 'skk-dic-file-name
 
49
                   'custom-set-hooks
 
50
                   skk-reload-dic)
 
51
 
 
52
  There are some limitations for the set-hook feature.
 
53
 
 
54
  - Runtime version of the custom facility (custom-rt.scm) only
 
55
    accepts at most one hook per custom variable (full-featured
 
56
    version can handle multiple hooks)
 
57
 
 
58
  - Custom API enabled only in full-featured version (custom.scm)
 
59
    cannot be invoked in the hook procedure.
 
60
 
 
61
    Enclose such code into conditional block as follows. This ensures
 
62
    that custom-rt.scm ignores the hook.
 
63
 
 
64
    (if custom-full-featured?
 
65
        (custom-add-hook 'anthy-kana-input-method-actions
 
66
                         'custom-set-hooks
 
67
                         (lambda ()
 
68
                           (custom-choice-range-reflect-olist-val
 
69
                            'default-widget_anthy_kana_input_method
 
70
                            'anthy-kana-input-method-actions
 
71
                            anthy-kana-input-method-indication-alist))))
 
72
 
 
73
 
 
74
* Control activity of a custom variable
 
75
 
 
76
  Any custom variables has a state named 'activity'. This state
 
77
  indicates whether the value set in the custom variable makes sense
 
78
  or not. The state should be reflected to value editability of the
 
79
  corresponding widget on preference tools. i.e. Use
 
80
  gtk_widget_set_sensitive() for the corresponding widget to reflect
 
81
  the state.
 
82
 
 
83
  To control activity of a custom variable, configure the hook for the
 
84
  custom variable. Otherwise all custom variables are always active.
 
85
 
 
86
 
 
87
  Example1: Simple activity
 
88
 
 
89
  Following example shows that the custom variable
 
90
  my-frequently-used-string1 is active only when username is
 
91
  "yamaken". The third argument of custom-add-hook can be any
 
92
  predicate to indicate whether the custom variable is active or
 
93
  inactive.
 
94
 
 
95
  The activity is tested by the predicate when:
 
96
 
 
97
  - The custom variable has been acquired by uim_custom_get().
 
98
 
 
99
  - Invoking custom-active? explicitly
 
100
 
 
101
  - Any custom variable has been set. See next example for further
 
102
    information
 
103
 
 
104
  (define-custom 'my-frequently-used-string1 "I'm hungry! Give me some sweets."
 
105
    '(my-private)
 
106
    '(string)
 
107
    (_ "My frequently used string 1")
 
108
    (_ "long description will be here."))
 
109
 
 
110
  (custom-add-hook 'my-frequently-used-string1
 
111
                   'custom-activity-hooks
 
112
                   (lambda ()
 
113
                     (string=? (getenv "USER")
 
114
                               "yamaken")))
 
115
 
 
116
 
 
117
  Example2: Dynamic activity update reflecting other custom variable
 
118
 
 
119
  The activity alters when other custom variables have been set.
 
120
 
 
121
  In following example, segment-separator will be active only when
 
122
  show-segment-separator? is true. The activity will be changed
 
123
  automatically and noticed to client of uim-custom via callback for
 
124
  the segment-separator previously set immediately after new value of
 
125
  show-segment-separator? has been set.
 
126
 
 
127
  The predicate will be evaluated when any of custom variables have
 
128
  been set (changing to different value is not required). So you can
 
129
  place any flexible predicate as the third argument for the
 
130
  custom-add-hook.
 
131
 
 
132
  All activity predicates will be evaluated and noticed via
 
133
  corresponding callback when any of custom variables has been set.
 
134
 
 
135
  No group relationships including subgrouping is not required to set
 
136
  variable relationships.
 
137
 
 
138
  (define-custom 'show-segment-separator? #f
 
139
    '(foo)
 
140
    '(boolean)
 
141
    (_ "Show segment separator")
 
142
    (_ "long description will be here."))
 
143
 
 
144
  (define-custom 'segment-separator "|"
 
145
    '(bar)
 
146
    '(string ".*")
 
147
    (_ "Segment separator")
 
148
    (_ "long description will be here."))
 
149
 
 
150
  (custom-add-hook 'segment-separator
 
151
                   'custom-activity-hooks
 
152
                   (lambda ()
 
153
                     show-segment-separator?))