summaryrefslogtreecommitdiff
path: root/support/tcltexed/lib/bindings.tcl
blob: e4284f1fea165c765eb0da2c70a01ebc3cd3fc94 (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
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
# Copyright (C) 1999 - Martin Strauss - under terms of GPL
 ##############################################################################
 # Umdefinition des Defaultverhaltens fuer Text-variablen
 bind Text <Control-k> {}
 bind Text <Control-b> {}
 # Block Anfang
 bind Text <Control-k><b> {
  set BlockBeginFlag 1
  %W mark set BlockBegin insert
  if {[string compare %W $BlockEditor] == 0} then {
   if $BlockEndFlag then {
    %W tag remove BlockTag 1.0 end
    %W tag add BlockTag BlockBegin BlockEnd
  }} else {
   if {$BlockBeginFlag && $BlockEndFlag} then {
    $BlockEditor tag remove BlockTag 1.0 end
   }
   set BlockEndFlag 0
   set BlockEditor %W
  }
 }
 # Block Ende
 bind Text <Control-k><k> {
  set BlockEndFlag 1
  %W mark set BlockEnd insert
  %W mark gravity BlockEnd left
  if {[string compare %W $BlockEditor] == 0} then {
   if $BlockBeginFlag then {
    %W tag remove BlockTag 1.0 end
    %W tag add BlockTag BlockBegin BlockEnd
  }} else {
   if {$BlockBeginFlag && $BlockEndFlag} then {
    $Blockeditor tag remove BlockTag 1.0 end
   }
   set BlockBeginFlag 0
   set BlockEditor %W
  }
 }
 # Block kopieren
 bind Text <Control-k><c> {
  if {$BlockBeginFlag && $BlockEndFlag} then {
   set ksp [%W index {insert linestart}]
   undo_switch %W {Save UndoBegin}
   %W insert insert [$BlockEditor get BlockBegin BlockEnd]
   undo_switch %W {UndoEnd Save UndoMax}
   Syntax %W $ksp "insert lineend"
  }
 }
 # Block verschieben
 bind Text <Control-k><v> {
  if {$BlockBeginFlag && $BlockEndFlag} then {
   set ksp [%W index "insert linestart"]
   undo_switch %W {Save UndoBegin}
   %W insert insert [$BlockEditor get BlockBegin BlockEnd]
   undo_switch %W {UndoEnd Save}
   undo_switch $BlockEditor {{BlockBegin BlockEnd} Delete UndoMax}
   if {[string compare %W $BlockEditor] == 0} then {
    undo_switch %W UndoMul
   }
   Syntax %W $ksp "insert lineend"
   Syntax $BlockEditor "BlockBegin linestart" "BlockEnd lineend"
  }
 }
 bind Text <Control-k><m> {
  event generate %W <Control-k> 
  event generate %W <v> 
 }
 # Block loeschen
 bind Text <Control-k><y> {
  if {$BlockBeginFlag && $BlockEndFlag} then {
   undo_switch $BlockEditor {Save {BlockBegin BlockEnd} Delete UndoMax}
  }
 }
 # Block auskommentieren
proc AusKomm {E A B} {
 set i [lindex "[split [$E index $A] .]" 0]
 set i_max [lindex "[split [$E index $B] .]" 0]
 incr i_max
 set ksp $i.0
 while {$i < $i_max} {
  if [expr [string compare [$E get "$i.0 linestart" "$i.0 linestart+1c"] "%"] != 0] {
   $E insert "$i.0 linestart" "%"
  }
  incr i
 }
 Syntax $E $ksp $i_max.0
 event generate $E <<Modified>>
}
 # Block auskommentieren rueckgaengig
proc AusKommRueck {E A B} {
 set i [lindex "[split [$E index $A] .]" 0]
 set i_max [lindex "[split [$E index $B] .]" 0]
 incr i_max
 set ksp $i.0
 while {$i < $i_max} {
  if [expr [string compare [$E get "$i.0 linestart" "$i.0 linestart+1c"] "%"] == 0] {
   $E delete "$i.0 linestart" "$i.0 linestart+1c"
  }
  incr i
 }
 Syntax $E $ksp $i_max.0
 event generate $E <<Modified>>
}

switch $tcl_platform(platform) windows {
# Auf jedenfall fuer Windows !!!
 bind Text <Control-k><%> {
  if { $BlockBeginFlag && $BlockEndFlag} then {
   AusKomm %W BlockBegin BlockEnd
  }
 }
} unix {
# fuer linux ???
 bind Text <Control-k><Shift-5> {
  if { $BlockBeginFlag && $BlockEndFlag} then {
   AusKomm %W BlockBegin BlockEnd
  }
 }
}
 bind Text <Control-k><space> {
  if { $BlockBeginFlag && $BlockEndFlag} then {
   AusKommRueck %W BlockBegin BlockEnd
  }
 }
 # Block in Clipboard kopieren
 bind Text <Control-k><g> {
  if { $BlockBeginFlag && $BlockEndFlag} then {
   clipboard clear -displayof %W
   catch {clipboard append -displayof %W [$BlockEditor get BlockBegin BlockEnd]}
  }
 }
 # aus Clipboard kopieren
 bind Text <Control-k><p> {
  set ksp [%W index {insert linestart}]
  undo_switch %W {Save UndoBegin}
  tk_textPaste %W
  undo_switch %W {UndoEnd Save UndoMax}
  Syntax %W $ksp "insert lineend"
 }
 bind Text <Control-k><h> {break}

 bind Text <Insert> {
  undo_switch %W {Save UndoBegin}
  catch {tkTextInsert %W [selection get -displayof %W]}
  undo_switch %W {UndoEnd Save}
 }

 # Block eliminieren
 bind Text <Destroy> {
  set BlockBeginFlag 0
  set BlockEndFlag 0
  if {[lsearch [array names ModifiedArray] %W] != -1} {
   unset ModifiedArray(%W)
  }
  if {[lsearch [array names UndoArray] %W] != -1} {
   unset UndoArray(%W)
  }
  if {[lsearch [array names FilenameArray] %W] != -1} {
   unset FilenameArray(%W)
  }
 }

 # Zeile aus Text loeschen
 bind Text <Control-y> {
  undo_switch %W {{"insert linestart" "insert lineend+1c"} Delete}
 }
 bind Text <Control-d> {
  if $FocusEditorFlag {
   focus $FocusEditor.te.edit1
   set ksp [$FocusEditor.te.edit1 get {insert wordstart-1c} {insert wordstart}]
   if ![string compare "\\" $ksp] then {
    set Text [$FocusEditor.te.edit1 get {insert wordstart} {insert wordend}]
    if {[llength [array names I_befehl $Text]] != 1} {set Text "\\section"} else {set Text "\\$Text"}
   } {set Text "\\section"}
   set ksp [$FocusEditor.te.edit1 search -- $Text {insert wordend} end]
   if {$ksp != ""} then {
    $FocusEditor.te.edit1 mark set insert "$ksp + 1 chars"
    $FocusEditor.te.edit1 see insert
    event generate $FocusEditor.te.edit1 <<Position_tail>> -when tail
 }}}
 bind Text <Control-u> {
  if $FocusEditorFlag {
   focus $FocusEditor.te.edit1
   set ksp [$FocusEditor.te.edit1 get {insert wordstart-1c} {insert wordstart}]
   if ![string compare "\\" $ksp] then {
    set Text [$FocusEditor.te.edit1 get {insert wordstart} {insert wordend}]
    if {[llength [array names I_befehl $Text]] != 1} {set Text "\\section"} else {set Text "\\$Text"}
   } {set Text "\\section"}
   set ksp [$FocusEditor.te.edit1 search -backwards -- $Text {insert wordstart-1c} 1.0]
   if {$ksp != ""} then {
    $FocusEditor.te.edit1 mark set insert "$ksp + 1 chars"
    $FocusEditor.te.edit1 see insert
    event generate $FocusEditor.te.edit1 <<Position_tail>> -when tail
 }}}
 bind Text <Control-b> {
  if $FocusEditorFlag {
   Line_breaking_switch $FocusEditor.te.edit1 section
  }
 }
 bind Text <Control-B> {
  if $FocusEditorFlag {
   Line_breaking_switch $FocusEditor.te.edit1 unsection
  }
 }
 bind Text <Alt-b> {
  if $FocusEditorFlag {
   Line_breaking_switch $FocusEditor.te.edit1 line
  }
 }
 bind Text <Alt-B> {
  if $FocusEditorFlag {
   Line_breaking_switch $FocusEditor.te.edit1 unline
  }
 }

 # Was passiert wenn man ein Fenster vernichtet
 bind Toplevel <Destroy> {
  # Fenster war Master dann Master loeschen
  if $MasterFlag then {if {[string compare $Master %W] == 0} then {set MasterFlag 0}}
  if $FocusEditorFlag then {if {[string compare $FocusEditor %W] == 0} then {set FocusEditorFlag 0}}
 }


bind Text <KeyPress> {
 if $erg_flag(%W) then {
  if {[%W get insert insert+1c] == "%A"} then {
   %W mark set insert insert+1c
   continue
  } else {
   erg_proc %W
  }
 }
 if {"%A" != "{}"} then { 
 undo_switch %W {SelSave UndoBegin}
 tkTextInsert %W %A
 undo_switch %W {UndoEnd SelMul}

  if $BeginFlag(%W) then {
   %W insert BeginMark %A
   undo_switch %W BeginMark
  }
  event generate %W <<ERG>> 
  event generate %W <<Modified>>
  if $KlammerFlag then {
     switch -- "%A" "(" {
      tkTextInsert %W ")"
      undo_switch %W UndoEnd
      tkTextSetCursor %W insert-1c
     } "\{" {
      if {[string compare [%W get insert-2c] "\\"] == 0} {
       tkTextInsert %W "\\\}"
       undo_switch %W UndoEnd
       tkTextSetCursor %W insert-2c
      } {
       tkTextInsert %W "\}"
       undo_switch %W UndoEnd
       tkTextSetCursor %W insert-1c
      }
     } "\[" {
      if {[string compare [%W get insert-2c] "\\"] == 0} {
       tkTextInsert %W "\\\]"
       undo_switch %W UndoEnd
       tkTextSetCursor %W insert-2c
      } {
       tkTextInsert %W "\]"
       undo_switch %W UndoEnd
       tkTextSetCursor %W insert-1c
      }
     } "$" {
      tkTextInsert %W "$"
      undo_switch %W UndoEnd
      tkTextSetCursor %W insert-1c
}}}}