Proper procedure to react to web messages - for "Category Changed"

Started by ubacher, January 27, 2018, 09:27:09 PM

Previous topic - Next topic

ubacher

When I look at the messages I get on the Imatch.websocket when a different category is selected I get:

Quote{"msg":"app.contextChanged","data":{"id": 252707584,"name":"CONTEXTID_PANELS_DBCLIENT_GROUP_TREE"}}
{"msg":"categories.tree.setFocus"}
{"msg":"app.contextChanged","data":{"id": 252707584,"name":"CONTEXTID_PANELS_DBCLIENT_GROUP_TREE"}}
{"msg":"app.selectedCategoriesChanged"}
{"msg":"fileWindow.selectionChanged"}
{"msg":"fileWindow.scopeChanged"}
{"msg":"fileWindow.selectionChanged"}
{"msg":"fileWindow.selectionChanged"}
{"msg":"fileWindow.focusChanged","data":{"id":1045543}}
{"msg":"fileWindow.scopeChanged"}

If I react to selectedCategoriesChanged it seems too early and I do not get the new category.
What is the recommended sequence to react to the category change so I get the correct, new category which I
then read via filewindowstate.


Mario

How to you try to "get" the new category?
When I look at the code it looks good. When the tree sends a message to IMatch about a change in the selected categories, IMatch records the selected categories in the current state, and then sends a notification over the web socket. The idlist @imatch.selectedCategories uses the cached state so it should always see the currently selected set of categories.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

As mentioned in my posting I use filewindowstate to get the category.
It should be returned in .state.title.
When I call it at app startup it works. If I call it after detecting  selectedCategoriesChangedit still contains the previous cat.
Should it work?


Mario

This is not deterministic. There can be a one second to 10 seconds delay between the user chooses a new category and the file window updates. This depends on the number of files, if filters are applied, if the new categories are cached or need to be re-calculated and on my other factors.

For your purpose, the scope changed is probably the best event. It is fired when the file is has loaded a new set of files or updated the scope for other reasons (filter, certain database operations or other events which invalidate the scope).
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook