Changeset 650 for trunk


Ignore:
Timestamp:
Dec 4, 2009 5:09:43 PM (14 years ago)
Author:
toby
Message:

# on 2002/09/05 21:03:37, toby did:
Major revision.

Implement undo
get rid of "Save Changes"
change use of icons
don't show tables with more than 100 loop values (by "column")

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/browsecif.tcl

    • Property rcs:date changed from 2002/09/05 18:24:04 to 2002/09/05 21:03:37
    • Property rcs:lines changed from +151 -41 to +313 -122
    • Property rcs:rev changed from 1.2 to 1.3
    r646 r650  
    1 #!/usr/bin/wish
    21# $Id$
    32
     
    433432
    434433
     434    set CIF(undolist) {}
     435    set CIF(redolist) {}
    435436    set pos 1.0
    436437    set blocks 0
     
    712713    eval $CIF(tree) delete [$CIF(tree) nodes root]
    713714    catch {unset CIFtreeindex}
    714     pack forget $CIF(EditSaveButton) $CIF(AddtoLoopButton) \
     715    pack forget $CIF(AddtoLoopButton) \
    715716            $CIF(LoopSpinBox) $CIF(DeleteLoopEntry)
    716717    # delete old contents of frame
    717718    set frame [$CIF(displayFrame) getframe]
    718719    eval destroy [grid slaves $frame]
     720    set CIF(widgetlist) {}
    719721    # reset the scrollbars
    720722    $CIF(tree) see 0
     
    735737        if {[lsearch $selected $n] != -1} {set open 1}
    736738        $CIF(tree) insert end root block$n -text "_data_$blockname" \
    737                 -open $open -image [Bitmap::get copy]
     739                -open $open -image [Bitmap::get folder]
    738740
    739741        # show errors, if any
     
    747749            if {[lsearch $looplist $name] == -1} {
    748750                $CIF(tree) insert end block$n [incr num] -text $name \
    749                         -image [Bitmap::get folder] -data block$n
     751                        -image [Bitmap::get file] -data block$n
    750752                set CIFtreeindex(block${n}$name) $num
    751753            }
     
    767769            $CIF(tree) insert end block$n block${n}$loop \
    768770                    -text "$loop ($catlist)" \
    769                     -image [Bitmap::get file] -data "block$n loop"
     771                    -image [Bitmap::get copy] -data "block$n loop"
    770772            set CIFtreeindex(block${n}$loop) block${n}$loop
    771773            foreach name [lsort [set block${n}($loop)]] {
    772774                $CIF(tree) insert end block${n}$loop [incr num] -text $name \
    773                         -image [Bitmap::get folder] -data "block$n $loop"
     775                        -image [Bitmap::get file] -data "block$n $loop"
    774776                set CIFtreeindex(block${n}$name) $num
    775777            }
     
    826828
    827829    pack [frame $pane.f] -fill x
    828     set CIF(EditSaveButton) [button $pane.f.b -text "Save Changes" -state disabled \
    829             -command "SaveCIFedits"]
    830830    set CIF(AddtoLoopButton) [button $pane.f.l -text "Add to loop"]
    831831    set CIF(DeleteLoopEntry) [button $pane.f.d -text "Delete loop entry" \
     
    840840# Warn to save changes that are not saved in a file
    841841proc CheckForCIFEdits {} {
     842    #puts "CheckForCIFEdits [info level [expr [info level]-1]]"
    842843    global CIF
    843     if {$CIF(entry_changed) != ""} {
    844         set ans [MyMessageBox -parent . -title "Discard Changes?" \
    845                 -message "You have changed this entry. Do you want to keep or discard this edit?" \
    846                 -icon question -type {Save Discard} -default Save]
    847         if {$ans == "save"} {
    848             SaveCIFedits
    849             # did this save anything?
    850             if {$CIF(entry_changed) != ""} {
    851                 # if not, don't allow the mode/loop value to change
    852                 set CIF(editmode) 1
    853                 catch {
    854                     $CIF(LoopSpinBox) setvalue @$CIF(lastLoopIndex)
    855                 }
    856                 return 1
    857             }
    858         } else {
    859             set CIF(entry_changed) {}
    860             $CIF(EditSaveButton) config -state disabled
     844    set errorlist {}
     845    set errorflag 0
     846    set msg "The following edits cannot be saved due to errors:\n"
     847    foreach widget $CIF(widgetlist) {
     848        CheckChanges $widget 1
     849        if {$CIF(errormsg) != ""} {
     850            set errorflag 1
     851            foreach err $CIF(errormsg) {
     852                append msg "  " $err \n
     853            }
     854        }
     855
     856    }
     857    if {$errorflag} {
     858        append msg \n {Do you want to make corrections, or discard these edits?}
     859        set ans [MyMessageBox -parent . -title "Invalid edits" \
     860                -message $msg -icon error -type "Correct Discard" \
     861                -default correct]
     862        if {$ans == "correct"} {
     863            # if not, don't allow the mode/loop value to change
     864            set CIF(editmode) 1
     865            catch {
     866                $CIF(LoopSpinBox) setvalue @$CIF(lastLoopIndex)
     867            }
     868            return 1
    861869        }
    862870    }
     
    867875#   shows the contents data name or a loop
    868876proc showCIFbyTreeID {name} {
     877    if {[CheckForCIFEdits]} return
     878
    869879    global CIF
    870     if {[CheckForCIFEdits]} return
    871880    set pointer [$CIF(tree) itemcget $name -data]
    872881    set dataname [lindex [$CIF(tree) itemcget $name -text] 0]
     882    set CIF(lastShownTreeID) $name
    873883    showCIFbyDataname $pointer $dataname
    874884}
    875885
    876886proc showCIFbyDataname {pointer dataname "loopindex {}"} {
    877     if {[CheckForCIFEdits]} return
    878     global CIF
     887    global CIF CIFtreeindex
    879888    set CIF(lastShownItem) [list $pointer $dataname]
    880     # include a save button
    881     if {$CIF(editmode)} {
    882         pack $CIF(EditSaveButton) -side left
    883     } else {
    884         pack forget $CIF(EditSaveButton)
    885     }
    886889    pack forget $CIF(AddtoLoopButton) $CIF(LoopSpinBox) $CIF(DeleteLoopEntry)
    887890
     
    915918            # get number of elements for first name
    916919            set names [llength [set ${block}([lindex $looplist 0])]]
     920            # can't delete the only entry
     921            if {$names == 1 && $CIF(editmode)} {
     922                $CIF(DeleteLoopEntry) configure -state disabled
     923            } else {
     924                $CIF(DeleteLoopEntry) configure -state normal
     925            }
    917926            $CIF(LoopSpinBox) configure -range "1 $names 1" \
    918927                    -command    "ShowLoopVar ${block} $dataname" \
    919928                    -modifycmd  "ShowLoopVar ${block} $dataname"
     929            set CIF(lastLoopIndex) {}
    920930            if {$loopindex == ""} {
    921931                $CIF(LoopSpinBox) setvalue first
     
    946956            set frame0 [$frame.0 getframe]
    947957            grid columnconfig $frame0 2 -weight 1
     958            if {[set l [llength [set ${block}($dataname)]]] > 100} {
     959                grid [label $frame0.a$i -justify left \
     960                        -text "$dataname has $l entries, too many to display by column" \
     961                        ] -sticky w -column 0 -row $i
     962                return
     963            }
    948964            foreach mark [set ${block}($dataname)] {
    949965                incr i
     
    981997proc RepeatLastshowCIFvalue {} {
    982998    global CIF
     999    if {[CheckForCIFEdits]} return
     1000    set lastLoopIndex $CIF(lastLoopIndex)
     1001
    9831002    catch {
    9841003        eval showCIFbyDataname $CIF(lastShownItem)
     1004        # if we are in a loop, display the element
     1005        if {[lindex [lindex $CIF(lastShownItem) 0] 1] == "loop"} {
     1006            $CIF(LoopSpinBox) setvalue @$lastLoopIndex
     1007            ShowLoopVar [lindex [lindex $CIF(lastShownItem) 0] 0] \
     1008                    [lindex $CIF(lastShownItem) 1]
     1009        }
     1010       
    9851011    }
    9861012}
     
    9911017    global $array CIF
    9921018    # check for unsaved changes here
    993     if {[CheckForCIFEdits]} return
     1019    if {$CIF(lastLoopIndex) != ""} {
     1020        if {[CheckForCIFEdits]} return
     1021    }
    9941022
    9951023    set looplist [set ${array}($loop)]
     
    10291057            }
    10301058            set CIFinfoArr($widget) [lreplace $CIFinfoArr($widget) 2 2 $index]
    1031             $CIF(EditSaveButton) config -state disabled
    10321059        } else {
    10331060            [$frame.$i getframe].l config -text $value
     
    13251352        set v $item
    13261353        # remove s.u., if allowed & present
     1354        set vals [ParseSU $item]
     1355        if {[set v [lindex $vals 0]] == "."} {
     1356            return "error: value $item is not a valid number for $dataname"
     1357        }
    13271358        if {$esd} {
    1328             regsub {\([0-9]+\)} $v {} v
    1329         }
    1330         if [catch {expr $v}] {return "error: value $item is not a valid number for $dataname"}
     1359            if {[lindex $vals 1] == "."} {
     1360                return "error: value $item for $dataname has an invalid uncertainty (esd)"
     1361            }
     1362        } elseif {[llength $vals] == 2} {
     1363            return "error: $item is invalid for $dataname, an uncertainty (esd) is not allowed"
     1364        }
     1365
     1366        # now validate the range
    13311367        if {$range != ""} {
    13321368            # is there a decimal point in the range?
     
    13401376            if {$min != ""} {
    13411377                if {$v < $min} {
    1342                     return "error: value $item is too small for $dataname"
     1378                    return "error: value $item is too small for $dataname (allowed range $range)"
    13431379                }
    13441380            }
    13451381            if {$max != ""} {
    13461382                if {$v > $max} {
    1347                     return "error: value $item is too big for $dataname"
     1383                    return "error: value $item is too big for $dataname(allowed range $range)"
    13481384                }
    13491385            }
    13501386        }
    13511387    }
     1388    return {}
    13521389}
    13531390
     
    13871424
    13881425    lappend CIF(widgetlist) $widget
     1426    set CIFinfoArr($widget) {}
    13891427
    13901428    if $CIF(editmode) {
     
    13941432            set widgetinfo [list $dataname $block 0]
    13951433        }
     1434        set CIFeditArr($widget) $value
     1435        set CIFinfoArr($widget) $widgetinfo
     1436
    13961437        if {$type == "n"} {
    1397             set CIFeditArr($widget) $value
    1398             set CIFinfoArr($widget) $widgetinfo
    13991438            entry $widget -justify left -textvariable CIFeditArr($widget)
    14001439            bind $widget <Leave> "CheckChanges $widget"
     
    14061445            }
    14071446        } elseif {$elist != ""} {
    1408             set CIFeditArr($widget) $value
    1409             set CIFinfoArr($widget) $widgetinfo
    14101447            set enum {}
    14111448            foreach e $elist {
     
    14291466            $widget insert end $value
    14301467            bind $widget <Leave> "CheckChanges $widget"
    1431             set CIFeditArr($widget) $value
    1432             set CIFinfoArr($widget) $widgetinfo
    14331468            if {$nlines > 1} {
    14341469                grid $ws -sticky nsew -column 1 -row $row
     
    14511486
    14521487# this is called to see if the user has changed the value for a CIF
    1453 # data item. If the value has changed, the "Save Changes" button is
    1454 # made active.
    1455 proc CheckChanges {widget} {
     1488# data item and to validate it.
     1489#   save the change if $save is 1
     1490#   return 1 if the widget contents has changed
     1491proc CheckChanges {widget "save 0"} {
    14561492    global CIFeditArr CIFinfoArr CIF
    1457     foreach {dataname block index} $CIFinfoArr($widget) {}
     1493
     1494    set CIF(errormsg) {}
     1495
     1496    if {![winfo exists $widget]} return
     1497
     1498    set dataname {}
     1499    catch {
     1500        foreach {dataname block index} $CIFinfoArr($widget) {}
     1501    }
     1502    # if this widget is a label, the info above will not be defined & checks are not needed
     1503    if {$dataname == ""} {return 0}
     1504
    14581505    global ${block}
    14591506    set mark [lindex [set ${block}($dataname)] $index]
    1460     set orig [StripQuotes [$CIF(txt) get $mark.l $mark.r]]         
     1507    if {$mark == ""} return
     1508    set orig [StripQuotes [$CIF(txt) get $mark.l $mark.r]]
     1509
     1510    # validate the entry
     1511    set error {}
    14611512    set err {}
    14621513    switch [winfo class $widget] {
    14631514        Text {
    1464             set current [$widget get 1.0 end]
     1515            set current [string trim [$widget get 1.0 end]]
    14651516            set l 0
    14661517            foreach line [set linelist [split $current \n]] {
    14671518                incr l
    1468                 if {[string length $line] > 80} {lappend err $l}
     1519                if {[string length $line] > 80} {
     1520                    lappend err $l
     1521                    lappend error "Error: line $l for $dataname is >80 characters"
     1522                }
    14691523            }
    14701524            if {$err != ""} {
     
    14741528                $widget tag config error -foreground red
    14751529            } else {
    1476                 $widget tag delete error 
     1530                $widget tag delete error
    14771531            }
    14781532            # see if box should expand
     
    15001554            if {$err != "" && \
    15011555                    [string tolower [lindex $err 0]] != "warning:"} {
     1556                lappend error $err
    15021557                $widget config -fg red
    15031558            } else {
     
    15081563            set current $CIFeditArr($widget)
    15091564        }
     1565        Label {
     1566            return 0
     1567        }
    15101568    }
    15111569    if {[string trim $orig] != [string trim $current]} {
    1512         if {$CIF(autosave_edits) && $err == ""} {
    1513             lappend CIF(entry_changed) $widget
    1514             SaveCIFedits
    1515             return
    1516         }
    1517         if {[string first $widget $CIF(entry_changed)] == -1} {
    1518             lappend CIF(entry_changed) $widget
    1519         }
    1520         $CIF(EditSaveButton) config -state normal
    1521     }
     1570        if {$err != ""} {
     1571            set CIF(errormsg) $error
     1572        } elseif {$save} {
     1573            SaveCIFedits $widget
     1574            return 0
     1575        }
     1576        return 1
     1577    }
     1578    return 0
    15221579}
    15231580
    15241581# save the CIF edits into the CIF text widget
    1525 proc SaveCIFedits {} {
     1582proc SaveCIFedits {widget} {
    15261583    global CIFeditArr CIFinfoArr CIF
    1527     # validate the entries
    1528     set error {}
    1529     foreach widget $CIF(entry_changed) {
    1530         foreach {dataname block index} $CIFinfoArr($widget) {}
    1531         global ${block}
    1532         set mark [lindex [set ${block}($dataname)] $index]
    1533         set orig [StripQuotes [$CIF(txt) get $mark.l $mark.r]]     
    1534         switch [winfo class $widget] {
    1535             Text {
    1536                 set current [$widget get 1.0 end]
    1537                 set l 0
    1538                 foreach line [split $current \n] {
    1539                     incr l
    1540                     if {[string length $line] > 80} {
    1541                         lappend error "Error: line $l for $dataname is >80 characters"
    1542                     }
    1543                 }
    1544             }
    1545             Entry {
    1546                 set current [string trim [$widget get]]
    1547                 set err [ValidateCIFItem [lindex $CIFinfoArr($widget) 0] $current]
    1548                 if {$err != "" && [lindex $err 0] != "warning:"} {
    1549                     lappend error $err
    1550                 }
    1551             }
    1552         }
    1553     }
    1554     if {$error != ""} {
    1555         set msg "The attempted changes cannot be saved due to:\n"
    1556         foreach err $error {
    1557             append msg "  " $err \n
    1558         }
    1559         append msg \n {Please correct and then press "Save Changes"}
    1560         MyMessageBox -parent . -title "Invalid Changes?" \
    1561                 -message $msg -icon error -type Continue -default continue
    1562         return
    1563     }
    1564     foreach widget $CIF(entry_changed) {
    1565         foreach {dataname block index} $CIFinfoArr($widget) {}
    1566         global ${block}
    1567         set mark [lindex [set ${block}($dataname)] $index]
    1568         switch [winfo class $widget] {
    1569             Text {
    1570                 set value [string trim [$widget get 1.0 end]]
    1571             }
    1572             Entry {
    1573                 set value [string trim [$widget get]]
    1574             }
    1575             Menubutton {
    1576                 set value $CIFeditArr($widget)
    1577             }
    1578         }
    1579         ReplaceMarkedText $CIF(txt) $mark $value
    1580         incr CIF(changes)
    1581     }
    1582     set CIF(entry_changed) {}
    1583     $CIF(EditSaveButton) config -state disabled
    1584     pack $CIF(EditSaveButton) -side left
     1584
     1585    foreach {dataname block index} $CIFinfoArr($widget) {}
     1586    global ${block}
     1587    set mark [lindex [set ${block}($dataname)] $index]
     1588    set orig [StripQuotes [$CIF(txt) get $mark.l $mark.r]]
     1589    switch [winfo class $widget] {
     1590        Text {
     1591            set current [string trim [$widget get 1.0 end]]
     1592        }
     1593        Entry {
     1594            set current [string trim [$widget get]]
     1595        }
     1596        Menubutton {
     1597            set current $CIFeditArr($widget)
     1598        }
     1599    }
     1600    # save for undo & clear the redo list
     1601    set CIF(redolist) {}
     1602    if {[lindex [lindex $CIF(lastShownItem) 0] 1] == "loop"} {
     1603        lappend CIF(undolist) [list $mark $orig \
     1604                $CIF(lastShownItem) $CIF(lastShownTreeID) $CIF(lastLoopIndex)]
     1605    } else {
     1606        lappend CIF(undolist) [list $mark $orig \
     1607                $CIF(lastShownItem) $CIF(lastShownTreeID)]
     1608    }
     1609    # count it
     1610    incr CIF(changes)
     1611    # make the change
     1612    ReplaceMarkedText $CIF(txt) $mark $current
    15851613}
    15861614
     
    16021630    set epos $line.0
    16031631    $CIF(txt) insert $epos \n
     1632
    16041633    # insert a ? token for each entry & add to marker list for each variable
     1634    set addlist {}
    16051635    foreach var $looplist {
    1606         incr CIF(changes)
    16071636        # go to next line?
    16081637        if {[string length \
     
    16191648        $CIF(txt) mark gravity $CIF(markcount).r right
    16201649        set epos [$CIF(txt) index "$epos + 2c"]
     1650        set index [llength [set ${block}($var)]]
    16211651        lappend ${block}($var) $CIF(markcount)
    1622     }
     1652        lappend addlist [list $CIF(markcount) $var $index $block]
     1653    }
     1654    incr CIF(changes)
     1655    lappend CIF(undolist) [list "loop add" $addlist \
     1656            $CIF(lastShownItem) $CIF(lastShownTreeID) $CIF(lastLoopIndex)]
     1657    set CIF(redolist) {}
     1658
    16231659    # now show the value we have added
    16241660    set frame [$CIF(displayFrame) getframe]
     
    16291665    ShowLoopVar $block $loop
    16301666    $CIF(txt) configure -state disabled
     1667    $CIF(DeleteLoopEntry) configure -state normal
    16311668}
    16321669
     
    16751712
    16761713    $CIF(txt) configure -state normal
     1714    set deletelist {}
    16771715    foreach widget $CIF(widgetlist) {
    16781716        foreach {dataname block index} $CIFinfoArr($widget) {}
    16791717        global $block
    16801718        set mark [lindex [set ${block}($dataname)] $index]
     1719        set orig [StripQuotes [$CIF(txt) get $mark.l $mark.r]]
     1720        lappend deletelist [list $mark $dataname $index $block $orig]
    16811721        $CIF(txt) delete $mark.l $mark.r
    16821722        set ${block}($dataname) [lreplace [set ${block}($dataname)] $index $index]
    16831723    }
     1724    set CIF(redolist) {}
     1725    lappend CIF(undolist) [list "loop delete" $deletelist \
     1726            $CIF(lastShownItem) $CIF(lastShownTreeID) $CIF(lastLoopIndex)]
     1727    # count it
     1728    incr CIF(changes)
     1729
    16841730    $CIF(txt) configure -state disabled
    16851731
     
    16871733    incr max -1
    16881734    $CIF(LoopSpinBox) configure -range "1 $max 1"
    1689     $CIF(LoopSpinBox) setvalue last
     1735    if {$index >= $max} {set index $max; incr index -1}
     1736    $CIF(LoopSpinBox) setvalue @$index
     1737    if {$max == 1} {$CIF(DeleteLoopEntry) configure -state disabled}
     1738    # don't check for changes
     1739    set CIF(lastLoopIndex) {}
     1740    ShowLoopVar $block [lindex $CIF(lastShownItem) 1]
    16901741}
    16911742
     
    17161767}
    17171768
     1769proc UndoChanges {} {
     1770    global CIF
     1771    # save any current changes, if possible
     1772    if {[CheckForCIFEdits]} return
     1773    # are there edits to undo?
     1774    if {[llength $CIF(undolist)] == 0} return
     1775
     1776    foreach {mark orig lastShownItem lastShownTreeID lastLoopIndex} \
     1777            [lindex $CIF(undolist) end] {}
     1778
     1779    if {[llength $mark] == 1} {
     1780        # get the edited value
     1781        set edited [StripQuotes [$CIF(txt) get $mark.l $mark.r]]
     1782        # make the change back
     1783        ReplaceMarkedText $CIF(txt) $mark $orig
     1784        # add this undo to the redo list
     1785        lappend CIF(redolist) [list $mark $edited $lastShownItem \
     1786                $lastShownTreeID $lastLoopIndex]
     1787    } elseif {[lindex $mark 1] == "add"} {
     1788        set deletelist {}
     1789        $CIF(txt) configure -state normal
     1790        foreach m $orig {
     1791            foreach {mark dataname index block} $m {}
     1792            # get the inserted value
     1793            set edited [StripQuotes [$CIF(txt) get $mark.l $mark.r]]   
     1794            $CIF(txt) delete $mark.l $mark.r
     1795            lappend deletelist [list $mark $dataname $index $block $edited]
     1796            global $block
     1797            set ${block}($dataname) [lreplace [set ${block}($dataname)] $index $index]
     1798        }
     1799        $CIF(txt) configure -state disabled
     1800        # add this action to the redo list
     1801        lappend CIF(redolist) [list "loop delete" $deletelist \
     1802                $lastShownItem $lastShownTreeID $lastLoopIndex]
     1803    } elseif {[lindex $mark 1] == "delete"} {
     1804        set addlist {}
     1805        foreach m $orig {
     1806            foreach {mark dataname index block orig} $m {}
     1807            # make the change back
     1808            ReplaceMarkedText $CIF(txt) $mark $orig
     1809            lappend addlist [list $mark $dataname $index $block]
     1810            global $block
     1811            set ${block}($dataname) [linsert [set ${block}($dataname)] $index $mark]
     1812        }
     1813        # show the entry that was added
     1814        set lastLoopIndex $index
     1815        # add this last entry to the redo list
     1816        lappend CIF(redolist) [list "loop add" $addlist \
     1817                $lastShownItem $lastShownTreeID $lastLoopIndex]
     1818    }
     1819
     1820    # drop the action from the undo list
     1821    set CIF(undolist) [lreplace $CIF(undolist) end end]
     1822    # count back
     1823    incr CIF(changes) -1
     1824    # scroll on the tree
     1825    $CIF(tree) see $lastShownTreeID
     1826    eval showCIFbyDataname $lastShownItem
     1827
     1828    # if we are in a loop, display the element
     1829    if {[lindex [lindex $lastShownItem 0] 1] == "loop"} {
     1830        $CIF(LoopSpinBox) setvalue @$lastLoopIndex
     1831        ShowLoopVar [lindex [lindex $lastShownItem 0] 0] \
     1832                [lindex $lastShownItem 1]
     1833    }
     1834}
     1835
     1836
     1837proc RedoChanges {} {
     1838    global CIF
     1839    # save any current changes, if possible
     1840    if {[CheckForCIFEdits]} return
     1841    # are there edits to redo?
     1842    if {[llength $CIF(redolist)] == 0} return
     1843
     1844    foreach {mark edited lastShownItem lastShownTreeID lastLoopIndex} \
     1845            [lindex $CIF(redolist) end] {}
     1846
     1847    if {[llength $mark] == 1} {
     1848        # get the edited value
     1849        set orig [StripQuotes [$CIF(txt) get $mark.l $mark.r]]
     1850        # make the change back
     1851        ReplaceMarkedText $CIF(txt) $mark $edited
     1852        # add this action back to the undo list
     1853        lappend CIF(undolist) [list $mark $orig $lastShownItem \
     1854                $lastShownTreeID $lastLoopIndex]
     1855        # count up
     1856        incr CIF(changes)
     1857    } elseif {[lindex $mark 1] == "add"} {
     1858        set deletelist {}
     1859        $CIF(txt) configure -state normal
     1860        foreach m $edited {
     1861            foreach {mark dataname index block} $m {}
     1862            # get the inserted value
     1863            set edited [StripQuotes [$CIF(txt) get $mark.l $mark.r]]   
     1864            $CIF(txt) delete $mark.l $mark.r
     1865            lappend deletelist [list $mark $dataname $index $block $edited]
     1866            global $block
     1867            set ${block}($dataname) [lreplace [set ${block}($dataname)] $index $index]
     1868        }
     1869        $CIF(txt) configure -state disabled
     1870        # add this action back to the undo list
     1871        lappend CIF(undolist) [list "loop delete" $deletelist \
     1872                $lastShownItem $lastShownTreeID $lastLoopIndex]
     1873        # count up
     1874        incr CIF(changes)
     1875    } elseif {[lindex $mark 1] == "delete"} {
     1876        set addlist {}
     1877        foreach m $edited {
     1878            foreach {mark dataname index block orig} $m {}
     1879            # make the change back
     1880            ReplaceMarkedText $CIF(txt) $mark $orig
     1881            lappend addlist [list $mark $dataname $index $block]
     1882            global $block
     1883            set ${block}($dataname) [linsert [set ${block}($dataname)] $index $mark]
     1884        }
     1885        # show the entry that was added
     1886        set lastLoopIndex $index
     1887        # add this action back to the undo list
     1888        lappend CIF(undolist) [list "loop add" $addlist \
     1889                $lastShownItem $lastShownTreeID $lastLoopIndex]
     1890        # count up
     1891        incr CIF(changes)
     1892    }
     1893   
     1894    # drop the action from the redo list
     1895    set CIF(redolist) [lreplace $CIF(redolist) end end]
     1896    # scroll on the tree
     1897    $CIF(tree) see $lastShownTreeID
     1898    eval showCIFbyDataname $lastShownItem
     1899   
     1900    # if we are in a loop, display the element
     1901    if {[lindex [lindex $lastShownItem 0] 1] == "loop"} {
     1902        $CIF(LoopSpinBox) setvalue @$lastLoopIndex
     1903        ShowLoopVar [lindex [lindex $lastShownItem 0] 0] \
     1904                [lindex $lastShownItem 1]
     1905    }
     1906}
     1907
    17181908# initialize misc variables
    1719 set CIF(entry_changed) {}
    17201909set CIF(changes) 0
    17211910set CIF(widgetlist) {}
    17221911set CIF(lastShownItem) {}
    17231912set CIF(lastLoopIndex) {}
    1724 set CIF(autosave_edits) 0
    17251913set CIF(editmode) 0
     1914set CIF(undolist) {}
     1915set CIF(redolist) {}
     1916set CIF(treeSelectedList) {}
Note: See TracChangeset for help on using the changeset viewer.