Skip to content

@mnogu /annotation.patch
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
* 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.
---
qt4/immodule/candidatewindow.cpp | 13 ++++----
scm/Makefile.am | 3 +-
scm/annotation-eb.scm | 56 ++++++++++++++++++++++++++++++++++
scm/annotation.scm | 61 ++++++++++++++++++++++++++++++++++++++
scm/im-custom.scm | 40 ++++++++++++++++++++++--
scm/im.scm | 14 ++++++--
scm/init.scm | 4 ++
7 files changed, 176 insertions(+), 15 deletions(-)
create mode 100644 scm/annotation-eb.scm
create mode 100644 scm/annotation.scm
diff --git a/qt4/immodule/candidatewindow.cpp b/qt4/immodule/candidatewindow.cpp
index c958e73..398cba2 100644
--- a/qt4/immodule/candidatewindow.cpp
+++ b/qt4/immodule/candidatewindow.cpp
@@ -63,7 +63,7 @@ CandidateWindow::CandidateWindow( QWidget *parent )
: 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 @@ void CandidateWindow::setPage( int page )
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 @@ QSize CandidateListView::sizeHint() const
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 );
}
diff --git a/scm/Makefile.am b/scm/Makefile.am
index 8e5b040..2d9b97f 100644
--- a/scm/Makefile.am
+++ b/scm/Makefile.am
@@ -52,7 +52,8 @@ SCM_FILES = plugin.scm im.scm im-custom.scm lazy-load.scm init.scm \
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)
diff --git a/scm/annotation-eb.scm b/scm/annotation-eb.scm
new file mode 100644
index 0000000..598c2bd
--- /dev/null
+++ b/scm/annotation-eb.scm
@@ -0,0 +1,56 @@
+;;; 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)
+ (if (and eb-ctx eb-enable-for-annotation?)
+ (eb-search-text eb-ctx text)
+ "")))
+
+(define eb-release
+ (lambda ()
+ (and eb-ctx
+ (eb-destroy eb-ctx))))
diff --git a/scm/annotation.scm b/scm/annotation.scm
new file mode 100644
index 0000000..c527c27
--- /dev/null
+++ b/scm/annotation.scm
@@ -0,0 +1,61 @@
+;;; 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)
+ (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))))))
diff --git a/scm/im-custom.scm b/scm/im-custom.scm
index 6619cf0..2b876ed 100644
--- a/scm/im-custom.scm
+++ b/scm/im-custom.scm
@@ -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 <ashie@homa.ne.jp>
-;; 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")
diff --git a/scm/im.scm b/scm/im.scm
index 15413a0..41552dc 100644
--- a/scm/im.scm
+++ b/scm/im.scm
@@ -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)))
+ (if (string=? (last c) "")
+ (set-cdr! (cdr c) (list (annotation-get-text (car c)))))
+ c)))
(define set-candidate-index
(lambda (uc idx)
diff --git a/scm/init.scm b/scm/init.scm
index 44ccafc..7468f21 100644
--- a/scm/init.scm
+++ b/scm/init.scm
@@ -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"))
--
1.6.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.