1;;; canna-custom.scm: Customization variables for canna.scm
2;;;
3;;; Copyright (c) 2003-2013 uim Project https://github.com/uim/uim
4;;;
5;;; All rights reserved.
6;;;
7;;; Redistribution and use in source and binary forms, with or without
8;;; modification, are permitted provided that the following conditions
9;;; are met:
10;;; 1. Redistributions of source code must retain the above copyright
11;;;    notice, this list of conditions and the following disclaimer.
12;;; 2. Redistributions in binary form must reproduce the above copyright
13;;;    notice, this list of conditions and the following disclaimer in the
14;;;    documentation and/or other materials provided with the distribution.
15;;; 3. Neither the name of authors nor the names of its contributors
16;;;    may be used to endorse or promote products derived from this software
17;;;    without specific prior written permission.
18;;;
19;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
20;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22;;; ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
23;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29;;; SUCH DAMAGE.
30;;;;
31
32(require "i18n.scm")
33
34
35(define canna-im-name-label (N_ "Canna"))
36(define canna-im-short-desc (N_ "A multi-segment kana-kanji conversion engine"))
37
38(define-custom-group 'canna
39                     canna-im-name-label
40                     canna-im-short-desc)
41
42(define-custom-group 'cannaserver
43		     (N_ "Canna server")
44		     (N_ "long description will be here."))
45
46(define-custom-group 'canna-advanced
47		     (N_ "Canna (advanced)")
48		     (N_ "long description will be here."))
49
50(define-custom-group 'canna-prediction
51		     (N_ "Prediction")
52		     (N_ "long description will be here."))
53
54;;
55;; segment separator
56;;
57
58(define-custom 'canna-show-segment-separator? #f
59  '(canna segment-sep)
60  '(boolean)
61  (N_ "Show segment separator")
62  (N_ "long description will be here."))
63
64(define-custom 'canna-segment-separator "|"
65  '(canna segment-sep)
66  '(string ".*")
67  (N_ "Segment separator")
68  (N_ "long description will be here."))
69
70(custom-add-hook 'canna-segment-separator
71		 'custom-activity-hooks
72		 (lambda ()
73		   canna-show-segment-separator?))
74
75;;
76;; candidate window
77;;
78
79(define-custom 'canna-use-candidate-window? #t
80  '(canna candwin)
81  '(boolean)
82  (N_ "Use candidate window")
83  (N_ "long description will be here."))
84
85(define-custom 'canna-candidate-op-count 1
86  '(canna candwin)
87  '(integer 0 99)
88  (N_ "Conversion key press count to show candidate window")
89  (N_ "long description will be here."))
90
91(define-custom 'canna-nr-candidate-max 10
92  '(canna candwin)
93  '(integer 1 20)
94  (N_ "Number of candidates in candidate window at a time")
95  (N_ "long description will be here."))
96
97(define-custom 'canna-select-candidate-by-numeral-key? #f
98  '(canna candwin)
99  '(boolean)
100  (N_ "Select candidate by numeral keys")
101  (N_ "long description will be here."))
102
103;; activity dependency
104(custom-add-hook 'canna-candidate-op-count
105		 'custom-activity-hooks
106		 (lambda ()
107		   canna-use-candidate-window?))
108
109(custom-add-hook 'canna-nr-candidate-max
110		 'custom-activity-hooks
111		 (lambda ()
112		   canna-use-candidate-window?))
113
114(custom-add-hook 'canna-select-candidate-by-numeral-key?
115		 'custom-activity-hooks
116		 (lambda ()
117		   canna-use-candidate-window?))
118
119;;
120;; toolbar
121;;
122
123;; Can't be unified with action definitions in canna.scm until uim
124;; 0.4.6.
125(define canna-input-mode-indication-alist
126  (list
127   (list 'action_canna_direct
128	 'ja_direct
129	 "-"
130	 (N_ "Direct input")
131	 (N_ "Direct input mode"))
132   (list 'action_canna_hiragana
133	 'ja_hiragana
134	 "��"
135	 (N_ "Hiragana")
136	 (N_ "Hiragana input mode"))
137   (list 'action_canna_katakana
138	 'ja_katakana
139	 "��"
140	 (N_ "Katakana")
141	 (N_ "Katakana input mode"))
142   (list 'action_canna_halfkana
143	 'ja_halfkana
144	 "��"
145	 (N_ "Halfwidth Katakana")
146	 (N_ "Halfwidth Katakana input mode"))
147   (list 'action_canna_halfwidth_alnum
148	 'ja_halfwidth_alnum
149	 "a"
150	 (N_ "Halfwidth Alphanumeric")
151	 (N_ "Halfwidth Alphanumeric input mode"))
152
153   (list 'action_canna_fullwidth_alnum
154	 'ja_fullwidth_alnum
155	 "��"
156	 (N_ "Fullwidth Alphanumeric")
157	 (N_ "Fullwidth Alphanumeric input mode"))))
158
159(define canna-kana-input-method-indication-alist
160  (list
161   (list 'action_canna_roma
162	 'ja_romaji
163	 "��"
164	 (N_ "Romaji")
165	 (N_ "Romaji input mode"))
166   (list 'action_canna_kana
167	 'ja_kana
168	 "��"
169	 (N_ "Kana")
170	 (N_ "Kana input mode"))
171   (list 'action_canna_azik
172	 'ja_azik
173	 "��"
174	 (N_ "AZIK")
175	 (N_ "AZIK extended romaji input mode"))
176   (list 'action_canna_act
177	 'ja_act
178	 "��"
179	 (N_ "ACT")
180	 (N_ "ACT extended romaji input mode"))
181   (list 'action_canna_kzik
182	 'ja_kzik
183	 "��"
184	 (N_ "KZIK")
185	 (N_ "KZIK extended romaji input mode"))))
186
187;;; Buttons
188
189(define-custom 'canna-widgets '(widget_canna_input_mode
190				widget_canna_kana_input_method)
191  '(canna toolbar-widget)
192  (list 'ordered-list
193	(list 'widget_canna_input_mode
194	      (N_ "Input mode")
195	      (N_ "Input mode"))
196	(list 'widget_canna_kana_input_method
197	      (N_ "Kana input method")
198	      (N_ "Kana input method")))
199  (N_ "Enabled toolbar buttons")
200  (N_ "long description will be here."))
201
202;; dynamic reconfiguration
203;; canna-configure-widgets is not defined at this point. So wrapping
204;; into lambda.
205(custom-add-hook 'canna-widgets
206		 'custom-set-hooks
207		 (lambda ()
208		   (canna-configure-widgets)))
209
210
211;;; Input mode
212
213(define-custom 'default-widget_canna_input_mode 'action_canna_direct
214  '(canna toolbar-widget)
215  (cons 'choice
216	(map indication-alist-entry-extract-choice
217	     canna-input-mode-indication-alist))
218  (N_ "Default input mode")
219  (N_ "long description will be here."))
220
221(define-custom 'canna-input-mode-actions
222               (map car canna-input-mode-indication-alist)
223  '(canna toolbar-widget)
224  (cons 'ordered-list
225	(map indication-alist-entry-extract-choice
226	     canna-input-mode-indication-alist))
227  (N_ "Input mode menu items")
228  (N_ "long description will be here."))
229
230;; value dependency
231(if custom-full-featured?
232    (custom-add-hook 'canna-input-mode-actions
233		     'custom-set-hooks
234		     (lambda ()
235		       (custom-choice-range-reflect-olist-val
236			'default-widget_canna_input_mode
237			'canna-input-mode-actions
238			canna-input-mode-indication-alist))))
239
240;; activity dependency
241(custom-add-hook 'default-widget_canna_input_mode
242		 'custom-activity-hooks
243		 (lambda ()
244		   (memq 'widget_canna_input_mode canna-widgets)))
245
246(custom-add-hook 'canna-input-mode-actions
247		 'custom-activity-hooks
248		 (lambda ()
249		   (memq 'widget_canna_input_mode canna-widgets)))
250
251;; dynamic reconfiguration
252(custom-add-hook 'default-widget_canna_input_mode
253		 'custom-set-hooks
254		 (lambda ()
255		   (canna-configure-widgets)))
256
257(custom-add-hook 'canna-input-mode-actions
258		 'custom-set-hooks
259		 (lambda ()
260		   (canna-configure-widgets)))
261
262;;; Kana input method
263
264(define-custom 'default-widget_canna_kana_input_method 'action_canna_roma
265  '(canna toolbar-widget)
266  (cons 'choice
267	(map indication-alist-entry-extract-choice
268	     canna-kana-input-method-indication-alist))
269  (N_ "Default kana input method")
270  (N_ "long description will be here."))
271
272(define-custom 'canna-kana-input-method-actions
273               (map car canna-kana-input-method-indication-alist)
274  '(canna toolbar-widget)
275  (cons 'ordered-list
276	(map indication-alist-entry-extract-choice
277	     canna-kana-input-method-indication-alist))
278  (N_ "Kana input method menu items")
279  (N_ "long description will be here."))
280
281;; value dependency
282(if custom-full-featured?
283    (custom-add-hook 'canna-kana-input-method-actions
284		     'custom-set-hooks
285		     (lambda ()
286		       (custom-choice-range-reflect-olist-val
287			'default-widget_canna_kana_input_method
288			'canna-kana-input-method-actions
289			canna-kana-input-method-indication-alist))))
290
291;; activity dependency
292(custom-add-hook 'default-widget_canna_kana_input_method
293		 'custom-activity-hooks
294		 (lambda ()
295		   (memq 'widget_canna_kana_input_method canna-widgets)))
296
297(custom-add-hook 'canna-kana-input-method-actions
298		 'custom-activity-hooks
299		 (lambda ()
300		   (memq 'widget_canna_kana_input_method canna-widgets)))
301
302;; dynamic reconfiguration
303(custom-add-hook 'default-widget_canna_kana_input_method
304		 'custom-set-hooks
305		 (lambda ()
306		   (canna-configure-widgets)))
307
308(custom-add-hook 'canna-kana-input-method-actions
309		 'custom-set-hooks
310		 (lambda ()
311		   (canna-configure-widgets)))
312
313
314;;
315;; canna-server-name
316;;
317
318; TODO: support cannaserver on other host
319(define canna-server-name #f)
320;(define canna-server-name "localhost")
321;(define canna-server-name "127.0.0.1")
322
323;; warning: must be defined before custom-preserved-canna-server-name
324(define-custom 'custom-activate-canna-server-name? #f
325  '(canna-advanced cannaserver)
326  '(boolean)
327  (N_ "Specify Canna server")
328  (N_ "long description will be here."))
329
330(define-custom 'custom-preserved-canna-server-name ""
331  '(canna-advanced cannaserver)
332  '(string ".*")
333  (N_ "Canna server name")
334  (N_ "long description will be here."))
335
336(define-custom 'canna-user-name (user-name)
337  '(canna-advanced cannaserver)
338  '(string ".*")
339  (N_ "Canna user name")
340  (N_ "long description will be here."))
341
342;; activity dependency
343(custom-add-hook 'custom-preserved-canna-server-name
344		 'custom-activity-hooks
345		 (lambda ()
346		   custom-activate-canna-server-name?))
347
348(define custom-hook-get-canna-server-name
349  (lambda ()
350    (set! custom-activate-canna-server-name? canna-server-name)
351    (set! custom-preserved-canna-server-name (or canna-server-name
352						 custom-preserved-canna-server-name
353						 ""))))
354
355(custom-add-hook 'canna-user-name
356		 'custom-activity-hooks
357		 (lambda ()
358		   custom-activate-canna-server-name?))
359
360;; decode #f from canna-server-name
361(custom-add-hook 'custom-activate-canna-server-name?
362		 'custom-get-hooks
363		 custom-hook-get-canna-server-name)
364(custom-add-hook 'canna-server-name
365		 'custom-get-hooks
366		 custom-hook-get-canna-server-name)
367
368(define custom-hook-set-canna-server-name
369  (lambda ()
370    (set! canna-server-name
371	  (and custom-activate-canna-server-name?
372	       custom-preserved-canna-server-name))))
373
374;; encode #f into canna-server-name
375(custom-add-hook 'custom-activate-canna-server-name?
376		 'custom-set-hooks
377		 custom-hook-set-canna-server-name)
378(custom-add-hook 'custom-preserved-canna-server-name
379		 'custom-set-hooks
380		 custom-hook-set-canna-server-name)
381
382(define custom-hook-literalize-preserved-canna-server-name
383  (lambda ()
384    (string-append
385     "(define custom-preserved-canna-server-name "
386     (custom-value-as-literal 'custom-preserved-canna-server-name)
387     ")\n"
388     "(define canna-server-name "
389     (if canna-server-name
390	 (string-append "\"" canna-server-name "\"")
391	 "#f")
392     ")")))
393
394(custom-add-hook 'custom-preserved-canna-server-name
395		 'custom-literalize-hooks
396		 custom-hook-literalize-preserved-canna-server-name)
397
398(define-custom 'canna-use-with-vi? #f
399  '(canna-advanced special-op)
400  '(boolean)
401  (N_ "Enable vi-cooperative mode")
402  (N_ "long description will be here."))
403
404(define-custom 'canna-auto-start-henkan? #f
405 '(canna-advanced special-op)
406 '(boolean)
407 (N_ "Enable auto conversion with punctuation marks")
408 (N_ "long description will be here."))
409
410(define-custom 'canna-use-mode-transition-keys-in-off-mode? #f
411  '(canna-advanced mode-transition)
412  '(boolean)
413  (N_ "Enable input mode transition keys in direct (off state) input mode")
414  (N_ "long description will be here."))
415
416;; prediction
417(define-custom 'canna-use-prediction? #f
418  '(canna-advanced canna-prediction)
419  '(boolean)
420  (N_ "Enable input prediction")
421  (N_ "long description will be here."))
422
423(define-custom 'canna-select-prediction-by-numeral-key? #f
424  '(canna-advanced canna-prediction)
425  '(boolean)
426  (N_ "Select prediction candidate by numeral keys")
427  (N_ "long description will be here."))
428
429(define-custom 'canna-use-implicit-commit-prediction? #t
430  '(canna-advanced canna-prediction)
431  '(boolean)
432  (N_ "Show selected prediction candidate in preedit area")
433  (N_ "long description will be here."))
434
435(define-custom 'canna-prediction-cache-words 256
436  '(canna-advanced canna-prediction)
437  '(integer 1 65535)
438  (N_ "Number of cache of prediction candidates")
439  (N_ "long description will be here."))
440
441(define-custom 'canna-prediction-start-char-count 2
442  '(canna-advanced canna-prediction)
443  '(integer 1 65535)
444  (N_ "Character count to start input prediction")
445  (N_ "long description will be here."))
446
447(custom-add-hook 'canna-use-candidate-window?
448                 'custom-get-hooks
449                 (lambda ()
450                   (if (not canna-use-candidate-window?)
451                       (set! canna-use-prediction? #f))))
452
453(custom-add-hook 'canna-use-prediction?
454                 'custom-activity-hooks
455                 (lambda ()
456                   canna-use-candidate-window?))
457
458(custom-add-hook 'canna-select-prediction-by-numeral-key?
459                 'custom-activity-hooks
460                 (lambda ()
461                   canna-use-prediction?))
462
463(custom-add-hook 'canna-use-implicit-commit-prediction?
464                 'custom-activity-hooks
465                 (lambda ()
466                   canna-use-prediction?))
467
468(custom-add-hook 'canna-prediction-cache-words
469                 'custom-activity-hooks
470                 (lambda ()
471                   canna-use-prediction?))
472
473(custom-add-hook 'canna-prediction-start-char-count
474                 'custom-activity-hooks
475                 (lambda ()
476                   canna-use-prediction?))
477