Tk Text Edit

Check-in [fbd262b600]
Login

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

Overview
Comment:Added -buffer param to all load types
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:fbd262b6003b658c6854a22fae105a15dafa91d1
User & Date: dennis 2001-06-11 20:59:46
Context
2002-01-11
21:49
#493414 Changed default font for editor to Courier check-in: acd50af3d5 user: dennis2 tags: trunk
2001-06-11
20:59
Added -buffer param to all load types check-in: fbd262b600 user: dennis tags: trunk
19:33
Add callback function from flist to set path whenever changed check-in: ae02a91c0a user: dennis tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/file.tcl.

383
384
385
386
387
388
389











390
391
392
393
394
395
396
...
398
399
400
401
402
403
404





















405
406
407
408
409
410
411
...
423
424
425
426
427
428
429























430
431
432
433
434
435
436
...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
...
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

proc FILESaveRequest {param} {
return "file {[tk_getSaveFile -title "Save file" -initialfile [lindex $param 1]]}"
}


#=============================== Load Level 1  =================================================












proc DoLoadFile { fi } {
c $fi
if {[lindex $fi 1]!=""} {
if {[file exist [lindex $fi 1]]!=1} { return "error File [lindex $fi 1] does not exist" }
set f [open [lindex $fi 1]  "RDONLY" ]
.text delete 1.0 end
................................................................................
	.text insert end [read $f 10000]
    }
close $f
}
return $fi
}























proc DoLoadFTP { fi } {
global home
c $fi
c [lindex $fi 1]
c [lindex $fi 2]
c [lindex $fi 3]
................................................................................
    }
close $f     
file delete -force "$home/temp~"
} else { return "" }
return $fi
}

























proc DoLoadHTTP { fi } {
c $fi
if {[lindex $fi 1]!=""} {
set filename [lindex $fi 1]
set host [lindex $fi 2]
set port 80
................................................................................
fconfigure $sock -blocking 0
while {![eof $sock]} {
.text insert end [read $sock 100]
}
close $sock
}
return $fi
	}

#=============================== Save Level 1  =================================================
proc DoSaveFile { fi } {
if {[lindex $fi 1]!=""} {
c $fi
 set f [open [lindex $fi 1] w]
 puts $f [.text get 0.1 "end-1 char"] nonewline
................................................................................
proc Load {info args} {
global current_window window c

c "Trying to load: $info"

set inf $info

if {$args!="-force"} {






c "Not forced"
switch [lindex $info 0] {
file {set inf [FILELoadRequest $info] }
ftp  {set inf [FTPLoadRequest $info] }
http {set inf [HTTPLoadRequest $info] }
}
}

win::activate [GetNextFree]

switch [lindex $inf 0] {
file {
     if { [llength $inf]<2 } {set inf [FILELoadRequest $inf] }

     set inf [DoLoadFile $inf]
     Supertext::reset $current_window 



     }

ftp  {
     if { [llength $inf]<5 } {set inf [FTPLoadRequest $inf] }

     set inf [DoLoadFTP  $inf] 
     Supertext::reset $current_window



     }

http {
     if { [llength $inf]<2 } {set inf [HTTPLoadRequest $inf] }

     set inf [DoLoadHTTP $inf]
     Supertext::reset $current_window 



     }
}


if {[lindex $inf 1]==""} {
        c "Load was canceled!"
        global current_window
        CloseFile $current_window
         win::Prev
        return ""
       }


if {[lindex $inf 0]=="error"} { bgerror [lrange $inf 1 end]
                                return ""
                               }  


        set window($current_window,name) [lindex $inf 1]
	set window($current_window,change) 0	
	set window($current_window,echange) 1
	set window($current_window,info) $inf
	addrecent $window($current_window,info)
	win::update

................................................................................

macro::rec "file::Load" $inf -force

c "Action taken: $inf"
tkTextSetCursor .text 1.0
focus .text
if {$c(flist)==1} {flist::showdir .flist *}

}

#=============================== Save Level 2  =================================================
# With the -force argument the Load procedure tries to load the file without prompting the user,
# however if there are any missing arguments in the info argument the user will be prompted.
#








>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|
>
>
>
>
>
>






|

|




>
|
|
>
>
>




>
|
|
>
>
>




>
|
|
>
>
>



>







|





|







 







>







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
...
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
...
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
...
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
...
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
...
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632

proc FILESaveRequest {param} {
return "file {[tk_getSaveFile -title "Save file" -initialfile [lindex $param 1]]}"
}


#=============================== Load Level 1  =================================================

proc DoLoadFileBuff { fi buff } {
global $buff
if {[lindex $fi 1]!=""} {
if {[file exist [lindex $fi 1]]!=1} { return "error File [lindex $fi 1] does not exist" }
set f [open [lindex $fi 1]  "RDONLY" ]
set $buff [read $f [file size [lindex $fi 1]]]
close $f
}
return $fi
}

proc DoLoadFile { fi } {
c $fi
if {[lindex $fi 1]!=""} {
if {[file exist [lindex $fi 1]]!=1} { return "error File [lindex $fi 1] does not exist" }
set f [open [lindex $fi 1]  "RDONLY" ]
.text delete 1.0 end
................................................................................
	.text insert end [read $f 10000]
    }
close $f
}
return $fi
}

proc DoLoadFTPBuff { fi buff} {
global home $buff
c $fi
c [lindex $fi 1]
c [lindex $fi 2]
c [lindex $fi 3]
c [lindex $fi 4]

if {[lindex $fi 1]!=""} {
if {[FTP::Open [lindex $fi 2] [lindex $fi 3] [lindex $fi 4] ]!=1} { return "error Unable to connect to ftp host" }
if {[FTP::Get [lindex $fi 1] "$home/temp~" ]!=1} { return "error File not found" }
FTP::Close

set f [open "$home/temp~" "RDONLY" ]
set $buff [read $f [file size "$home/temp~" ]]
close $f     
file delete -force "$home/temp~"

} else { return "" }
return $fi
}

proc DoLoadFTP { fi } {
global home
c $fi
c [lindex $fi 1]
c [lindex $fi 2]
c [lindex $fi 3]
................................................................................
    }
close $f     
file delete -force "$home/temp~"
} else { return "" }
return $fi
}

