home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
stinterfac.tcl
< prev
next >
Wrap
Text File
|
1997-08-13
|
7KB
|
236 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)stinterfac.tcl /main/titanic/4
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)stinterfac.tcl /main/titanic/4 13 Aug 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
require platform.tcl
# End user added include file section
# This class is the interface to a Smalltalk
# system. It is responsible for: code generation settings,
# creating dialogs, generating special files and
# starting Smalltalk.
Class STInterface : {Object} {
constructor
method destructor
method generateImport
method generateExport
method getSelectedFiles
method readFiles
method addSuperClasses
method createSettingsDialog
# All files of type smalltalk in the current system.
#
attribute allFiles
# The selected files in the current system.
#
attribute selectedFiles
# The selected classes in the current system.
#
attribute selectedClasses
# Mapping from class name to file name.
#
attribute classToFile
# Mapping from classes to super classes.
#
attribute classToSuper
# The filehandler instance used by this interface.
#
attribute fileHandler
# Generator used by this interface.
#
attribute generator
}
constructor STInterface {class this name} {
set this [Object::constructor $class $this $name]
# Start constructor user section
$this classToSuper [Dictionary new]
$this classToFile [Dictionary new]
$this selectedClasses [List new]
$this selectedFiles [List new]
$this allFiles [List new]
$this createSettingsDialog
# End constructor user section
return $this
}
method STInterface::destructor {this} {
# Start destructor user section
# End destructor user section
}
# Generates the import script: determines the files to be included,
# reads the class hierarchy from all files and calls the generator. <selection>
# indicates whether selected or all was chosen in
# the Smalltalk menu.
#
method STInterface::generateImport {this selection} {
$this getSelectedFiles
if { $selection == "all" } {
[$this selectedFiles] contents [[$this allFiles] contents]
}
if [[$this selectedFiles] empty] {
wmtkerror "No class files selected"
return
}
$this readFiles
$this addSuperClasses
[$this generator] generateImport [$this selectedClasses] [$this classToSuper] [$this classToFile]
}
# Generates the export script for the classes in <selection>: determines the files to be
# included, reads all files to find the corresponding classes
# and calls the generator.
# <selection> indicates whether all or selected was chosen in the
# Smalltalk menu.
#
method STInterface::generateExport {this selection} {
$this getSelectedFiles
if { $selection == "all" } {
[$this selectedFiles] contents [[$this allFiles] contents]
}
if [[$this selectedFiles] empty] {
wmtkerror "No class files selected"
return
}
$this readFiles
[$this generator] generateExport [$this selectedClasses] [$this classToFile]
}
# Gets the selected files from the browser
# and sets selectedFiles.
#
method STInterface::getSelectedFiles {this} {
set stType [[$this fileHandler] stType]
if { ![[$this selectedFiles] empty] } {
[$this selectedFiles] remove 0 end
}
foreach obj [$wmttoolObj selectedObjSet] {
if [$obj isA SystemFileReference] {
set fileV [$obj getInfo "File Version"]
if {"$fileV" != ""} {
set type [[$fileV file] type]
if { $type == $stType } {
[$this selectedFiles] append "[[$fileV file] name].$type"
}
}
} elseif [$obj isA FileVersion] {
set type [[$obj file] type]
if { $type == $stType } {
[$this selectedFiles] append "[[$obj file] name].$type"
}
}
}
[$this allFiles] contents [fstorage::dir [[$this fileHandler] stType]]
# import and export scripts are discarded
[[$this fileHandler] getSpecialFiles] foreach fileName {
[$this allFiles] removeValue $fileName
[$this selectedFiles] removeValue $fileName
}
}
# Reads all files and fills classToSuper,
# classToFile and selectedClasses.
#
method STInterface::readFiles {this} {
if { ![[$this selectedClasses] empty] } {
[$this selectedClasses] remove 0 end
}
[$this allFiles] foreach fileName {
set fd [fstorage::open $fileName r]
while {[gets $fd line] >= 0} {
set wordList [split $line " "]
# check if second word is subclass keyword
if [regexp ubclass: [lindex $wordList 1]] {
regsub -all # [lindex $wordList 2] "" className
set superName [lindex $wordList 0]
[$this classToFile] set $className $fileName
[$this classToSuper] set $className $superName
if { [[$this selectedFiles] search $fileName] != -1 } {
[$this selectedClasses] append $className
}
break
}
}
fstorage::close $fd
}
}
# Adds the superclasses of the classes
# selectedClasses to selectedClasses.
#
method STInterface::addSuperClasses {this} {
[$this selectedClasses] foreach className {
if [[$this classToSuper] exists $className] {
set super [[$this classToSuper] set $className]
if [[$this classToFile] exists $super] {
if { [[$this selectedClasses] search $super] == - 1} {
[$this selectedClasses] append $super
}
}
}
}
}
# Creates the dialog for the code generation
# settings.
#
method STInterface::createSettingsDialog {this} {
require stgentor.tcl
set st_default_category [STGGlobal::getDefaultCategory]
set st_default_category "${st_default_category} Name"
set st_generate_print [STGGlobal::getGeneratePrint]
TemplateDialog new .main.stconfig \
-title "Smalltalk code generation" \
-okPressed { .main.stconfig popDown }
.main.stconfig delCancelButton
DlgColumn new .main.stconfig.col
NamedGroup new .main.stconfig.col.grp \
-label "Code generation settings"
DlgColumn new .main.stconfig.col.grp.col
DlgRow new .main.stconfig.col.grp.col.print
DlgRow new .main.stconfig.col.grp.col.category
if {$st_generate_print} {
Label new .main.stconfig.col.grp.col.print.label \
-text "- Generate print methods for classes"
} else {
Label new .main.stconfig.col.grp.col.print.label \
-text "- Not generating print methods for classes"
}
Label new .main.stconfig.col.grp.col.category.label \
-text "- \'$st_default_category\' is used as default category name"
Label new .main.stconfig.col.info \
-text "Settings can be changed using the System Properties"
}
# Do not delete this line -- regeneration end marker