home *** CD-ROM | disk | FTP | other *** search
/ TestDrive Super Store 3.0 / TESTDRIVE_3.ISO / realizer / formdev / savefile.rlz < prev    next >
Encoding:
Text File  |  1992-09-30  |  5.5 KB  |  200 lines

  1. '***********************************************************************
  2. '    FormDev: SaveFile.RLZ
  3. '
  4. '    Copyright ⌐ 1991-1992 Computer Associates International, Inc.
  5. '    All rights reserved.
  6. '
  7. '***********************************************************************
  8.  
  9. PROC FDShutdown ()
  10.     IF SaveIfChanged("Save current form before exiting FormDev?") = _Cancel THEN
  11.         EXIT PROC
  12.     END IF
  13.     ' Reset the world.
  14.     RESET _All - _Log
  15.     EXIT PROGRAM
  16. END PROC
  17.  
  18. PROC ShutdownProc (v)
  19.     IF v[_Invoke] = _Close THEN
  20.         FDShutdown()
  21.         v[_UseRealizer] = 0
  22.     END IF
  23. END PROC
  24.  
  25. FUNC SaveIfChanged(message)
  26.     IF fdChanged THEN
  27.         SELECT CASE MessageBox(message, "FormDev", _MB_YesNoCancel, _MB_Question)
  28.             CASE _Yes
  29.                 IF SaveForm(1) = 0 THEN
  30.                     RETURN _Cancel
  31.                 END IF
  32.                 RETURN _Yes
  33.             CASE _No
  34.                 RETURN _No
  35.             CASE _Cancel
  36.                 RETURN _Cancel
  37.         END SELECT
  38.     END IF
  39.     RETURN 0
  40. END FUNC
  41.  
  42. FUNC ReplaceDlg(fName)
  43.     SELECT CASE MessageBox("Replace existing " + fName + "?", "FormDev", _MB_YesNoCancel, _MB_Question)
  44.         CASE _Yes
  45.             RETURN 1
  46.         CASE _No, _Cancel
  47.             RETURN 0
  48.     END SELECT
  49. END FUNC
  50.  
  51. FUNC SaveForm(sType)
  52.     'sType = 0 for save and 1 for save as
  53.  
  54.     LOCAL    fdSaveForm, fdFileName, fdFileDir, fdOutLog, fdOutFile, badDir
  55.     LOCAL    dirPart, filePart
  56.  
  57.     PROC SetGrayNormal (toNormal; ..)
  58.         LOCAL    rsAttr, J
  59.         rsAttr = IF toNormal THEN _Normal ELSE _Gray
  60.         FOR J = 1 TO QNOptMods
  61.             FormModifyObject(QOptMod(J), rsAttr)
  62.         NEXT
  63.     END PROC
  64.  
  65.     fdFileDir = LCase$(fdOpenPath)
  66.     fdSaveForm = FormQUnique
  67.     FormNew(fdSaveForm; "Save File", _Title)
  68.     FormControl(_Size; _Center, _Center, 50 pct, 80 pct)
  69.  
  70.     FormSetObject(10, _CaptionLeft, "Directory:", 3 pct, 4 pct)
  71.     FormSetObject(14, _CaptionLeft, "Form Name:", 3 pct, 14 pct)
  72.     IF sType THEN
  73.         FormSetObject(11, _TextBox, fdFileDir, 34 pct, 3 pct, 61 pct, _Default)
  74.         FormSetObject(15, _TextBox, theform.name, 34 pct, 13 pct, 61 pct, _Default)
  75.     ELSE
  76.         FormSetObject(11, _CaptionLeft, fdFileDir, 35 pct, 4 pct)
  77.         FormSetObject(15, _CaptionLeft, theform.name, 35 pct, 14 pct)
  78.     END IF
  79.  
  80.     FormSetObject(20, _CheckBox, "Generate Code", 10 pct, 24 pct; _Notify, bitand(theform.saveflags, 1))
  81.  
  82.     FormSetObject(30, _GroupBox, "Generate:", 7 pct, 34 pct, 86 pct, 49 pct)
  83.     FormSetObject(40, _OptionButton, "Form creation code only", 10 pct, 41 pct; bitand(theform.saveflags, 4))
  84.     FormSetObject(50, _OptionButton, "Form creation and processing", 10 pct, 51 pct; bitand(theform.saveflags, 8))
  85.     FormSetObject(60, _OptionButton, "Full application", 10 pct, 61 pct; bitand(theform.saveflags, 16))
  86.     FormSetObject(70, _CheckBox, "Show code", 10 pct, 71 pct; bitand(theform.saveflags, 2))
  87.     SetGrayNormal(FormQNum(20); 40, 50, 60, 70)
  88.  
  89.     FormSetObject(1, _DefButton, "OK", _Left, _Bottom)
  90.     FormSetObject(2, _Button, "Cancel", _Right, _Bottom)
  91.     LOOP
  92.         FormSelect(fdSaveForm)
  93.         LOOP
  94.             SELECT CASE FormWait
  95.                 CASE 2
  96.                     FormControl(_Close)
  97.                     FormSelect(fdMain)
  98.                     RETURN 0
  99.                 CASE 1
  100.                     IF ValidFormName(FormQStr(15)) THEN
  101.                         EXIT LOOP
  102.                     END IF
  103.                     FormSetFoc(15)
  104.                 CASE 20
  105.                     SetGrayNormal(FormQNum(20); 40, 50, 60, 70)
  106.             END SELECT
  107.         END LOOP
  108.         theform.saveflags = FormQNum(20) + 2*FormQNum(70) + 4*FormQNum(40) + 8*FormQNum(50) + 16*FormQNum(60)
  109.         fdFileDir = FormQStr(11)
  110.         IF FileQ(fdFileDir, _Directory) THEN
  111.             badDir = 0
  112.         ELSEIF Len(fdFileDir) = 2 AND Right$(fdFileDir, 1) = ":" THEN
  113.             badDir = 2
  114.         ELSEIF Len(fdFileDir) = 3 AND Right$(fdFileDir, 2) = ":\" THEN
  115.             badDir = 2
  116.         ELSE
  117.             badDir = 1
  118.         END IF
  119.         IF badDir = 2 THEN
  120.             IF FileQ(fdFileDir + ".", _Directory) THEN
  121.                 badDir = 0
  122.                 fdFileDir = fdFileDir + "."
  123.             END IF
  124.         END IF
  125.         IF badDir THEN
  126.             INPUT "Invalid directory.", "FormDev";
  127.             FormSetFoc(11)
  128.         ELSE
  129.             IF Right$(fdFileDir, 1) <> "\" THEN
  130.                 fdFileDir = fdFileDir + "\"
  131.             END IF
  132.             fdFileName = fdFileDir + FormQStr(15) + ".RFD"
  133.             IF FDParseFN(fdFileName, ".RFD", dirPart, filePart) THEN
  134.                 SELECT CASE FileQ(fdFileName, _Exists)
  135.                     CASE 0    ' File doesn't exist
  136.                         EXIT LOOP
  137.                     CASE 1    ' File exists
  138.                         IF sType = 0 THEN
  139.                             EXIT LOOP
  140.                         END IF
  141.                         IF ReplaceDlg(fdFileName) THEN
  142.                             EXIT LOOP
  143.                         END IF
  144.                     CASE 2    ' File Read-ONLY
  145.                         INPUT "Unable to write to a Read-Only file.", "FormDev";                     
  146.                         FormSetFoc(15)
  147.             END SELECT
  148.             END IF
  149.         END IF
  150.     END LOOP
  151.     FormSelect(fdSaveForm)
  152.     FormControl(_Close)
  153.     FormSelect(fdMain)
  154.     fdOpenPath = dirPart
  155.     theform.name = filePart
  156.  
  157.     SetHourglass
  158.  
  159.     fdChanged = 0 
  160.     MainFormLocate
  161.     ItemsLocateAll
  162.  
  163.     'Write the RFD file out
  164.     ItemsIntoRaw
  165.     fdFileName = fdOpenPath + theform.name
  166.     IF fdNumItems > 0 THEN
  167.         FileExport(fdFileName + ".RFD", _Realizer, _Named, theform, item, fonts, fdNumItems, fdNextItem)    
  168.     ELSE
  169.         FileExport(fdFileName + ".RFD", _Realizer, _Named, theform, fonts, fdNumItems, fdNextItem)    
  170.     END IF    
  171.     ItemsIntoPixels
  172.  
  173.     fdFormSaved = 1
  174.     IF bitand(theform.saveflags, 1) THEN
  175.         fdOutLog = LogQUnique
  176.         LogNew(fdOutLog; fdFileName + ".code")
  177.         IF NOT(GenerateCode(fdOutLog, theform.saveflags)) THEN
  178.             ResetHourglass
  179.             INPUT "The form was saved, but the code generation failed.", "FormDev";
  180.             RETURN 0
  181.         ELSE
  182.             'Write out source file.
  183.             fdOutFile = FileQUnique
  184.             FileOpen(fdOutFile, fdFileName + ".RLZ", _Write)
  185.             FileWrite(fdOutFile, LogQStr(1))
  186.             FileClose(fdOutFile)
  187.             ResetHourglass
  188.             IF bitand(theform.saveflags, 2) THEN
  189.                 LogControl(_Show)
  190.             ELSE
  191.                 INPUT "Code generation complete.", "FormDev";
  192.                 LogControl(_Close)
  193.             END IF
  194.         END IF
  195.     END IF
  196.  
  197.     ResetHourglass
  198.     RETURN 1
  199. END FUNC
  200.