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

Saves and loads control bindings to/from .frm files.

This commit is contained in:
FellippeHeitor 2020-02-16 14:39:59 -03:00
parent bd01e48060
commit e926e788b0
4 changed files with 115 additions and 54 deletions

View file

@ -6953,11 +6953,11 @@ SUB __UI_CheckBinding(id AS LONG)
BindTarget = Control(id).BoundTo BindTarget = Control(id).BoundTo
IF BindTarget = 0 THEN EXIT SUB IF BindTarget = 0 THEN EXIT SUB
IF Control(id).BoundProperty = Control(BindTarget).BoundProperty AND _ 'IF Control(id).BoundProperty = Control(BindTarget).BoundProperty AND _
Control(id).BoundProperty = __UI_PropertyEnum&("Value", 0) THEN ' Control(id).BoundProperty = __UI_PropertyEnum&("Value", 0) THEN
Control(id).Min = Control(BindTarget).Min ' Control(id).Min = Control(BindTarget).Min
Control(id).Max = Control(BindTarget).Max ' Control(id).Max = Control(BindTarget).Max
END IF 'END IF
SELECT CASE Control(id).BoundProperty SELECT CASE Control(id).BoundProperty
CASE __UI_PropertyEnum&("Top", 0) CASE __UI_PropertyEnum&("Top", 0)

View file

