public
Last active

  • Download Gist
annotation.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
* 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.