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
|
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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
+
+
+
+
|
# Create window
destroy $wt
toplevel $wt -padx 3 -pady 3
ttk::frame $wt._bg
place $wt._bg -x 0 -y 0 -relwidth 1.0 -relheight 1.0 -border outside
wm title $wt "Preferences: Plugins"
set plugins [listPlugins]
if {[llength $plugins] == 0} {
grid [ttk::label $wt.l -text "No plugins found."] - -padx 3 -pady 3
}
if {![info exists ::eskil($top,pluginname)]} {
set ::eskil($top,pluginname) ""
}
if {![info exists ::eskil($top,plugininfo)]} {
set ::eskil($top,plugininfo) ""
}
if {![info exists ::eskil($top,pluginallow)]} {
set ::eskil($top,pluginallow) 0
}
set ::eskil($top,edit,pluginname) $::eskil($top,pluginname)
set ::eskil($top,edit,plugininfo) $::eskil($top,plugininfo)
set ::eskil($top,edit,pluginallow) $::eskil($top,pluginallow)
ttk::labelframe $wt.lfs -text "Select"
grid columnconfigure $wt.lfs 1 -weight 1
set t 0
ttk::notebook $wt.tab
ttk::frame $wt.tab.plus
$wt.tab add $wt.tab.plus -text "+"
set n [llength [array names ::eskil $top,pluginname,*]]
if {$n < 1} { set n 1 }
foreach {plugin info} $plugins {
set descr [dict get $info descr]
if {$dirdiff && ![dict get $info dir]} continue
ttk::radiobutton $wt.rb$t -variable ::eskil($top,edit,pluginname) \
-value $plugin -text $plugin
ttk::label $wt.l$t -text $descr -anchor w
grid $wt.rb$t $wt.l$t -in $wt.lfs -sticky we -padx 3 -pady 3
incr t
for {set t 0} {$t < $n} {incr t} {
EditPrefPluginsAddTab $top $dirdiff
}
ttk::radiobutton $wt.rb$t -variable ::eskil($top,edit,pluginname) \
-value "" -text "No Plugin"
ttk::button $wt.bs -text "Show" \
-command "ShowPlugin $wt \$::eskil($top,edit,pluginname)"
addBalloon $wt.bs "Show plugin source code."
grid $wt.rb$t $wt.bs -in $wt.lfs -sticky we -padx 3 -pady 3
grid $wt.bs -sticky e
$wt.tab select 0
bind $wt.tab <<NotebookTabChanged>> \
ttk::labelframe $wt.lfgc -text "Generic Configuration"
grid columnconfigure $wt.lfgc 1 -weight 1
[list EditPrefPluginsChangeTab $top $dirdiff]
ttk::label $wt.li -text "Info" -anchor w
addBalloon $wt.li "Info passed to plugin. Plugin specific."
ttk::entry $wt.ei -textvariable ::eskil($top,edit,plugininfo)
grid $wt.li $wt.ei -in $wt.lfgc -sticky we -padx 3 -pady 3
bind $wt.tab <ButtonPress-3> \
ttk::checkbutton $wt.cb -text "Privilege" \
-variable ::eskil($top,edit,pluginallow)
addBalloon $wt.cb "Run plugin with raised privileges"
grid $wt.cb - -in $wt.lfgc -sticky w -padx 3 -pady 3
[list EditPrefPluginsRightClick $top $dirdiff %x %y %X %Y]
ttk::labelframe $wt.lfsc -text "Specific Configuration"
set ::widgets($top,prefPluginsSpec) $wt.lfsc
trace add variable ::eskil($top,edit,pluginname) write \
[list UpdateSpecificPluginConf $top]
UpdateSpecificPluginConf $top
ttk::frame $wt.fb -padding 3
ttk::button $wt.fb.b1 -text "Ok" \
-command [list EditPrefPluginsOk $top $wt 0]
ttk::button $wt.fb.b2 -text "Apply" \
-command [list EditPrefPluginsOk $top $wt 1]
ttk::button $wt.fb.b3 -text "Cancel" -command [list destroy $wt]
set ::widgets($top,prefPluginsOk) $wt.fb.b1
grid $wt.fb.b1 x $wt.fb.b2 x $wt.fb.b3 -sticky we
grid columnconfigure $wt.fb {0 2 4} -uniform a
grid columnconfigure $wt.fb {1 3} -weight 1
grid $wt.tab -sticky news -padx 3 -pady 3
grid $wt.fb -sticky we -padx 3 -pady 3
grid columnconfigure $wt 0 -weight 1
grid row $wt 0 -weight 1
}
# Detect a plugin tab change to add tab when "+" is selected.
proc EditPrefPluginsChangeTab {top dirdiff} {
set wt $top.prefplugin.tab
set n [$wt index end]
set t [$wt index [$wt select]]
if {$t + 1 == $n} {
# Plus selected
EditPrefPluginsAddTab $top $dirdiff
$wt select $t
}
}
# Context menu
proc EditPrefPluginsRightClick {top dirdiff x y X Y} {
set wt $top.prefplugin.tab
set elem [$wt identify element $x $y]
set t [$wt identify tab $x $y]
if {$elem eq "" || ![string is integer -strict $t]} return
set m [winfo toplevel $wt].pm
destroy $m
menu $m
set n [$wt index end]
$m add command -label "Add left" \
-command [list EditPrefPluginsAddTab $top $dirdiff $t]
if {$t > 0 && $t < ($n - 1)} {
$m add command -label "Move left" \
-command [list EditPrefPluginsMoveLeft $top $t]
}
tk_popup $m $X $Y
}
# Move a tab to the left
proc EditPrefPluginsMoveLeft {top pos} {
set wt $top.prefplugin.tab
set win [lindex [$wt tabs] $pos]
incr pos -1
$wt insert $pos $win
}
# Add a tab to plugin prefernces
proc EditPrefPluginsAddTab {top dirdiff {pos {}}} {
set wt $top.prefplugin.tab
set n [$wt index end]
if {$pos eq "" || $pos >= ($n - 1)} {
# Since the "+" tab is last, the index is n for any new one
set pos [expr {$n - 1}]
}
ttk::frame $wt.f,$n
$wt insert $pos $wt.f,$n -text "Plugin"
set wt $wt.f,$n
set plugins [listPlugins]
if {[llength $plugins] == 0} {
grid [ttk::label $wt.l -text "No plugins found."] - -padx 3 -pady 3
}
if {![info exists ::eskil($top,pluginname,$n)]} {
set ::eskil($top,pluginname,$n) ""
}
if {![info exists ::eskil($top,plugininfo,$n)]} {
set ::eskil($top,plugininfo,$n) ""
}
if {![info exists ::eskil($top,pluginallow,$n)]} {
set ::eskil($top,pluginallow,$n) 0
}
set ::eskil($top,edit,pluginname,$n) $::eskil($top,pluginname,$n)
set ::eskil($top,edit,plugininfo,$n) $::eskil($top,plugininfo,$n)
set ::eskil($top,edit,pluginallow,$n) $::eskil($top,pluginallow,$n)
ttk::labelframe $wt.lfs -text "Select"
grid columnconfigure $wt.lfs 1 -weight 1
set t 0
foreach {plugin info} $plugins {
set descr [dict get $info descr]
if {$dirdiff && ![dict get $info dir]} continue
ttk::radiobutton $wt.rb$t -variable ::eskil($top,edit,pluginname,$n) \
-value $plugin -text $plugin
ttk::label $wt.l$t -text $descr -anchor w
grid $wt.rb$t $wt.l$t -in $wt.lfs -sticky we -padx 3 -pady 3
incr t
}
ttk::radiobutton $wt.rb$t -variable ::eskil($top,edit,pluginname,$n) \
-value "" -text "No Plugin"
ttk::button $wt.bs -text "Show" \
-command "ShowPlugin $wt \$::eskil($top,edit,pluginname,$n)"
addBalloon $wt.bs "Show plugin source code."
grid $wt.rb$t $wt.bs -in $wt.lfs -sticky we -padx 3 -pady 3
grid $wt.bs -sticky e
ttk::labelframe $wt.lfgc -text "Generic Configuration"
grid columnconfigure $wt.lfgc 1 -weight 1
ttk::label $wt.li -text "Info" -anchor w
addBalloon $wt.li "Info passed to plugin. Plugin specific."
ttk::entry $wt.ei -textvariable ::eskil($top,edit,plugininfo,$n)
grid $wt.li $wt.ei -in $wt.lfgc -sticky we -padx 3 -pady 3
ttk::checkbutton $wt.cb -text "Privilege" \
-variable ::eskil($top,edit,pluginallow,$n)
addBalloon $wt.cb "Run plugin with raised privileges"
grid $wt.cb - -in $wt.lfgc -sticky w -padx 3 -pady 3
ttk::labelframe $wt.lfsc -text "Specific Configuration"
set ::widgets($top,prefPluginsSpec,$n) $wt.lfsc
trace add variable ::eskil($top,edit,pluginname,$n) write \
[list UpdateSpecificPluginConf $top $n]
UpdateSpecificPluginConf $top $n
grid $wt.lfs -sticky we -padx 3 -pady 3
grid $wt.lfgc -sticky we -padx 3 -pady 3
grid $wt.lfsc -sticky we -padx 3 -pady 3
grid $wt.fb -sticky we -padx 3 -pady 3
grid columnconfigure $wt 0 -weight 1
}
# When a new plugin is selected, update the list of specific options.
# "args" is needed to swallow the extra variable trace args.
proc UpdateSpecificPluginConf {top args} {
set w $::widgets($top,prefPluginsSpec)
proc UpdateSpecificPluginConf {top n args} {
set w $::widgets($top,prefPluginsSpec,$n)
# If the dialog is closed w might not exist
if {![winfo exists $w]} return
eval destroy [winfo children $w]
set arg $::eskil($top,edit,pluginname)
set arg $::eskil($top,edit,pluginname,$n)
set pOpts {}
if {$arg ne ""} {
set res [LocatePlugin $arg]
set pOpts [dict get $res opts]
}
# Look for declarations of command line options
set n 0
set ::eskil($top,edit,opts) $pOpts
set t 0
set ::eskil($top,edit,opts,$n) $pOpts
foreach {name flag doc} $pOpts {
ttk::label $w.l$n -text $name
addBalloon $w.l$n $doc
grid $w.l$n -sticky "w" -padx 3 -pady 3
ttk::label $w.l$t -text $name
addBalloon $w.l$t $doc
grid $w.l$t -sticky "w" -padx 3 -pady 3
if {$flag} {
ttk::checkbutton $w.s$n -text "On" \
-variable ::eskil($top,edit,$name)
grid $w.s$n -row $n -column 1 -sticky "w" -padx 3 -pady 3
ttk::checkbutton $w.s$t -text "On" \
-variable ::eskil($top,edit,$name,$n)
grid $w.s$t -row $t -column 1 -sticky "w" -padx 3 -pady 3
} else {
ttk::entry $w.s$n \
-textvariable ::eskil($top,edit,$name)
grid $w.s$n -row $n -column 1 -sticky we -padx 3 -pady 3
ttk::entry $w.s$t \
-textvariable ::eskil($top,edit,$name,$n)
grid $w.s$t -row $t -column 1 -sticky we -padx 3 -pady 3
}
incr n
incr t
}
grid columnconfigure $w 1 -weight 1
if {$n == 0} {
if {$t == 0} {
ttk::label $w.l -text "No specific configuration"
grid $w.l -sticky "w" -padx 3 -pady 3
return
}
}
# Ok or Apply pressend in Plugin Preference
proc EditPrefPluginsOk {top wt apply} {
# Compress plugin info in tab order
set allN {}
foreach win [$wt.tab tabs] {
set n [lindex [split $win ","] end]
if {![string is integer -strict $n]} continue
# Find all used.
if {$::eskil($top,edit,pluginname,$n) ne ""} {
lappend allN $n
}
}
if {[llength $allN] == 0} {
lappend allN 1
}
# Keep the dialog if we are only applying
if {!$apply} {
destroy $wt
}
# Transfer them to consecutive numbers
set t 1
foreach n $allN {
set ::eskil($top,pluginname,$t) $::eskil($top,edit,pluginname,$n)
set ::eskil($top,plugininfo,$t) $::eskil($top,edit,plugininfo,$n)
set ::eskil($top,pluginallow,$t) $::eskil($top,edit,pluginallow,$n)
incr t
}
# Remove any old
foreach item [array names ::eskil $top,pluginname,*] {
set n [lindex [split $item ","] end]
if {$n >= $t} {
set ::eskil($top,pluginname) $::eskil($top,edit,pluginname)
set ::eskil($top,plugininfo) $::eskil($top,edit,plugininfo)
set ::eskil($top,pluginallow) $::eskil($top,edit,pluginallow)
if {$::eskil($top,pluginname) ne ""} {
set pinterp [createPluginInterp $::eskil($top,pluginname) \
$::eskil($top,plugininfo) \
$::eskil($top,pluginallow) pinfo]
unset ::eskil($top,pluginname,$n)
set ::eskil($top,plugininfo,$n) ""
set ::eskil($top,pluginallow,$n) 0
}
}
# TBD PLUGIN: Actually use multiple
if {$::eskil($top,pluginname,1) ne ""} {
set pinterp [createPluginInterp $::eskil($top,pluginname,1) \
$::eskil($top,plugininfo,1) \
$::eskil($top,pluginallow,1) pinfo]
} else {
set pinterp ""
set pinfo ""
}
set ::eskil($top,plugin) $pinterp
set ::eskil($top,pluginpinfo) $pinfo
set ::eskil($top,pluginargv) {}
foreach {name flag doc} $::eskil($top,edit,opts) {
foreach {name flag doc} $::eskil($top,edit,opts,1) {
if {$flag} {
if {[info exists ::eskil($top,edit,$name)] && \
$::eskil($top,edit,$name)} {
if {[info exists ::eskil($top,edit,$name,1)] && \
$::eskil($top,edit,$name,1)} {
lappend ::eskil($top,pluginargv) $name
}
} else {
if {[info exists ::eskil($top,edit,$name)] && \
$::eskil($top,edit,$name) ne ""} {
lappend ::eskil($top,pluginargv) $name $::eskil($top,edit,$name)
if {[info exists ::eskil($top,edit,$name,1)] && \
$::eskil($top,edit,$name,1) ne ""} {
lappend ::eskil($top,pluginargv) $name \
$::eskil($top,edit,$name,1)
}
}
}
}
# Put Tcl code in a text widget, with some syntax highlighting
proc TextViewTcl {t data} {
|