Opentribe KeyCuts is a C# open source library which provide a new way of managing shortcuts in WPF applications.
In WPF applications following the Model View ViewModel architecture pattern, Keyboard shortcups are commonly managed via the ICommand and Window CommandBinding. The WPF solution is, from my point of view, heavy and not elegant.
In my previous job I used the command pattern to implement the Undo/Redo. I recently used in my current job a middleware implemented by an external guys who used the command pattern in the same way.
In my very first job I worked on a multimedia authoring tool (iShell) which was based on the command pattern. Commands were used to represent graphically a kind of script which was executed. When I started my current job in 2009, my new colleagues were surprised to see how I was familiar with their program. It is based on the command pattern to represent graphically a kind of script…
Obviously, the command pattern can be used in various situations like GUI buttons and menu items, macro recording, Mobile code, multi-level undo…
By the way, I have recently implemented a memento library to manage undo/redo. It is not based on the command design pattern nor the memento pattern… it is something between. And it is something out of the model and independent of the GUI.
Shortcuts is a GUI problem. Shortcuts problem has been solved in a simply and elegant way in Winforms or Delphi. I do not like how the problem is solved in WPF for 2 reasons :
- love to click on event and add source directly in the delegate method provide by the IDE.
- I do not want to write source code to manage this kind of stuff (I do not like to write code for UI).
- I do not want to write commands in my UI.
Initialize the sortcuts
// add the using reference
// in your dialog / Window constructor initialize the shortcuts
// in the MenuItem properties, set the Click event
<MenuItem Header=”Save” Click=”MenuItem_Click”/>
// in the MenuItem properties, set the InputGestuteText
<MenuItem Header=”Save” Click=”MenuItem_Click” InputGestureText=”Ctrl+S”/>
Thats all !!!
Copyright (c) 2017 Fred Morales <firstname.lastname@example.org> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of mosquitto nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.