public void DetachInfoBar(IInfoBar currentInfoBar)
        {
            if (currentInfoBar == null)
            {
                throw new ArgumentNullException(nameof(currentInfoBar));
            }

            PrivateInfoBarWrapper wrapper = currentInfoBar as PrivateInfoBarWrapper;
            if (wrapper == null)
            {
                throw new ArgumentException(Strings.InvalidInfoBarInstance, nameof(currentInfoBar));
            }

            currentInfoBar.Close();

            IVsInfoBarHost host;
            if (TryGetInfoBarHost(wrapper.Frame, out host))
            {
                host.RemoveInfoBar(wrapper.InfoBarUIElement);
            }
        }
        public void DetachInfoBar(IInfoBar currentInfoBar)
        {
            if (currentInfoBar == null)
            {
                throw new ArgumentNullException(nameof(currentInfoBar));
            }

            if (!(currentInfoBar is PrivateInfoBarWrapper wrapper))
            {
                throw new ArgumentException(Strings.InvalidInfoBarInstance, nameof(currentInfoBar));
            }

            currentInfoBar.Close();

            ThreadHelper.ThrowIfNotOnUIThread();
            IVsInfoBarHost host;

            if (TryGetInfoBarHost(wrapper.Frame, out host))
            {
                host.RemoveInfoBar(wrapper.InfoBarUIElement);
            }
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     deprecationBar?.Close();
     deprecationBar = null;
 }
Exemplo n.º 4
0
        public void InfoBarManager_AttachInfoBar()
        {
            // Setup
            Guid windowGuid = new Guid();
            ConfigurableVsWindowFrame frame = this.shell.RegisterToolWindow(windowGuid);

            this.serviceProvider.RegisterService(typeof(SVsInfoBarUIFactory), new ConfigurableVsInfoBarUIFactory());
            var testSubject = new InfoBarManager(this.serviceProvider);
            ConfigurableVsInfoBarHost host = RegisterFrameInfoBarHost(frame);

            // Sanity
            host.AssertInfoBars(0);

            // Act
            IInfoBar infoBarWrapper = testSubject.AttachInfoBar(windowGuid, "Hello", "world", KnownMonikers.UserWarning);

            frame.AssertShowNoActivateCalled(1);
            bool actionClicked = false;
            bool closed        = false;

            infoBarWrapper.ButtonClick += (s, e) => actionClicked = true;
            infoBarWrapper.Closed      += (s, e) => closed = true;

            // Verify
            Assert.IsNotNull(infoBarWrapper);
            host.AssertInfoBars(1);
            var infoBarUI = host.MockedElements.Single();

            Assert.AreEqual(1, infoBarUI.Model.TextSpans.Count);
            Assert.AreEqual("Hello", infoBarUI.Model.TextSpans.GetSpan(0).Text);
            Assert.AreEqual(1, infoBarUI.Model.ActionItems.Count);
            Assert.AreEqual("world", infoBarUI.Model.ActionItems.GetItem(0).Text);

            // Sanity
            Assert.IsFalse(actionClicked);
            Assert.IsFalse(closed);

            // Act (check if close event is fired)
            infoBarUI.SimulateClickEvent();

            // Verify
            Assert.IsTrue(actionClicked);
            Assert.IsFalse(closed);

            // Act (check if close event is fired)
            infoBarUI.SimulateClosedEvent();

            // Verify
            Assert.IsTrue(closed);

            // Act (check that events won't fire once closed)
            actionClicked = false;
            closed        = false;
            infoBarUI.SimulateClickEvent();
            infoBarWrapper.Close();
            infoBarUI.SimulateClosedEvent();

            // Verify
            Assert.IsFalse(actionClicked);
            Assert.IsFalse(closed);
            frame.AssertShowNoActivateCalled(1); // Should only be called once in all this flow
        }