summaryrefslogtreecommitdiff
path: root/support/tcltexed/lib/complition.tcl
blob: 79d1670a458512622c604beb8c2372f28e100be2 (plain)
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
# Copyright (C) 1999 - Martin Strauss - under terms of GPL
################################
# auto complition
# ok !
proc ergaenzung {E} {
 global I_befehl I_back I_state
 global BeginFlag
 global erg_flag erg_back
 set ksp [$E get {insert-1c wordstart-1c} {insert-1c wordstart}]
 if ![string compare "\\" $ksp] then {
  set TEXT [$E get {insert-1c wordstart} insert]
  set LISTE [array names I_state "$TEXT*"]
  if {1 == [llength $LISTE]} then {
   set sp1 [string length $LISTE]
   set sp2 [string length $TEXT]
   if {$sp1 > $sp2} then {
    erg_insert $E $LISTE [$E index insert]
   } elseif {$sp1 == $sp2} {
    Syntax $E {insert-1c wordstart-1c} insert
}}}}
#############################################
# complition per mouse : the start
# ok !
menu .pop_menu -tearoff 0
COLOR .pop_menu
proc ergaenzung2 {E} {
 global I_state
 set ksp [$E get {insert-1c wordstart-1c} {insert-1c wordstart}]
 if ![string compare "\\" $ksp] then {
  set TEXT [$E get {insert-1c wordstart} insert]
  set sp1 [string length $TEXT]
  set LISTE [lsort [array names I_state "$TEXT*"]]
  if {0 < [llength $LISTE]} then {
   erg2_weiter $E $LISTE $sp1 [$E index insert]
}}}
##############################################
# complition per mouse : construction
proc erg2_weiter {E LISTE laenge index} {
 global erg2_max T
 .pop_menu delete 0 end
 .pop_menu add command -label $T(cancel)
 if {[llength $LISTE] > $erg2_max} {
  .pop_menu add command -label $T(more) -command "erg2_weiter $E {[lrange $LISTE $erg2_max end]} $laenge $index"
 }
 .pop_menu add separator
 foreach i [lrange $LISTE 0 [expr $erg2_max - 1]] {
  if {$laenge == [string length $i]} {
   .pop_menu add command -label $i
  } {
   .pop_menu add command -label $i -command "erg_insert $E $i $index"
  }
 }
 tk_popup .pop_menu [expr [winfo rootx $E] + [lindex [$E bbox insert] 0]] [expr [winfo rooty $E] + [lindex [$E bbox insert] 1]]
}
###################################
# functions for complitions in general
# ok ?
proc erg_insert {E T index} {
 global I_befehl I_back
 global BeginFlag
 global erg_flag erg_back

 $E mark set insert $index
 set erg_flag($E) 1

 undo_switch $E {Save {{insert-1c wordstart-1c} insert} Delete UndoBegin}
 $E mark set erg_begin insert
 $E mark gravity erg_begin left
 $E insert insert $I_befehl($T)
 $E mark set erg_end insert
 undo_switch $E {UndoEnd Save UndoMax UndoMul}

 switch $T begin {
  $E mark set BeginMark insert-2c
  set BeginFlag($E) 1
 }
 $E tag add erg_tag erg_begin erg_end
 $E mark set insert $index
 set erg_back($E) $I_back($T)
}
proc erg_proc {E} {
 global erg_flag
 global erg_back
 if $erg_flag($E) then {
  Syntax $E erg_begin erg_end
  $E mark set insert "erg_end - $erg_back($E) chars"
  $E tag remove erg_tag 1.0 end
  set erg_flag($E) 0
 }
}