Revision: 6344
Author: ek.kato
Date: Tue Apr 27 18:51:37 2010
Log: * scm/annotation.scm
  - (annotation-load) : Init agent at loading time.
  - (annotation-unload) : New.
  - (annotation-agent-reset) : Ditto.
* scm/annotation-eb.scm
  - (eb-init) : Fix leak.
  - (eb-release) : Ditto.
* scm/im-custom.scm
  - (annotation-agent)
    * Add 'im choice to use annotation of input method
      exclusively.
    * Add custom-set-hooks.
* scm/im.scm
  - (create-context) : Fix leak of annotation.
  - (release-context) : Ditto.
  - (get-candidate) : Check enable-annotation? here.
* uim/uim.c (uim_quit) : Unload annotation agent.

http://code.google.com/p/uim/source/detail?r=6344

Modified:
 /trunk/scm/annotation-eb.scm
 /trunk/scm/annotation.scm
 /trunk/scm/im-custom.scm
 /trunk/scm/im.scm
 /trunk/uim/uim.c

=======================================
--- /trunk/scm/annotation-eb.scm        Mon Apr 26 15:50:19 2010
+++ /trunk/scm/annotation-eb.scm        Tue Apr 27 18:51:37 2010
@@ -42,6 +42,7 @@
   (lambda ()
     (and (provided? "eb")
       eb-enable-for-annotation?
+      (not eb-ctx)
       (set! eb-ctx (eb-new eb-dic-path)))))

 (define eb-get-text
@@ -53,5 +54,7 @@

 (define eb-release
   (lambda ()
-    (and eb-ctx
-      (eb-destroy eb-ctx))))
+    (if eb-ctx
+      (begin
+        (eb-destroy eb-ctx)
+        (set! eb-ctx #f)))))
=======================================
--- /trunk/scm/annotation.scm   Mon Apr 26 15:50:19 2010
+++ /trunk/scm/annotation.scm   Tue Apr 27 18:51:37 2010
@@ -51,12 +51,33 @@

 (define annotation-load
   (lambda (name)
-    (or (and (try-require (string-append "annotation-" name ".scm"))
-          (let ((env (interaction-environment)))
-            (set! annotation-init
-              (eval (string->symbol (string-append name "-init")) env))
-            (set! annotation-get-text
-              (eval (string->symbol (string-append name "-get-text")) env))
-            (set! annotation-release
- (eval (string->symbol (string-append name "-release")) env))))
-      (uim-notify-info (N_ "invalid annotation agent name")))))
+    (or (and name
+             (try-require (string-append "annotation-" name ".scm"))
+             (let ((env (interaction-environment)))
+               (set! annotation-init
+                 (eval (string->symbol (string-append name "-init")) env))
+               (set! annotation-get-text
+ (eval (string->symbol (string-append name "-get-text")) env))
+               (set! annotation-release
+ (eval (string->symbol (string-append name "-release")) env))
+               #t)
+             (begin
+               (annotation-init)
+               #t))
+        (and
+          (begin
+            (annotation-agent-reset)
+            (if (and name
+                     (not (string=? name "im")))
+              (uim-notify-info (N_ "invalid annotation agent name"))))))))
+
+(define annotation-unload
+  (lambda ()
+    (annotation-release)
+    (annotation-agent-reset)))
+
+(define annotation-agent-reset
+  (lambda ()
+    (set! annotation-init (lambda () #f))
+    (set! annotation-get-text (lambda (text) ""))
+    (set! annotation-release (lambda () #f))))
=======================================
--- /trunk/scm/im-custom.scm    Mon Apr 26 15:50:19 2010
+++ /trunk/scm/im-custom.scm    Tue Apr 27 18:51:37 2010
@@ -554,7 +554,10 @@
   (list 'choice
     (list 'eb
       (N_ "EB library")
-      (N_ "EB library")))
+      (N_ "EB library"))
+    (list 'im
+      (N_ "Annotation from IM only")
+      (N_ "long description will be here.")))
   (N_ "Annotation agent name")
   (N_ "long description will be here."))

@@ -563,6 +566,15 @@
   (lambda ()
     enable-annotation?))

+(custom-add-hook 'annotation-agent
+                 'custom-set-hooks
+                 (lambda ()
+                   (annotation-unload)
+                   (annotation-load
+                     (if enable-annotation?
+                       (symbol->string annotation-agent)
+                       #f))))
+
 ;; EB Library support
 (define-custom-group 'eb
                     (N_ "EB library")
=======================================
--- /trunk/scm/im.scm   Mon Apr 26 15:50:19 2010
+++ /trunk/scm/im.scm   Tue Apr 27 18:51:37 2010
@@ -358,7 +358,6 @@
       (im-set-encoding uc (im-encoding im))
       (let* ((handler (im-init-handler im))
              (c (handler uc im arg)))
-        (annotation-init)
         (register-context c)
;; im-* procedures that require uc->sc must not called here since it
         ;; is not filled yet. Place such procedures to setup-context.
@@ -373,7 +372,6 @@

 (define release-context
   (lambda (uc)
-    (annotation-release)
     (invoke-handler im-release-handler uc)
     (remove-context (im-retrieve-context uc))
     #f))
@@ -518,8 +516,11 @@
 (define get-candidate
   (lambda (uc idx accel-enum-hint)
(let ((c (invoke-handler im-get-candidate-handler uc idx accel-enum-hint)))
-      (and (string=? (last c) "")
-        (set-cdr! (cdr c) (list (annotation-get-text (car c)))))
+      (if (and (not enable-annotation?)
+               (not (string=? (last c) "")))
+          (set-cdr! (cdr c) (list ""))
+          (and (string=? (last c) "")
+               (set-cdr! (cdr c) (list (annotation-get-text (car c))))))
       c)))

 (define set-candidate-index
=======================================
--- /trunk/uim/uim.c    Sun Apr  4 20:35:54 2010
+++ /trunk/uim/uim.c    Tue Apr 27 18:51:37 2010
@@ -184,6 +184,7 @@
 #if UIM_USE_NOTIFY
   uim_notify_quit();
 #endif
+  uim_scm_callf("annotation-unload", "");
   uim_scm_callf("module-unload-all", "");
   uim_quit_dynlib();
   uim_scm_quit();

Reply via email to