home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-12-10 | 9.3 KB | 371 lines | [TEXT/ALFA] |
-
- namespace eval app {}
- namespace eval file {}
- namespace eval dialog {}
-
- proc app::ensureRunning {sig {in_front 0}} {
- # See if a process w/ any of the acceptable
- # sigs already running.
- if [app::isRunning $sig name] {
- if {$in_front} {switchTo '$sig'}
- return $name
- }
- if {[catch {nameFromAppl $sig} name]} {
- alertnote "Can't find app w/ sig '$sig'.\
- Try rebuilding your desktop or changing your helper apps."
- error ""
- }
- if {![file exists $name]} {
- alertnote "Sig '$sig' is mapped to '$name', which doesn't\
- exist. Try changing your helper apps."
- error ""
- }
- # Launch the app
- if {$in_front} {
- launch -f $name
- } else {
- launch $name
- }
- hook::callAll launch $sig
- return $name
- }
-
- # Switch to 'sig', launching if necesary
- proc app::launchFore {sig} {
- app::ensureRunning $sig 1
- }
-
- # Ensure that the app is at least running in the background.
- proc app::launchBack {sig} {
- app::ensureRunning $sig 0
- }
-
- proc app::launchAnyOfThese {sigs sig {prompt "Please locate the application:"}} {
- app::launchBackSigs $sigs $sig $prompt 0
- }
- proc app::launchElseTryThese {sigs sig {prompt "Please locate the application:"}} {
- app::launchBackSigs $sigs $sig $prompt 1
- }
-
- # Check to see if any of the 'sigs' is running. If so, return its name.
- # Otherwise, attempt to launch the file named by 'sig'.
- proc app::launchBackSigs {sigs sig {prompt "Please locate the application:"} {running_first 1} } {
- global $sig
- if {$running_first || ![info exists $sig] || [catch {nameFromAppl [set $sig]}]} {
- app::setRunningSig $sigs $sig
- app::getSig $prompt $sig
- }
- return [app::launchBack [set $sig]]
- }
-
- proc app::getSig {prompt sig} {
- global $sig modifiedVars
- if {[catch {nameFromAppl [set $sig]}]} {
- set $sig [getFileSig [getfile $prompt]]
- lappend modifiedVars $sig
- }
- }
-
-
- proc app::setRunningSig {sigs sig} {
- global $sig modifiedVars
- if [app::isRunning $sigs name s] {
- if {![info exists $sig] || ($s != [set $sig])} {
- set $sig $s
- lappend modifiedVars $sig
- }
- return 1
- }
- return 0
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "app::isRunning" --
- #
- # Is an app with one of the given sigs running. Set the global $sig
- # to the name of that thing if it is
- #
- # {"Finder" "MACS" 978944 182209 }
- #
- # Much improved by Vince to avoid scanning the processes list one at a
- # time.
- #
- # We have to workaround a bug in tcl 7.4-7.5
- # -------------------------------------------------------------------------
- ##
- if {[info tclversion] < 8.0} {
- proc app::isRunning {sigs {n ""} {s ""}} {
- if {$n != ""} {upvar $n name}
- if {$s != ""} {upvar $s sig}
- return [regexp "\"(\[^\"\]+)\" \"([join [quote::Regfind [quote::Regfind $sigs]] |])\" " [processes] "" name sig]
- }
- } else {
- proc app::isRunning {sigs {n ""} {s ""}} {
- if {$n != ""} {upvar $n name}
- if {$s != ""} {upvar $s sig}
- return [regexp "\"(\[^\"\]+)\" \"([join [quote::Regfind $sigs] |])\" " [processes] "" name sig]
- }
- }
-
-
- proc printLeftHeader {pg} {
- global printHeader printHeaderTime printHeaderFullPath
-
- if {!$printHeader} return ""
-
- if {$printHeaderFullPath} {
- set text [win::Current]
- } else {
- set text [win::CurrentTail]
- }
-
- if {$printHeaderTime} {
- append text " [join [mtime [now] short]]"
- }
- }
-
- proc printRightHeader {pg} {
- return "Page $pg"
- }
-
- proc revertToBackup {} {
- global backup backupExtension backupFolder win::Modes
-
- set fname [win::Current]
- set dir $backupFolder
- set bname "$dir:[file tail $fname]$backupExtension"
- if {![file exists $bname]} {
- message "Backup file '$bname' does not exist"
- return
- }
-
- if [dialog::yesno "Revert to backup dated '[join [mtime [file mtime $bname]]]'?"] {
- killWindow
-
- edit $bname
- saveAs -f $fname
- }
- }
-
-
- ##
- # -------------------------------------------------------------------------
- #
- # "app::registerMultiple" --
- #
- # Does the dirty work so a mode can use different icons for its menu
- # according to which application a particular user has selected for
- # that mode. The arguments are as follows:
- #
- # type - a prefix such as 'java' which is used to create variables
- # such as 'javaSig' 'javaMenu'
- # creators - the list of recognised creators (1st is default)
- # icons - the list of icon resources
- # menurebuild - the procedure which is used to rebuild the mode menu
- #
- # here's an example:
- #
- # app::registerMultiple java [list Javc WARZ] \
- # [list •140 •285] rebuildJavaMenu
- #
- # of course the rebuild procedure must use the correct icon like this:
- #
- # proc rebuildJavaMenu {} {
- # global javaMenu
- # menu -n $javaMenu -p javaMenuProc {
- # }
- # }
- #
- # Note: this procedure ensures the menu is created the first time it
- # is called.
- # --Version--Author------------------Changes-------------------------------
- # 1.0 <darley@fas.harvard.edu> original
- # -------------------------------------------------------------------------
- ##
- proc app::registerMultiple {type creators icons menurebuild} {
- global ${type}Sig multiApp
- if ![info exists ${type}Sig] {
- set ${type}Sig [lindex $creators 0]
- }
- set multiApp($type) [list $creators $icons $menurebuild]
- app::multiChanged ${type}Sig
- trace variable ${type}Sig w app::multiChanged
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "app::multiChanged" --
- #
- # Utility procedure used by the above. No need to call it manually.
- # -------------------------------------------------------------------------
- ##
- proc app::multiChanged {type args} {
- set type [string range $type 0 [expr [string last "Sig" $type] -1]]
- global ${type}Menu ${type}Sig multiApp
- # remove old menu
- catch {removeMenu [set ${type}Menu]}
- # update the icon according to signature
- set info $multiApp($type)
- if {[set i [lsearch -exact [lindex $info 0] [set ${type}Sig]]] == -1} {
- set i 0
- }
- set ${type}Menu [lindex [lindex $info 1] $i]
- # rebuild the menu
- eval [lindex $multiApp($type) 2]
- # insert the new menu
- insertMenu [set ${type}Menu]
- }
-
- proc file::ensureDirExists {dir} {
- if ![file exists $dir] {
- file::ensureDirExists [file dirname $dir]
- mkdir $dir
- return 1
- }
- return 0
- }
-
-
- proc file::openAny {file} {
- getFileInfo $file a
- if {$a(type) == "TEXT"} {
- edit $file
- return
- } else {
- sendOpenEvent -noreply Finder "${file}"
- }
- }
-
- proc file::renameTo {} {
- set c [win::Current]
- if {![file exists $c]} { alertnote "Not a file window!" ; return }
- set new [prompt "New name for file:" [file tail $c]]
- if [file exists [set to [file dirname $c]:$new]] {
- alertnote "Already exists!"
- return
- }
- killWindow
- moveFile $c $to
- edit $to
- }
-
- proc helperApps {} {
- set sigs [info globals *Sig]
- regsub -all {Sig} $sigs {} sigs
- set sig [listpick -p "Change/inspect which helper?" [lsort $sigs]]
- set sig ${sig}Sig
- global $sig
- if ![info exists $sig] { set $sig "" }
- set nsig [dialog::askFindApp $sig [set $sig]]
- if {$nsig != "" && [set $sig] != $nsig} {
- set $sig $nsig
- global modifiedVars
- lappend modifiedVars $sig
- }
- }
-
- proc dialog::askFindApp {var sig} {
- if {$sig == ""} {
- set text "Currently unassigned. Set?"
- } elseif {[catch {nameFromAppl '$sig'} name]} {
- set text "App w/ sig '$sig' doesn't seem to exist. Change?"
- } else {
- set text "Current value is '$name'. Change?"
- }
- if [dialog::yesno $text] {
- set nsig [dialog::findApp $var $sig]
- set app [nameFromAppl $nsig]
- if [dialog::yesno "Are you sure you want to set $var to '$nsig' (mapped to '$app')?"] {
- return $nsig
- }
- }
- return ""
- }
-
- proc dialog::findApp {var sig} {
- global ${var}s modifiedVars
- if [info exists ${var}s] {
- # have a list of items
- set sigs [set ${var}s]
-
- set s 0
- foreach f $sigs {
- if ![catch {nameFromAppl $f} path] {
- lappend items [file tail $path]
- lappend itemsigs $f
- incr s
- }
- }
- if $s {
- lappend items "-" "Locate manually…"
- if [catch {dialog::optionMenu "Select a new helper for '$var':" \
- $items "" 1} p] {
- return ""
- }
- # we removed a bunch of items above, so have to look here
- if {$p < $s} {
- return [lindex $itemsigs $p]
- }
- }
- if {!$s || $p >= $s} {
- set nsig [dialog::_findApp $var $sig]
- if {$nsig != ""} {
- if {[lsearch $sigs $nsig] == -1} {
- lappend ${var}s $nsig
- lappend modifiedVars ${var}s
- }
- }
- } else {
- set nsig [lindex $sigs $p]
- }
- return $nsig
- } else {
- return [dialog::_findApp $var $sig]
- }
- }
-
- proc dialog::_findApp {var sig} {
- if [catch {getfile "Locate new helper for '$var':"} path] { return "" }
- set nsig [getFileSig $path]
- set app [nameFromAppl $nsig]
- if {$app != $path} {
- alertnote "Appl sig '$nsig' is mapped to '$app', not '$path'. Remove the former, or rebuild your desktop."
- return ""
- }
- return $nsig
- }
-
- #================================================================================
- # Excalibur is the only Mac spell-checker that I know of which will handle
- # LaTeX as well as ordinary text.
-
-
- proc spellcheckWindow {} {
- global resumeRevert
-
- set name [app::launchFore XCLB]
-
- if {[winDirty]} {
- if {[dialog::yesno "Save '[win::CurrentTail]'?"]} {
- save
- }
- }
- sendOpenEvent noReply [file tail $name] [win::Current]
- set resumeRevert 1
- }
-
- proc spellcheckSelection {} {
- if {[getPos] == [selEnd]} {
- beep
- message "No selection"
- return;
- }
- set name [app::launchBack XCLB]
- copy
- switchTo $name
- }
-
-