AndreasvanHaren Posted April 27, 2019 Posted April 27, 2019 Is there a way to let fm remember the open windows so that when opening the solution later, all the open windows are restored?
bcooney Posted April 28, 2019 Posted April 28, 2019 i’d bet you could script this. However, there are a lot of tricky parts. Was the window on a record that’s been deleted? Then what should happen? https://fmhelp.filemaker.com/help/17/fmp/en/index.html#page/FMP_Help%2Fwindownames.html%23 will probably come in handy. Also, you’d need to store the list per user.
AndreasvanHaren Posted April 28, 2019 Author Posted April 28, 2019 (edited) To be clear, I am not talking about the main window, but about 4 smaller windows that contain other information about the openend record. I have it now so far as that it's being remembered in a variable when a window is open or closed. When a specific window is being openend, the variable is set to 1 in the open window script. That variable is set to 0 with the script trigger OnLayoutExit of that specific window. The value of this variable is saved in a Preferences table and set to a field when opening or closing the window and this variable is being set again when the program is started, read from the preference field/variable. If it turns out to be 1, then it runs the script to open the window. I used this same methode for other things, like remembering windows positions and open tabs and it works great. However... the problem here is that if the window is open and I close the database completely, that specific window will also be closed and therefor, the variable will be set to 0 and not being openend when I start the database. Any suggestion at what point I should run the script that puts the variable to 0? Edited April 28, 2019 by AndreasvanHaren
bcooney Posted April 28, 2019 Posted April 28, 2019 Instead of storing indicators, why not have an on layout enter trigger that opens the supporting windows, if they aren’t yet opened?
tonywhitelive Posted April 29, 2019 Posted April 29, 2019 You will need to have a way to store the window locations that persists across FileMaker restarts. An Account table is good for this…either by itself or with a more relational structure: Account-<Account_Window>-Window When a user quits the system, use the OnLastWindowClose Script Trigger and store each window position as table data using Get (Functions) http://www.twdesigns.com/filemaker-15-functions-list/ When the user logs back in, use onFirstWindowOpen to trigger a script that uses Get (AccountName) to located the saved window settings for that AccountName. Then use the Windowing scripts steps: New Window, Move/Resize Window, etc. to restore the windows.
AndreasvanHaren Posted April 29, 2019 Author Posted April 29, 2019 9 hours ago, bcooney said: Instead of storing indicators, why not have an on layout enter trigger that opens the supporting windows, if they aren’t yet opened? The main window has 5 layouts and the supporting windows and the supporting windows could be open at any point. Wouldn't this mean I have to run the same script from every layout? Still, the man problem is: how does the solution remember if a window was closed or open after closing the program? 4 hours ago, tonywhitelive said: You will need to have a way to store the window locations that persists across FileMaker restarts. An Account table is good for this…either by itself or with a more relational structure: Account-<Account_Window>-Window When a user quits the system, use the OnLastWindowClose Script Trigger and store each window position as table data using Get (Functions) http://www.twdesigns.com/filemaker-15-functions-list/ When the user logs back in, use onFirstWindowOpen to trigger a script that uses Get (AccountName) to located the saved window settings for that AccountName. Then use the Windowing scripts steps: New Window, Move/Resize Window, etc. to restore the windows. The solution is only to be used by a single user, would using account tables still be needed to do this? I never worked with the user account option in fm, not sure how to use this part of the program yet.
tonywhitelive Posted April 29, 2019 Posted April 29, 2019 (edited) Make a script named “Save Window Sizes and Positions” and tell the user to run that script before closing The “Save Window Sizes and Positions” script Uses the WindowNames design function to get the names of open windows Loops through the list or window names looking for windows that you want to restore (using the Select Window script step) Use Get functions and and set field to save window settings to a table Use a script named “Restore Window Sizes and Positions” to restore the windows Use onFirstWindowOpen to trigger a script that runs on open (or run the script from a button) Read the data stored about the saved windows Loop through the window data and use the New Window script step to open windows (from the correct context) with the correct name and position. Edited April 29, 2019 by tonywhitelive 1
AndreasvanHaren Posted April 29, 2019 Author Posted April 29, 2019 Thanks for the help. I was able to put this script together, it only seems to remember the last window in the variable though. Not sure if I am on the right track for what I am trying to do.
AndreasvanHaren Posted April 30, 2019 Author Posted April 30, 2019 Things work better already. Running the script with an extra window open is being reopened when restarting the solution. However, it seems that only the window that is focused on at the moment I run the Save script, is being set correctly in the variable. How can all the windows that are open at the moment of running the save script, being remembered? Here is my current script:
bcooney Posted April 30, 2019 Posted April 30, 2019 https://fmhelp.filemaker.com/help/17/fmp/en/#page/FMP_Help%2Fwindownames.html
AndreasvanHaren Posted April 30, 2019 Author Posted April 30, 2019 33 minutes ago, bcooney said: https://fmhelp.filemaker.com/help/17/fmp/en/#page/FMP_Help%2Fwindownames.html Yes, I am able to get the list with open windows, but I don't see how this can be used to restore them again after a restart. 33 minutes ago, bcooney said:
comment Posted April 30, 2019 Posted April 30, 2019 (edited) 14 minutes ago, AndreasvanHaren said: I don't see how this can be used to restore them again If you have a script that opens a window named "Calculator", then your restore script should have something like: If [ not IsEmpty ( FilterValues ( "Calculator" ; $listOfWindows ) ) ] Perform Script [ "Open Calculator Window" ] End If Edited April 30, 2019 by comment
AndreasvanHaren Posted April 30, 2019 Author Posted April 30, 2019 1 hour ago, comment said: If you have a script that opens a window named "Calculator", then your restore script should have something like: If [ not IsEmpty ( FilterValues ( "Calculator" ; $listOfWindows ) ) ] Perform Script [ "Open Calculator Window" ] End If Thanks! This appears to be much easier than I thought. It looks like a loop script isn't needed either, right? Just the script step Windownames. Only weird thing is that this only seems to remember 4 windows in total. A 5th open window will not open with restart. But I cannot image that a user will ever have 5 windows open at the time.
comment Posted April 30, 2019 Posted April 30, 2019 52 minutes ago, AndreasvanHaren said: It looks like a loop script isn't needed either, right? It depends: If you want to restore all existing windows and what's in them, no matter how they were created, then you will need a looping script to store the data of each open window (including name, current layout, and any other detail you will want to restore), and another looping script to reopen all these windows and restore all their remembered details. But if - as it seems - you have 4 predefined windows, with a script to open each one, then you only need to remember the names of the currently opened ones and run the corresponding scripts on restore - none of which requires looping. 1 hour ago, AndreasvanHaren said: this only seems to remember 4 windows in total I am afraid I don't follow you here. The WindowNames function returns the names of all open windows.
AndreasvanHaren Posted May 1, 2019 Author Posted May 1, 2019 11 hours ago, comment said: It depends: If you want to restore all existing windows and what's in them, no matter how they were created, then you will need a looping script to store the data of each open window (including name, current layout, and any other detail you will want to restore), and another looping script to reopen all these windows and restore all their remembered details. But if - as it seems - you have 4 predefined windows, with a script to open each one, then you only need to remember the names of the currently opened ones and run the corresponding scripts on restore - none of which requires looping. What I miss now is actually that their positions are not being saves, so I probalby do need a looping for this to make that work. 11 hours ago, comment said: I am afraid I don't follow you here. The WindowNames function returns the names of all open windows. It seems also random on which windows are being saved AND openend even if the names are saved in a variable. According to the custom dialoge window that runs after restarting, only 4 out of 5 (main window and 4 extra) windows are being remembered, and it seems to be depending on in which order I had the windows openend. This is the save script: And this is the script that runs when restarting the solution:
comment Posted May 1, 2019 Posted May 1, 2019 4 minutes ago, AndreasvanHaren said: It seems also random on which windows are being saved AND openend even if the names are saved in a variable. You can see which windows were saved by looking at the contents of the Preferences::OpenWindows field. As for reopening, find out which one is not being reopened and examine your script for errors in that section (most likely, the names do not match exactly). Nothing a computer does is random.
AndreasvanHaren Posted May 1, 2019 Author Posted May 1, 2019 1 minute ago, comment said: You can see which windows were saved by looking at the contents of the Preferences::OpenWindows field. As for reopening, find out which one is not being reopened and examine your script for errors in that section (most likely, the names do not match exactly). Nothing a computer does is random. Yes, I did that by using a custom dialogue window which is being run after a restart and immediately after the preferences are being read. Even with all windows open saved, the result is always different. Also, when only having a single windows open up till 3 extra windows, everything works correctly. It goes wrong the moment I add that 4th extra window. This can be any kind of window, it doesn't depend on which window.
AndreasvanHaren Posted May 1, 2019 Author Posted May 1, 2019 I found out why not all windows were listed. They were listed but I didn't see them, because... the custom dialogue window was not resized long enough to show them to me! 🤫
AndreasvanHaren Posted May 1, 2019 Author Posted May 1, 2019 All the windows are now being restored after restarting the solution, this is great! Thanks so much for the help. Only one thing to do is restoring the zoom level from these windows. I know how to set the current window zoom in a variable, but how do I restore it? I cannot find a zoom script step that can be defined by a variable.
comment Posted May 1, 2019 Posted May 1, 2019 (edited) It seems you need to do this the old fashioned way: if the stored zoom level is 25, then set the zoom level to 25%. Else if ... Edited May 3, 2019 by comment
AndreasvanHaren Posted May 2, 2019 Author Posted May 2, 2019 Thanks. I got it to work. All windows are now remembered on position, zoom level and also size.
AndreasvanHaren Posted May 3, 2019 Author Posted May 3, 2019 After a zoom setting I add an Adjust window step so the layout of that window will be shown correctly without scroll bars, however this also places a window in a way that it always stays inside the visible area of the screen, even though it was half off screen when saving the windows settings before closing the solution. Is there are way to avoid this from happening?
comment Posted May 4, 2019 Posted May 4, 2019 I am not sure why you need to adjust the window after you have restored its original size. Anyway, you can add a Move/Resize Window step to move the adjusted window to the stored position.
AndreasvanHaren Posted May 4, 2019 Author Posted May 4, 2019 3 hours ago, comment said: I am not sure why you need to adjust the window after you have restored its original size. You have a valid point there, something must be wrong. I will check this.
Recommended Posts
This topic is 2028 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