New commands lose keyboard shortcut when LoadBarLayoutFromFile is called

Bars for Windows Forms Forum

Posted 3 years ago by Simon Sprott
Version: 14.1.0323
Avatar

We have an app that creates command objects up front, the state of the menu (and commands) is later persisted via SaveBarLayoutToFile.

When the app re-starts this is all re-loaded via LoadBarLayoutFromFile, this works fine and any changes the user has made to keybord shortcuts and menu layouts are re-loaded.

However if we add a new command (i.e. version 1.1 of our app has some new commands) with a shortcut key assigned to it when the LoadBarLayoutFromFile function is called it removes the keyboard shortcut for this new (previously unseen) command.

It seems to me that LoadBarLayoutFromFile should leave the command object alone if it has no entry in the XML file, but it seems to be clearing this (and maybe other) properties.

Note: this has always been the way that this has worked, but I've never gotten around to raising it in older releases!

Any thoughts?

Simon

Comments (3)

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Simon,

Yes a "complete" bar layout load will wipe out all existing commands and layout data since it is intended to be a total refresh of the layout. 

Have you tried passing "false" to the "isComplete" parameter of your SaveBarLayoutToFile?  That's the mode that is intended for apps to use at run-time in general.  When a non-complete layout is loaded, commands aren't touched.  The complete layout is more for backup purposes, such as you need to do a complete layout reset to defaults.


Actipro Software Support

Posted 3 years ago by Simon Sprott
Avatar

Hi

SaveBarLayoutToFile is always called with isComplete set to false (should I call be calling it with true the first time?), but it always clears any shortcuts associated with commands that are new (i.e. not in the previously seen in the saved layout info).

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Somon,

Ok I think I see what's happening here.  When you load a differential layout (and you do want a differential layout for application run-time save/load in general), it's running through all commands, resetting them back to their default keyboard shortcuts, and then going through the list of commands in the bar layout data that say to add/remove commands differential to those default keyboard shortcuts.  For new commands, it should be doing the reset to defaults but shouldn't be touching them afterwards.

The default keyboard shortcuts should be saved over from the KeyboardShortcuts collection for each known command when the designer initialization ends.  As long as you load your differential layout after that point, I would think that the default keyboard shortcuts for the new command would be held in place.

If you could make a new simple sample project that shows this issue and email it over to our support address, we will debug it and see what's happening to cause the problem.  Please reference this thread in your email and rename the .zip file extension of the attachment so it doesn't get spam blocked.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.