コード例 #1
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Initialize settings manager (TODO: could be done lazily on get)
            SettingsManager = (ISettingsManager)this.GetService(typeof(SVsSettingsPersistenceManager));

            // Adds commands handlers for the VS Shortcuts operations (Apply, Backup, Restore, Reset)
            VSShortcutsManager.Initialize(this);
        }
コード例 #2
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override async System.Threading.Tasks.Task InitializeAsync(System.Threading.CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            // When initialized asynchronously, we *may* be on a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            // Otherwise, remove the switch to the UI thread if you don't need it.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            // Initialize settings manager (TODO: could be done lazily on get)
            SettingsManager = (ISettingsManager)await this.GetServiceAsync(typeof(SVsSettingsPersistenceManager));

            // Adds commands handlers for the VS Shortcuts operations (Apply, Backup, Restore, Reset)
            VSShortcutsManager.Initialize(this);
        }
コード例 #3
0
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 public static void Initialize(Package package)
 {
     Instance = new VSShortcutsManager(package);
 }
コード例 #4
0
        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);
        }