Exemple #1
0
        private void ShowDeprecationBar()
        {
            const string message = "SonarLint for Visual Studio versions 4.0+ will no longer support this version of Visual " +
                                   "Studio. Please update to Visual Studio 2015 Update 3 or Visual Studio 2017 to benefit from new features.";

            deprecationBar = infoBarManager.AttachInfoBar(DeprecationBarGuid, message, default(ImageMoniker));
        }
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="customInfoBarMessage">Optional. If provided than this will be the message that will appear in info bar, otherwise a standard one will appear instead</param>
        private void UpdateRequired(string customInfoBarMessage = null)
        {
            this.AssertOnUIThread();
            IInfoBarManager manager = this.host.GetMefService <IInfoBarManager>();

            if (manager == null)
            {
                Debug.Fail("Cannot find IInfoBarManager");
                return;
            }

            this.currentErrorWindowInfoBar = manager.AttachInfoBarWithButton(
                ErrorListToolWindowGuid,
                customInfoBarMessage ?? Strings.SonarLintInfoBarUnboundProjectsMessage,
                Strings.SonarLintInfoBarUpdateCommandText,
                KnownMonikers.RuleWarning);

            if (this.currentErrorWindowInfoBar == null)
            {
                this.OutputMessage(Strings.SonarLintFailedToAttachInfoBarToErrorList);
                Debug.Fail("Failed to add an info bar to the error list tool window");
            }
            else
            {
                var componentModel = host.GetService <SComponentModel, IComponentModel>();
                TelemetryLoggerAccessor.GetLogger(componentModel)?.ReportEvent(TelemetryEvent.ErrorListInfoBarShow);

                this.currentErrorWindowInfoBar.Closed      += this.CurrentErrorWindowInfoBar_Closed;
                this.currentErrorWindowInfoBar.ButtonClick += this.CurrentErrorWindowInfoBar_ButtonClick;

                // Need to capture the current binding information since the user can change the binding
                // and running the Update should just no-op in that case.
                this.infoBarBinding = configProvider.GetConfiguration().Project;
            }
        }
Exemple #3
0
        private void ShowDeprecationBar()
        {
            const string message = "Newer versions of SonarLint will not work with this version of Visual Studio. Please " +
                                   "update to Visual Studio 2015 Update 3 or Visual Studio 2017 to benefit from new features.";

            deprecationBar = infoBarManager.AttachInfoBar(DeprecationBarGuid, message, default(ImageMoniker));
        }
Exemple #4
0
        private void AddInfoBar(Guid toolWindowId)
        {
            currentInfoBar = infoBarManager.AttachInfoBarWithButton(toolWindowId, OpenInIDEResources.RequestValidator_InfoBarMessage, "Show Output Window", default);
            Debug.Assert(currentInfoBar != null, "currentInfoBar != null");

            currentInfoBar.ButtonClick += ShowOutputWindow;
            currentInfoBar.Closed      += CurrentInfoBar_Closed;
        }
Exemple #5
0
 private void RemoveExistingInfoBar()
 {
     if (currentInfoBar != null)
     {
         currentInfoBar.ButtonClick -= ShowOutputWindow;
         currentInfoBar.Closed      -= CurrentInfoBar_Closed;
         infoBarManager.DetachInfoBar(currentInfoBar);
         currentInfoBar = null;
     }
 }
        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);
            }
        }
Exemple #7
0
        public RPackageManagerViewModel(IRPackageManager packageManager, IInfoBar infoBar, IServiceContainer services)
        {
            _packageManager = packageManager;
            _infoBar        = infoBar;
            _services       = services;
            _settings       = services.GetService <IRSettings>();
            _mainThread     = services.MainThread();

            _selectedTab            = Tab.None;
            _availablePackages      = new List <IRPackageViewModel>();
            _installedPackages      = new List <IRPackageViewModel>();
            _loadedPackages         = new List <IRPackageViewModel>();
            _availableLock          = new BinaryAsyncLock();
            _installedAndLoadedLock = new BinaryAsyncLock();
            _items         = new BatchObservableCollection <object>();
            _errorMessages = new ErrorMessageCollection(this);
            Items          = new ReadOnlyObservableCollection <object>(_items);

            _packageManager.AvailablePackagesInvalidated += AvailablePackagesInvalidated;
            _packageManager.InstalledPackagesInvalidated += InstalledPackagesInvalidated;
            _packageManager.LoadedPackagesInvalidated    += LoadedPackagesInvalidated;
        }
        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);
            }
        }
