Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OptionsViewModel" /> class.
        /// </summary>
        /// <param name="package">The hosting package.</param>
        /// <param name="initiallySelectedPageType">The type of the initially selected page.</param>
        public OptionsViewModel(CodeMaidPackage package, Type initiallySelectedPageType = null)
        {
            _settingsContextHelper = SettingsContextHelper.GetInstance(package);

            ActiveSettings = (Settings)SettingsBase.Synchronized(new Settings());
            IsActiveSolutionSpecificSettings = _settingsContextHelper.LoadSolutionSpecificSettings(ActiveSettings);

            Package = package;
            Pages   = new OptionsPageViewModel[]
            {
                new GeneralViewModel(package, ActiveSettings)
                {
                    Children = new OptionsPageViewModel[]
                    {
                        new FeaturesViewModel(package, ActiveSettings)
                    }
                },
                new CleaningParentViewModel(package, ActiveSettings)
                {
                    Children = new OptionsPageViewModel[]
                    {
                        new CleaningGeneralViewModel(package, ActiveSettings),
                        new CleaningFileTypesViewModel(package, ActiveSettings),
                        new CleaningVisualStudioViewModel(package, ActiveSettings),
                        new CleaningInsertViewModel(package, ActiveSettings),
                        new CleaningRemoveViewModel(package, ActiveSettings),
                        new CleaningUpdateViewModel(package, ActiveSettings)
                    }
                },
                new CollapsingViewModel(package, ActiveSettings),
                new DiggingViewModel(package, ActiveSettings),
                new FindingViewModel(package, ActiveSettings),
                new FormattingViewModel(package, ActiveSettings),
                new ProgressingViewModel(package, ActiveSettings),
                new ReorganizingParentViewModel(package, ActiveSettings)
                {
                    Children = new OptionsPageViewModel[]
                    {
                        new ReorganizingGeneralViewModel(package, ActiveSettings),
                        new ReorganizingTypesViewModel(package, ActiveSettings),
                        new ReorganizingRegionsViewModel(package, ActiveSettings)
                    }
                },
                new SwitchingViewModel(package, ActiveSettings),
                new ThirdPartyViewModel(package, ActiveSettings)
            };

            SelectedPage = Pages.Flatten().FirstOrDefault(x => x.GetType() == (initiallySelectedPageType ?? typeof(GeneralViewModel)));

            ReloadPagesFromSettings();
        }
