1
1
Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2025-01-15 11:59:34 +00:00

Preserves existing code when overwriting .bas files. Closes #14.

This commit is contained in:
FellippeHeitor 2018-05-20 10:55:08 -03:00
parent 8addacb12a
commit 5c9ecff2b8

View file

@ -124,11 +124,6 @@ TYPE newInputBox
Sent AS _BYTE
END TYPE
TYPE newExistingControl
Name AS STRING * 40
Status AS _BYTE '0 = Kept, 1 = Renamed, 2 = Deleted, 3 = Added
END TYPE
CONST OffsetEditorPID = 1
CONST OffsetPreviewPID = 5
CONST OffsetWindowLeft = 9
@ -160,7 +155,6 @@ REDIM SHARED PreviewParentIDS(0) AS STRING
REDIM SHARED zOrderIDs(0) AS LONG
REDIM SHARED InputBox(1 TO 100) AS newInputBox
REDIM SHARED InputBoxText(1 TO 100) AS STRING
REDIM SHARED ExistingControls(1 TO 100) AS newExistingControl
DIM SHARED PreviewDefaultButtonID AS LONG
'DIM SHARED FontList.Names AS STRING
@ -6312,6 +6306,7 @@ SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
DIM TextFileNum AS INTEGER, Answer AS _BYTE, b$, i AS LONG
DIM a$, FontSetup$, FindSep AS INTEGER, NewFontFile AS STRING
DIM NewFontSize AS INTEGER, Dummy AS LONG, BackupFile$
DIM PreserveBackup AS _BYTE, BackupCode$
BaseOutputFileName = CurrentPath$ + PathSep$ + RTRIM$(PreviewControls(PreviewFormID).Name)
IF _FILEEXISTS(BaseOutputFileName + ".bas") OR _FILEEXISTS(BaseOutputFileName + ".frm") THEN
@ -6341,14 +6336,22 @@ SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
OPEN BackupFile$ + "-backup" FOR BINARY AS #TextFileNum
PUT #TextFileNum, 1, b$
CLOSE #TextFileNum
IF i = 1 THEN
IF INSTR(b$, "': External modules: ---------------------------------------------------------------") > 0 THEN
BackupCode$ = MID$(b$, INSTR(b$, "': External modules: ---------------------------------------------------------------"))
PreserveBackup = True
END IF
END IF
END IF
NEXT
TextFileNum = FREEFILE
OPEN BaseOutputFileName + ".frm" FOR OUTPUT AS #TextFileNum
PRINT #TextFileNum, "': This form was generated by"
PRINT #TextFileNum, "': InForm - GUI system for QB64 - "; __UI_Version
PRINT #TextFileNum, "': InForm - GUI library for QB64 - "; __UI_Version
PRINT #TextFileNum, "': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor"
PRINT #TextFileNum, "': https://github.com/FellippeHeitor/InForm"
PRINT #TextFileNum, "'-----------------------------------------------------------"
PRINT #TextFileNum, "SUB __UI_LoadForm"
PRINT #TextFileNum,
@ -6576,18 +6579,32 @@ SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
CLOSE #TextFileNum
IF NOT SaveOnlyFrm THEN
OPEN BaseOutputFileName + ".bas" FOR OUTPUT AS #TextFileNum
PRINT #TextFileNum, "': This program was generated by"
PRINT #TextFileNum, "': InForm - GUI system for QB64 - "; __UI_Version
PRINT #TextFileNum, "': This program uses"
PRINT #TextFileNum, "': InForm - GUI library for QB64 - "; __UI_Version
PRINT #TextFileNum, "': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor"
PRINT #TextFileNum, "': https://github.com/FellippeHeitor/InForm"
PRINT #TextFileNum, "'-----------------------------------------------------------"
PRINT #TextFileNum,
PRINT #TextFileNum, "': Controls' IDs: ------------------------------------------------------------------"
IF PreserveBackup THEN
PRINT #TextFileNum, "REM NOTICE: THIS FORM HAS BEEN RECENTLY EDITED"
PRINT #TextFileNum, "'>> The controls in the list below may have been added or renamed,"
PRINT #TextFileNum, "'>> and previously existing controls may have been deleted since"
PRINT #TextFileNum, "'>> this program's structure was first generated."
PRINT #TextFileNum, "'>> Make sure to check your code in the events SUBs so that"
PRINT #TextFileNum, "'>> you can take your recent edits into consideration."
PRINT #TextFileNum, "': ---------------------------------------------------------------------------------"
END IF
FOR i = 1 TO UBOUND(PreviewControls)
IF PreviewControls(i).ID > 0 AND PreviewControls(i).Type <> __UI_Type_Font AND PreviewControls(i).Type <> __UI_Type_MenuPanel AND PreviewControls(i).Type <> __UI_Type_ContextMenu THEN
PRINT #TextFileNum, "DIM SHARED " + RTRIM$(__UI_TrimAt0$(PreviewControls(i).Name)) + " AS LONG"
END IF
NEXT
PRINT #TextFileNum,
IF PreserveBackup THEN
PRINT #TextFileNum, BackupCode$
GOTO BackupRestored
END IF
PRINT #TextFileNum, "': External modules: ---------------------------------------------------------------"
PRINT #TextFileNum, "'$INCLUDE:'InForm\InForm.ui'"
PRINT #TextFileNum, "'$INCLUDE:'InForm\xp.uitheme'"
@ -6677,6 +6694,7 @@ SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
PRINT #TextFileNum, "END SUB"
PRINT #TextFileNum,
NEXT
BackupRestored:
CLOSE #TextFileNum
END IF