Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

YadaConfigItem.tcl

00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## YadaConfigItem - interface for configurable objects. 00013 ## This class has no implementation and only serves as a marker of derived 00014 ## configurable items in YadaConfigDocument. 00015 ## \ingroup YadaConfiguration 00016 ## 00017 ## \author Michael Daum 00018 ## 00019 ## $Id: YadaConfigItem.tcl,v 1.7 2004/09/06 13:41:13 micha Exp $ 00020 ## ---------------------------------------------------------------------------- 00021 class YadaConfigItem { 00022 protected variable _modified 0 00023 00024 public variable name 00025 00026 public method load {} 00027 public method save {} 00028 public method toDOM {} 00029 public method fromDOM {node}; ## \type domNode 00030 public method hasSavedState {} 00031 public method isModified {} 00032 public method setModified {} 00033 public method resetModified {} 00034 public method displayTitle {} 00035 public method getPersistanceFileName {}; ## \purevirtual 00036 }; 00037 00038 00039 00040 ## ---------------------------------------------------------------------------- 00041 ## Serializes object state to unique file (depends on object name) 00042 ## ---------------------------------------------------------------------------- 00043 body YadaConfigItem::save {} { 00044 set domNode [toDOM] 00045 set fileNameToSave [getPersistanceFileName] 00046 00047 if { [::file exists ${fileNameToSave}.gz] } { 00048 ::file delete ${fileNameToSave}.gz 00049 } 00050 00051 set fileID [open $fileNameToSave {CREAT WRONLY}] 00052 puts $fileID [$domNode asXML] 00053 close $fileID 00054 00055 if {[catch {exec gzip -f $fileNameToSave} errMsg]} { 00056 error "Saving failed: $errMsg" 00057 } 00058 resetModified 00059 } 00060 00061 ## ---------------------------------------------------------------------------- 00062 ## Loads object state from unique file (depends on object name) 00063 ## ---------------------------------------------------------------------------- 00064 body YadaConfigItem::load {} { 00065 set zippedFileName [getPersistanceFileName].gz 00066 00067 if { ![::file exists $zippedFileName]} { 00068 error "File $zippedFileName not found." 00069 } 00070 00071 set fileID [open "|zcat $zippedFileName" {RDONLY}] 00072 set xmlData [read $fileID] 00073 close $fileID 00074 00075 set document [dom parse $xmlData] 00076 fromDOM [$document documentElement] 00077 resetModified 00078 00079 } 00080 00081 00082 ## ---------------------------------------------------------------------------- 00083 ## Predicate returning 1, if configuration data has changed, 0 otherwise 00084 ## ---------------------------------------------------------------------------- 00085 body YadaConfigItem::isModified {} { 00086 return $_modified 00087 } 00088 00089 ## ---------------------------------------------------------------------------- 00090 ## Marks item as modified 00091 ## ---------------------------------------------------------------------------- 00092 body YadaConfigItem::setModified {} { 00093 set _modified 1 00094 if { [string compare $name "<none>"] == 0 } { 00095 return 00096 } 00097 displayTitle 00098 } 00099 00100 ## ---------------------------------------------------------------------------- 00101 ## Removes modification mark 00102 ## ---------------------------------------------------------------------------- 00103 body YadaConfigItem::resetModified {} { 00104 set _modified 0 00105 displayTitle 00106 } 00107 00108 00109 ## ---------------------------------------------------------------------------- 00110 ## Predicate returning 1, if file containing persistant state of YadaGrammar 00111 ## exists, otherwise 0 00112 ## ---------------------------------------------------------------------------- 00113 body YadaConfigItem::hasSavedState {} { 00114 set zippedFileName [getPersistanceFileName].gz 00115 if { [::file exists $zippedFileName] } { 00116 return 1 00117 } else { 00118 return 0 00119 } 00120 } 00121 00122 00123 ## ---------------------------------------------------------------------------- 00124 ## Displays title in main window (reflecting modification state of document) 00125 ## ---------------------------------------------------------------------------- 00126 body YadaConfigItem::displayTitle {} { 00127 if { [isModified] && $name != "<none>" } { 00128 wm title . "$name *** changed *** " 00129 } else { 00130 wm title . "$name" 00131 } 00132 } 00133 00134 00135 00136

YADA 2.0-alpha (20 Oct 2004)