void OnAccelEntryKeyPress(object sender, KeyPressEventArgs e) { Gdk.Key key = e.Event.Key; string accel; e.RetVal = true; if (accelComplete) { CurrentBinding = String.Empty; accelIncomplete = false; accelComplete = false; mode = null; if (key.Equals(Gdk.Key.BackSpace)) { return; } } accelComplete = false; bool combinationComplete; accel = KeyBindingManager.AccelFromKey(e.Event, out combinationComplete); if (combinationComplete) { CurrentBinding = KeyBindingManager.Binding(mode, accel); accelIncomplete = false; if (mode != null) { accelComplete = true; } else { mode = accel; } } else { accel = (mode != null ? mode + "|" : String.Empty) + accel; accelIncomplete = true; CurrentBinding = accel; } }
void OnAccelEntryKeyPress(object sender, KeyPressEventArgs e) { Gdk.Key key = e.Event.Key; string accel; e.RetVal = true; if (accelComplete) { CurrentKey = String.Empty; accelIncomplete = false; accelComplete = false; chord = null; if (key == Gdk.Key.BackSpace) { return; } } accelComplete = false; bool combinationComplete; accel = KeyBindingManager.AccelLabelFromKey(e.Event, out combinationComplete); if (combinationComplete) { CurrentKey = KeyBindingManager.Binding(chord, accel); accelIncomplete = false; if (chord != null) { accelComplete = true; } else { chord = accel; } } else { accel = (chord != null ? chord + "|" : string.Empty) + accel; accelIncomplete = true; CurrentKey = accel; } }
public static void Postfix(Player __instance) { // TODO: Use proper way to check if input is free, because players can be editing labels etc. if ((bool)((DevConsole)ReflectionHelper.ReflectionGet <DevConsole>(null, "instance", false, true)).ReflectionGet("state")) { return; } KeyBindingManager keyBindingManager = new KeyBindingManager(); foreach (KeyBinding keyBinding in keyBindingManager.KeyboardKeyBindings) { bool isButtonDown = (bool)ReflectionHelper.ReflectionCall <GameInput>(null, "GetButtonDown", new Type[] { typeof(GameInput.Button) }, true, true, keyBinding.Button); if (isButtonDown) { keyBinding.Action.Execute(); } } }
// Update is called once per frame void Update() { if (KeyBindingManager.GetKeyDown(KeyAction.up)) { box1.SetActive(!box1.activeSelf); } if (KeyBindingManager.GetKeyDown(KeyAction.down)) { box2.SetActive(!box2.activeSelf); } if (KeyBindingManager.GetKeyDown(KeyAction.left)) { box3.SetActive(!box3.activeSelf); } if (KeyBindingManager.GetKeyDown(KeyAction.right)) { box4.SetActive(!box4.activeSelf); } }
private void App_Startup(object sender, StartupEventArgs e) { // Load skins: if (!DirectoryEx.Exists(InstanceManager.Instance.SkinsFolderPath)) { DirectoryEx.CreateDirectory(InstanceManager.Instance.SkinsFolderPath); } SkinManager.Instance.LoadAllSkins(InstanceManager.Instance.SkinsFolderPath); // Load settings: SettingsManager.Init(InstanceManager.Instance.SettingsFilePath); // Set skin: if (!IconManager.Instance.LoadFromSkin((string)SettingsManager.Instance["SelectedSkin"].Value)) { MessageBox.Show("Failed to load skin: " + SettingsManager.Instance["SelectedSkin"].Value, "Error", MessageBoxButton.OK, MessageBoxImage.Asterisk); SettingsManager.Instance["SelectedSkin"].ResetValue(); if (!IconManager.Instance.LoadFromSkin((string)SettingsManager.Instance["SelectedSkin"].Value)) { MessageBox.Show("Failed to load fallback default skin!", "This is a bug!", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } // Load key bindings: KeyBindingManager.Init(InstanceManager.Instance.KeyConfigFilePath); // KeyBindingManager.Instance.Disable = !(bool)SettingsManager.Instance["EnableGlobalKeyBindings"].Value; SettingsManager.Instance["EnableGlobalKeyBindings"].PropertyChanged += (s, args) => KeyBindingManager.Instance.Disable = !(bool)SettingsManager.Instance["EnableGlobalKeyBindings"].Value; // Load plugins: // VERY IMPORTANT: Force evaluation of IEnumerable InstanceManager.Instance.LoadedExtensions = ExtensionLoader.GetCompatibleExtensions <IExtension>(Lib.PathStringUtils.GetExePath()).ToList(); _extAccess = new ExtensionAccess(); foreach (var ex in InstanceManager.Instance.LoadedExtensions) { ex.Instance.Init(_extAccess); } }
private static ActionCommand CreateActionCommand(object cmdEnum, ActionType cmdType, string label, string shortCut, string macShortCut, bool isArray) { ActionCommand actionCommand = !isArray ? (ActionCommand) new CommandProxy() : (ActionCommand) new CommandArrayProxy(); actionCommand.ActionType = cmdType; actionCommand.CommandArray = isArray; actionCommand.Id = (object)(cmdEnum.GetType().FullName + "." + cmdEnum.ToString()); actionCommand.Text = label; if (macShortCut == null) { macShortCut = shortCut; } string binding = Platform.IsMac ? macShortCut : shortCut; if (Platform.IsWindows && !string.IsNullOrEmpty(shortCut)) { binding = shortCut; } actionCommand.AccelKey = KeyBindingManager.CanonicalizeBinding(binding); GlobalCommand.GlobalCmdManager.RegisterCommand((Command)actionCommand); return(actionCommand); }
protected override bool OnKeyPressEvent(EventKey evnt) { Gdk.Key key; Gdk.ModifierType mod; KeyBindingManager.MapRawKeys(evnt, out key, out mod); switch (key) { case Gdk.Key.Left: LeftItem(); break; case Gdk.Key.Right: RightItem(); break; case Gdk.Key.Up: PrevItem(); break; case Gdk.Key.Down: NextItem(); break; case Gdk.Key.Tab: if ((mod & ModifierType.ShiftMask) == 0) { NextItem(); } else { PrevItem(); } break; } return(base.OnKeyPressEvent(evnt)); }
//FIXME: get ctrl(-shift)-tab keybindings from the Switch(Next|Previous)Document commands? protected override bool OnKeyPressEvent(Gdk.EventKey evnt) { Gdk.Key key; Gdk.ModifierType mod; KeyBindingManager.MapRawKeys(evnt, out key, out mod); switch (key) { case Gdk.Key.Left: SwitchToPad(); break; case Gdk.Key.Right: SwitchToDocument(); break; case Gdk.Key.Up: Previous(); break; case Gdk.Key.Down: Next(); break; case Gdk.Key.Tab: if ((mod & ModifierType.ShiftMask) == 0) { Next(); } else { Previous(); } break; } return(true); }
KeyBindingHitTestResult HitTest(double mouseX, double mouseY) { KeyBindingHitTestResult result = new KeyBindingHitTestResult(); TreeIter iter; TreePath path; int cellx, celly, mx, my; mx = (int)mouseX; my = (int)mouseY; if (!GetCellPosition(mx, my, out cellx, out celly, out iter, out path)) { return(result); } Text = keyBindingsTree.Model.GetValue(iter, bindingCol) as string ?? string.Empty; Command = keyBindingsTree.Model.GetValue(iter, commandCol) as Command; var filter = keyBindingsTree.Model as TreeModelFilter; if (filter != null) { iter = filter.ConvertIterToChildIter(iter); } result.Command = Command; result.AllKeys = Text.Split(new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); result.Iter = iter; using (var layout = new Pango.Layout(keyBindingsTree.PangoContext)) { // GetCellArea reports the outer cell bounds, therefore we need to add 2px var xpad = (int)Xpad + 2; var cellBounds = keyBindingsTree.GetCellArea(path, keyBindingsPanel.bindingTVCol); keyBindingsTree.ConvertBinWindowToWidgetCoords(cellBounds.X, cellBounds.Y, out cellBounds.X, out cellBounds.Y); int i = 0; foreach (var key in result.AllKeys) { layout.SetText(KeyBindingManager.BindingToDisplayLabel(key, false)); layout.FontDescription = KeySymbolFont; int w, h; layout.GetPixelSize(out w, out h); int buttonWidth = w + (2 * KeyHPadding); int buttonHeight = h + (2 * KeyVPadding); var ypad = 2 + ((cellBounds.Height / 2) - (buttonHeight / 2)); if (cellx > xpad && cellx <= xpad + buttonWidth && celly > ypad && celly <= ypad + buttonHeight) { keyBindingsPanel.bindingTVCol.CellGetPosition(this, out cellx, out w); cellBounds.X += cellx; result.SelectedKey = i; result.ButtonBounds = new Gdk.Rectangle(cellBounds.X + xpad, cellBounds.Y + ypad, buttonWidth, buttonHeight); result.ButtonBounds.Inflate(0, 2); return(result); } xpad += buttonWidth + Spacing; i++; } } return(result); }
public TitleMenuItem(MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null, Menu menu = null) { this.manager = manager; this.initialCommandTarget = initialCommandTarget; this.commandSource = commandSource; this.commandArrayInfo = commandArrayInfo; this.menu = menu; menuEntry = entry; menuEntrySet = entry as CommandEntrySet; menuLinkEntry = entry as LinkCommandEntry; if (commandArrayInfo != null) { Header = commandArrayInfo.Text; var commandArrayInfoSet = commandArrayInfo as CommandInfoSet; if (commandArrayInfoSet != null) { foreach (var item in commandArrayInfoSet.CommandInfos) { if (item.IsArraySeparator) { Items.Add(new Separator { UseLayoutRounding = true, }); } else { Items.Add(new TitleMenuItem(manager, entry, item, commandSource, initialCommandTarget, menu)); } } } } if (menuEntrySet != null) { Header = menuEntrySet.Name; foreach (CommandEntry item in menuEntrySet) { if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator) { Items.Add(new Separator { UseLayoutRounding = true, }); } else { Items.Add(new TitleMenuItem(manager, item, menu: menu)); } } } else if (menuLinkEntry != null) { Header = menuLinkEntry.Text; Click += OnMenuLinkClicked; } else if (entry != null) { actionCommand = manager.GetCommand(menuEntry.CommandId) as ActionCommand; if (actionCommand == null) { return; } IsCheckable = actionCommand.ActionType == ActionType.Check; // FIXME: Use proper keybinding text. if (actionCommand.KeyBinding != null) { InputGestureText = KeyBindingManager.BindingToDisplayLabel(actionCommand.KeyBinding, true); } try { if (!actionCommand.Icon.IsNull) { Icon = new ImageBox(actionCommand.Icon.GetStockIcon().WithSize(Xwt.IconSize.Small)); } } catch (Exception ex) { MonoDevelop.Core.LoggingService.LogError("Failed loading menu icon: " + actionCommand.Icon, ex); } Click += OnMenuClicked; } Height = SystemParameters.CaptionHeight; UseLayoutRounding = true; }
public override object CreateInstance() { ActionType ct = ActionType.Normal; bool isArray = false; bool custom = false; bool isAction = false; foreach (string p in type.Split('|')) { switch (p) { case "check": ct = ActionType.Check; if (isAction) { throw new InvalidOperationException("Action type specified twice."); } isAction = true; break; case "radio": ct = ActionType.Radio; if (isAction) { throw new InvalidOperationException("Action type specified twice."); } isAction = true; break; case "normal": ct = ActionType.Normal; if (isAction) { throw new InvalidOperationException("Action type specified twice."); } isAction = true; break; case "custom": if (widget == null) { throw new InvalidOperationException("Widget type not specified in custom command."); } custom = true; break; case "array": isArray = true; break; default: throw new InvalidOperationException("Unknown command type: " + p); } } if (isAction && custom) { throw new InvalidOperationException("Invalid command type combination: " + type); } Command cmd; if (custom) { if (isArray) { throw new InvalidOperationException("Array custom commands are not allowed."); } CustomCommand ccmd = new CustomCommand(); ccmd.Text = label; ccmd.WidgetType = Addin.GetType(widget); if (ccmd.WidgetType == null) { throw new InvalidOperationException("Could not find command type '" + widget + "'."); } cmd = ccmd; } else { if (widget != null) { throw new InvalidOperationException("Widget type can only be specified for custom commands."); } ActionCommand acmd = new ActionCommand(); acmd.ActionType = ct; acmd.CommandArray = isArray; if (defaultHandler != null) { acmd.SetDefaultHandlerTypeInfo(Addin, defaultHandler); } cmd = acmd; } cmd.Id = ParseCommandId(this); cmd.Text = StringParserService.Parse(BrandingService.BrandApplicationName(label)); if (!String.IsNullOrWhiteSpace(_displayName)) { cmd.DisplayName = StringParserService.Parse(BrandingService.BrandApplicationName(_displayName)); } if ((_description != null) && (_description.Length > 0)) { cmd.Description = BrandingService.BrandApplicationName(_description); } cmd.Description = cmd.Description; if (icon != null) { cmd.Icon = GetStockId(Addin, icon); } var keyBinding = Platform.IsMac ? macShortcut : shortcut; if (Platform.IsWindows && !string.IsNullOrEmpty(winShortcut)) { keyBinding = winShortcut; } string[] splittedKeys = (keyBinding ?? "").Split(' '); cmd.AccelKey = KeyBindingManager.FixChordSeparators(KeyBindingManager.CanonicalizeBinding(splittedKeys[0])); if (splittedKeys.Length > 1) { cmd.AlternateAccelKeys = splittedKeys.Skip(1).Select(key => KeyBindingManager.FixChordSeparators(key)).ToArray(); } cmd.DisabledVisible = disabledVisible; // Assign the category of the command CommandCategoryCodon cat = Parent as CommandCategoryCodon; if (cat != null) { cmd.Category = cat.Name; } return(cmd); }
public MenuBindings(KeyBindingManager bindManager) { _bindManager = bindManager; }
void UpdateSearchEntryLabel() { var info = IdeApp.CommandService.GetCommand(Commands.NavigateTo); if (!string.IsNullOrEmpty(info.AccelKey)) { matchEntry.EmptyMessage = GettextCatalog.GetString("Press '{0}' to search", KeyBindingManager.BindingToDisplayLabel(info.AccelKey, false)); } else { matchEntry.EmptyMessage = GettextCatalog.GetString("Search solution"); } }
public void Update(CommandTargetRoute targetRoute) { CommandInfo cmdInfo = IdeApp.CommandService.GetCommandInfo(cmdId, targetRoute); bool hasAccel = string.IsNullOrEmpty(cmdInfo.AccelKey); bool hasIcon = !cmdInfo.Icon.IsNull; string desc = cmdInfo.Description; bool displayText = !(displayType == CommandEntryDisplayType.IconHasPriority && hasIcon) && displayType != CommandEntryDisplayType.IconOnly; //If the button only has an icon it's not always clear what it does. In such cases, use the label as a //fallback tooltip. Also do this if there's an accelerator, so the user can see what it is. if (string.IsNullOrEmpty(desc) && (!displayText || hasAccel)) { desc = cmdInfo.Text; } if (lastDesc != desc) { string toolTip; if (hasAccel) { toolTip = desc; } else { toolTip = desc + " (" + KeyBindingManager.BindingToDisplayLabel(cmdInfo.AccelKey, false) + ")"; } button.TooltipText = toolTip; lastDesc = desc; } if (displayText && button.Label != cmdInfo.Text) { button.Label = cmdInfo.Text; } if (displayType != CommandEntryDisplayType.TextOnly && cmdInfo.Icon != stockId) { stockId = cmdInfo.Icon; button.Image = new Gtk.Image(cmdInfo.Icon, Gtk.IconSize.Menu); } if (cmdInfo.Enabled != button.Sensitive) { button.Sensitive = cmdInfo.Enabled; } if (cmdInfo.Visible != button.Visible) { button.Visible = cmdInfo.Visible; } ToggleButton toggle = button as ToggleButton; if (toggle != null && cmdInfo.Checked != toggle.Active) { toggle.Active = cmdInfo.Checked; } if (button.Image != null) { button.Image.Show(); } }
public override object CreateInstance() { ActionType ct = ActionType.Normal; bool isArray = false; bool custom = false; bool isAction = false; foreach (string p in type.Split('|')) { switch (p) { case "check": ct = ActionType.Check; if (isAction) { throw new InvalidOperationException("Action type specified twice."); } isAction = true; break; case "radio": ct = ActionType.Radio; if (isAction) { throw new InvalidOperationException("Action type specified twice."); } isAction = true; break; case "normal": ct = ActionType.Normal; if (isAction) { throw new InvalidOperationException("Action type specified twice."); } isAction = true; break; case "custom": if (widget == null) { throw new InvalidOperationException("Widget type not specified in custom command."); } custom = true; break; case "array": isArray = true; break; default: throw new InvalidOperationException("Unknown command type: " + p); } } if (isAction && custom) { throw new InvalidOperationException("Invalid command type combination: " + type); } Command cmd; if (custom) { if (isArray) { throw new InvalidOperationException("Array custom commands are not allowed."); } CustomCommand ccmd = new CustomCommand(); ccmd.Text = label; ccmd.WidgetType = Addin.GetType(widget); if (ccmd.WidgetType == null) { throw new InvalidOperationException("Could not find command type '" + widget + "'."); } cmd = ccmd; } else { if (widget != null) { throw new InvalidOperationException("Widget type can only be specified for custom commands."); } ActionCommand acmd = new ActionCommand(); acmd.ActionType = ct; acmd.CommandArray = isArray; if (defaultHandler != null) { acmd.SetDefaultHandlerTypeInfo(Addin, defaultHandler); } cmd = acmd; } cmd.Id = ParseCommandId(this); cmd.Text = StringParserService.Parse(label); if ((_description != null) && (_description.Length > 0)) { cmd.Description = _description; } cmd.Description = cmd.Description; if (icon != null) { cmd.Icon = GetStockId(Addin, icon); } cmd.AccelKey = KeyBindingManager.CanonicalizeBinding(PropertyService.IsMac? macShortcut : shortcut); cmd.DisabledVisible = disabledVisible; // Assign the category of the command CommandCategoryCodon cat = Parent as CommandCategoryCodon; if (cat != null) { cmd.Category = cat.Name; } return(cmd); }
public KeyBindingsPanel() { this.Build(); keyStore = new TreeStore(typeof(Command), typeof(string), typeof(string), typeof(string), typeof(int), typeof(string), typeof(bool), typeof(bool)); keyTreeView.Model = filterModel = new TreeModelFilter(keyStore, null); filterModel.VisibleColumn = visibleCol; TreeViewColumn col = new TreeViewColumn(); col.Title = GettextCatalog.GetString("Command"); col.Spacing = 4; CellRendererImage crp = new CellRendererImage(); col.PackStart(crp, false); col.AddAttribute(crp, "stock-id", iconCol); col.AddAttribute(crp, "visible", iconVisibleCol); CellRendererText crt = new CellRendererText(); col.PackStart(crt, true); col.AddAttribute(crt, "text", labelCol); col.AddAttribute(crt, "weight", boldCol); keyTreeView.AppendColumn(col); TreeViewColumn bindingTVCol = new TreeViewColumn(); bindingTVCol.Title = GettextCatalog.GetString("Key Binding"); CellRendererText bindingRenderer = new CellRendererText(); bindingTVCol.PackStart(bindingRenderer, false); bindingTVCol.SetCellDataFunc(bindingRenderer, delegate(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { string binding = (model.GetValue(iter, bindingCol) as string) ?? ""; ((CellRendererText)cell).Text = binding.Length > 0 ? KeyBindingManager.BindingToDisplayLabel(binding, false) : binding; }); keyTreeView.AppendColumn(bindingTVCol); keyTreeView.AppendColumn(GettextCatalog.GetString("Description"), new CellRendererText(), "text", descCol); keyTreeView.Selection.Changed += OnKeysTreeViewSelectionChange; accelEntry.KeyPressEvent += OnAccelEntryKeyPress; accelEntry.KeyReleaseEvent += OnAccelEntryKeyRelease; accelEntry.Changed += delegate { UpdateWarningLabel(); }; updateButton.Clicked += OnUpdateButtonClick; currentBindings = KeyBindingService.CurrentKeyBindingSet.Clone(); schemes = new List <KeyBindingScheme> (KeyBindingService.Schemes); schemeCombo.AppendText(GettextCatalog.GetString("Custom")); foreach (KeyBindingScheme s in schemes) { schemeCombo.AppendText(s.Name); } SelectCurrentScheme(); schemeCombo.Changed += OnKeyBindingSchemeChanged; searchEntry.Ready = true; searchEntry.Visible = true; searchEntry.Changed += delegate { processedFilterTerms = searchEntry.Entry.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.ToLower()).ToArray();; filterChanged = true; if (!filterTimeoutRunning) { filterTimeoutRunning = true; GLib.Timeout.Add(50, delegate { if (!filterChanged) { if (filterTimeoutRunning) { Refilter(); } filterTimeoutRunning = false; return(false); } filterChanged = false; return(true); }); } ; }; //HACK: workaround for MD Bug 608021: Stetic loses values assigned to "new" properties of custom widget conflicButton.Label = GettextCatalog.GetString("_View Conflicts"); conflicButton.UseUnderline = true; }
//FIXME: handle the mode key static bool GetAcceleratorKeys(string accelKey, out ushort glyphCode, out ushort charCode, out ushort virtualHardwareCode, out MenuAccelModifier outMod) { uint modeKey, key; Gdk.ModifierType modeMod, mod; glyphCode = charCode = virtualHardwareCode = 0; outMod = (MenuAccelModifier)0; if (!KeyBindingManager.BindingToKeys(accelKey, out modeKey, out modeMod, out key, out mod)) { return(false); } if (modeKey != 0) { System.Console.WriteLine("WARNING: Cannot display accelerators with mode keys ({0})", accelKey); return(false); } glyphCode = (ushort)GlyphMappings((Gdk.Key)key); if (glyphCode == 0) { charCode = (ushort)Gdk.Keyval.ToUnicode(key); if (charCode == 0) { var map = keymap.GetEntriesForKeyval(key); if (map != null && map.Length > 0) { virtualHardwareCode = (ushort)map [0].Keycode; } if (virtualHardwareCode == 0) { System.Console.WriteLine("WARNING: Could not map key ({0})", key); return(false); } } else { charCode = (ushort)char.ToUpper((char)charCode); } } if ((mod & Gdk.ModifierType.Mod1Mask) != 0) { outMod |= MenuAccelModifier.OptionModifier; mod ^= Gdk.ModifierType.Mod1Mask; } if ((mod & Gdk.ModifierType.ShiftMask) != 0) { outMod |= MenuAccelModifier.ShiftModifier; mod ^= Gdk.ModifierType.ShiftMask; } if ((mod & Gdk.ModifierType.ControlMask) != 0) { outMod |= MenuAccelModifier.ControlModifier; mod ^= Gdk.ModifierType.ControlMask; } // This is inverted, because by default on OSX no setting means use the Command-key if ((mod & Gdk.ModifierType.MetaMask) == 0) { outMod |= MenuAccelModifier.None; } else { mod ^= Gdk.ModifierType.MetaMask; } if (mod != 0) { System.Console.WriteLine("WARNING: Cannot display accelerators with modifiers: {0}", mod); return(false); } return(true); }
public LabyrinthBindings(KeyBindingManager bindManager) { _bindManager = bindManager; }
void UpdateSearchEntryLabel() { var info = IdeApp.CommandService.GetCommand(Commands.NavigateTo); ToolbarView.SearchPlaceholderMessage = !string.IsNullOrEmpty(info.AccelKey) ? GettextCatalog.GetString("Press \u2018{0}\u2019 to search", KeyBindingManager.BindingToDisplayLabel(info.AccelKey, false)) : GettextCatalog.GetString("Search solution"); }
//updates dictionary on key bindings manager public void UpdateKeyCode() { KeyBindingManager.UpdateDictionary(this); }
static void SetAccel(NSMenuItem item, string accelKey) { uint modeKey; Gdk.ModifierType modeMod; uint key; Gdk.ModifierType mod; if (!KeyBindingManager.BindingToKeys(accelKey, out modeKey, out modeMod, out key, out mod)) { item.KeyEquivalent = ""; item.KeyEquivalentModifierMask = (NSEventModifierMask)0; return; } if (modeKey != 0) { LoggingService.LogWarning("Mac menu cannot display accelerators with mode keys ({0})", accelKey); item.KeyEquivalent = ""; item.KeyEquivalentModifierMask = (NSEventModifierMask)0; return; } var keyEq = GetKeyEquivalent((Gdk.Key)key); item.KeyEquivalent = keyEq; if (keyEq.Length == 0) { item.KeyEquivalentModifierMask = 0; } NSEventModifierMask outMod = 0; if ((mod & Gdk.ModifierType.Mod1Mask) != 0) { outMod |= NSEventModifierMask.AlternateKeyMask; mod ^= Gdk.ModifierType.Mod1Mask; } if ((mod & Gdk.ModifierType.ShiftMask) != 0) { outMod |= NSEventModifierMask.ShiftKeyMask; mod ^= Gdk.ModifierType.ShiftMask; } if ((mod & Gdk.ModifierType.ControlMask) != 0) { outMod |= NSEventModifierMask.ControlKeyMask; mod ^= Gdk.ModifierType.ControlMask; } if ((mod & Gdk.ModifierType.MetaMask) != 0) { outMod |= NSEventModifierMask.CommandKeyMask; mod ^= Gdk.ModifierType.MetaMask; } if (mod != 0) { LoggingService.LogWarning("Mac menu cannot display accelerators with modifiers {0}", mod); } item.KeyEquivalentModifierMask = outMod; }
private Command CreateCommand() { ActionType actionType = ActionType.Normal; bool flag1 = false; bool flag2 = false; bool flag3 = false; string type = this.type; char[] chArray = new char[1] { '|' }; foreach (string str in type.Split(chArray)) { switch (str) { case "check": actionType = ActionType.Check; if (flag3) { throw new InvalidOperationException("Action type specified twice."); } flag3 = true; break; case "radio": actionType = ActionType.Radio; if (flag3) { throw new InvalidOperationException("Action type specified twice."); } flag3 = true; break; case "normal": actionType = ActionType.Normal; if (flag3) { throw new InvalidOperationException("Action type specified twice."); } flag3 = true; break; case "custom": if (this.widget == null) { throw new InvalidOperationException("Widget type not specified in custom command."); } flag2 = true; break; case "array": flag1 = true; break; default: throw new InvalidOperationException("Unknown command type: " + str); } } if (flag3 && flag2) { throw new InvalidOperationException("Invalid command type combination: " + this.type); } Command command; if (flag2) { if (flag1) { throw new InvalidOperationException("Array custom commands are not allowed."); } CustomCommand customCommand = new CustomCommand(); customCommand.Text = this.label; customCommand.WidgetType = this.Addin.GetType(this.widget); if (customCommand.WidgetType == (Type)null) { throw new InvalidOperationException("Could not find command type '" + this.widget + "'."); } command = (Command)customCommand; } else { if (this.widget != null) { throw new InvalidOperationException("Widget type can only be specified for custom commands."); } ActionCommand actionCommand = new ActionCommand(); actionCommand.ActionType = actionType; actionCommand.CommandArray = flag1; if (this.handler != null) { try { MenuHandler instance = (MenuHandler)Activator.CreateInstance(this.Addin.GetType(this.handler, true)); if (instance != null) { actionCommand.DefaultHandler = (CommandHandler) new CcsCmdHandler(instance); actionCommand.DefaultHandlerType = actionCommand.DefaultHandler.GetType(); } } catch { LogConfig.Output.Error((object)string.Format("Failed to create MenuHandler: {0}", (object)this.handler)); } } command = (Command)actionCommand; } command.Id = CmdEntryCodon.ParseCommandId((ExtensionNode)this); command.Text = this.label; if (this.description != null && this.description.Length > 0) { command.Description = BrandingService.BrandApplicationName(this.description); } command.Description = command.Description; if (this.icon != null) { command.Icon = (IconId)CmdEntryCodon.GetStockId(this.Addin, this.icon); } string str1 = Platform.IsMac ? this.macShortcut : this.shortcut; if (Platform.IsWindows && !string.IsNullOrEmpty(this.winShortcut)) { str1 = this.winShortcut; } string[] strArray = (str1 ?? "").Split(' '); command.AccelKey = KeyBindingManager.CanonicalizeBinding(strArray[0]); if (strArray.Length > 1) { command.AlternateAccelKeys = ((IEnumerable <string>)strArray).Skip <string>(1).ToArray <string>(); } command.DisabledVisible = this.disabledVisible; CommandCategoryCodon parent = this.Parent as CommandCategoryCodon; if (parent != null) { command.Category = parent.Name; } return(command); }