Tk Text Edit

Check-in [fbb8fbef44]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Code cleanup
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:fbb8fbef445ce25ad53ef931103e2a6211932f78
User & Date: dennis2 2002-06-15 19:42:37
Context
2002-06-15
19:47
Cleanup check-in: 13a5f0c2ec user: dennis2 tags: trunk
19:42
Code cleanup check-in: fbb8fbef44 user: dennis2 tags: trunk
2002-01-11
21:49
#493414 Changed default font for editor to Courier check-in: acd50af3d5 user: dennis2 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/macro.tcl.

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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436


437
438
439

440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#? Related topics: %lMACROS% %lMACRO_MANAGER%

namespace eval macro {

namespace export rec play new buttonconf update names files manager realnames

proc realnames {} {
global home installdir
set k [glob -nocomplain "$home/*.mac"]
set n $k
set k [glob -nocomplain "$installdir/*.mac"]
set n "$n $k"
return $n
}

proc names {} {
set n ""
foreach k [macro::realnames] {
set n "$n {[file rootname [file tail $k]]}" 
}
return $n
}

proc update {} {
global c home

.menu.macromenu delete 0 end
.menu.macromenu add command -label "Record macro" -underline 0 -accelerator "($c(key-newmacro))" -command macro::new
.menu.macromenu add command -label "Macro manager" -underline 7 -accelerator "($c(key-macromgr))" -command macro::manager
.menu.macromenu add separator

set k [macro::names]

foreach n $k {
.menu.macromenu add command -label $n -command "macro::play {$n}"
}

}

proc stop {} {
global macro_rec
set macro_rec 0
 .menu.macromenu entryconfigure [.menu.macromenu index "Stop recording"] -label "Record macro"
 .status.filler config -text ""
}

proc new {} {
global macro_data macro_rec cu_macro

if {!$macro_rec} {
 .menu.macromenu entryconfigure [.menu.macromenu index "Record macro"] -label "Stop recording"
 set macro_data ""
 set macro_rec 1
 .status.filler config -text "Recording.. (press F5 to stop)"
} else {
 

   switch [ macro::store] {

   ok       {macro::stop
             macro::msave
            }

   abort    {macro::stop}

   continue {}
   }
 
}
}


proc key {data} {
global current_window window

 set window($current_window,echange) 1
 set window($current_window,change) 1
 win::update

 switch $data  {
 Return	{.text insert insert "\n"}
 Alt_L 	{}
 Alt_R 	{}
 Shift_L    {}
 Shift_R   {}
 Alt_L       {}
 Control_L {}
 Control_R {}
 Caps_Lock {}
 Home      {tkTextSetCursor .text {insert linestart} }
 End       {tkTextSetCursor .text {insert lineend} }
 Mode_switch {}
 Delete    { txt::cut .text }
 BackSpace { txt::backspace .text }
 space     {.text insert insert " "}
 Right     { tkTextSetCursor .text  "insert + 1 chars"}
 Left      { tkTextSetCursor .text  "insert - 1 chars"}
 Up        { tkTextSetCursor .text  "insert - 1 lines"}
 Down      { tkTextSetCursor .text  "insert + 1 lines"}

 default   {   .text insert insert $data }
  }

.text see insert   

}

proc rec { cmd args } {
global macro_data macro_rec

if {$macro_rec} {

if {$args=="\r"} {set args "Return"}
if {$args=="\n"} {set args "Return"}
if {$args=="\b"} {set args "BackSpace"}
if {$args=="\x7f"} {set args "Delete"}

set macro_data "$macro_data$cmd $args\n"
c $cmd $args
}

}


proc msave {} {
global env macro_data home current_macro prgname
set n $current_macro
file delete -force "$home/$n.mac"
set f [open "$home/$n.mac" "CREAT WRONLY" ]

puts $f "###################################################"
puts $f "# Macro recorded by $prgname"
puts $f "###################################################\n"

puts $f $macro_data nonewline
close $f
macro::update
speed::Update
}

proc play {n} {
global c window current_window

set last_macro $n
macro::rec macro::play $n

c $n

set file [macro::get_path $n]
if {[macro::get_type $n]=="sh"} {
	c "Macro type SH"
	exec "chmod" "774" "$file"
	if {$c(textshell)} { 
	
		set p1 $window($current_window,name)
		set l  [file split $p1]
		set p2 [lindex $l [expr [llength $l] -1]]
		set p3 [file dirname $p1]
		set p4 [file rootname $p2]
		textsh::runcmd $file "$p1 $p2 $p3 $p4"


		 
		} else { exec "$file" }
	} else {
	c "Macro type TCL $file"
	source $file
	}
}

proc get_path {n} {
global home installdir
c $n
if {[file exists "$home/$n.mac"]==1} { 
	return "$home/$n.mac"
	} else {
		if {[file exists "$installdir/$n.mac"]==1} {
			return "$installdir/$n.mac"
			}
	}
return ""
}

proc get_type {n} {
set file [macro::get_path $n]
if {$file!=""} {
	set f [open $file r]
	fconfigure $f -blocking 0
	set s [gets $f]
	close $f

	if {[string first "#!/bin/sh" $s]!=-1} { return "sh" } else { return "tktcl" }
	}
return ""
}

proc store {} {
global url current_window window c current_macro r c
set current_macro ""
set ou .ou
catch {destroy $ou}
toplevel $ou
wm title $ou "Save macro as:"
frame $ou.fr1
frame $ou.fr2
pack $ou.fr1 $ou.fr2 -side left
label $ou.fr1.lab -text "Name:"
xentry $ou.fr1.ent -textvariable current_macro
pack $ou.fr1.lab $ou.fr1.ent -side left -pady 10 -padx 10
$ou.fr1.ent selection range 0 end
xbutton $ou.fr2.ok -text "Ok" -width 10 -command "set r ok"
xbutton $ou.fr2.can -text "Abort" -width 10 -command "set r abort"
xbutton $ou.fr2.con -text "Continue.." -width 10 -command "set r continue"

pack $ou.fr2.ok $ou.fr2.con $ou.fr2.can -side top -padx 10 -pady 5
focus $ou.fr1.ent
bind $ou.fr1.ent <Return> "set r ok"
bind $ou.fr1.ent <KP_Enter> "set r ok"
bind $ou.fr1.ent <Escape> "set r continue"
grab $ou
powin $ou

vwait r
destroy $ou
return $r
}                                          

proc edit {n} {
c
macro::rec macro::edit $n
set file [macro::get_path $n]
file::Load "file {$file}" -force
}

proc delete {n} {
macro::rec macro::delete $n
c

set file [macro::get_path $n]
if {$file!=""} {file delete -force "$file"}

macro::update
speed::Update
macro::manager_update
}

proc rename {old new} {
macro::rec macro::rename $old $new
c
set o "[macro::get_path $old]"
set n  "[file join [file dirname $o] $new].mac"
c $o to $n

file rename $o $n

macro::update
speed::Update
macro::manager_update
}



proc create {} {
global home
set info [get_macrotype]

set typ [lindex $info 0]
set name [lindex $info 1]


if {$typ!="cancel"} {
set f [open "$home/$name.mac" "CREAT WRONLY" ]

if {$typ=="sh"} { 
puts $f "#!/bin/sh"
puts $f "#Shell script macro file\n\n"
} else {
puts $f "#TK/Tcl script macro file\n\n"
}

close $f
macro::update
speed::Update
macro::manager_update
file::Load "file {$home/$name.mac}" -force
}

}


#Get macro type dialog
proc get_macrotype {} {
global c
set w .mseltype
catch {destroy $w}
toplevel $w
wm title $w "Select macro type"
global typ r
set typ "tktcl"

radiobutton $w.b1 -text "Tk/Tcl Macro file" -variable typ -value "tktcl"
radiobutton $w.b2 -text "Shell script" -variable typ -value "sh"
xbutton $w.ok -text "Ok" -width 6 -command "set r ok"
xbutton $w.cancel -width 6 -text "Cancel" -command "set r cancel"
label $w.l -text "Macro name:"
entry $w.e -width 30 -background $c(color-editbg) 

grid $w.l -column 0 -row 0 -sticky w
grid $w.e -column 1 -row 0 -sticky w -columnspan 2
grid $w.b1 -column 0 -row 1 -sticky w -columnspan 2
grid $w.b2 -column 2 -row 1 -sticky w
grid $w.ok -column 2 -row 2 -sticky e
grid $w.cancel -column 0 -row 2 -sticky w

powin $w
focus $w.e
vwait r
set typ "$typ {[$w.e get]}"
destroy $w
if {$r=="ok"} { return $typ } else { return $r}



}


proc manager_update {} {
c
if {[winfo exists .mgui.l]} {
	set w .mgui.l
	$w delete 0 end
	foreach n [macro::names] {
		$w insert end "{$n} {[macro::get_type $n]}"
		}
}
}

proc Rename_DLG {s} {
global r  
set ou .ou
catch {destroy $ou}
toplevel $ou
wm title $ou "Rename macro"
set r "cancel"
frame $ou.f
label $ou.f.label -text "Rename $s to:"
xbutton $ou.f.rename -text "Rename" -command "set r rename" -width 5   
xbutton $ou.f.cancel -text "Cancel" -command "set r cancel" -width 5
xentry $ou.f.e
pack $ou.f.label
pack $ou.f.e
pack $ou.f.rename $ou.f.cancel -side left  -padx 10
bind $ou <Escape> "set r cancel"
bind $ou <Return> "set r rename"
pack $ou.f -side left
$ou.f.e insert end $s
powin $ou
focus $ou.f.e
$ou.f.e selection range 0 end
vwait r
set r "$r {[$ou.f.e get]}"
destroy $ou
return $r
}


proc manager {} {
global c
c "Macro manager"
set w .mgui
catch {destroy $w}
toplevel $w
wm title $w "Macro manager"

scrollbar $w.scroll -command "$w.l yview"
mclistbox::mclistbox $w.l -yscrollcommand "$w.scroll set" -width 47  -background $c(color-listbg) -labelbg $c(color-background)
 
frame $w.b
xbutton $w.b.new -text "New"    -width 6 -command "macro::create"
xbutton $w.b.del -text "Delete" -width 6 -command {
set sel [.mgui.l curselection]


if {$sel!=""} { macro::delete "[lindex [macro::names] $sel]" }
}


xbutton $w.b.ren -text "Rename" -width 6 -command {
set sel [.mgui.l curselection]
if {$sel!=""} { 
	set oname "[lindex [macro::names] $sel]"
	set r [macro::Rename_DLG $oname]
	
	if {[lindex $r 0]=="rename"} {
	set nname "[lindex $r 1]"
	macro::rename $oname $nname
	}

	}
}


xbutton $w.b.ed  -text "Edit"   -width 6 -command {
set sel [.mgui.l curselection]

if {$sel!=""} { macro::edit "[lindex [macro::names] $sel]" }

}
 
xbutton $w.ok  -text "Ok"     -width 6 -command "destroy $w"

grid $w.l -column 0 -row 0 -rowspan 10 -sticky nsew
grid $w.scroll -column 1 -row 0 -rowspan 10 -sticky ns
grid $w.b.new -column 0 -row 0 
grid $w.b.del -column 0 -row 1  
grid $w.b.ren -column 0 -row 2  
grid $w.b.ed  -column 0 -row 3                              
grid $w.b -column 2 -row 0 -sticky n
grid $w.ok  -column 2 -row 9 -sticky s
grid columnconfigure $w 0 -weight 1
grid rowconfigure $w 0 -weight 1

$w.l column add macro -label "Macro" -width 40 
$w.l column add type  -label "Type" -width 7

manager_update

bind $w.l <Double-Button-1> {
macro::edit "[lindex [macro::names] [.mgui.l curselection]]"
}

powin $w
}







}







