Revision: 6341
Author: nogu.dev
Date: Mon Apr 26 15:50:19 2010
Log: * qt4/immodule/candidatewindow.cpp
  - (CandidateWindow::CandidateWindow):
    See value of "enable-annotation?"
    instead of "eb-enable-for-annotation?".
  - (CandidateWindow::setPage): Uncomment lines.
  - (CandidateListView::sizeHint): Adjust size.
* scm/Makefile.am
  - (SCM_FILES): Add annotation.scm and annotation-eb.scm.
* scm/annotation.scm
  - New file.
* scm/annotation-eb.scm
  - New file.
* scm/im-custom.scm
  - Add "enable-annotation?" and "annotation-agent".
* scm/im.scm
  - (create-context): Call annotation-init for annotation support.
  - (release-context): Call annotation-release for annotation support.
  - (get-candidate): Call annotation-get-text for annotation support.
* scm/init.scm
  - Load annotation-related file.
http://code.google.com/p/uim/source/detail?r=6341

Added:
 /trunk/scm/annotation-eb.scm
 /trunk/scm/annotation.scm
Modified:
 /trunk/qt4/immodule/candidatewindow.cpp
 /trunk/scm/Makefile.am
 /trunk/scm/im-custom.scm
 /trunk/scm/im.scm
 /trunk/scm/init.scm

