Portage Bay
Solutions
Portage Bay

Navigating Multiple Windows in Windows

With the introduction of FileMaker 16 for Windows, the FileMaker interface was redesigned to handle multiple windows, more akin to the Mac OS. Instead of using one application window, Windows users can now run multiple windows, each with their own menu and toolbars.

Multiple windows in FileMaker 15 and prior in Windows OS

 

Multiple windows in FileMaker 16 and up in Windows OS

While this is a better way of handling windows for most solutions, it can cause some unforeseen issues when upgrading from prior versions of FileMaker to v16. We recently came across this issue with a client’s application that was built with data and interface elements separated into multiple files. Prior to 16, in Windows, each “Go to Related Record” (GTRR) script step activated the window holding the related records, but in 16, the child window would show behind the parent window unless the “Select Window” was specified subsequent to the GTRR step. On top of that, unless a “Close/Hide Window” was specified, the user would be left with a number of erroneous windows, causing even more confusion.

As with most processes, we decided to take a modular look at building a fix for handling the multiple windows. In the end, our solution wasn’t exactly modular by definition, but it did allow for one parent script to handle the window selection process. Since the application uses a single file as a sort of “global access” menu file, we decided to use that file as the primary window handler. This file would contain the script that selected the window the user wanted to see, then hide all other windows. Since the client wanted to be able to open new windows from the menu, but didn’t want to those windows to stay open when navigating between files, the process also closes additional windows that were created using “New Window” from the menu.

The entire process boiled down to two scripts: one script would be copied to all files to handle the window-hiding, and one script would exist only in the global menu file to handle the active window selection. The window-selector script runs the “hide window” script in each file, then selects the appropriate window that the user should see.

First, the window-selector script:

# Selects the appropriate window based on the param passed into it and hides all other windows
#
# Get selected window from param
Set Variable [ $SelectedWindow ; Value: Get ( ScriptParameter ) ]
#
# Get list of all open windows
Set Variable [ $WindowList ; Value: WindowNames ]
#
# Do not run when there's only one window open (typically on startup)
If [ ValueCount ( $WindowList ) > 1 ]
    # Verify that selected window exists in the available window names
     If [ PatternCount ( $WindowList ; $SelectedWindow ) > 0 ]
          #
          # Hide and close all other windows
          Perform Script [ “HideWindow” from file: “FILE1” ; Parameter: "FILE1" ]
          Perform Script [ “HideWindow” from file: “FILE2” ; Parameter: "FILE2"]
          Perform Script [ “HideWindow” from file: “FILE3” ; Parameter: "FILE3" ]
          Perform Script [ “HideWindow” from file: “FILE4” ; Parameter: "FILE4" ]
          Perform Script [ “HideWindow” from file: “FILE5” ; Parameter: "FILE5" ]
          Perform Script [ “HideWindow” from file: “FILE6” ; Parameter: "FILE6" ]
          Perform Script [ “HideWindow” from file: “FILE7” ; Parameter: "FILE7" ]
          #
          # Hide the global Menu file if it’s not the selected window#
          If [ $SelectedWindow ≠ "Menu" ]
                Adjust Window [ Hide ]
          End If
          #
          # Show selected window
          Select Window [ Name: $SelectedWindow ]
          #
    Else
          # Selected window does not exist. Show error
          Show Custom Dialog [ "The selected window " & $SelectedWindow & " does not exist. Please contact your system administrator." ]
          #
    End If
End If

Here’s the script which exists in all files that handles the window-hiding/closing:

# Selects the appropriate window based on the param passed into it and hides all other windows
#
# Get selected window from param
Set Variable [ $SelectedWindow ; Value: Get ( ScriptParameter ) ]
#
# Get the open windows for the current file only
Set Variable [ $windows ; Value: WindowNames ( Get ( FileName ) ) ]
#
# If multiple windows exist for the current file, close all iterations except the initial file window
Set Variable [ $total ; Value: ValueCount ( $windows ) ]
If [ $total > 1 ]
    # Loop through windows and close
    Set Variable [ $counter ; Value: 1 ]
    Loop
          # get window name from list
          Set Variable [ $WindowName ; Value: GetValue ( $windows ; $counter ) ]
          If [ $SelectedWindow ≠ $WindowName ]
              Close Window [ Name: $WindowName ]
          End If
          Set Variable [ $counter ; Value: $counter + 1 ]
          Exit Loop If [ $counter > ( $total ) ]
    End Loop
End If
#
# Hide window
Adjust Window [ Hide ]

The only caveat to this entire process is, the window-selection script needs to be called each time another file is called with the application. We attempted a number of alternatives to achieve the desired result using script triggers, but couldn’t quite get the result we were looking for.

How would you approach this scenario? Let us know your thoughts in the comments below.