|
|
|
|
|
|



|
|
|
|
|



|

|
|
|
|

|

|
|
|
<



|
|
|
|



|

|
|
|
|
|
|

<
|
>
|
|
|
>
|
>
|
|
|

|

<

|

|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
<

|

|
<
|
|
|
|

|
|
|
|
|
<
<

|
|
|
|

|
|
|

|
|
|
|



|

|
|

|

|
|
|
|
|
<
|
|
|
|
|
|
>
>
|
<

|
|




|
|
|
|



|

|



|
|
|
|
|
|

|

|



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|

|
|
|



|
|
|
|



|
|

|
|

|
|
|



|
|
|
|
|

|

|
|
|


<
<

|
|

|
|


|
|

|
|
|
|
|
|
>
|
|
|
|
|
|






|
|
|
|
|
|
|

|
|
|
|
|
|

|
|
|
|
|
|

|
|
|
|
|
|
>
>
>
|
|


|
|
|
|
|
|
|
|



|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|


<

|
|
|
|
|
|

|
|

|
|
|
|
>
>
|
|
|
>
|
|
|
|
|

|
|
|
|
|

|
<
<
|
|
>
|
|
|

|

|
|
|
|
|
|
|
|
|
|

|
|

|

|
|
|

|


|
<
<
<
<
<
<
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452


