Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the menu.
        /// </summary>
        /// <param name="menu">The menu whose items are to be set.</param>
        /// <param name="addShortcuts">If <c>true</c>, add menu item shortcuts to the items.</param>
        private static void InitializeAvailableDevicesMenu(Gtk.Menu menu, bool addShortcuts)
        {
            var items = menu.Children;

            for (var i = 0; i < items.Length; ++i)
            {
                var menuItem = items[i] as Gtk.MenuItem;
                if (menuItem != null)
                {
                    // Remove any existing accelerators
                    if (addShortcuts)
                    {
                        var key            = Gdk.Key.Key_0 + i + 1;
                        var modifiers      = Gdk.ModifierType.ControlMask;
                        var acceleratorKey = new Gtk.AccelKey(key, modifiers, Gtk.AccelFlags.Visible);
                        SetActiveDeviceCommand.RemoveAccelerator(menuItem, acceleratorKey);
                    }
                    menu.Remove(menuItem);
                }
            }

            var ports          = DeviceConnectionViewModel.GetAvailableConnections(Group.Context as LtoFlashViewModel);
            var shortcutNumber = 0;

            foreach (var port in ports)
            {
                ++shortcutNumber;
                var menuItem = SetActiveDeviceCommand.CreateMenuItem(menu, ConnectToDeviceSubmenuCommand, Gtk.StockItem.Zero, null, null);
                menuItem.SetName(port.Name);
                menuItem.NativeMenuItem.Sensitive = SetActiveDeviceCommand.CanExecute(port);
                if (addShortcuts && (shortcutNumber < 10))
                {
                    var key            = Gdk.Key.Key_0 + shortcutNumber;
                    var modifiers      = Gdk.ModifierType.ControlMask;
                    var acceleratorKey = new Gtk.AccelKey(key, modifiers, Gtk.AccelFlags.Visible);
                    SetActiveDeviceCommand.AddAccelerator(menuItem, acceleratorKey);
                }
                menuItem.SetValue(IFakeDependencyObjectHelpers.DataContextPropertyName, port);
            }
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Initializes the menu.
            /// </summary>
            /// <param name="menu">The menu whose items are to be set.</param>
            internal void InitializeMenu(NSMenu menu)
            {
                _deviceConnectionViewModels.Clear();
                var ports = DeviceConnectionViewModel.GetAvailableConnections(_ltoFlash);

                menu.RemoveAllItems();
                var shortcutNumber = 0;

                foreach (var port in ports)
                {
                    ++shortcutNumber;
                    var menuItem = SetActiveDeviceCommand.CreateMenuItemForCommand(_group, true, null);
                    menuItem.Title      = port.Name;
                    menuItem.Activated += HandleSetActiveDeviceCommandActivated; // doesn't use standard approach
                    menuItem.Enabled    = SetActiveDeviceCommand.CanExecute(port);
                    if (shortcutNumber < 10)
                    {
                        menuItem.KeyEquivalent             = shortcutNumber.ToString();
                        menuItem.KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask;
                    }
                    _deviceConnectionViewModels[menuItem.GetHashCode()] = port;
                }
            }