An experimental GetTextSheet procedure


#1

I was intrigued by the suggestion made on this forum a while back for the gettext window to be a sheet attached to the active window. I worked out a unique method to do this using a procedure that would be called from any another procedure. There are no permanent forms involved since the procedure will first create a new blank form, open it as a sheet attached to the current window, set the form options and then create all the form objects on the fly. When text has been entered and one of the buttons have been pressed or the editor closed the sheet window is closed and the form itself is deleted.

The calling format would be: call .gettextsheet theText, thePrompt

Once the call is made the new GetTextSheet would open on the form and operate as a normal GetText would operate but as a sheet instead. Here is what the GetTextSheet looks like in action:

The TextEditor opens with all existing text highlighted and ready to go. Hitting Enter or Return or the OK button will return the new text value while Stop returns the original text value. Here is the procedure code for the needed procedure you would name .gettextsheet. Of course this could be easily converted into a custom statement.

__TheText__=parameter(2)
__ThePrompt__=parameter(1)
local targetFormName
define targetFormName,"•••"
makenewform targetFormName
opendialogsheet "•••","Rectangle",rectanglesize(1,1,150,450)
restoreFormFromBlueprint:
setformoptions "",targetFormName,
    "ALTERNATINGBACKGROUNDCOLORS",-1,
    "BACKGROUNDCOLOR",htmlrgb("EDEDED")
makeFormObjectsFromBluePrint:
newformobject "ImageDisplayObject",
    "rectangle",rectanglesize(12, 23, 62, 62),
    "color",htmlrgb("000000"),
    "Procedure","if info({modifiers}) contains {option} closewindow endif",
    "Formula",""""+bundleresourcepath("")+"/AppIcon.icns""",
    "$ImageDisplayAlignment","Proportional"
newformobject "PushButtonObject",
    "rectangle",rectanglesize(82, 221, 26, 80),
    "color",htmlrgb("000000"),
    "name","",
    "TextSize","13 px",
    "ControlSize","Regular",
    "Procedure","resume {}",
    "$PushButtonStyle","Push Button",
    "Title","Stop"
newformobject "PushButtonObject",
    "rectangle",rectanglesize(82, 319, 26, 88),
    "color",htmlrgb("000000"),
    "name","",
    "TextSize","13 px",
    "ControlSize","Regular",
    "Procedure","resume {}",
    "Title","Ok",
    "$PushButtonDefaultButton","1"
newformobject "TextEditorObject",
    "rectangle",rectanglesize(44, 101, 22, 308),
    "color",htmlrgb("000000"),
    "name","Button.Ok",
    "$TextEditorTerminateReturn","1",
    "$TextEditorTriggerFinished","1",
    "$TextEditorEditWindowHeight","100",
    "$TextEditorEmptyPrompt","Enter text...",
    "Procedure","resume {}",
    "$TextEditorInsertionPoint","All",
    "$TextEditorDataMode","Field/Variable",
    "FieldName","__TheText__",
    "$TextEditorBorderStyle","Bezel",
    "$TextEditorEditWindowWidth","100",
    "TextSize","13 px",
    "$TextEditorFocusRing","1",
    "Alignment","Left",
    "$TextEditorTerminateTab","0",
    "$TextEditorUpdateVariableEveryKey","1"
newformobject "TextDisplayObject",
    "rectangle",rectanglesize(14, 99, 22, 308),
    "color",htmlrgb("000000"),
    "Formula","__ThePrompt__",
    "TextSize","14 px",
    "$TextDisplayFormulaMode","Formula",
    "$TextDisplayAutoScaleSize","1",
    "$TextDisplayVerticalTextAlignment","Center",
    "Alignment","Left",
    "Font","#SystemBoldFont"
selectnoobjects
settrigger ""
SuperObject "Button.Ok","Open"
pause {}
SuperObject "Button.Ok","Close"
closewindow
setformoptions "","•••","DELETE",""
If info("trigger")="Button.Ok"
    setparameter 2, __TheText__