453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485






#? Related topics: %lMACROS% %lMACRO_MANAGER%

namespace eval macro {

namespace export rec play new buttonconf update names files manager realnames

proc realnames {} {
	global home installdir
	set k [glob -nocomplain "$home/*.mac"]
	set n $k
	set k [glob -nocomplain "$installdir/*.mac"]
	set n "$n $k"
	return $n
}

proc names {} {
	set n ""
	foreach k [macro::realnames] {
		set n "$n {[file rootname [file tail $k]]}" 
	}
	return $n
}

proc update {} {
	global c home

	.menu.macromenu delete 0 end
	.menu.macromenu add command -label "Record macro" -underline 0 -accelerator "($c(key-newmacro))" -command macro::new
	.menu.macromenu add command -label "Macro manager" -underline 7 -accelerator "($c(key-macromgr))" -command macro::manager
	.menu.macromenu add separator

	set k [macro::names]

	foreach n $k {
		.menu.macromenu add command -label $n -command "macro::play {$n}"
	}

}

proc stop {} {
	global macro_rec
	set macro_rec 0
	.menu.macromenu entryconfigure [.menu.macromenu index "Stop recording"] -label "Record macro"
 	.status.filler config -text ""
}

proc new {} {
	global macro_data macro_rec cu_macro

	if {!$macro_rec} {
		.menu.macromenu entryconfigure [.menu.macromenu index "Record macro"] -label "Stop recording"
		set macro_data ""
		set macro_rec 1
		.status.filler config -text "Recording.. (press F5 to stop)"
	} else {
 

	switch [ macro::store] {
		ok	{
			macro::stop
			macro::msave
 			}
		abort	{
			macro::stop
			}
			continue {}
			}
	}
}



proc key {data} {
	global current_window window

	set window($current_window,echange) 1
	set window($current_window,change) 1
	win::update

	switch $data  {
		Return	{.text insert insert "\n"}
		Alt_L 	{}
		Alt_R 	{}
		Shift_L    {}
		Shift_R   {}
		Alt_L       {}
		Control_L {}
		Control_R {}
		Caps_Lock {}
		Home      {tkTextSetCursor .text {insert linestart} }
		End       {tkTextSetCursor .text {insert lineend} }
		Mode_switch {}
		Delete    { txt::cut .text }
		BackSpace { txt::backspace .text }
		space     {.text insert insert " "}
		Right     { tkTextSetCursor .text  "insert + 1 chars"}
		Left      { tkTextSetCursor .text  "insert - 1 chars"}
		Up        { tkTextSetCursor .text  "insert - 1 lines"}
		Down      { tkTextSetCursor .text  "insert + 1 lines"}

		default   {   .text insert insert $data }
	}
	
	.text see insert   
}


proc rec { cmd args } {
	global macro_data macro_rec

	if {$macro_rec} {

		if {$args=="\r"} {set args "Return"}
		if {$args=="\n"} {set args "Return"}
		if {$args=="\b"} {set args "BackSpace"}
		if {$args=="\x7f"} {set args "Delete"}

		set macro_data "$macro_data$cmd $args\n"
		c $cmd $args
	}
}



proc msave {} {
	global env macro_data home current_macro prgname
	set n $current_macro
	file delete -force "$home/$n.mac"
	set f [open "$home/$n.mac" "CREAT WRONLY" ]

	puts $f "###################################################"
	puts $f "# Macro recorded by $prgname"
	puts $f "###################################################\n"

	puts $f $macro_data nonewline
	close $f
	macro::update
	speed::Update
}

proc play {n} {
	global c window current_window

	set last_macro $n
	macro::rec macro::play $n

	c $n

	set file [macro::get_path $n]
	if {[macro::get_type $n]=="sh"} {
		c "Macro type SH"
		exec "chmod" "774" "$file"
		if {$c(textshell)} { 

			set p1 $window($current_window,name)
			set l  [file split $p1]
			set p2 [lindex $l [expr [llength $l] -1]]
			set p3 [file dirname $p1]
			set p4 [file rootname $p2]
			textsh::runcmd $file "$p1 $p2 $p3 $p4"
		} else { 
			exec "$file"
		}

	} else {
		c "Macro type TCL $file"
		source $file
	}
}

proc get_path {n} {
	global home installdir
	c $n
	if {[file exists "$home/$n.mac"]==1} { 
		return "$home/$n.mac"
	} else {
		if {[file exists "$installdir/$n.mac"]==1} {
			return "$installdir/$n.mac"
		}
	}
	return ""
}

proc get_type {n} {
	set file [macro::get_path $n]
	if {$file!=""} {
		set f [open $file r]
		fconfigure $f -blocking 0
		set s [gets $f]
		close $f

		if {[string first "#!/bin/sh" $s]!=-1} { return "sh" } else { return "tktcl" }
	}
	return ""
}

proc store {} {
	global url current_window window c current_macro r c
	set current_macro ""
	set ou .ou
	catch {destroy $ou}
	toplevel $ou
	wm title $ou "Save macro as:"
	frame $ou.fr1
	frame $ou.fr2
	pack $ou.fr1 $ou.fr2 -side left
	label $ou.fr1.lab -text "Name:"
	xentry $ou.fr1.ent -textvariable current_macro
	pack $ou.fr1.lab $ou.fr1.ent -side left -pady 10 -padx 10
	$ou.fr1.ent selection range 0 end
	xbutton $ou.fr2.ok -text "Ok" -width 10 -command "set r ok"
	xbutton $ou.fr2.can -text "Abort" -width 10 -command "set r abort"
	xbutton $ou.fr2.con -text "Continue.." -width 10 -command "set r continue"

	pack $ou.fr2.ok $ou.fr2.con $ou.fr2.can -side top -padx 10 -pady 5
	focus $ou.fr1.ent
	bind $ou.fr1.ent <Return> "set r ok"
	bind $ou.fr1.ent <KP_Enter> "set r ok"
	bind $ou.fr1.ent <Escape> "set r continue"
	grab $ou
	powin $ou

	vwait r
	destroy $ou
	return $r
}                                          

proc edit {n} {
	c
	macro::rec macro::edit $n
	set file [macro::get_path $n]
	file::Load "file {$file}" -force
}

proc delete {n} {
	macro::rec macro::delete $n
	c

	set file [macro::get_path $n]
	if {$file!=""} {file delete -force "$file"}

	macro::update
	speed::Update
	macro::manager_update
}

proc rename {old new} {
	macro::rec macro::rename $old $new
	c
	set o "[macro::get_path $old]"
	set n  "[file join [file dirname $o] $new].mac"
	c $o to $n

	file rename $o $n

	macro::update
	speed::Update
	macro::manager_update
}



proc create {} {
	global home
	set info [get_macrotype]

	set typ [lindex $info 0]
	set name [lindex $info 1]


	if {$typ!="cancel"} {
		set f [open "$home/$name.mac" "CREAT WRONLY" ]

		if {$typ=="sh"} { 
			puts $f "#!/bin/sh"
			puts $f "#Shell script macro file\n\n"
		} else {
			puts $f "#TK/Tcl script macro file\n\n"
		}

	close $f
	macro::update
	speed::Update
	macro::manager_update
	file::Load "file {$home/$name.mac}" -force
	}

}


#Get macro type dialog
proc get_macrotype {} {
	global c
	set w .mseltype
	catch {destroy $w}
	toplevel $w
	wm title $w "Select macro type"
	global typ r
	set typ "tktcl"

	radiobutton $w.b1 -text "Tk/Tcl Macro file" -variable typ -value "tktcl"
	radiobutton $w.b2 -text "Shell script" -variable typ -value "sh"
	xbutton $w.ok -text "Ok" -width 6 -command "set r ok"
	xbutton $w.cancel -width 6 -text "Cancel" -command "set r cancel"
	label $w.l -text "Macro name:"
	entry $w.e -width 30 -background $c(color-editbg) 

	grid $w.l -column 0 -row 0 -sticky w
	grid $w.e -column 1 -row 0 -sticky w -columnspan 2
	grid $w.b1 -column 0 -row 1 -sticky w -columnspan 2
	grid $w.b2 -column 2 -row 1 -sticky w
	grid $w.ok -column 2 -row 2 -sticky e
	grid $w.cancel -column 0 -row 2 -sticky w

	powin $w
	focus $w.e
	vwait r
	set typ "$typ {[$w.e get]}"
	destroy $w
	if {$r=="ok"} { 
		return $typ
	} else {
		return $r
	}
}

proc manager_update {} {
	c
	if {[winfo exists .mgui.l]} {
		set w .mgui.l
		$w delete 0 end
		foreach n [macro::names] {
			$w insert end "{$n} {[macro::get_type $n]}"
			}
	}
}

proc Rename_DLG {s} {
	global r  
	set ou .ou
	catch {destroy $ou}
	toplevel $ou
	wm title $ou "Rename macro"
	set r "cancel"
	frame $ou.f
	label $ou.f.label -text "Rename $s to:"
	xbutton $ou.f.rename -text "Rename" -command "set r rename" -width 5   
	xbutton $ou.f.cancel -text "Cancel" -command "set r cancel" -width 5
	xentry $ou.f.e
	pack $ou.f.label
	pack $ou.f.e
	pack $ou.f.rename $ou.f.cancel -side left  -padx 10
	bind $ou <Escape> "set r cancel"
	bind $ou <Return> "set r rename"
	pack $ou.f -side left
	$ou.f.e insert end $s
	powin $ou
	focus $ou.f.e
	$ou.f.e selection range 0 end
	vwait r
	set r "$r {[$ou.f.e get]}"
	destroy $ou
	return $r
}


proc manager {} {
	global c
	c "Macro manager"
	set w .mgui
	catch {destroy $w}
	toplevel $w
	wm title $w "Macro manager"

	scrollbar $w.scroll -command "$w.l yview"
	mclistbox::mclistbox $w.l -yscrollcommand "$w.scroll set" -width 47  -background $c(color-listbg) -labelbg $c(color-background)
 
	frame $w.b
	xbutton $w.b.new -text "New"    -width 6 -command "macro::create"
	xbutton $w.b.del -text "Delete" -width 6 -command {
	set sel [.mgui.l curselection]

	if {$sel!=""} { 
		macro::delete "[lindex [macro::names] $sel]"
	}
	}

	xbutton $w.b.ren -text "Rename" -width 6 -command {
	set sel [.mgui.l curselection]
	if {$sel!=""} { 
		set oname "[lindex [macro::names] $sel]"
		set r [macro::Rename_DLG $oname]
	
		if {[lindex $r 0]=="rename"} {
			set nname "[lindex $r 1]"
			macro::rename $oname $nname
		}
	}
	}



	xbutton $w.b.ed  -text "Edit"   -width 6 -command {
	set sel [.mgui.l curselection]
	if {$sel!=""} { 
		macro::edit "[lindex [macro::names] $sel]"
	}
	}
 
	xbutton $w.ok  -text "Ok" -width 6 -command "destroy $w"

	grid $w.l -column 0 -row 0 -rowspan 10 -sticky nsew
	grid $w.scroll -column 1 -row 0 -rowspan 10 -sticky ns
	grid $w.b.new -column 0 -row 0 
	grid $w.b.del -column 0 -row 1  
	grid $w.b.ren -column 0 -row 2  
	grid $w.b.ed  -column 0 -row 3                              
	grid $w.b -column 2 -row 0 -sticky n
	grid $w.ok  -column 2 -row 9 -sticky s
	grid columnconfigure $w 0 -weight 1
	grid rowconfigure $w 0 -weight 1

	$w.l column add macro -label "Macro" -width 40 
	$w.l column add type  -label "Type" -width 7

	manager_update

	bind $w.l <Double-Button-1> {
		macro::edit "[lindex [macro::names] [.mgui.l curselection]]"
	}

	powin $w
}

}