Beispiel #2
0
        /// <summary>
        /// Default constructor of the package. Inside this method you can place any initialization
        /// code that does not require any Visual Studio service because at this point the package
        /// object is created but not sited yet inside Visual Studio environment. The place to do
        /// all the other initialization is the Initialize method.
        /// </summary>
        public CodeMaidPackage()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this));

            if (Application.Current != null)
            {
                Application.Current.DispatcherUnhandledException += OnDispatcherUnhandledException;
            }

            // If an existing user settings file cannot be found, perform a one-time settings upgrade.
            if (!File.Exists(SettingsContextHelper.GetUserSettingsPath()))
            {
                Settings.Default.Upgrade();
                Settings.Default.Save();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Register the package event listeners.
        /// </summary>
        /// <remarks>
        /// This must occur after the DTE service is available since many of the events are based
        /// off of the DTE object.
        /// </remarks>
        private void RegisterNonShellEventListeners()
        {
            // Create event listeners and register for events.
            var menuCommandService = MenuCommandService;

            if (menuCommandService != null)
            {
                var buildProgressToolWindowCommand     = _commands.OfType <BuildProgressToolWindowCommand>().First();
                var cleanupActiveCodeCommand           = _commands.OfType <CleanupActiveCodeCommand>().First();
                var collapseAllSolutionExplorerCommand = _commands.OfType <CollapseAllSolutionExplorerCommand>().First();
                var spadeToolWindowCommand             = _commands.OfType <SpadeToolWindowCommand>().First();

                var codeModelManager      = CodeModelManager.GetInstance(this);
                var settingsContextHelper = SettingsContextHelper.GetInstance(this);

                BuildProgressEventListener                       = new BuildProgressEventListener(this);
                BuildProgressEventListener.BuildBegin           += buildProgressToolWindowCommand.OnBuildBegin;
                BuildProgressEventListener.BuildProjConfigBegin += buildProgressToolWindowCommand.OnBuildProjConfigBegin;
                BuildProgressEventListener.BuildProjConfigDone  += buildProgressToolWindowCommand.OnBuildProjConfigDone;
                BuildProgressEventListener.BuildDone            += buildProgressToolWindowCommand.OnBuildDone;

                DocumentEventListener = new DocumentEventListener(this);
                DocumentEventListener.OnDocumentClosing += codeModelManager.OnDocumentClosing;

                RunningDocumentTableEventListener             = new RunningDocumentTableEventListener(this);
                RunningDocumentTableEventListener.BeforeSave += cleanupActiveCodeCommand.OnBeforeDocumentSave;
                RunningDocumentTableEventListener.AfterSave  += spadeToolWindowCommand.OnAfterDocumentSave;

                SolutionEventListener = new SolutionEventListener(this);
                SolutionEventListener.OnSolutionOpened += collapseAllSolutionExplorerCommand.OnSolutionOpened;
                SolutionEventListener.OnSolutionOpened += settingsContextHelper.OnSolutionOpened;
                SolutionEventListener.OnSolutionClosed += settingsContextHelper.OnSolutionClosed;
                SolutionEventListener.OnSolutionClosed += OnSolutionClosedShowStartPage;

                // Check if a solution has already been opened before CodeMaid was initialized.
                if (IDE.Solution != null && IDE.Solution.IsOpen)
                {
                    collapseAllSolutionExplorerCommand.OnSolutionOpened();
                }

                TextEditorEventListener = new TextEditorEventListener(this);
                TextEditorEventListener.OnLineChanged += codeModelManager.OnDocumentChanged;

                WindowEventListener = new WindowEventListener(this);
                WindowEventListener.OnWindowChange += spadeToolWindowCommand.OnWindowChange;
            }
        }
        /// <summary>
        /// Register the package event listeners.
        /// </summary>
        /// <remarks>
        /// Every event listener registers VS events by itself.
        /// </remarks>
        private async Task RegisterEventListenersAsync()
        {
            var codeModelManager      = CodeModelManager.GetInstance(this);
            var settingsContextHelper = SettingsContextHelper.GetInstance(this);

            VSColorTheme.ThemeChanged += _ => ThemeManager.ApplyTheme();

            await BuildProgressEventListener.InitializeAsync(this);

            BuildProgressEventListener.Instance.BuildBegin           += BuildProgressToolWindowCommand.Instance.OnBuildBegin;
            BuildProgressEventListener.Instance.BuildProjConfigBegin += BuildProgressToolWindowCommand.Instance.OnBuildProjConfigBegin;
            BuildProgressEventListener.Instance.BuildProjConfigDone  += BuildProgressToolWindowCommand.Instance.OnBuildProjConfigDone;
            BuildProgressEventListener.Instance.BuildDone            += BuildProgressToolWindowCommand.Instance.OnBuildDone;

            await DocumentEventListener.InitializeAsync(this);

            DocumentEventListener.Instance.OnDocumentClosing += codeModelManager.OnDocumentClosing;

            await RunningDocumentTableEventListener.InitializeAsync(this);

            await SettingsMonitor.WatchAsync(s => s.Feature_SettingCleanupOnSave, on =>
            {
                if (on)
                {
                    RunningDocumentTableEventListener.Instance.BeforeSave += CleanupActiveCodeCommand.Instance.OnBeforeDocumentSave;
                }
                else
                {
                    RunningDocumentTableEventListener.Instance.BeforeSave -= CleanupActiveCodeCommand.Instance.OnBeforeDocumentSave;
                }

                return(Task.CompletedTask);
            });

            await SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, on =>
            {
                if (on)
                {
                    RunningDocumentTableEventListener.Instance.AfterSave += SpadeToolWindowCommand.Instance.OnAfterDocumentSave;
                }
                else
                {
                    RunningDocumentTableEventListener.Instance.AfterSave -= SpadeToolWindowCommand.Instance.OnAfterDocumentSave;
                }

                return(Task.CompletedTask);
            });

            await SolutionEventListener.InitializeAsync(this);

            await SettingsMonitor.WatchAsync(s => s.Feature_CollapseAllSolutionExplorer, on =>
            {
                if (on)
                {
                    SolutionEventListener.Instance.OnSolutionOpened += CollapseAllSolutionExplorerCommand.Instance.OnSolutionOpened;
                }
                else
                {
                    SolutionEventListener.Instance.OnSolutionOpened -= CollapseAllSolutionExplorerCommand.Instance.OnSolutionOpened;
                }

                return(Task.CompletedTask);
            });

            SolutionEventListener.Instance.OnSolutionOpened += settingsContextHelper.OnSolutionOpened;
            SolutionEventListener.Instance.OnSolutionClosed += settingsContextHelper.OnSolutionClosed;
            SolutionEventListener.Instance.OnSolutionClosed += OnSolutionClosedShowStartPage;

            await TextEditorEventListener.InitializeAsync(this);

            TextEditorEventListener.Instance.OnLineChanged += codeModelManager.OnDocumentChanged;

            await WindowEventListener.InitializeAsync(this);

            WindowEventListener.Instance.OnWindowChange += SpadeToolWindowCommand.Instance.OnWindowChange;

            // Check if a solution has already been opened before CodeMaid was initialized.
            if (IDE.Solution?.IsOpen == true)
            {
                SolutionEventListener.Instance.FireSolutionOpenedEvent();
            }
        }