示例#1
0
        private void ExecuteUserShortcutsCommand(object sender, EventArgs args)
        {
            DynamicItemMenuCommand invokedCommand = (DynamicItemMenuCommand)sender;
            string           shortcutDefName      = invokedCommand.Text.Replace("&", "");// Remove the & (keyboard accelerator) from of the menu text
            ShortcutFileInfo userShortcutsDef     = userShortcutsManager.GetUserShortcutsInfo(shortcutDefName);
            string           importFilePath       = userShortcutsDef.Filepath;

            if (!File.Exists(importFilePath))
            {
                if (MessageBox.Show($"File does not exist: {importFilePath}\nRemove from shortcuts registry?", MSG_CAPTION_IMPORT, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    userShortcutsManager.DeleteUserShortcutsDef(shortcutDefName);
                }
                return;
            }
            LoadKeyboardShortcutsFromVSSettingsFile(importFilePath);
        }
        /// <summary>
        /// Handler for the Load User Shortcuts menu items.
        /// </summary>
        private void ExecuteUserShortcutsCommand(object sender, EventArgs args)
        {
            // Get the name of shortcuts file from the invoked menu item (Dynamic menu - can't know at compile time)
            DynamicItemMenuCommand invokedCommand = (DynamicItemMenuCommand)sender;
            string shortcutDefName = invokedCommand.Text.Replace("&", "");  // Remove the & (keyboard accelerator) from the menu text

            // Lookup the cache of known keyoard import files and get the full filepath
            ShortcutFileInfo userShortcutsDef = userShortcutsManager.GetUserShortcutsInfo(shortcutDefName);
            string           importFilePath   = userShortcutsDef.Filepath;

            // If file is not available on the drive, abort and offer to remove it from the list.
            if (!File.Exists(importFilePath))
            {
                if (MessageBox.Show($"File does not exist: {importFilePath}\nRemove from shortcuts registry?", MSG_CAPTION_IMPORT, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    userShortcutsManager.DeleteUserShortcutsDef(shortcutDefName);
                }
                return;
            }

            // Load the user shortcuts from the VSSettings file.
            var success = LoadKeyboardShortcutsFromVSSettingsFile(importFilePath);
        }