Tcl Library Source Code

View Ticket
Login
Ticket UUID: 1167772
Title: code/block expansion
Type: Patch Version: None
Submitter: georgeps Created on: 2005-03-21 18:22:34
Subsystem: tklib: ctext Assigned To: georgeps
Priority: 5 Medium Severity:
Status: Open Last Modified: 2005-03-21 18:22:34
Resolution: None Closed By:
    Closed on:
Description:
I've sat on this long enough, and I lack the motivation
to work on the ctext 3.x series much anymore.  So,
here's an email with some code that could be merged in
to provide code expansion, or whatever it's called when
you click the + to expand a block.  He also mentions a
bug that should be fixed.

Date: Tue, 12 Oct 2004 12:27:03 +0200
From: Jos Decoster <[email protected]>
To: [email protected]
Subject: ctext and tags
Parts/Attachments:
   1 Shown    84 lines  Text, "message body text"
   2          24 KB     Application
----------------------------------------


Dear mister Staplin,

I'm using your ctext widget in an application. Syntax
highlighting works fine. But when I use tags, the ctext
widget reports errors. 

In my application, I modify the text based on tags I
placed during insert. The ctext widget however removes
tags during insert and delete (all but _cComment).
Consider the example at the end of the mail. It uses
both the text and ctext widget to show the differences.
Double clicking on a line will show or hide a '+' at
the beginning of the line.

After modifying the ctext widget to prepend each tag
added by ctext with __ctext and to only delete __ctext
tag during insert and delete, the example works as
expected.

I attached the modified code in case you would find
this modification usefull.

Kind regards,

Jos.


set t [text .t]
set c [ctext .c -linemap 0]

bind $t <Double-1> [list toggle_prefix $t %x %y]
bind $c <Double-1> [list toggle_prefix $c %x %y]

pack .t .c

proc test_insert { txt ln dta } {
    $txt insert end " >" [list 1.$ln prefix] \
        [format " %5d : " $ln] [list 1.$ln line] \
        $dta [list 1.$ln source] \
        "\n" ""
}

proc toggle_prefix { txt x y } {

    global line_char

    set tl [$txt tag names @$x,$y]
    set line -1
    foreach t $tl {
        puts "t = $t @ $x,$y"
        if { [regexp {^([0-9]+)[.]([0-9]+)$} $t match
p1 p3] } {
            if { $p1 == 1 } {
                set line $p3
                break
            }
        }       
    }

    if { $line < 0 } {
        puts "No line found!"
        return
    }

    set iidx [expr {[$txt index 1.$line.first]}]
    
    puts "iidx = $iidx"

    $txt delete $iidx

    if { [info exists line_char($txt,$line)] && 
         [string equal $line_char($txt,$line) "+"] } {
        $txt insert $iidx " " 1.$line
        set line_char($txt,$line) " "
    } else {
        $txt insert $iidx "+" 1.$line   
        set line_char($txt,$line) "+"
    }
}

set dtal [list qwerty azerty test foo bar brol]
set ln 1

foreach dta $dtal {
    test_insert $t $ln $dta
    test_insert $c $ln $dta
    incr ln
}