Example #1
0
        /// <summary>
        /// Adds an accelerator given a command with keyboard shortcut information defined.
        /// </summary>
        /// <param name="command">For convenience - not actually used.</param>
        /// <param name="visual">The visual for which to register the accelerator.</param>
        /// <param name="key">The keyboard shortcut.</param>
        /// <remarks>If the visual is null, the shortcut will be registered using the
        /// current application's MainWindow. In any case, all accelerators are placed in
        /// the first accelerator group associated with the application's main window.</remarks>
        public static void AddAccelerator(this VisualRelayCommand command, Gtk.Widget visual, Gtk.AccelKey key)
        {
            var mainWindow = SingleInstanceApplication.Instance.MainWindow;

            visual = visual ?? mainWindow;
            var groups           = Gtk.Accel.GroupsFromObject(mainWindow);
            var createAccelGroup = (groups == null) || (groups.Length < 1);
            var accelGroup       = createAccelGroup ? new Gtk.AccelGroup() : groups[0];

            if (createAccelGroup)
            {
                mainWindow.AddAccelGroup(accelGroup);
            }
            visual.AddAccelerator("activate", accelGroup, (uint)key.Key, key.AccelMods, key.AccelFlags);
        }