@ -107,7 +107,7 @@ DIM SHARED SourceControlLB AS LONG
DIM SHARED SourceControlNameLB AS LONG DIM SHARED SourceControlNameLB AS LONG
DIM SHARED TargetControlLB AS LONG DIM SHARED TargetControlLB AS LONG
DIM SHARED TargetControlNameLB AS LONG DIM SHARED TargetControlNameLB AS LONG
DIM SHARED SwapBT AS LONG 'DIM SHARED SwapBT AS LONG
DIM SHARED SourcePropertyLB AS LONG DIM SHARED SourcePropertyLB AS LONG
DIM SHARED SourcePropertyList AS LONG DIM SHARED SourcePropertyList AS LONG
DIM SHARED TargetPropertyLB AS LONG DIM SHARED TargetPropertyLB AS LONG
@ -189,6 +189,7 @@ REDIM SHARED PreviewControls(0) AS __UI_ControlTYPE
REDIM SHARED PreviewParentIDS(0) AS STRING REDIM SHARED PreviewParentIDS(0) AS STRING
REDIM SHARED PreviewContextMenu(0) AS STRING REDIM SHARED PreviewContextMenu(0) AS STRING
REDIM SHARED PreviewBoundTo(0) AS STRING REDIM SHARED PreviewBoundTo(0) AS STRING
REDIM SHARED PreviewBoundProperty(0) AS STRING
REDIM SHARED PreviewKeyCombos(0) AS STRING REDIM SHARED PreviewKeyCombos(0) AS STRING
REDIM SHARED PreviewAnimatedGif(0) AS _BYTE REDIM SHARED PreviewAnimatedGif(0) AS _BYTE
REDIM SHARED PreviewAutoPlayGif(0) AS _BYTE REDIM SHARED PreviewAutoPlayGif(0) AS _BYTE
@ -604,7 +605,7 @@ SUB __UI_Click (id AS LONG)
__UI_Focus = ControlList __UI_Focus = ControlList
ZOrderingDialogOpen = True ZOrderingDialogOpen = True
CASE EditMenuBindControls CASE EditMenuBindControls
'Get controls' names 'Get controls' names and bound properties
DIM CurrentSource$ DIM CurrentSource$
j = 0 j = 0
FOR i = 1 TO UBOUND(PreviewControls) FOR i = 1 TO UBOUND(PreviewControls)
@ -613,17 +614,29 @@ SUB __UI_Click (id AS LONG)
IF j = 1 THEN IF j = 1 THEN
Caption(SourceControlNameLB) = RTRIM$(PreviewControls(i).Name) Caption(SourceControlNameLB) = RTRIM$(PreviewControls(i).Name)
CurrentSource$ = PreviewBoundTo(i) CurrentSource$ = PreviewBoundTo(i)
IF LEN(PreviewBoundProperty(i)) = 0 THEN
Dummy = SelectItem(SourcePropertyList, "Value")
ELSE
Dummy = SelectItem(SourcePropertyList, PreviewBoundProperty(i))
END IF
END IF END IF
IF j = 2 THEN IF j = 2 THEN
Caption(TargetControlNameLB) = RTRIM$(PreviewControls(i).Name) Caption(TargetControlNameLB) = RTRIM$(PreviewControls(i).Name)
IF LEN(PreviewBoundProperty(i)) = 0 THEN
Dummy = SelectItem(TargetPropertyList, "Value")
ELSE
Dummy = SelectItem(TargetPropertyList, PreviewBoundProperty(i))
END IF
EXIT FOR EXIT FOR
END IF END IF
END IF END IF
NEXT NEXT
IF CurrentSource$ = Caption(TargetControlNameLB) THEN IF CurrentSource$ = Caption(TargetControlNameLB) THEN
Caption(BindBT) = "Rebind"
Caption(CancelBindBT) = "Unbind" Caption(CancelBindBT) = "Unbind"
ELSE ELSE
Caption(BindBT) = "Bind"
Caption(CancelBindBT) = "Cancel" Caption(CancelBindBT) = "Cancel"
END IF END IF
@ -632,9 +645,9 @@ SUB __UI_Click (id AS LONG)
Control(SetControlBinding).Left = 83: Control(SetControlBinding).Top = 169 Control(SetControlBinding).Left = 83: Control(SetControlBinding).Top = 169
__UI_Focus = SourcePropertyList __UI_Focus = SourcePropertyList
SetBindingDialogOpen = True SetBindingDialogOpen = True
CASE SwapBT 'CASE SwapBT
SWAP Caption(SourceControlNameLB), Caption(TargetControlNameLB) ' SWAP Caption(SourceControlNameLB), Caption(TargetControlNameLB)
SWAP Control(SourcePropertyList).Value, Control(TargetPropertyList).Value ' SWAP Control(SourcePropertyList).Value, Control(TargetPropertyList).Value
CASE BindBT CASE BindBT
Control(DialogBG).Left = -600: Control(DialogBG).Top = -600 Control(DialogBG).Left = -600: Control(DialogBG).Top = -600
Control(SetControlBinding).Left = -600: Control(SetControlBinding).Top = -600 Control(SetControlBinding).Left = -600: Control(SetControlBinding).Top = -600
@ -1596,18 +1609,6 @@ SUB __UI_BeforeUpdateDisplay
__UI_ShowInvisibleControls = CVI(thisData$) __UI_ShowInvisibleControls = CVI(thisData$)
Control(ViewMenuShowInvisibleControls).Value = __UI_ShowInvisibleControls Control(ViewMenuShowInvisibleControls).Value = __UI_ShowInvisibleControls
CASE "SHOWBINDCONTROLDIALOG" CASE "SHOWBINDCONTROLDIALOG"
b$ = ReadSequential(thisData$, 4)
IF CVL(b$) = 0 THEN
j = SelectItem(SourcePropertyList, "Value")
ELSE
j = SelectItem(SourcePropertyList, ReadSequential(thisData$, CVL(b$)))
END IF
b$ = ReadSequential(thisData$, 4)
IF CVL(b$) = 0 THEN
j = SelectItem(TargetPropertyList, "Value")
ELSE
j = SelectItem(TargetPropertyList, ReadSequential(thisData$, CVL(b$)))
END IF
__UI_Click EditMenuBindControls __UI_Click EditMenuBindControls
CASE "ORIGINALIMAGEWIDTH" CASE "ORIGINALIMAGEWIDTH"
OriginalImageWidth = CVI(thisData$) OriginalImageWidth = CVI(thisData$)
@ -3778,16 +3779,17 @@ SUB LoadPreview
b$ = ReadSequential$(FormData$, 4) b$ = ReadSequential$(FormData$, 4)
REDIM PreviewCaptions(1 TO CVL(b$)) AS STRING REDIM PreviewCaptions(0 TO CVL(b$)) AS STRING
REDIM PreviewTexts(1 TO CVL(b$)) AS STRING REDIM PreviewTexts(0 TO CVL(b$)) AS STRING
REDIM PreviewMasks(1 TO CVL(b$)) AS STRING REDIM PreviewMasks(0 TO CVL(b$)) AS STRING
REDIM PreviewTips(1 TO CVL(b$)) AS STRING REDIM PreviewTips(0 TO CVL(b$)) AS STRING
REDIM PreviewFonts(1 TO CVL(b$)) AS STRING REDIM PreviewFonts(0 TO CVL(b$)) AS STRING
REDIM PreviewActualFonts(1 TO CVL(b$)) AS STRING REDIM PreviewActualFonts(0 TO CVL(b$)) AS STRING
REDIM PreviewControls(0 TO CVL(b$)) AS __UI_ControlTYPE REDIM PreviewControls(0 TO CVL(b$)) AS __UI_ControlTYPE
REDIM PreviewParentIDS(0 TO CVL(b$)) AS STRING REDIM PreviewParentIDS(0 TO CVL(b$)) AS STRING
REDIM PreviewContextMenu(0 TO CVL(b$)) AS STRING REDIM PreviewContextMenu(0 TO CVL(b$)) AS STRING
REDIM PreviewBoundTo(0 TO CVL(b$)) AS STRING REDIM PreviewBoundTo(0 TO CVL(b$)) AS STRING
REDIM PreviewBoundProperty(0 TO CVL(b$)) AS STRING
REDIM PreviewKeyCombos(0 TO CVL(b$)) AS STRING REDIM PreviewKeyCombos(0 TO CVL(b$)) AS STRING
REDIM PreviewAnimatedGif(0 TO CVL(b$)) AS _BYTE REDIM PreviewAnimatedGif(0 TO CVL(b$)) AS _BYTE
REDIM PreviewAutoPlayGif(0 TO CVL(b$)) AS _BYTE REDIM PreviewAutoPlayGif(0 TO CVL(b$)) AS _BYTE
@ -3966,6 +3968,9 @@ SUB LoadPreview
b$ = ReadSequential$(FormData$, 2) b$ = ReadSequential$(FormData$, 2)
b$ = ReadSequential$(FormData$, CVI(b$)) b$ = ReadSequential$(FormData$, CVI(b$))
PreviewBoundTo(Dummy) = b$ PreviewBoundTo(Dummy) = b$
b$ = ReadSequential$(FormData$, 2)
b$ = ReadSequential$(FormData$, CVI(b$))
PreviewBoundProperty(Dummy) = b$
CASE -1 'new control CASE -1 'new control
EXIT DO EXIT DO
CASE -1024 CASE -1024
@ -4146,7 +4151,7 @@ SUB CheckPreview
END SUB END SUB
SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE) SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
DIM BaseOutputFileName AS STRING DIM BaseOutputFileName AS STRING, j AS LONG
DIM TextFileNum AS INTEGER, Answer AS _BYTE, b$, i AS LONG DIM TextFileNum AS INTEGER, Answer AS _BYTE, b$, i AS LONG
DIM a$, FontSetup$, FindSep AS INTEGER, NewFontFile AS STRING DIM a$, FontSetup$, FindSep AS INTEGER, NewFontFile AS STRING
DIM NewFontSize AS INTEGER, Dummy AS LONG, BackupFile$ DIM NewFontSize AS INTEGER, Dummy AS LONG, BackupFile$
@ -4485,6 +4490,31 @@ SUB SaveForm (ExitToQB64 AS _BYTE, SaveOnlyFrm AS _BYTE)
NEXT NEXT
NEXT ThisPass NEXT ThisPass
'Save control bindings
DIM BindingsSection AS _BYTE
DIM BindingDone(0 TO UBOUND(PreviewControls)) AS _BYTE
FOR i = 1 TO UBOUND(PreviewControls)
IF LEN(PreviewBoundTo(i)) > 0 AND BindingDone(i) = False THEN
IF BindingsSection = False THEN
PRINT #TextFileNum, " 'Control bindings:"
BindingsSection = True
END IF
BindingDone(i) = True
PRINT #TextFileNum, " __UI_Bind __UI_GetID(" + CHR$(34);
PRINT #TextFileNum, RTRIM$(__UI_TrimAt0$(PreviewControls(i).Name)) + CHR$(34) + "), ";
PRINT #TextFileNum, "__UI_GetID(" + CHR$(34);
PRINT #TextFileNum, PreviewBoundTo(i) + CHR$(34) + "), ";
PRINT #TextFileNum, CHR$(34) + PreviewBoundProperty(i) + CHR$(34) + ", ";
FOR j = 1 TO UBOUND(PreviewControls)
IF PreviewBoundTo(j) = RTRIM$(__UI_TrimAt0$(PreviewControls(i).Name)) THEN
BindingDone(j) = True
PRINT #TextFileNum, CHR$(34) + PreviewBoundProperty(j) + CHR$(34)
EXIT FOR
END IF
NEXT
END IF
NEXT
PRINT #TextFileNum, "END SUB" PRINT #TextFileNum, "END SUB"
PRINT #TextFileNum, PRINT #TextFileNum,
PRINT #TextFileNum, "SUB __UI_AssignIDs" PRINT #TextFileNum, "SUB __UI_AssignIDs"

