Skip to content

Commit

Permalink
Add toggle button for daemon activation/deactivation (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Gyerik authored May 8, 2017
1 parent a201ba5 commit 05b35ca
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<TextBlock Margin="20,5,10,5"
Text="SonarLint for Visual Studio can also analyze JavaScript files, limited to standalone mode for now. After installing JavaScript support, it will be activated for newly opened files."
TextWrapping="Wrap"/>
<Button Margin="20,5,10,5" Content="Install JavaScript support" Click="OnInstallJavaScriptClicked" />
<Button Margin="20,5,10,5" Content="Install JavaScript support" Click="OnActivateMoreClicked" x:Name="ActivateMoreButton" />
</StackPanel>
</UserControl>
68 changes: 64 additions & 4 deletions src/Integration.Vsix/Settings/GeneralOptionsDialogControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Microsoft.VisualStudio.Shell;
using System.Windows;
using System.Windows.Controls;
using System;

namespace SonarLint.VisualStudio.Integration.Vsix
{
Expand All @@ -29,17 +30,76 @@ namespace SonarLint.VisualStudio.Integration.Vsix
/// </summary>
public partial class GeneralOptionsDialogControl : UserControl
{
private ISonarLintSettings settings;
private ISonarLintDaemon daemon;

public GeneralOptionsDialogControl()
{
InitializeComponent();
}

private void OnInstallJavaScriptClicked(object sender, RoutedEventArgs e)
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);

UpdateActivateMoreButtonText();
}

private void UpdateActivateMoreButtonText()
{
ActivateMoreButton.Content = Settings.IsActivateMoreEnabled
? "Deactivate JavaScript support"
: "Install and activate JavaScript support";
}

private void OnActivateMoreClicked(object sender, RoutedEventArgs e)
{
var daemon = ServiceProvider.GlobalProvider.GetMefService<ISonarLintDaemon>();
if (!daemon.IsInstalled)
if (Settings.IsActivateMoreEnabled)
{
if (Daemon.IsRunning)
{
Daemon.Stop();
}
}
else
{
new SonarLintDaemonInstaller().Show();
if (!Daemon.IsInstalled)
{
new SonarLintDaemonInstaller().Show();
}
else if (!Daemon.IsRunning)
{
Daemon.Start();
}
}

Settings.IsActivateMoreEnabled = !Settings.IsActivateMoreEnabled;
UpdateActivateMoreButtonText();
}

private ISonarLintSettings Settings
{
get
{
if (this.settings == null)
{
this.settings = ServiceProvider.GlobalProvider.GetMefService<ISonarLintSettings>();
}

return this.settings;
}
}

private ISonarLintDaemon Daemon
{
get
{
if (this.daemon == null)
{
this.daemon = ServiceProvider.GlobalProvider.GetMefService<ISonarLintDaemon>();
}

return this.daemon;
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/Integration.Vsix/Settings/SonarLintSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public interface ISonarLintSettings
{
bool ShowServerNuGetTrustWarning { get; set; }
bool IsAnonymousDataShared { get; set; }
bool IsActivateMoreEnabled { get; set; }
bool SkipActivateMoreDialog { get; set; }
}

Expand Down Expand Up @@ -114,8 +115,14 @@ public bool IsAnonymousDataShared

public bool SkipActivateMoreDialog
{
get { return this.GetValueOrDefault(nameof(SkipActivateMoreDialog), true); }
get { return this.GetValueOrDefault(nameof(SkipActivateMoreDialog), false); }
set { this.SetValue(nameof(SkipActivateMoreDialog), value); }
}

public bool IsActivateMoreEnabled
{
get { return this.GetValueOrDefault(nameof(IsActivateMoreEnabled), false); }
set { this.SetValue(nameof(IsActivateMoreEnabled), value); }
}
}
}
1 change: 1 addition & 0 deletions src/Integration.Vsix/SonarLintDaemon/ISonarLintDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface ISonarLintDaemon : IDisposable

void Install();
void Start();
void Stop();
void RequestAnalysis(string path, string charset, IIssueConsumer consumer);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Integration.Vsix/SonarLintDaemonPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public sealed class SonarLintDaemonPackage : Package
{
public const string PackageGuidString = "6f63ab5a-5ab8-4a0d-9914-151911885966";

private readonly ISonarLintSettings settings = ServiceProvider.GlobalProvider.GetMefService<ISonarLintSettings>();
private readonly ISonarLintDaemon daemon = ServiceProvider.GlobalProvider.GetMefService<ISonarLintDaemon>();

/// <summary>
Expand All @@ -75,7 +76,7 @@ protected override void Initialize()
{
base.Initialize();

if (daemon.IsInstalled)
if (settings.IsActivateMoreEnabled && daemon.IsInstalled)
{
if (!daemon.IsRunning)
{
Expand All @@ -100,8 +101,10 @@ private void LaunchActivateMoreDialog()
var result = MessageBox.Show(message, title, MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
settings.IsActivateMoreEnabled = true;
new SonarLintDaemonInstaller().Show();
}
settings.SkipActivateMoreDialog = true;
}

protected override void Dispose(bool disposing)
Expand Down

0 comments on commit 05b35ca

Please sign in to comment.