home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-04 | 7.6 KB | 278 lines | [TEXT/ALFA] |
- #===============================================================================================
- # Alpha calls two fileset-related routines, 'getCurrFileSet', and
- # 'getFileSetNames'. Alpha will also attempt to set the variable 'currFileSet'
- # on occasion, but this isn't critical.
- #===============================================================================================
-
- #===========================================================================
- # The filesets.
- #===========================================================================
-
- # Build some filesets on the fly.
- catch {unset fileSets}
- catch {unset currFileSet}
- set gfileSets(Help) "$HOME:Help:*"
- set gfileSets(System) "$HOME:Tcl:SystemCode:*.tcl"
- set gfileSets(User) "$HOME:Tcl:UserCode:*.tcl"
-
- # Default curr fileset is the first one. Can be changed in 'userStartup.tcl'.
- set currFileSet [lindex [array names gfileSets] 0]
-
- #===========================================================================
- # The support routines.
- #===========================================================================
- # Called from Alpha to get list of files for current file set.
- proc getCurrFileSet {} {
- global fileSets
- global currFileSet
- return $fileSets($currFileSet)
- }
- # Called from Alpha to get names. The first name returned is taken to
- # be the current fileset.
- proc getFileSetNames {} {
- global fileSets
- global currFileSet
- set ind [lsearch [array names fileSets] $currFileSet]
- if {$ind < 0} {set ind 0}
- return [linsert [lsort [lreplace [array names fileSets] $ind $ind]] 0 $currFileSet]
- }
-
-
- # Keep 'sets' menu up to date.
- trace vdelete currFileSet w shadowCurrFileSet
- trace variable currFileSet w shadowCurrFileSet
- proc shadowCurrFileSet {nm1 nm2 op} {
- global fileSets
- global currFileSet
- foreach name [array names fileSets] {
- if {$name == $currFileSet} {
- markMenuItem -m choose $name on
- } else {
- markMenuItem -m choose $name off
- }
- }
- return $currFileSet
- }
-
- # Called in response to user changing filesets from the fileset menu.
- proc changeFileSet {menu item} {
- global currFileSet
-
- markMenuItem -m choose $currFileSet off
- set currFileSet $item
- markMenuItem -m choose $currFileSet on
- }
-
-
-
- #===========================================================================
- # Add fileset.
- #===========================================================================
- proc createFileset {} {
- global gfileSets fileSets currFileSet
-
- set name [getline "New fileset name:" ""]
- if {![string length $name]} return
-
- set dir [string trim [get_directory -p "New fileset dir:"] ":"]
- if {![string length $dir]} return
-
- set filePat [getline "File pattern:" "*"]
- if {![string length $filePat]} return
-
- set "gfileSets($name)" "$dir:$filePat"
- menu -n choose -m -p changeFileSet [lsort [array names fileSets]]
- set currFileSet $name
-
- if {[askyesno "Save new fileset?"] == "yes"} {
- addArrDef gfileSets $name "$dir:$filePat"
- }
- rebuildFilesetMenu
- return $name
- }
-
-
- # Open entire fileset.
- proc openEntireFileset {} {
- global fileSets
- set name [eval [list prompt "Open which fileset?" [lindex [array names fileSets] 0] "FileSet:"] [lsort -ignore [array names fileSets]]]
- foreach f $fileSets($name) {
- edit $f
- }
- }
-
- # Create a fileset fromt containing all windows currently open.
- proc createFilesetFromWins {} {
- global fileSets currFileSet
-
- set name [prompt "Create fileset containing current windows under what name?" "OpenWins"]
- set currFileSet $name
- addArrDef fileSets $name [winNames -f]
- set fileSets($name) [winNames -f]
- rebuildFilesetMenu
- }
-
-
-
- #===========================================================================
- # Dump fileset to current window. If you dump at the end of this file,
- # the fileset will be reloaded the next time you run Alpha.
- #===========================================================================
- proc dumpFileset {} {
- global fileSets
- global currFileSet
- if {![catch {prompt "Fileset name:" $currFileSet} name]} {
- insertText "set \"fileSets($name)\" \{\r"
- foreach file "$fileSets($name)" {
- insertText "\t\"$file\"\r"
- }
- insertText "\}\r"
- }
- }
-
-
-
- #================================================================================
- # Edit a file from a fileset via list dialogs (no mousing around).
- #================================================================================
- proc editFile {} {
- global fileSets
-
- set fset [listpick -p {Fileset?} [lsort -ignore [concat {*recent*} [array names fileSets]]]]
- if {[string length $fset]} {
- if {$fset == {*recent*}} {return [editRecentFile]}
- foreach f $fileSets($fset) {
- lappend disp [file tail $f]
- }
- foreach res [listpick -l -p {File?} [lsort -ignore $disp]] {
- set ind [lsearch $fileSets($fset) \*:$res]
- catch {edit [lindex $fileSets($fset) $ind]}
- }
- }
- }
-
-
- proc deleteFileset {} {
- global fileSets gfileSets currFileSet
-
- set fset [listpick -p {Fileset?} [lsort -ignore [array names fileSets]]]
- if {$currFileSet == $fset} {catch {set currFileSet System}}
-
- if {[askyesno "Delete fileset \"$fset\"?"] == "yes"} {
- catch {unset "fileSets($fset)"}
- catch {unset "gfileSets($fset)"}
-
- if {[askyesno "Permanently?"] == "yes"} {
- removeArrDef gfileSets $fset
- }
- rebuildFilesetMenu
- }
- }
-
-
- #===============================================================================
- proc replaceInFileset {} {
- global fileSets
-
- set from [prompt "Search string:" ""]
- set to [prompt "Replace string:" ""]
- set fset [listpick -p "Which fileset?" [array names fileSets]]
-
- if {[buttonAlert "Save all windows?" "Yes" "Cancel"] != "Yes"} return
- saveAll
-
- set cid [scancontext create]
- scanmatch $cid $from {
- set matches($f) 1
- }
- foreach f $fileSets($fset) {
- if {![catch {set fid [open $f]}]} {
- message "Looking at '[file tail $f]'â"
- scanfile $cid $fid
- close $fid
- }
- }
- scancontext delete $cid
-
- foreach f [array names matches] {
- message "Modifying $fâ"
- set cid [open $f "r"]
- if {[regsub -all $from [read $cid] $to out]} {
- set ocid [open $f "w+"]
- puts -nonewline $ocid $out
- close $ocid
- }
- close $cid
- }
-
- if {[buttonAlert "Revert affected windows?" "Yes" "No"] == "Yes"} {
- foreach f [array names matches] {
- bringToFront $f
- revert
- }
- }
- message ""
- }
-
- #================================================================================
- # Create a heirarchical fileset menu that allows you
- # to open any file in any fileset.
- #
- # Doesn't bother trying to specialcase names or pathnames that have
- # non-alphanumeric characters in them.
-
- proc filesetProc {menu item} {
- global fileSets
- if {$item == "Edit File"} {
- editFile
- return
- }
- if {[set match [lsearch $fileSets($menu) *:$item]] >= 0} {
- edit [lindex $fileSets($menu) $match]
- }
- }
-
-
- proc rebuildFilesetMenu {} {
- global fileSets gfileSets fsetMenuName currFileSet
-
- foreach f [array names gfileSets] {
- catch {set "fileSets($f)" [glob -t TEXT "$gfileSets($f)"]}
- }
-
- foreach f [lsort [array names fileSets]] {
- if {$f == "Help"} continue
- set menu {}
- foreach m "$fileSets($f)" {
- lappend menu "[file tail $m]\&"
- }
- lappend sets [list menu -s -m -n $f -p filesetProc [lsort -i $menu]]
- }
- menu -m -n $fsetMenuName -p filesetProc [concat {{/'Edit File} {menu -n Utilities {}} "(-"} $sets]
-
- menu -n "Utilities" {
- {menu -n choose -p changeFileSet {}}
- "createFileset"
- "deleteFileset"
- "(-"
- "createThinkFileset"
- "createWarriorFileset"
- "(-"
- "createFilesetFromWins"
- "openEntireFileset"
- "(-"
- "/T<I<OfindTag"
- "createTagFile"
- "(-"
- "replaceInFileset"
- "(-"
- "rebuildFilesetMenu"
- }
-
- menu -n choose -m -p changeFileSet [lsort [array names fileSets]]
- markMenuItem -m choose $currFileSet on
- }
-
-
- insertMenu $fsetMenuName
-