protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            await JoinableTaskFactory.SwitchToMainThreadAsync();    // Command constructors need to be on main thread.

            PickColorCommand.Initialize(this);
            ResetColorCommand.Initialize(this);
            EnableAutoPickColorCommand.Initialize(this);

            listener = new SolutionOpenListener(this);

            await UpdateTitleBarControllerListAsync();

            // Window events won't give us events for undocking so we can't use that.
            //var dte = VSUtils.GetDTE();
            //windowEvents = dte.Events.WindowEvents;
            //windowEvents.WindowCreated += (Window) => CheckForNewController();
            //windowEvents.WindowClosing += (Window) => CheckForNewController();

            // Instead we're using a bigger gun: The Automation framework!
            // Sadly, it is not enough to listen to child windows of VS since code window popups are direct children of the desktop in terms of UI.
            Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Children, OnWindowOpenedClosed);
            // Weirdly, this doesn't apply to ALL child windows, and some are children of the main window after all. (Repro: Create a window out of two non-code views)
            var windowHandle            = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            var windowAutomationElement = AutomationElement.FromHandle(windowHandle);

            Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, windowAutomationElement, TreeScope.Subtree, OnWindowOpenedClosed);

            // Cant use TreeScope.Children on WindowClosedEvent.
            Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, AutomationElement.RootElement, TreeScope.Subtree, OnWindowOpenedClosed);
        }
Ejemplo n.º 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 void Initialize()
        {
            TitleBarColorControl = new TitleBarColorController();
            PickColorCommand.Initialize(this);
            ResetColorCommand.Initialize(this);

            solutionEvents         = VSUtils.GetDTE().Events.SolutionEvents;
            solutionEvents.Opened += SolutionOpened;

            base.Initialize();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 public static void Initialize(SolutionColorPackage package)
 {
     Instance = new PickColorCommand(package);
 }