View file

@ -790,9 +790,9 @@ SUB __UI_LoadForm
SetCaption __UI_NewID, "TargetControlName" SetCaption __UI_NewID, "TargetControlName"
Control(__UI_NewID).VAlign = __UI_Middle Control(__UI_NewID).VAlign = __UI_Middle
__UI_NewID = __UI_NewControl(__UI_Type_Button, "SwapBT", 160, 23, 19, 220, __UI_GetID("SetControlBinding")) '__UI_NewID = __UI_NewControl(__UI_Type_Button, "SwapBT", 160, 23, 19, 220, __UI_GetID("SetControlBinding"))
SetCaption __UI_NewID, "Swap source and target" 'SetCaption __UI_NewID, "Swap source and target"
Control(__UI_NewID).CanHaveFocus = True 'Control(__UI_NewID).CanHaveFocus = True
__UI_NewID = __UI_NewControl(__UI_Type_DropdownList, "SourcePropertyList", 380, 23, 35, 71, __UI_GetID("SetControlBinding")) __UI_NewID = __UI_NewControl(__UI_Type_DropdownList, "SourcePropertyList", 380, 23, 35, 71, __UI_GetID("SetControlBinding"))
AddItem __UI_NewID, "Top" AddItem __UI_NewID, "Top"
@ -1018,7 +1018,7 @@ SUB __UI_AssignIDs
SourceControlNameLB = __UI_GetID("SourceControlNameLB") SourceControlNameLB = __UI_GetID("SourceControlNameLB")
TargetControlLB = __UI_GetID("TargetControlLB") TargetControlLB = __UI_GetID("TargetControlLB")
TargetControlNameLB = __UI_GetID("TargetControlNameLB") TargetControlNameLB = __UI_GetID("TargetControlNameLB")
SwapBT = __UI_GetID("SwapBT") 'SwapBT = __UI_GetID("SwapBT")
SourcePropertyLB = __UI_GetID("SourcePropertyLB") SourcePropertyLB = __UI_GetID("SourcePropertyLB")
SourcePropertyList = __UI_GetID("SourcePropertyList") SourcePropertyList = __UI_GetID("SourcePropertyList")
TargetPropertyLB = __UI_GetID("TargetPropertyLB") TargetPropertyLB = __UI_GetID("TargetPropertyLB")

