/// <summary> /// Converts a Sce.Atf.Input.Keys to a System.Windows.Input.ModifierKeys</summary> /// <param name="atfKeys">AtfKeys enum</param> /// <returns>Converted WpfModifierKeys enum</returns> public static WpfModifierKeys ToWpfModifiers(AtfKeys atfKeys) { // TODO: need to verify this all works correctly var modifiers = atfKeys &= AtfKeys.Modifiers; WpfModifierKeys result = WpfModifierKeys.None; if ((modifiers & AtfKeys.Alt) > 0) { result |= WpfModifierKeys.Alt; } if ((modifiers & AtfKeys.Shift) > 0) { result |= WpfModifierKeys.Shift; } if ((modifiers & AtfKeys.Control) > 0) { result |= WpfModifierKeys.Control; } if ((atfKeys & AtfKeys.RWin) > 0 || (atfKeys & AtfKeys.RWin) > 0) { result |= WpfModifierKeys.Windows; } return(result); }
private void RegisterClientCommands() { int clientCount = m_documentClients.Length; // for each document client, build file/new and file/open commands int index = 0; foreach (Lazy <IDocumentClient> lazy in m_documentClients) { IDocumentClient client = lazy.Value; Keys newShortcut = Keys.None; Keys openShortcut = Keys.None; if (index == 0) { newShortcut = Keys.Control | Keys.N; openShortcut = Keys.Control | Keys.O; } string newIconName = client.Info.NewIconName; if ((RegisterCommands & CommandRegister.FileNew) == CommandRegister.FileNew) { CommandService.RegisterCommand( new CommandInfo( new FileCommandTag(Command.FileNew, client), StandardMenu.File, StandardCommandGroup.FileNew, clientCount > 1 ? "New".Localize("Name of a command") + '/' + client.Info.FileType : string.Format("New {0}".Localize(), client.Info.FileType), string.Format("Creates a new {0} document".Localize("{0} is the type of document to create"), client.Info.FileType), newShortcut, newIconName, (!string.IsNullOrEmpty(newIconName)) ? CommandVisibility.All : CommandVisibility.Menu), this); } string openIconName = client.Info.OpenIconName; if ((RegisterCommands & CommandRegister.FileOpen) == CommandRegister.FileOpen) { CommandService.RegisterCommand( new CommandInfo( new FileCommandTag(Command.FileOpen, client), StandardMenu.File, StandardCommandGroup.FileNew, clientCount > 1 ? "Open".Localize("Name of a command") + '/' + client.Info.FileType : string.Format("Open {0}".Localize(), client.Info.FileType), string.Format("Open an existing {0} document".Localize(), client.Info.FileType), openShortcut, openIconName, (!string.IsNullOrEmpty(openIconName)) ? CommandVisibility.All : CommandVisibility.Menu), this); } index++; } }
// Removes a shortcut from the Keys property of all Shortcut objects private void RemoveShortcut(Keys key) { if (key == Keys.None) { return; } foreach (Shortcut shortcut in m_shortcuts) { if (shortcut.Keys.Contains(key)) { List <Keys> newKeys = new List <Keys>(shortcut.Keys); newKeys.Remove(key); shortcut.Keys = newKeys; } } }
/// <summary> /// Processes the key as a command shortcut</summary> /// <param name="key">Key to process</param> /// <returns>True iff the key was processed as a command shortcut</returns> public override bool ProcessKey(Keys key) { if (key == Keys.F1 && m_lastHoveringToolStrip != null) { foreach (var item in m_lastHoveringToolStrip.Items) { var button = item as ToolStripButton; if (button != null) { if (button.Selected) { foreach (KeyValuePair <CommandInfo, CommandControls> commandAndControl in m_commandControls) { if (commandAndControl.Value.Button == button && !string.IsNullOrEmpty(commandAndControl.Key.HelpUrl)) { // There doesn't seem to be a way to prevent the WM_HELP message that gets generated // during the call to Process.Start(). We can't add a filter to every Control's // WndProc. So, let's use a static way of stopping WebHelp for a little bit. WebHelp.SupressHelpRequests = true; Process.Start(commandAndControl.Key.HelpUrl); if (m_webHelpTimer == null) { m_webHelpTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(1000) }; m_webHelpTimer.Tick += (o, e) => { WebHelp.SupressHelpRequests = false; m_webHelpTimer.Stop(); }; } m_webHelpTimer.Start(); return(true); } } } } } } return(base.ProcessKey(key)); }
private string GetUsedByText(Keys key) { var sb = new StringBuilder(); if (key != Keys.None) { // linearly search for a command that uses this shortcut foreach (Shortcut shortcut in m_shortcuts) { if (shortcut.Keys.Contains(key)) { sb.AppendLine(shortcut.DisplayPath + "\r\n" + shortcut.Info.Description); break; } } } return(sb.ToString()); }
public static SelectMode GetSelectMode(Keys modifiers) { Sce.Atf.Input.Keys modkeys = KeysInterop.ToAtf(modifiers); if (ActiveControlScheme.ToggleSelection != Sce.Atf.Input.Keys.None && modkeys == ActiveControlScheme.ToggleSelection) { return(SelectMode.Toggle); } if (ActiveControlScheme.AddSelection != Sce.Atf.Input.Keys.None && modkeys == ActiveControlScheme.AddSelection) { return(SelectMode.Extend); } if (ActiveControlScheme.RemoveSelection != Sce.Atf.Input.Keys.None && modkeys == ActiveControlScheme.RemoveSelection) { return(SelectMode.Remove); } return(SelectMode.Normal); }
/// <summary> /// Converts a Sce.Atf.Input.Keys to a System.Windows.Input.ModifierKeys</summary> /// <param name="atfKeys">AtfKeys enum</param> /// <returns>Converted WpfModifierKeys enum</returns> public static WpfModifierKeys ToWpfModifiers(AtfKeys atfKeys) { var modifiers = atfKeys & AtfKeys.Modifiers; var result = WpfModifierKeys.None; if ((modifiers & AtfKeys.Alt) > 0) { result |= WpfModifierKeys.Alt; } if ((modifiers & AtfKeys.Shift) > 0) { result |= WpfModifierKeys.Shift; } if ((modifiers & AtfKeys.Control) > 0) { result |= WpfModifierKeys.Control; } return(result); }
/// <summary> /// Converts a Sce.Atf.Input.Keys to a System.Windows.Input.ModifierKeys</summary> /// <param name="atfKeys">AtfKeys enum</param> /// <returns>Converted WpfModifierKeys enum</returns> public static WpfModifierKeys ToWpfModifiers(AtfKeys atfKeys) { // TODO: need to verify this all works correctly var modifiers = atfKeys &= AtfKeys.Modifiers; WpfModifierKeys result = WpfModifierKeys.None; if ((modifiers & AtfKeys.Alt) > 0) result |= WpfModifierKeys.Alt; if ((modifiers & AtfKeys.Shift) > 0) result |= WpfModifierKeys.Shift; if ((modifiers & AtfKeys.Control) > 0) result |= WpfModifierKeys.Control; if ((atfKeys & AtfKeys.RWin) > 0 || (atfKeys & AtfKeys.RWin) > 0) result |= WpfModifierKeys.Windows; return result; }
private void RegisterClientCommands() { var clientList = m_documentClients.Select(l => l.Value) .Where(dc => dc.Info.AllowStandardFileCommands) .ToList(); // for each document client, build file/new and file/open commands var index = 0; foreach (var client in clientList) { Keys newShortcut = Keys.None; Keys openShortcut = Keys.None; if (index == 0) { newShortcut = Keys.Control | Keys.N; openShortcut = Keys.Control | Keys.O; } object newIconKey = client.Info.NewIconKey; string newIconName = client.Info.NewIconName; if ((RegisterCommands & CommandRegister.FileNew) == CommandRegister.FileNew) { CommandService.RegisterCommand( new CommandInfo( new FileCommandTag(Command.FileNew, client), StandardMenu.File, StandardCommandGroup.FileNew, clientList.Count > 1 ? "New".Localize("Name of a command") + '/' + client.Info.FileType : string.Format("New {0}".Localize(), client.Info.FileType), string.Format("Creates a new {0} document".Localize("{0} is the type of document to create"), client.Info.FileType), newShortcut, (newIconKey != null) ? newIconKey : newIconName, ((!string.IsNullOrEmpty(newIconName)) || (newIconKey != null)) ? CommandVisibility.All : CommandVisibility.Menu), this); } object openIconKey = client.Info.OpenIconKey; string openIconName = client.Info.OpenIconName; if ((RegisterCommands & CommandRegister.FileOpen) == CommandRegister.FileOpen) { CommandService.RegisterCommand( new CommandInfo( new FileCommandTag(Command.FileOpen, client), StandardMenu.File, StandardCommandGroup.FileNew, clientList.Count > 1 ? "Open".Localize("Name of a command") + '/' + client.Info.FileType : string.Format("Open {0}".Localize(), client.Info.FileType), string.Format("Open an existing {0} document".Localize(), client.Info.FileType), openShortcut, (openIconKey != null) ? openIconKey : openIconName, ((!string.IsNullOrEmpty(openIconName)) || (openIconKey != null)) ? CommandVisibility.All : CommandVisibility.Menu), this); } index++; } }
/// <summary> /// Process ATF message and command key by calling the base ProcessCmdKey with converted arguments, /// which allows this key press to be consumed by owning /// controls like PropertyView and PropertyGridView and be seen by ControlHostService. /// Returning false allows the key press to escape to IsInputKey, OnKeyDown, OnKeyUp, etc. /// Returning true means that this key press has been consumed by this method and this /// event is not passed on to any other methods or controls.</summary> /// <param name="msg">ATF message to process</param> /// <param name="keyData">ATF key data</param> /// <returns>False to allow the key press to escape to IsInputKey, OnKeyDown, OnKeyUp, etc. /// True to consume this key press, so this /// event is not passed on to any other methods or controls.</returns> protected virtual bool ProcessCmdKey(ref AtfMessage msg, AtfKeys keyData) { WfMessage wfMsg = MessageInterop.ToWf(msg); return(base.ProcessCmdKey(ref wfMsg, KeysInterop.ToWf(keyData))); }
/// <summary> /// Tests if ATF key is an input key by calling Windows IsInputKey with converted argument</summary> /// <param name="keyData">ATF key data</param> /// <returns>True iff key is an input key</returns> protected virtual bool IsInputKey(AtfKeys keyData) { return(base.IsInputKey(KeysInterop.ToWf(keyData))); }
/// <summary> /// Modifies the given collection with the given items based on standard Windows convention /// of using the Control key to toggle the selection of items, Shift key to add the items, /// and otherwise to set the selection to the items</summary> /// <typeparam name="T">The type of items contained in the selection</typeparam> /// <param name="collection">Collection of already selected items that is modified</param> /// <param name="items">Items to add or remove from collection, or to set the collection to</param> /// <param name="modifiers">Selection modifier AtfKeys</param> public static void Select <T>(ICollection <T> collection, IEnumerable <T> items, AtfKeys modifiers) { Input.KeysUtil.Select(collection, items, modifiers); }
/// <summary> /// Converts a Sce.Atf.Input.Keys to a System.Windows.Input.ModifierKeys</summary> /// <param name="atfKeys">AtfKeys enum</param> /// <returns>Converted WpfModifierKeys enum</returns> public static WpfModifierKeys ToWpfModifiers(AtfKeys atfKeys) { var modifiers = atfKeys & AtfKeys.Modifiers; var result = WpfModifierKeys.None; if ((modifiers & AtfKeys.Alt) > 0) result |= WpfModifierKeys.Alt; if ((modifiers & AtfKeys.Shift) > 0) result |= WpfModifierKeys.Shift; if ((modifiers & AtfKeys.Control) > 0) result |= WpfModifierKeys.Control; return result; }
/// <summary> /// Converts a Sce.Atf.Input.Keys to a System.Windows.Forms.Keys</summary> /// <param name="keys">AtfKeys enum</param> /// <returns>Converted WfKeys enum</returns> public static WfKeys ToWf(AtfKeys keys) { return (WfKeys)keys; }
/// <summary> /// Modifies the given collection with the given item based on standard Windows convention /// of using the Control key to toggle the selection of the given item, Shift key to add the /// item, and otherwise to set the selection to the item</summary> /// <typeparam name="T">The type of items contained in the selection</typeparam> /// <param name="collection">Collection of already selected items that is modified</param> /// <param name="item">Item to add or remove from collection</param> /// <param name="modifiers">Selection modifier AtfKeys</param> public static void Select <T>(ICollection <T> collection, T item, AtfKeys modifiers) { Input.KeysUtil.Select(collection, item, modifiers); }
// Removes a shortcut from the Keys property of all Shortcut objects private void RemoveShortcut(Keys key) { if (key == Keys.None) return; foreach (Shortcut shortcut in m_shortcuts) { if (shortcut.Keys.Contains(key)) { List<Keys> newKeys = new List<Keys>(shortcut.Keys); newKeys.Remove(key); shortcut.Keys = newKeys; } } }
private string GetUsedByText(Keys key) { var sb = new StringBuilder(); if (key != Keys.None) { // linearly search for a command that uses this shortcut foreach (Shortcut shortcut in m_shortcuts) { if (shortcut.Keys.Contains(key)) { sb.AppendLine(shortcut.DisplayPath + "\r\n" + shortcut.Info.Description); break; } } } return sb.ToString(); }
/// <summary> /// Converts a AtfKeys value to a string</summary> /// <param name="k">AtfKeys value</param> /// <param name="digitOnly">If true, for numeric pad or digit keys, only return /// the number. For example, numpad0 becomes 0, and D0 becomes 0.</param> /// <returns>String representation of the AtfKeys value</returns> public static string KeysToString(AtfKeys k, bool digitOnly) { return(Input.KeysUtil.KeysToString(k, digitOnly)); }
/// <summary> /// Returns whether or not the given modifier AtfKeys should add an item from a selection</summary> /// <param name="modifiers">Modifier AtfKeys</param> /// <returns>Whether or not the given modifier AtfKeys should add an item from a selection</returns> public static bool AddsSelection(AtfKeys modifiers) { return(Input.KeysUtil.AddsSelection(modifiers)); }
/// <summary> /// Returns whether or not the given modifier AtfKeys should toggle an item from a selection</summary> /// <param name="modifiers">Modifier AtfKeys</param> /// <returns>Whether or not the given modifier AtfKeys should toggle an item from a selection</returns> public static bool TogglesSelection(AtfKeys modifiers) { return(Input.KeysUtil.TogglesSelection(modifiers)); }
/// <summary> /// Determines whether or not the given AtfKeys should be considered a TextBox input and be handled /// by that control. For example, if this method returns true, ProcessCmdKey should return false /// and not call base.ProcessCmdKey.</summary> /// <param name="isMultiline">Whether the control (typically a TextBox or ComboBox) that received the key press is multiline</param> /// <param name="k">AtfKeys value</param> /// <returns>Whether or not the given key press should be considered a TextBox input</returns> /// <remarks> /// Some examples from a class deriving from TextBox and what its ProcessCmdKey should do: /// Keypress | IsInputKey | ProcessCmdKey should | Because /// -------- ---------- ------------------------- -------------------------------------- /// s false return false Even if this is a command shortcut, the TextBox input takes priority. /// 1 false return false Even if this is a command shortcut, the TextBox input takes priority. /// F10 false return base.ProcessCmdKey Might be a command shortcut. /// Ctrl+Z false return base.ProcessCmdKey Might be a command shortcut and that takes priority over the TextBox's limited undo. /// Ctrl+C false return false The TextBox copy command takes priority. /// Home true return false The TextBox navigation takes priority. /// Delete false return false The TextBox navigation takes priority. Why does IsInputKey() return false?! .NET bug? /// Up false return false We want our IsInputKey override to receive this. /// </remarks> public static bool IsTextBoxInput(bool isMultiline, AtfKeys k) { return(Input.KeysUtil.IsTextBoxInput(isMultiline, k)); }
/// <summary> /// Converts a Sce.Atf.Input.Keys to a System.Windows.Input.Key</summary> /// <remarks>Warning: this will only return a single Key as the WPF Key /// structure is not flags based</remarks> /// <param name="atfKey">AtfKeys enum</param> /// <returns>Converted WpfKey enum</returns> public static WpfKey ToWpf(AtfKeys atfKey) { var keys = atfKey & ~AtfKeys.Modifiers; return(System.Windows.Input.KeyInterop.KeyFromVirtualKey((int)keys)); }
/// <summary> /// Returns whether or not the given AtfKeys represents a human-readable character that could /// be inserted into a text box, for example</summary> /// <param name="k">AtfKeys value</param> /// <returns>True iff the given AtfKeys value represents a human-readable character</returns> public static bool IsPrintable(AtfKeys k) { return(Input.KeysUtil.IsPrintable(k)); }
/// <summary> /// Attempts to process the key as a command shortcut</summary> /// <param name="key">Key to process</param> /// <returns>True iff the key was processed as a command shortcut</returns> public bool ProcessKey(Sce.Atf.Input.Keys key) { throw new NotImplementedException(); }
/// <summary> /// Converts a Sce.Atf.Input.Keys to a System.Windows.Input.Key</summary> /// <remarks>Warning: this will only return a single Key as the WPF Key /// structure is not flags based</remarks> /// <param name="atfKey">AtfKeys enum</param> /// <returns>Converted WpfKey enum</returns> public static WpfKey ToWpf(AtfKeys atfKey) { var keys = atfKey & ~AtfKeys.Modifiers; return System.Windows.Input.KeyInterop.KeyFromVirtualKey((int)keys); }
/// <summary> /// Processes the key as a command shortcut</summary> /// <param name="key">Key to process</param> /// <returns>True iff the key was processed as a command shortcut</returns> public override bool ProcessKey(Keys key) { if (key == Keys.F1 && m_lastHoveringToolStrip != null) { foreach (var item in m_lastHoveringToolStrip.Items) { var button = item as ToolStripButton; if (button != null) { if (button.Selected) { foreach (KeyValuePair<CommandInfo, CommandControls> commandAndControl in m_commandControls) { if (commandAndControl.Value.Button == button && !string.IsNullOrEmpty(commandAndControl.Key.HelpUrl)) { // There doesn't seem to be a way to prevent the WM_HELP message that gets generated // during the call to Process.Start(). We can't add a filter to every Control's // WndProc. So, let's use a static way of stopping WebHelp for a little bit. WebHelp.SupressHelpRequests = true; Process.Start(commandAndControl.Key.HelpUrl); if (m_webHelpTimer == null) { m_webHelpTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(1000) }; m_webHelpTimer.Tick += (o, e) => { WebHelp.SupressHelpRequests = false; m_webHelpTimer.Stop(); }; } m_webHelpTimer.Start(); return true; } } } } } } return base.ProcessKey(key); }
/// <summary> /// Tests if ATF key is an input key by calling Windows IsInputKey with converted argument</summary> /// <param name="keyData">ATF key data</param> /// <returns>True iff key is an input key</returns> protected virtual bool IsInputKey(AtfKeys keyData) { return base.IsInputKey(KeysInterop.ToWf(keyData)); }
/// <summary>Converts numeric pad AtfKeys to digit AtfKeys</summary> /// <param name="keys">AtfKeys number pad keys</param> /// <returns>AtfKeys digit equivalent</returns> public static AtfKeys NumPadToNum(AtfKeys keys) { return(Input.KeysUtil.NumPadToNum(keys)); }
/// <summary> /// Converts a Sce.Atf.Input.Keys to a System.Windows.Forms.Keys</summary> /// <param name="keys">AtfKeys enum</param> /// <returns>Converted WfKeys enum</returns> public static WfKeys ToWf(AtfKeys keys) { return((WfKeys)keys); }
/// <summary> /// Process ATF message and command key by calling the base ProcessCmdKey with converted arguments, /// which allows this key press to be consumed by owning /// controls like PropertyView and PropertyGridView and be seen by ControlHostService. /// Returning false allows the key press to escape to IsInputKey, OnKeyDown, OnKeyUp, etc. /// Returning true means that this key press has been consumed by this method and this /// event is not passed on to any other methods or controls.</summary> /// <param name="msg">ATF message to process</param> /// <param name="keyData">ATF key data</param> /// <returns>False to allow the key press to escape to IsInputKey, OnKeyDown, OnKeyUp, etc. /// True to consume this key press, so this /// event is not passed on to any other methods or controls.</returns> protected virtual bool ProcessCmdKey(ref AtfMessage msg, AtfKeys keyData) { WfMessage wfMsg = MessageInterop.ToWf(msg); return base.ProcessCmdKey(ref wfMsg, KeysInterop.ToWf(keyData)); }
/// <summary> /// Converts an ATF key code that invokes a command to the WPF keyboard combination used to invoke that command</summary> /// <param name="atfKey">ATF key code</param> /// <returns>WPF keyboard combination to invoke the command</returns> public static KeyGesture ConvertKey(Sce.Atf.Input.Keys atfKey) { return(ConvertKey(KeysInterop.ToWf(atfKey))); }
/// <summary> /// Reserves a shortcut key, so it is not available as a command shortcut</summary> /// <param name="key">Reserved key</param> /// <param name="reason">Reason why key is reserved, to display to user</param> public void ReserveKey(Sce.Atf.Input.Keys key, string reason) { throw new NotImplementedException(); }