xochi Posted January 12, 2012 Posted January 12, 2012 I have a file which has a two windows: a "Main" window that the user uses, and a "Log" window which holds debugging info that they don't generally see. Currently, if the user closes the Main window, then the Log window pops forward, which is not very user-friendly. I'd much rather just close the entire file if the user closes the Main window. So I'd like something like this: On Window Close if ValueCount(WindowNames(Get(FileName))) = 1 and WindowNames="Log" then # only 1 window left and it's the Log window so close the file Close File end if I thought about doing this in the OnLayoutExit trigger, but the main window has literally 100s of layouts, so adding that to every layout would take forever. Is there an easy way to do this? In particular, it needs to work if the user just clicks the window close button.
David Jondreau Posted January 12, 2012 Posted January 12, 2012 Why is the Log window open at all? With FMP Advanced, you can use a custom menu to run a script. Attach your script to the Close Window command in the File menu. If all the layouts are set to run the [File Default] menu set, you can set that in an opening script. If they're all set to Standard though, you might be out of luck. You could set those script triggers in a couple hours though just grinding it through it. That's a lot shorter than forever.
Vaughan Posted January 12, 2012 Posted January 12, 2012 Use custom menus to trap the close window command. Create a different menu set for the "main" window so that it closes all the file's open windows. One way to close all a file's open windows is to call WindowNames() function for the current file, loop through the list of windows and close them. Something like this: set variable [ $window_names = WindowNames( Get( FileName ) ) ] set variable [ $window_count = ValueCount( $window_names ) ] set variable [ $counter = 1 ] Loop Exit Loop If [ $window_count = $counter ] Close Window [ GetValue( $window_names ; $counter ) ] set variable [ $counter = $counter + 1 ] End Close Window [ ]
LaRetta Posted January 13, 2012 Posted January 13, 2012 also, if attempting to close all windows, keep in mind that if the layout has fields to related, it will open the related window again as soon as you close it. When bringing a solution in for a landing, switch to a null layout.
xochi Posted January 13, 2012 Author Posted January 13, 2012 Thanks for all the suggestions! I did some more testing. One "bright" idea I had was to add the script to the Log window's OnLayoutEnter script trigger. My thought was that once the Nth-1 window closes, the Log window would be activated and that trigger would fire. Sadly, it does not. Would be nice if there were a "OnWindowActivate"-type trigger. The File/Close menuhandler is a great idea. The users are on a separate menuset with restricted options. Question: does this technique work regardless of whether the user chooses File/Close vs. just clicking the window's close widget? Finally : I did exaggerate a bit, and if I do the brute-force approach, it's probably "dozens" of layouts not hundreds, and I could do it in under an hour. But I'd still prefer the more elegant solution if available.
dansmith65 Posted January 13, 2012 Posted January 13, 2012 Question: does this technique work regardless of whether the user chooses File/Close vs. just clicking the window's close widget? Yes, it does work when clicking the window close icon provided by the OS. also, if attempting to close all windows, keep in mind that if the layout has fields to related, it will open the related window again as soon as you close it. When bringing a solution in for a landing, switch to a null layout. I think this is a good practice to get into. I recently found that it was necessary when using SuperContainer to prevent FileMaker from crashing: http://forums.filema...1#comment138579
Recommended Posts
This topic is 4971 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now