Jump to content
Sign in to follow this  
AndreasvanHaren

Restoring open windows possible?

Recommended Posts

Is there a way to let fm remember the open windows so that when opening the solution later, all the open windows are restored?

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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 by AndreasvanHaren

Share this post


Link to post
Share on other sites

Instead of storing indicators, why not have an on layout enter trigger that opens  the supporting windows, if they aren’t yet opened? 

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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 by tonywhitelive

Share this post


Link to post
Share on other sites

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.

1772085481_Screenshot2019-04-29at19_54_22.thumb.png.0d54f377e64939cc72c525059a383f3d.png

 

 

 

Share this post


Link to post
Share on other sites

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:

1936064283_Screenshot2019-04-30at07_02_07.thumb.png.6623bd6bf0def06d90e59d4615aa0eaa.png

 

Share this post


Link to post
Share on other sites
33 minutes ago, bcooney said:

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:

 

 

Share this post


Link to post
Share on other sites
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 by comment

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

1963137126_Screenshot2019-05-01at07_50_12.png.6a20260281e16d9359db1682027f4070.png

And this is the script that runs when restarting the solution:841044984_Screenshot2019-05-01at07_54_50.thumb.png.e8ede09be4272dda5ea8bdcb3b493377.png

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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! 🤫

 

 

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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 by comment

Share this post


Link to post
Share on other sites

Thanks. I got it to work. All windows are now remembered on position, zoom level and also size. 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.