proc DoLoadHTTPBuff { fi buff} {
global $buff
c $fi
if {[lindex $fi 1]!=""} {
set filename [lindex $fi 1]
set host [lindex $fi 2]
set port 80

set sock [socket $host $port]
puts $sock "GET $filename\n"
c "GET $filename\n"
flush $sock
fconfigure $sock -blocking 0
set tmp ""
while {![eof $sock]} {
	set tmp "$tmp[read $sock 100]"
}
set $buff $tmp
set tmp ""
close $sock
}
return $fi
}

proc DoLoadHTTP { fi } {
c $fi
if {[lindex $fi 1]!=""} {
set filename [lindex $fi 1]
set host [lindex $fi 2]
set port 80
................................................................................
fconfigure $sock -blocking 0
while {![eof $sock]} {
.text insert end [read $sock 100]
}
close $sock
}
return $fi
}

#=============================== Save Level 1  =================================================
proc DoSaveFile { fi } {
if {[lindex $fi 1]!=""} {
c $fi
 set f [open [lindex $fi 1] w]
 puts $f [.text get 0.1 "end-1 char"] nonewline
................................................................................
proc Load {info args} {
global current_window window c

c "Trying to load: $info"

set inf $info

set n [lsearch $args "-buffer"]
if {$n!=-1} {
set buff [lindex $args [expr $n+1]]
c "Load to buffer <$buff>"
} else { set buff "" }

if {[lsearch $args "-force"]==-1} {
c "Not forced"
switch [lindex $info 0] {
file {set inf [FILELoadRequest $info] }
ftp  {set inf [FTPLoadRequest $info] }
http {set inf [HTTPLoadRequest $info] }
}
} else { c "Forced" }

if {$buff==""} { win::activate [GetNextFree] }

switch [lindex $inf 0] {
file {
     if { [llength $inf]<2 } {set inf [FILELoadRequest $inf] }
     if {$buff==""} { 
     	set inf [DoLoadFile $inf]
        Supertext::reset $current_window 
     } else {
     	set inf [DoLoadFileBuff $inf $buff] 
     }
     }

ftp  {
     if { [llength $inf]<5 } {set inf [FTPLoadRequest $inf] }
     if {$buff==""} { 
        set inf [DoLoadFTP $inf] 
        Supertext::reset $current_window 
     } else {
     	set inf [DoLoadFTPBuff $inf $buff] 
     }
     }

http {
     if { [llength $inf]<2 } {set inf [HTTPLoadRequest $inf] }
     if {$buff==""} { 
        set inf [DoLoadHTTP $inf] 
        Supertext::reset $current_window 
     } else {
     	set inf [DoLoadHTTPBuff $inf $buff] 
     }
     }
}

if {$buff==""} {
if {[lindex $inf 1]==""} {
        c "Load was canceled!"
        global current_window
        CloseFile $current_window
         win::Prev
        return ""
       }
}

if {[lindex $inf 0]=="error"} { bgerror [lrange $inf 1 end]
                                return ""
                               }  

if {$buff==""} {
        set window($current_window,name) [lindex $inf 1]
	set window($current_window,change) 0	
	set window($current_window,echange) 1
	set window($current_window,info) $inf
	addrecent $window($current_window,info)
	win::update

................................................................................

macro::rec "file::Load" $inf -force

c "Action taken: $inf"
tkTextSetCursor .text 1.0
focus .text
if {$c(flist)==1} {flist::showdir .flist *}
}
}

#=============================== Save Level 2  =================================================
# With the -force argument the Load procedure tries to load the file without prompting the user,
# however if there are any missing arguments in the info argument the user will be prompted.
#