=======================================
--- /dev/null
+++ /trunk/scm/annotation-eb.scm        Mon Apr 26 15:50:19 2010
@@ -0,0 +1,57 @@
+;;; annotation-eb.scm: EB Library functions for uim
+;;;
+;;; Copyright (c) 2010 uim Project http://code.google.com/p/uim/
+;;;
+;;; All rights reserved.
+;;;
+;;; Redistribution and use in source and binary forms, with or without
+;;; modification, are permitted provided that the following conditions
+;;; are met:
+;;; 1. Redistributions of source code must retain the above copyright
+;;;    notice, this list of conditions and the following disclaimer.
+;;; 2. Redistributions in binary form must reproduce the above copyright
+;;;    notice, this list of conditions and the following disclaimer in the
+;;;    documentation and/or other materials provided with the distribution.
+;;; 3. Neither the name of authors nor the names of its contributors
+;;; may be used to endorse or promote products derived from this software
+;;;    without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE +;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+;;; SUCH DAMAGE.
+;;;;
+(and (not (provided? "eb"))
+  (guard (err (else #f))
+    (module-load "eb"))
+  (provide "eb"))
+
+(define eb-ctx #f)
+
+;; eb-enable-for-annotation? exists only for compatibility.
+;; You shouldn't add similar variables to other annotation agents.
+
+(define eb-init
+  (lambda ()
+    (and (provided? "eb")
+      eb-enable-for-annotation?
+      (set! eb-ctx (eb-new eb-dic-path)))))
+
+(define eb-get-text
+  (lambda (text)
+    (or (and eb-ctx
+          eb-enable-for-annotation?
+          (eb-search-text eb-ctx text))
+      "")))
+
+(define eb-release
+  (lambda ()
+    (and eb-ctx
+      (eb-destroy eb-ctx))))
=======================================
--- /dev/null
+++ /trunk/scm/annotation.scm   Mon Apr 26 15:50:19 2010
@@ -0,0 +1,62 @@
+;;; annotation.scm: annotation functions for uim
+;;;
+;;; Copyright (c) 2010 uim Project http://code.google.com/p/uim/
+;;;
+;;; All rights reserved.
+;;;
+;;; Redistribution and use in source and binary forms, with or without
+;;; modification, are permitted provided that the following conditions
+;;; are met:
+;;; 1. Redistributions of source code must retain the above copyright
+;;;    notice, this list of conditions and the following disclaimer.
+;;; 2. Redistributions in binary form must reproduce the above copyright
+;;;    notice, this list of conditions and the following disclaimer in the
+;;;    documentation and/or other materials provided with the distribution.
+;;; 3. Neither the name of authors nor the names of its contributors
+;;; may be used to endorse or promote products derived from this software
+;;;    without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE +;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+;;; SUCH DAMAGE.
+;;;;
+;; The three procedures below are used when (enable-annotation?) is #f.
+;; When you add a new annotation agent named "foo", you need to create a file
+;; named "annotation-foo.scm", and define foo-init, foo-get-text
+;; and foo-release in annotation-foo.scm.
+;; See also: init.scm
+
+;; Initializes an annotation agent.
+(define annotation-init
+  (lambda ()
+    #f))
+
+;; Returns an annotation string from the given candidate.
+(define annotation-get-text
+  (lambda (text)
+    ""))
+
+;; Releases the annotation agent.
+(define annotation-release
+  (lambda ()
+    #f))
+
+(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")))))
=======================================
--- /trunk/qt4/immodule/candidatewindow.cpp     Sun Apr  4 20:35:54 2010
+++ /trunk/qt4/immodule/candidatewindow.cpp     Mon Apr 26 15:50:19 2010
@@ -63,7 +63,7 @@
 : QFrame( parent, candidateFlag ), ic( 0 ), subWin( 0 ), window( 0 ),
nrCandidates( 0 ), displayLimit( 0 ), candidateIndex( -1 ), pageIndex( -1 ),
     isAlwaysLeft( false ), hasAnnotation( uim_scm_symbol_value_bool(
-        "eb-enable-for-annotation?" ) )
+        "enable-annotation?" ) )
 {
     setFrameStyle( Raised | NoFrame );

@@ -294,10 +294,10 @@
         QString candString
             = QString::fromUtf8( uim_candidate_get_cand_str( cand ) );
         QString annotationString;
-        // if ( hasAnnotation ) {
-        //     annotationString
- // = QString::fromUtf8( uim_candidate_get_annotation_str( cand ) );
-        // }
+        if ( hasAnnotation ) {
+            annotationString
+ = QString::fromUtf8( uim_candidate_get_annotation_str( cand ) );
+        }

         // insert new item to the candidate list
         QTableWidgetItem *headItem = new QTableWidgetItem;
@@ -619,7 +619,8 @@
     int width = frame;
     // the size of the dummy column should be 0.
     for ( int i = 0; i < columnCount() - 1; i++ )
-        width += columnWidth( i );
+        width += ( i != ANNOTATION_COLUMN ) ?
+            columnWidth( i ) : qMin( columnWidth( i ), MIN_CAND_WIDTH );

     return QSize( width, rowHeight( 0 ) * rowNum + frame );
 }
=======================================
--- /trunk/scm/Makefile.am      Mon Apr 12 20:32:57 2010
+++ /trunk/scm/Makefile.am      Mon Apr 26 15:50:19 2010
@@ -52,7 +52,8 @@
  lolevel.scm \
  input-parse.scm match.scm pregexp.scm \
  http-client.scm http-server.scm \
- sxml-tools.scm sxpathlib.scm
+ sxml-tools.scm sxpathlib.scm \
+ annotation.scm annotation-eb.scm

 ETAGS_ARGS=$(SCM_FILES) $(GENERATED_SCM_FILES)

=======================================
--- /trunk/scm/im-custom.scm    Sun Apr  4 20:35:54 2010
+++ /trunk/scm/im-custom.scm    Mon Apr 26 15:50:19 2010
@@ -543,22 +543,48 @@
                         (eq? bridge-show-with?
                              'time))))

+(define-custom 'enable-annotation? #t
+  '(annotation candwin)
+  '(boolean)
+  (N_ "Enable annotation")
+  (N_ "long description will be here."))
+
+(define-custom 'annotation-agent 'eb
+  '(annotation candwin)
+  (list 'choice
+    (list 'eb
+      (N_ "EB library")
+      (N_ "EB library")))
+  (N_ "Annotation agent name")
+  (N_ "long description will be here."))
+
+(custom-add-hook 'annotation-agent
+  'custom-activity-hooks
+  (lambda ()
+    enable-annotation?))
+
 ;; EB Library support
-;; 2005-02-08 Takuro Ashie <[email protected]>
-;; FIXME! Here isn't suitable position for EB support preference
 (define-custom-group 'eb
                     (N_ "EB library")
                     (N_ "long description will be here."))

+;; eb-enable-for-annotation? exists only for compatibility.
+;; You shouldn't add similar variables to other annotation agents.
 (define-custom 'eb-enable-for-annotation? #f
-  '(eb candwin)
+  '(annotation eb)
   '(boolean)
   (N_ "Use EB library to search annotations")
   (N_ "long description will be here."))

+(custom-add-hook 'eb-enable-for-annotation?
+  'custom-activity-hooks
+  (lambda ()
+    (and enable-annotation?
+      (eq? annotation-agent 'eb))))
+
 (define-custom 'eb-dic-path
   (string-append (sys-datadir) "/dict")
-  '(eb candwin)
+  '(annotation eb)
   '(pathname directory)
   (N_ "The directory which contains EB dictionary file")
   (N_ "long description will be here."))
@@ -568,6 +594,12 @@
                 (lambda ()
                   eb-enable-for-annotation?))

+(custom-add-hook 'eb-dic-path
+  'custom-activity-hooks
+  (lambda ()
+    (and enable-annotation?
+      (eq? annotation-agent 'eb))))
+
 ;; uim-xim specific custom
 (define-custom-group 'xim
                     (N_ "XIM")
=======================================
--- /trunk/scm/im.scm   Sun Apr  4 20:35:54 2010
+++ /trunk/scm/im.scm   Mon Apr 26 15:50:19 2010
@@ -36,6 +36,7 @@
 (require "util.scm")
 (require "i18n.scm")
 (require "load-action.scm")
+(require "annotation.scm")

 ;; config
 (define default-im-name #f)
@@ -353,11 +354,12 @@
 (define create-context
   (lambda (uc lang name)
     (let* ((im (find-im name lang))
-          (arg (and im (im-init-arg im))))
+           (arg (and im (im-init-arg im))))
       (im-set-encoding uc (im-encoding im))
       (let* ((handler (im-init-handler im))
-            (c (handler uc im arg)))
-       (register-context c)
+             (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.
         c))))
@@ -371,6 +373,7 @@

 (define release-context
   (lambda (uc)
+    (annotation-release)
     (invoke-handler im-release-handler uc)
     (remove-context (im-retrieve-context uc))
     #f))
@@ -514,7 +517,10 @@

 (define get-candidate
   (lambda (uc idx accel-enum-hint)
-    (invoke-handler im-get-candidate-handler 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)))))
+      c)))

 (define set-candidate-index
   (lambda (uc idx)
=======================================
--- /trunk/scm/init.scm Sun Apr  4 20:35:54 2010
+++ /trunk/scm/init.scm Mon Apr 26 15:50:19 2010
@@ -131,6 +131,10 @@
 (if (symbol-bound? 'uim-notify-load)
     (uim-notify-load (symbol->string notify-agent)))

+;; redefine annotation-related procedures to use an annotation agent
+(and enable-annotation?
+  (annotation-load (symbol->string annotation-agent)))
+
 (or (getenv "LIBUIM_VANILLA")
     (load-user-conf)
     (load "default.scm"))


--
Subscription settings: http://groups.google.com/group/uim-commit/subscribe?hl=en

Reply via email to