Exemple #1
0
        private void OnBeforeQueryStatusClearUserShortcuts(object sender, EventArgs e)
        {
            OleMenuCommand command         = (OleMenuCommand)sender;
            bool           hasShortcutDefs = userShortcutsManager.GetUserShortcutsRegistry().Count > 0;

            command.Visible = hasShortcutDefs;
            command.Enabled = hasShortcutDefs;
        }
        public bool ScanForNewShortcutsDefs()
        {
            // Process VSSettings files

            // Scan All-Users and local-user extension directories for VSSettings files
            List <string> vsSettingsFilesInExtDirs = GetFilesFromFolder(AllUsersExtensionsPath, "*.vssettings");

            vsSettingsFilesInExtDirs.AddRange(GetFilesFromFolder(LocalUserExtensionsPath, "*.vssettings"));

            List <ShortcutFileInfo> userShortcutsRegistry = userShortcutsManager.GetUserShortcutsRegistry();

            // For each VSSettings found, check VSSettings registry
            List <string> newVsSettings     = new List <string>();
            List <string> updatedVsSettings = new List <string>();

            foreach (string vsSettingsFile in vsSettingsFilesInExtDirs)
            {
                ShortcutFileInfo shortcutFileInfo = userShortcutsRegistry.Find(x => x.Filepath.Equals(vsSettingsFile));
                if (shortcutFileInfo == null)
                {
                    // - New VSSettings file
                    // Add to VSSettings registry (update: prompt)
                    shortcutFileInfo = new ShortcutFileInfo(vsSettingsFile);
                    // Add to NewVSSettingsList (to alert users)
                    newVsSettings.Add(vsSettingsFile);
                    // Update the VSSettingsRegsitry
                    userShortcutsManager.AddUserShortcutsDef(shortcutFileInfo);
                }
                else
                {
                    // We already know about this file. Check update flag.
                    if (shortcutFileInfo.NotifyFlag == UPDATE_NEVER)
                    {
                        continue;
                    }

                    FileInfo vsSettingsFileInfo = new FileInfo(vsSettingsFile);
                    if (shortcutFileInfo.LastWriteTimeEquals(vsSettingsFileInfo.LastWriteTime))
                    {
                        continue;
                    }
                    // This entry has been updated since it was added to the registry. Update the entry.
                    shortcutFileInfo.LastWriteTime = vsSettingsFileInfo.LastWriteTime;
                    // Add to UpdatedVSSettingsList (to alert users)
                    updatedVsSettings.Add(vsSettingsFile);
                    // Update the SettingsStore
                    userShortcutsManager.UpdateShortcutsDefInSettingsStore(shortcutFileInfo);
                }
            }

            // Alert user of new and updated shortcut defs
            if (newVsSettings.Count == 1)
            {
                // Prompt to load the new VSSettings
                if (MessageBox.Show($"One new user shortcut definition was found.\n\n{PrintList(newVsSettings)}\n\nWould you like to load these shortcuts now?", MSG_CAPTION_IMPORT, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    // Load the settings
                    VSShortcutsManager.LoadKeyboardShortcutsFromVSSettingsFile(newVsSettings.First());
                }
            }
            else if (newVsSettings.Count > 1)
            {
                MessageBox.Show($"There were {newVsSettings.Count} new user shortcut files found.\n\n{PrintList(newVsSettings)}\n\nYou can load these shortcuts from Tools->Keyboard Shortcuts->Load Shortcuts");
            }
            // Updated settings files
            if (updatedVsSettings.Count > 0)
            {
                MessageBox.Show($"There were {updatedVsSettings.Count} updated user shortcut files found.\n\n{PrintList(updatedVsSettings)}\n\nYou might want to reapply these shortcuts.\nTool->Keyboard Shortcuts");
            }

            return(newVsSettings.Count > 0 || updatedVsSettings.Count > 0);
        }