From: marko Date: Wed, 22 Jun 2005 15:39:51 +0000 (+0000) Subject: Initial import X-Git-Tag: initial~8 X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=f7bd2258c0fa300b60dd50a953836f90abd607b6;p=imunes.git Initial import --- diff --git a/filemgmt.tcl b/filemgmt.tcl new file mode 100755 index 0000000..60f4c68 --- /dev/null +++ b/filemgmt.tcl @@ -0,0 +1,189 @@ +# +# Copyright 2004, 2005 University of Zagreb, Croatia. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the University of Zagreb, +# Croatia and its contributors. +# 4. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# This work was supported in part by Croatian Ministry of Science +# and Technology through the research contract #IP-2003-143. +# + + +# +# currentFile +# relative or absolute path to the current configuration file +# +# fileTypes +# types that will be displayed when opening new file +# +# +# procedures used for loading and storing the configuration file: +# +# newFile +# - creates an empty project +# +# openFile +# - loads configuration from currentFile +# +# saveFile {selectedFile} +# - saves current configuration to a file named selectedFile +# unless the file name is an empty string +# +# fileOpenStartUp +# - opens the file named as command line argument +# +# fileNewDialogBox +# - opens message box to optionally save the changes +# +# fileOpenDialogBox +# - opens dialog box for selecting a file to open +# +# fileSaveDialogBox +# - opens dialog box for saving a file under new name if there is no +# current file +# +# fileSaveAsDialogBox +# - opens dialog box for saving a file under new name + + +set currentFile "" + +set fileTypes {{"IMUNES network configuration" {.imn} } + { "All files" {*}}} + + +proc newFile {} { + global currentFile + + vimageCleanup + loadCfg "" + redrawAll + set currentFile "" + wm title . "IMUNES" +} + + +proc openFile {} { + global currentFile + global undolevel + global redolevel + global undolog + global activetool + + set fileName [file tail $currentFile] + wm title . "IMUNES $fileName" + set fileId [open $currentFile r] + set cfg "" + foreach entry [read $fileId] { + lappend cfg $entry + } + close $fileId + loadCfg $cfg + redrawAll + set undolevel 0 + set redolevel 0 + set undolog(0) $cfg + set activetool select +} + + +proc saveFile { selectedFile } { + global currentFile + if { $selectedFile != ""} { + set currentFile $selectedFile + set fileName [file tail $currentFile] + wm title . "IMUNES $fileName" + set fileId [open $currentFile w] + dumpCfg file $fileId + close $fileId + .bottom.textbox config -text "Saved $fileName" + } +} + + +proc fileOpenStartUp {} { + global argv + global currentFile + + if { $argv != "" } { + set currentFile $argv + openFile + } +} + + +proc fileNewDialogBox {} { + global currentFile + + set choice [tk_messageBox -type yesnocancel -default yes\ + -message "Save changes?" -icon question] + + if { $choice != "cancel"} { + if { $choice == "yes"} { + fileSaveDialogBox + newFile + } else { + newFile + } + } +} + + +proc fileOpenDialogBox {} { + global currentFile + global fileTypes + set selectedFile [tk_getOpenFile -filetypes $fileTypes] + if { $selectedFile != ""} { + set currentFile $selectedFile + openFile + } +} + + +proc fileSaveDialogBox {} { + global currentFile + global fileTypes + + if { $currentFile == "" } { + set selectedFile [tk_getSaveFile -filetypes $fileTypes -initialfile\ + untitled -defaultextension .imn] + saveFile $selectedFile + } else { + saveFile $currentFile + } +} + + +proc fileSaveAsDialogBox {} { + global currentFile + global fileTypes + set selectedFile [tk_getSaveFile -filetypes $fileTypes -initialfile\ + untitled -defaultextension .imn] + + saveFile $selectedFile +}