]> www.wagner.pp.ru Git - oss/fubar.git/blob - plugins/dict
Reimport after CVS crash
[oss/fubar.git] / plugins / dict
1
2 option add *Dict*Text.font -*-helvetica-medium-r-normal--12-*-iso10646-1
3 option add *Dict*Entry.font -*-helvetica-medium-r-normal--12-*-iso10646-1
4 namespace eval ::dict {
5         set m .find.m
6         $m add command -label "Word..." -command "create_or_raise\
7         .find_dict  dict::mkWindow -class Dict; focus .find_dict.e1"
8 #balloonhelp $m -index 2 "Search for a word in dictionary"      
9         if {![findInPath "dict"]} {
10                 $m entryconfigure "Word..." -state disabled
11         }   
12
13         proc mkWindow {w} {
14                 wm title $w "Dictionary lookup"
15                         label $w.l1 -text "Word"
16                         entry $w.e1 -exportselection false
17                         button $w.b1 -text Lookup -command "::dict::lookup $w \[$w.e1 get\]"
18                         bind $w.e1 <Return> "::dict::lookup $w \[$w.e1 get\]"
19                         text $w.t -yscrollcommand "$w.y set" -state disabled
20                         bind $w.t <<Paste>> [list event generate $w.e1 <<Paste>>]
21                         bind $w.t <<PasteSelection>> [list event generate $w.e1 <<PasteSelection>>]
22                         bind $w.t <Double-1> {%W tag delete sel
23                                 %W tag add sel "@%x,%y wordstart" "@%x,%y wordend"
24                                         event generate [winfo parent %W].e1 <<PasteSelection>>
25                                         break
26                         }
27                 bind $w.e1 <<Paste>> {%W delete 0 end;
28                         %W insert 0 [selection get -selection CLIPBOARD]
29                                 ::dict::lookup [winfo parent %W] [%W get]
30                                 break
31                 }
32                 bind $w.e1 <<PasteSelection>> {%W delete 0 end;
33                         %W insert 0 [selection get]
34                                 ::dict::lookup [winfo parent %W] [%W get]
35                                 break
36                 }
37                 scrollbar $w.y -orient vert -command "$w.t yview"
38
39                         grid $w.l1 $w.e1 $w.b1 - -sticky news
40                         grid $w.t - - $w.y -sticky news 
41                         grid rowconfigure $w 1 -weight 1
42                         grid columnconfigure $w  1 -weight 1
43                         $w.t tag configure error -foreground red
44                         $w.t tag configure source -foreground darkgreen -relief raised -borderwidth 2
45
46         }
47         proc lookup {w word} {
48                 if {![string length $word]} {
49                         return
50                 }       
51                 set f [open "|dict \"[encoding convertfrom [encoding convertto utf-8 $word]]\"" r]
52                         fconfigure $f -encoding utf-8
53                         set answer [read $f]
54                         $w.t configure -state normal
55                         $w.t delete 0.0 end
56                         if {[catch {close $f} msg]} {
57                                 $w.t insert 0.0 $msg error
58                         }
59                 $w.t insert 0.0 $answer
60                         $w.t see 0.0
61                         set mark 0.0
62                         while {[string length [set mark [$w.t search -regex -- {^From .*\[[^ ]+\]:} "$mark+1lines" end]]]} {
63                                 $w.t tag add source $mark "$mark lineend"
64                         }
65                 $w.t configure -state disabled
66                         $w.t see 0.0
67                         $w.e1 selection range 0 end
68         }
69 }