Endif
undefine __TheText__, __ThePrompt__
return```

For convenience I have my test file available containing two procedures, the one shown above as well as another in the Action menu called GetTextSheet which will demonstrate how the call to .gettextsheet works in practice.

http://www.unseensoft.com/Gettextsheet.zip

I tried to make this version have the exact same look as the standard `gettext` statement but in a sheet format.

Why isn't entry box open when gettext is invoked?
#2

That is exactly what I asked for! It looks great. Now what would go with it is MessageSheet, to unify the look. I suspect I could adapt that from your work, but it is late now.


#3

You can do that with alertsheet.


#4

Very nice! Much better than message!


#5

This is excellent. Thanks Gary. I plan to replace all of my Gettext statements with this new approach.


#6

I have rewritten the procedure to use the more standard rundialog statement taking advantage of the Dialog.Initialize trigger to populate the form. Also added a trap at the beginning in case the form was never deleted in a previous use. Note the use of a rectangle set to 0% opacity which is added to keep a background click from closing the Text Editor & dialog inadvertently. Note also that the Text Editor is named “Button.Ok” which will force the dialog to close when the Text Editor is closed. Finally, I also changed the name of the newly created form to “•|•|•” to further reduce the likelihood another existing form may be similarly named. You could change this to any name you want since it will never be displayed anywhere. Here is the revised procedure:

__theText__=parameter(2)
__thePrompt__=parameter(1)
local targetFormName
define targetFormName,"•|•|•"
If dbinfo("forms","") contains targetFormName
    setformoptions "",targetFormName,"DELETE",""
    //removes old form if for some reason it was not previously deleted
endif
makenewform targetFormName
setformoptions "",targetFormName,
            "ALTERNATINGBACKGROUNDCOLORS",-1,
            "BACKGROUNDCOLOR",htmlrgb("EDEDED")
            //had to run form options before opening form to take effect
loop
    rundialog {Form=}+targetFormName+{ Height=150 Width=450 sheet=true CancelButton=Stop}
    stoploopif info("trigger") = "Dialog.Close"
    if info("trigger") contains "Dialog.Initialize"
        makeFormObjectsFromBluePrint:
        newformobject  "RectangleShapeObject",
            "rectangle",rectanglesize(0, 0, 267, 679),
            "Opacity","0 %"
            //this object keeps the Text Editor from closing if the background is clicked
        newformobject "ImageDisplayObject",
            "rectangle",rectanglesize(12, 23, 62, 62),
            "color",htmlrgb("000000"),
            "Procedure","if info({modifiers}) contains {option} closewindow endif",
            "Formula",""""+bundleresourcepath("")+"/AppIcon.icns""",
            "$ImageDisplayAlignment","Proportional"
        newformobject "PushButtonObject",
            "rectangle",rectanglesize(82, 221, 26, 80),
            "color",htmlrgb("000000"),
            "name","",
            "TextSize","13 px",
            "ControlSize","Regular",
            "Procedure","resume {}",
            "$PushButtonStyle","Push Button",
            "Title","Stop"
        newformobject "PushButtonObject",
            "rectangle",rectanglesize(82, 319, 26, 88),
            "color",htmlrgb("000000"),
            "name","",
            "TextSize","13 px",
            "ControlSize","Regular",
            "Procedure","resume {}",
            "Title","Ok",
            "$PushButtonDefaultButton","1"
        newformobject "TextEditorObject",
            "rectangle",rectanglesize(44, 101, 22, 308),
            "color",htmlrgb("000000"),
            "name","Button.Ok",
            "$TextEditorTerminateReturn","1",
            "$TextEditorTriggerFinished","1",
            "$TextEditorEditWindowHeight","100",
            "$TextEditorEmptyPrompt","Enter text...",
            "Procedure","resume {}",
            "$TextEditorInsertionPoint","All",
            "$TextEditorDataMode","Field/Variable",
            "FieldName","__theText__",
            "$TextEditorBorderStyle","Bezel",
            "$TextEditorEditWindowWidth","100",
            "TextSize","13 px",
            "$TextEditorFocusRing","1",
            "Alignment","Left",
            "$TextEditorTerminateTab","0",
            "$TextEditorUpdateVariableEveryKey","1"
            //named Text Editor "Button.Ok" to return properly close the dialog
        newformobject "TextDisplayObject",
            "rectangle",rectanglesize(14, 99, 22, 308),
            "color",htmlrgb("000000"),
            "Formula","__thePrompt__",
            "TextSize","13 px",
            "$TextDisplayFormulaMode","Formula",
            "$TextDisplayAutoScaleSize","1",
            "$TextDisplayVerticalTextAlignment","Center",
            "Alignment","Left",
            "Font","#SystemBoldFont"
        selectnoobjects
        SuperObject "Button.Ok","Open"
        settrigger ""
    endif
endloop
setformoptions "",targetFormName,"DELETE",""
If dlgResult≠"Cancel"
    setparameter 2, __theText__
Endif
undefine __theText__, __thePrompt__```

I notice on **Bitbucket #489** that Jim mentioned he intended for some time to make his own sheet version of `GetText` so this might all be an exercise in futility, but an enjoyable endeavor nonetheless on my part .

The three 'gettext' statements are very awkward to use
#7

If I press either “Stop” or “Ok,” the only difference is that the Ok button changes the value of parameter(2), while pressing Stop does not stop the procedure that calls it, it just runs with the initial value of parameter(2).

Testing this, I ran into the same problem noted elsewhere: After I edit the procedure, if it is the topmost window, closing it crashes Panorama X, on the release version of Sierra.


#8

Change the last lines from:

If dlgResult≠"Cancel"
    setparameter 2, __theText__
Endif
undefine __theText__, __thePrompt__

To:

If dlgResult≠"Cancel"
    setparameter 2, __theText__
Else
    settrigger "Stop"
Endif
undefine __theText__, __thePrompt__
If info("trigger")="Stop"
    stop
Endif

#9

Thanks Gary - this is good.