View file

@ -1765,22 +1765,22 @@ SUB __UI_KeyPress (id AS LONG)
CASE 227 'Toggle __UI_ShowInvisibleControls CASE 227 'Toggle __UI_ShowInvisibleControls
__UI_ShowInvisibleControls = NOT __UI_ShowInvisibleControls __UI_ShowInvisibleControls = NOT __UI_ShowInvisibleControls
CASE 228 'Bind/unbind controls CASE 228 'Bind/unbind controls
DIM a$, b$, c$, found AS _BYTE 'DIM a$, b$, c$, found AS _BYTE
DIM i AS LONG, j AS LONG 'DIM i AS LONG, j AS LONG
FOR i = 1 TO UBOUND(Control) 'FOR i = 1 TO UBOUND(Control)
IF Control(i).ControlIsSelected THEN ' IF Control(i).ControlIsSelected THEN
j = j + 1 ' j = j + 1
IF j = 1 THEN ' IF j = 1 THEN
found = __UI_PropertyEnum(a$, Control(i).BoundProperty) ' found = __UI_PropertyEnum(a$, Control(i).BoundProperty)
IF __UI_TotalSelectedControls = 1 THEN EXIT FOR ' IF __UI_TotalSelectedControls = 1 THEN EXIT FOR
ELSEIF j = 2 THEN ' ELSEIF j = 2 THEN
found = __UI_PropertyEnum(b$, Control(i).BoundProperty) ' found = __UI_PropertyEnum(b$, Control(i).BoundProperty)
EXIT FOR ' EXIT FOR
END IF ' END IF
END IF ' END IF
NEXT 'NEXT
c$ = MKL$(LEN(a$)) + a$ + MKL$(LEN(b$)) + b$ 'c$ = MKL$(LEN(a$)) + a$ + MKL$(LEN(b$)) + b$
SendData c$, "SHOWBINDCONTROLDIALOG" SendData "", "SHOWBINDCONTROLDIALOG"
END SELECT END SELECT
END SUB END SUB
@ -3075,6 +3075,30 @@ SUB LoadPreviewText
'New Control 'New Control
IF LogFileLoad THEN PRINT #LogFileNum, "READ NEW CONTROL" IF LogFileLoad THEN PRINT #LogFileNum, "READ NEW CONTROL"
EXIT DO EXIT DO
ELSEIF LEFT$(b$, 10) = "__UI_Bind " THEN
ASC(b$, 10) = 40 'Changes first space into "(" for parsing
DIM SourceControl$, TargetControl$
DIM SourceProperty$, TargetProperty$
DIM SourceSet AS _BYTE, TargetSet AS _BYTE
SourceControl$ = nextParameter$(b$)
TargetControl$ = nextParameter$(b$)
SourceProperty$ = nextParameter$(b$)
TargetProperty$ = nextParameter$(b$)
SourceSet = False: TargetSet = False
FOR i = 1 TO UBOUND(Control)
IF RTRIM$(Control(i).Name) = SourceControl$ THEN
Control(i).BoundTo = __UI_GetID(TargetControl$)
Control(i).BoundProperty = __UI_PropertyEnum(SourceProperty$, 0)
SourceSet = True
ELSEIF RTRIM$(Control(i).Name) = TargetControl$ THEN
Control(i).BoundTo = __UI_GetID(SourceControl$)
Control(i).BoundProperty = __UI_PropertyEnum(TargetProperty$, 0)
TargetSet = True
END IF
IF SourceSet AND TargetSet THEN EXIT FOR
NEXT
ELSEIF b$ = "END SUB" THEN ELSEIF b$ = "END SUB" THEN
IF LogFileLoad THEN PRINT #LogFileNum, "END OF FILE" IF LogFileLoad THEN PRINT #LogFileNum, "END OF FILE"
__UI_EOF = True __UI_EOF = True
@ -3165,18 +3189,23 @@ FUNCTION nextParameter$ (__text$)
END FUNCTION END FUNCTION
FUNCTION removeQuotation$ (__text$) FUNCTION removeQuotation$ (__text$)
DIM text$ DIM text$, firstQ AS LONG, nextQ AS LONG
text$ = __text$ text$ = __text$
IF LEFT$(text$, 1) = CHR$(34) THEN text$ = MID$(text$, 2)
IF RIGHT$(text$, 1) = CHR$(34) THEN text$ = LEFT$(text$, LEN(text$) - 1) firstQ = INSTR(text$, CHR$(34))
removeQuotation$ = text$ IF firstQ = 0 THEN removeQuotation$ = text$: EXIT FUNCTION
nextQ = INSTR(firstQ + 1, text$, CHR$(34))
IF nextQ = 0 THEN removeQuotation$ = MID$(text$, firstQ + 1): EXIT FUNCTION
removeQuotation$ = MID$(text$, firstQ + 1, nextQ - firstQ - 1)
END FUNCTION END FUNCTION
SUB SavePreview (Destination AS _BYTE) SUB SavePreview (Destination AS _BYTE)
DIM b$, i AS LONG, a$, FontSetup$, TempValue AS LONG DIM b$, i AS LONG, a$, FontSetup$, TempValue AS LONG
DIM BinFileNum AS INTEGER, TxtFileNum AS INTEGER DIM BinFileNum AS INTEGER, TxtFileNum AS INTEGER
DIM Clip$, Disk AS _BYTE, TCP AS _BYTE, UndoBuffer AS _BYTE DIM Clip$, Disk AS _BYTE, TCP AS _BYTE, UndoBuffer AS _BYTE
DIM PreviewData$ DIM PreviewData$, Dummy AS LONG
CONST Debug = False CONST Debug = False
@ -3545,6 +3574,8 @@ SUB SavePreview (Destination AS _BYTE)
END IF END IF
IF Control(i).BoundTo > 0 THEN IF Control(i).BoundTo > 0 THEN
b$ = MKI$(-48) + MKI$(LEN(RTRIM$(Control(Control(i).BoundTo).Name))) + RTRIM$(Control(Control(i).BoundTo).Name) b$ = MKI$(-48) + MKI$(LEN(RTRIM$(Control(Control(i).BoundTo).Name))) + RTRIM$(Control(Control(i).BoundTo).Name)
Dummy = __UI_PropertyEnum&(a$, Control(i).BoundProperty)
b$ = b$ + MKI$(LEN(a$)) + a$
IF Disk THEN PUT #BinFileNum, , b$ ELSE Clip$ = Clip$ + b$ IF Disk THEN PUT #BinFileNum, , b$ ELSE Clip$ = Clip$ + b$
END IF END IF
END IF END IF