Exemple #9
0
        private void ClearCurrentInfoBar()
        {
            this.CancelQualityProfileProcessing();

            this.infoBarBinding = null;
            this.currentErrorWindowInfoBarHandlingClick = false;
            if (this.currentErrorWindowInfoBar == null)
            {
                return;
            }

            this.currentErrorWindowInfoBar.Closed      -= this.CurrentErrorWindowInfoBar_Closed;
            this.currentErrorWindowInfoBar.ButtonClick -= this.CurrentErrorWindowInfoBar_ButtonClick;

            IInfoBarManager manager = this.host.GetMefService <IInfoBarManager>();

            if (manager == null) // Could be null during shut down
            {
                return;
            }

            manager.DetachInfoBar(this.currentErrorWindowInfoBar);
            this.currentErrorWindowInfoBar = null;
        }
Exemple #10
0
        public void InfoBarManager_DetachInfoBar()
        {
            // 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);
            IInfoBar infoBarWrapper        = testSubject.AttachInfoBar(windowGuid, "Hello", "world", default(ImageMoniker));
            bool     closed = false;

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

            // Sanity
            host.AssertInfoBars(1);

            // Act
            testSubject.DetachInfoBar(infoBarWrapper);

            // Verify
            Assert.IsTrue(closed, "Expected to auto-close");
            host.AssertInfoBars(0);
        }
 void IInfoBarManager.DetachInfoBar(IInfoBar currentInfoBar)
 {
     Assert.IsTrue(this.attached.Values.Contains(currentInfoBar), "Info bar is not attached");
     this.attached.Remove(attached.Single(kv => kv.Value == currentInfoBar).Key);
 }
 void IInfoBarManager.DetachInfoBar(IInfoBar currentInfoBar)
 {
     Assert.IsTrue(this.attached.Values.Contains(currentInfoBar), "Info bar is not attached");
     this.attached.Remove(attached.Single(kv => kv.Value == currentInfoBar).Key);
 }
 void IInfoBarManager.DetachInfoBar(IInfoBar currentInfoBar)
 {
     this.attached.Values.Should().Contain((ConfigurableInfoBar)currentInfoBar, "Info bar is not attached");
     this.attached.Remove(attached.Single(kv => kv.Value == currentInfoBar).Key);
 }
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="customInfoBarMessage">Optional. If provided than this will be the message that will appear in info bar, otherwise a standard one will appear instead</param>
        private void UpdateRequired(string customInfoBarMessage = null)
        {
            this.AssertOnUIThread();
            IInfoBarManager manager = this.host.GetMefService<IInfoBarManager>();
            if (manager == null)
            {
                Debug.Fail("Cannot find IInfoBarManager");
                return;
            }

            this.currentErrorWindowInfoBar = manager.AttachInfoBar(
                ErrorListToolWindowGuid,
                customInfoBarMessage ?? Strings.SonarLintInfoBarUnboundProjectsMessage,
                Strings.SonarLintInfoBarUpdateCommandText,
                KnownMonikers.RuleWarning);

            if (this.currentErrorWindowInfoBar == null)
            {
                this.OutputMessage(Strings.SonarLintFailedToAttachInfoBarToErrorList);
                Debug.Fail("Failed to add an info bar to the error list tool window");
            }
            else
            {
                TelemetryLoggerAccessor.GetLogger(this.host)?.ReportEvent(TelemetryEvent.ErrorListInfoBarShow);

                this.currentErrorWindowInfoBar.Closed += this.CurrentErrorWindowInfoBar_Closed;
                this.currentErrorWindowInfoBar.ButtonClick += this.CurrentErrorWindowInfoBar_ButtonClick;

                // Need to capture the current binding information since the user can change the binding
                // and running the Update should just no-op in that case.
                var solutionBinding = this.host.GetService<ISolutionBindingSerializer>();
                solutionBinding.AssertLocalServiceIsNotNull();

                this.infoBarBinding = solutionBinding.ReadSolutionBinding();
            }
        }
Exemple #15
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
        }
Exemple #16
0
 public void Dispose()
 {
     deprecationBar?.Close();
     deprecationBar = null;
 }
        private void ClearCurrentInfoBar()
        {
            this.CancelQualityProfileProcessing();

            this.infoBarBinding = null;
            this.currentErrorWindowInfoBarHandlingClick = false;
            if (this.currentErrorWindowInfoBar == null)
            {
                return;
            }

            this.currentErrorWindowInfoBar.Closed -= this.CurrentErrorWindowInfoBar_Closed;
            this.currentErrorWindowInfoBar.ButtonClick -= this.CurrentErrorWindowInfoBar_ButtonClick;

            IInfoBarManager manager = this.host.GetMefService<IInfoBarManager>();
            if (manager == null) // Could be null during shut down
            {
                return;
            }

            manager.DetachInfoBar(this.currentErrorWindowInfoBar);
            this.currentErrorWindowInfoBar = null;
        }