Goodies 33: Custom context menu commands
At the FileMaker conference 2019 in Hamburg there was a nice idea from Russel Watson to extend the Script Workspace further. For our context menu showing in the Script Workspace, we give you a new function SyntaxColoring.AddContextMenuCommand to register a custom menu entry. You provide a title (with ΒΆ for submenus), an expression and whether you need a selection. Once the menu item is chosen the plugin will evaluate the expression.
We expect that some developers from the FileMaker community will provide their own database with various expressions you could install. Our examples for this function show a few possible commands. Our examples show you how to just add a dialog box. Another example uses Menubar.RunMenuCommand to ask FileMaker to copy the current script steps. Then Clipboard.GetFileMakerData is used to get the XML for the script steps. This XML can be modified and passed to Clipboard.SetFileMakerData to put it back on the clipboard and paste it again with Menubar.RunMenuCommand function. As you see, you can have commands to edit script steps in place with our new feature. You can include XSLT via XML.ApplyStylesheet, using a command line tool (Shell functions) or even an AppleScript.
Here is an example video:
Available in MBS Plugin version since version 9.5. Email us if you like to try it out.
Please check the example file Script Workspace Context Menu Commands, which contains a couple of example calculations. You can add your own snippets there.
The custom menu commands are stored in the FileMaker Pro preferences file and loaded on startup of the plugin.
Add a search and replace command for FileMaker Script Workspace
Have you seen the SyntaxColoring.AddContextMenuCommand command in our latest plugin?MBS( "SyntaxColoring.AddContextMenuCommand";
"Search and Replace";
"Let ([
/* ask for search text via dialog */
ResetResult = MBS( \"Dialog.Reset\" );
ClearResult = MBS( \"Dialog.ClearFields\" );
MessageResult = MBS( \"Dialog.SetMessage\"; \"Search and replace in script:\" );
InfoResult = MBS( \"Dialog.SetInformativeText\"; \"Search text can include XML tags.\" );
Field1Result = MBS( \"Dialog.AddField\"; \"Search for:\" );
Field2Result = MBS( \"Dialog.AddField\"; \"Replace with:\" );
Button1Result = MBS( \"Dialog.SetDefaultButton\"; \"Replace\");
Button2Result = MBS( \"Dialog.SetAlternateButton\"; \"Cancel\");
DialogResult = MBS( \"Dialog.Run\" );
SearchText = MBS( \"Dialog.GetFieldText\"; 0 );
ReplaceText = MBS( \"Dialog.GetFieldText\"; 1 );
/* do replace */
r = If(DialogResult = \"Replace\"; Let([
/* copy script steps */
r = MBS( \"Menubar.RunMenuCommand\"; 57634 );
/* get XML from clipboard */
xml = MBS( \"Clipboard.GetFileMakerData\"; \"ScriptStep\" );
/* search and replace */
xml = Substitute ( xml; SearchText; ReplaceText);
/* put XML back on clipboard */
r = MBS( \"Clipboard.SetFileMakerData\"; \"ScriptStep\"; xml );
/* paste script steps */
r = MBS( \"Menubar.RunMenuCommand\"; 57637 )
]; 1))
];1)"; 3 )
Let ([
/* ask for search text via dialog */
ResetResult = MBS( "Dialog.Reset" );
ClearResult = MBS( "Dialog.ClearFields" );
MessageResult = MBS( "Dialog.SetMessage"; "Search and replace in script:" );
InfoResult = MBS( "Dialog.SetInformativeText"; "Search text can include XML tags." );
Field1Result = MBS( "Dialog.AddField"; "Search for:" );
Field2Result = MBS( "Dialog.AddField"; "Replace with:" );
Button1Result = MBS( "Dialog.SetDefaultButton"; "Replace");
Button2Result = MBS( "Dialog.SetAlternateButton"; "Cancel");
DialogResult = MBS( "Dialog.Run" );
SearchText = MBS( "Dialog.GetFieldText"; 0 );
ReplaceText = MBS( "Dialog.GetFieldText"; 1 );
/* do replace */
r = If(DialogResult = "Replace"; Let([
/* copy script steps */
r = MBS( "Menubar.RunMenuCommand"; 57634 );
/* get XML from clipboard */
xml = MBS( "Clipboard.GetFileMakerData"; "ScriptStep" );
/* search and replace */
xml = Substitute ( xml; SearchText; ReplaceText);
/* put XML back on clipboard */
r = MBS( "Clipboard.SetFileMakerData"; "ScriptStep"; xml );
/* paste script steps */
r = MBS( "Menubar.RunMenuCommand"; 57637 )
]; 1))
← Variable Colors | 33 | Text position → |