diff --git a/Snyk.VisualStudio.Extension.2022/Settings/ISnykCliOptionsDialogPage.cs b/Snyk.VisualStudio.Extension.2022/Settings/ISnykCliOptionsDialogPage.cs new file mode 100644 index 00000000..ddcbb5a8 --- /dev/null +++ b/Snyk.VisualStudio.Extension.2022/Settings/ISnykCliOptionsDialogPage.cs @@ -0,0 +1,8 @@ +using Snyk.VisualStudio.Extension.Service; + +namespace Snyk.VisualStudio.Extension.Settings; + +public interface ISnykCliOptionsDialogPage +{ + void Initialize(ISnykServiceProvider provider); +} \ No newline at end of file diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsDialogPage.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsDialogPage.cs new file mode 100644 index 00000000..5f8b0361 --- /dev/null +++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsDialogPage.cs @@ -0,0 +1,72 @@ +using System; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using Microsoft.VisualStudio.Shell; +using Snyk.VisualStudio.Extension.Service; + +namespace Snyk.VisualStudio.Extension.Settings; + +[Guid("D1D89CEB-7691-4A67-8579-4C3DDE776982")] +[ComVisible(true)] +public class SnykCliOptionsDialogPage : DialogPage, ISnykCliOptionsDialogPage +{ + private SnykCliOptionsUserControl snykCliOptionsUserControl; + private ISnykServiceProvider serviceProvider; + + public void Initialize(ISnykServiceProvider provider) + { + this.serviceProvider = provider; + this.SnykOptions = provider.Options; + } + + public ISnykOptions SnykOptions { get; set; } + + protected override IWin32Window Window => SnykCliOptionsUserControl; + public SnykCliOptionsUserControl SnykCliOptionsUserControl + { + get + { + if (snykCliOptionsUserControl == null) + { + snykCliOptionsUserControl = new SnykCliOptionsUserControl(serviceProvider); + } + return snykCliOptionsUserControl; + } + } + + // This method is used when the user clicks "Ok" + public override void SaveSettingsToStorage() + { + HandleCliDownload(); + this.SnykOptions.SaveSettings(); + this.SnykOptions.InvokeSettingsChangedEvent(); + } + + protected override void OnClosed(EventArgs e) + { + + } + + private void HandleCliDownload() + { + var releaseChannel = SnykCliOptionsUserControl.GetReleaseChannel().Trim(); + var downloadUrl = SnykCliOptionsUserControl.GetCliDownloadUrl().Trim(); + var manageBinariesAutomatically = SnykCliOptionsUserControl.GetManageBinariesAutomatically(); + if (!manageBinariesAutomatically) + { + this.SnykOptions.CurrentCliVersion = string.Empty; + this.SnykOptions.BinariesAutoUpdate = false; + serviceProvider.TasksService.CancelDownloadTask(); + // Language Server restart will happen on DownloadCancelled Event. + return; + } + if (this.SnykOptions.CliReleaseChannel != releaseChannel || this.SnykOptions.CliDownloadUrl != downloadUrl || this.SnykOptions.BinariesAutoUpdate != manageBinariesAutomatically) + { + this.SnykOptions.CliDownloadUrl = downloadUrl; + this.SnykOptions.CliReleaseChannel = releaseChannel; + this.SnykOptions.BinariesAutoUpdate = manageBinariesAutomatically; + serviceProvider.TasksService.CancelDownloadTask(); + this.serviceProvider.TasksService.Download(); + } + } +} \ No newline at end of file diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.Designer.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.Designer.cs new file mode 100644 index 00000000..5f61ead5 --- /dev/null +++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.Designer.cs @@ -0,0 +1,238 @@ +namespace Snyk.VisualStudio.Extension.Settings +{ + partial class SnykCliOptionsUserControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.mainPanel = new System.Windows.Forms.Panel(); + this.ExecutablesGroupBox = new System.Windows.Forms.GroupBox(); + this.ReleaseChannelLink = new System.Windows.Forms.LinkLabel(); + this.releaseChannel = new System.Windows.Forms.ComboBox(); + this.cliReleaseChannelLabel = new System.Windows.Forms.Label(); + this.cliBaseDownloadUrl = new System.Windows.Forms.Label(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.cliDownloadUrlTextBox = new System.Windows.Forms.TextBox(); + this.CliPathLabel = new System.Windows.Forms.Label(); + this.resetCliPathToDefaultButton = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.CliPathBrowseButton = new System.Windows.Forms.Button(); + this.manageBinariesAutomaticallyCheckbox = new System.Windows.Forms.CheckBox(); + this.CliPathTextBox = new System.Windows.Forms.TextBox(); + this.customCliPathFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.mainPanel.SuspendLayout(); + this.ExecutablesGroupBox.SuspendLayout(); + this.SuspendLayout(); + // + // mainPanel + // + this.mainPanel.AutoScroll = true; + this.mainPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.mainPanel.Controls.Add(this.ExecutablesGroupBox); + this.mainPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.mainPanel.Location = new System.Drawing.Point(0, 0); + this.mainPanel.Name = "mainPanel"; + this.mainPanel.Size = new System.Drawing.Size(752, 285); + this.mainPanel.TabIndex = 0; + // + // ExecutablesGroupBox + // + this.ExecutablesGroupBox.Controls.Add(this.ReleaseChannelLink); + this.ExecutablesGroupBox.Controls.Add(this.releaseChannel); + this.ExecutablesGroupBox.Controls.Add(this.cliReleaseChannelLabel); + this.ExecutablesGroupBox.Controls.Add(this.cliBaseDownloadUrl); + this.ExecutablesGroupBox.Controls.Add(this.richTextBox1); + this.ExecutablesGroupBox.Controls.Add(this.cliDownloadUrlTextBox); + this.ExecutablesGroupBox.Controls.Add(this.CliPathLabel); + this.ExecutablesGroupBox.Controls.Add(this.resetCliPathToDefaultButton); + this.ExecutablesGroupBox.Controls.Add(this.label1); + this.ExecutablesGroupBox.Controls.Add(this.CliPathBrowseButton); + this.ExecutablesGroupBox.Controls.Add(this.manageBinariesAutomaticallyCheckbox); + this.ExecutablesGroupBox.Controls.Add(this.CliPathTextBox); + this.ExecutablesGroupBox.Location = new System.Drawing.Point(4, 4); + this.ExecutablesGroupBox.Margin = new System.Windows.Forms.Padding(4); + this.ExecutablesGroupBox.Name = "ExecutablesGroupBox"; + this.ExecutablesGroupBox.Padding = new System.Windows.Forms.Padding(4); + this.ExecutablesGroupBox.Size = new System.Drawing.Size(729, 261); + this.ExecutablesGroupBox.TabIndex = 20; + this.ExecutablesGroupBox.TabStop = false; + this.ExecutablesGroupBox.Text = "CLI Settings"; + // + // ReleaseChannelLink + // + this.ReleaseChannelLink.AutoSize = true; + this.ReleaseChannelLink.Location = new System.Drawing.Point(8, 241); + this.ReleaseChannelLink.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.ReleaseChannelLink.Name = "ReleaseChannelLink"; + this.ReleaseChannelLink.Size = new System.Drawing.Size(219, 16); + this.ReleaseChannelLink.TabIndex = 20; + this.ReleaseChannelLink.TabStop = true; + this.ReleaseChannelLink.Text = "Find out about our release channels"; + this.ReleaseChannelLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.ReleaseChannelLink_LinkClicked); + // + // releaseChannel + // + this.releaseChannel.FormattingEnabled = true; + this.releaseChannel.Location = new System.Drawing.Point(239, 208); + this.releaseChannel.Margin = new System.Windows.Forms.Padding(4); + this.releaseChannel.Name = "releaseChannel"; + this.releaseChannel.Size = new System.Drawing.Size(160, 24); + this.releaseChannel.TabIndex = 23; + // + // cliReleaseChannelLabel + // + this.cliReleaseChannelLabel.AutoSize = true; + this.cliReleaseChannelLabel.Location = new System.Drawing.Point(5, 212); + this.cliReleaseChannelLabel.Name = "cliReleaseChannelLabel"; + this.cliReleaseChannelLabel.Size = new System.Drawing.Size(128, 16); + this.cliReleaseChannelLabel.TabIndex = 22; + this.cliReleaseChannelLabel.Text = "CLI release channel:"; + // + // cliBaseDownloadUrl + // + this.cliBaseDownloadUrl.AutoSize = true; + this.cliBaseDownloadUrl.Location = new System.Drawing.Point(5, 27); + this.cliBaseDownloadUrl.Name = "cliBaseDownloadUrl"; + this.cliBaseDownloadUrl.Size = new System.Drawing.Size(194, 16); + this.cliBaseDownloadUrl.TabIndex = 20; + this.cliBaseDownloadUrl.Text = "Base URL to download the CLI: "; + // + // richTextBox1 + // + this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.richTextBox1.Location = new System.Drawing.Point(9, 155); + this.richTextBox1.Margin = new System.Windows.Forms.Padding(4); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.ReadOnly = true; + this.richTextBox1.Size = new System.Drawing.Size(684, 39); + this.richTextBox1.TabIndex = 18; + this.richTextBox1.Text = "Snyk will download, install and update the dependencies for you. If this option i" + + "s disabled, make sure valid paths to the dependencies are provided."; + // + // cliDownloadUrlTextBox + // + this.cliDownloadUrlTextBox.Location = new System.Drawing.Point(241, 23); + this.cliDownloadUrlTextBox.Margin = new System.Windows.Forms.Padding(4); + this.cliDownloadUrlTextBox.Name = "cliDownloadUrlTextBox"; + this.cliDownloadUrlTextBox.Size = new System.Drawing.Size(399, 22); + this.cliDownloadUrlTextBox.TabIndex = 21; + // + // CliPathLabel + // + this.CliPathLabel.AutoSize = true; + this.CliPathLabel.Location = new System.Drawing.Point(5, 71); + this.CliPathLabel.Name = "CliPathLabel"; + this.CliPathLabel.Size = new System.Drawing.Size(92, 16); + this.CliPathLabel.TabIndex = 14; + this.CliPathLabel.Text = "Snyk CLI Path:"; + // + // resetCliPathToDefaultButton + // + this.resetCliPathToDefaultButton.Location = new System.Drawing.Point(347, 65); + this.resetCliPathToDefaultButton.Margin = new System.Windows.Forms.Padding(4); + this.resetCliPathToDefaultButton.Name = "resetCliPathToDefaultButton"; + this.resetCliPathToDefaultButton.Size = new System.Drawing.Size(129, 28); + this.resetCliPathToDefaultButton.TabIndex = 17; + this.resetCliPathToDefaultButton.Text = "Reset to default"; + this.resetCliPathToDefaultButton.UseVisualStyleBackColor = true; + this.resetCliPathToDefaultButton.Click += new System.EventHandler(this.ClearCliCustomPathButton_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(41, 132); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(320, 16); + this.label1.TabIndex = 12; + this.label1.Text = "Update and install Snyk dependencies automatically"; + // + // CliPathBrowseButton + // + this.CliPathBrowseButton.Location = new System.Drawing.Point(239, 65); + this.CliPathBrowseButton.Margin = new System.Windows.Forms.Padding(4); + this.CliPathBrowseButton.Name = "CliPathBrowseButton"; + this.CliPathBrowseButton.Size = new System.Drawing.Size(100, 28); + this.CliPathBrowseButton.TabIndex = 16; + this.CliPathBrowseButton.Text = "Browse"; + this.CliPathBrowseButton.UseVisualStyleBackColor = true; + this.CliPathBrowseButton.Click += new System.EventHandler(this.CliPathBrowseButton_Click); + // + // manageBinariesAutomaticallyCheckbox + // + this.manageBinariesAutomaticallyCheckbox.AutoSize = true; + this.manageBinariesAutomaticallyCheckbox.Location = new System.Drawing.Point(16, 132); + this.manageBinariesAutomaticallyCheckbox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.manageBinariesAutomaticallyCheckbox.Name = "manageBinariesAutomaticallyCheckbox"; + this.manageBinariesAutomaticallyCheckbox.Size = new System.Drawing.Size(18, 17); + this.manageBinariesAutomaticallyCheckbox.TabIndex = 13; + this.manageBinariesAutomaticallyCheckbox.UseVisualStyleBackColor = true; + // + // CliPathTextBox + // + this.CliPathTextBox.Location = new System.Drawing.Point(241, 96); + this.CliPathTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.CliPathTextBox.Name = "CliPathTextBox"; + this.CliPathTextBox.ReadOnly = true; + this.CliPathTextBox.Size = new System.Drawing.Size(399, 22); + this.CliPathTextBox.TabIndex = 15; + // + // customCliPathFileDialog + // + this.customCliPathFileDialog.SupportMultiDottedExtensions = true; + // + // SnykCliOptionsUserControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.mainPanel); + this.Name = "SnykCliOptionsUserControl"; + this.Size = new System.Drawing.Size(752, 285); + this.mainPanel.ResumeLayout(false); + this.ExecutablesGroupBox.ResumeLayout(false); + this.ExecutablesGroupBox.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel mainPanel; + private System.Windows.Forms.GroupBox ExecutablesGroupBox; + private System.Windows.Forms.LinkLabel ReleaseChannelLink; + private System.Windows.Forms.ComboBox releaseChannel; + private System.Windows.Forms.Label cliReleaseChannelLabel; + private System.Windows.Forms.Label cliBaseDownloadUrl; + private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.TextBox cliDownloadUrlTextBox; + private System.Windows.Forms.Label CliPathLabel; + private System.Windows.Forms.Button resetCliPathToDefaultButton; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button CliPathBrowseButton; + private System.Windows.Forms.CheckBox manageBinariesAutomaticallyCheckbox; + private System.Windows.Forms.TextBox CliPathTextBox; + private System.Windows.Forms.OpenFileDialog customCliPathFileDialog; + } +} diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.cs new file mode 100644 index 00000000..6cda1928 --- /dev/null +++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.cs @@ -0,0 +1,105 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Windows.Forms; +using Microsoft.VisualStudio.Shell; +using Serilog; +using Snyk.VisualStudio.Extension.CLI; +using Snyk.VisualStudio.Extension.Service; + +namespace Snyk.VisualStudio.Extension.Settings +{ + public partial class SnykCliOptionsUserControl : UserControl + { + private readonly ISnykServiceProvider serviceProvider; + private readonly ISnykOptions snykOptions; + private static readonly ILogger Logger = LogManager.ForContext(); + + public SnykCliOptionsUserControl(ISnykServiceProvider serviceProvider) + { + this.serviceProvider = serviceProvider; + snykOptions = this.serviceProvider.Options; + InitializeComponent(); + this.Initialize(); + } + private void Initialize() + { + this.UpdateViewFromOptions(); + } + + private void UpdateViewFromOptions() + { + this.manageBinariesAutomaticallyCheckbox.Checked = snykOptions.BinariesAutoUpdate; + this.cliDownloadUrlTextBox.Text = snykOptions.CliDownloadUrl; + + var cliPath = string.IsNullOrEmpty(snykOptions.CliCustomPath) + ? SnykCli.GetSnykCliDefaultPath() + : snykOptions.CliCustomPath; + + this.CliPathTextBox.Text = cliPath; + if (releaseChannel.DataSource == null) + { + this.releaseChannel.DataSource = ReleaseChannelList(); + } + + this.releaseChannel.SelectedItem = snykOptions.CliReleaseChannel; + } + + private IEnumerable ReleaseChannelList() + { + var defaultList = new List() { "stable", "rc", "preview" }; + if (!defaultList.Contains(snykOptions.CliReleaseChannel)) + { + defaultList.Add(snykOptions.CliReleaseChannel); + } + return defaultList; + } + + private void CliPathBrowseButton_Click(object sender, System.EventArgs e) + { + if(this.customCliPathFileDialog.ShowDialog() == DialogResult.OK) + { + var selectedCliPath = this.customCliPathFileDialog.FileName; + this.SetCliCustomPathValue(selectedCliPath); + } + } + + private void SetCliCustomPathValue(string selectedCliPath) + { + snykOptions.CliCustomPath = selectedCliPath; + this.CliPathTextBox.Text = string.IsNullOrEmpty(snykOptions.CliCustomPath) + ? SnykCli.GetSnykCliDefaultPath() + : selectedCliPath; + } + + private void ClearCliCustomPathButton_Click(object sender, System.EventArgs e) + { + this.SetCliCustomPathValue(string.Empty); + } + + private void ReleaseChannelLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + this.ReleaseChannelLink.LinkVisited = true; + Process.Start("https://docs.snyk.io/snyk-cli/releases-and-channels-for-the-snyk-cli"); + } + + public string GetReleaseChannel() + { + return releaseChannel.Text; + } + + public string GetCliDownloadUrl() + { + return cliDownloadUrlTextBox.Text; + } + + public bool GetManageBinariesAutomatically() + { + return manageBinariesAutomaticallyCheckbox.Checked; + } + + public Panel GetPanel() + { + return this.mainPanel; + } + } +} diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.resx b/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.resx new file mode 100644 index 00000000..1e62546b --- /dev/null +++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykCliOptionsUserControl.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs index 62586245..d944dd1c 100644 --- a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs +++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs @@ -86,34 +86,10 @@ public SnykGeneralSettingsUserControl GeneralSettingsUserControl // This method is used when the user clicks "Ok" public override void SaveSettingsToStorage() { - HandleCliDownload(); this.SnykOptions.SaveSettings(); this.SnykOptions.InvokeSettingsChangedEvent(); } - private void HandleCliDownload() - { - var releaseChannel = generalSettingsUserControl.GetReleaseChannel().Trim(); - var downloadUrl = generalSettingsUserControl.GetCliDownloadUrl().Trim(); - var manageBinariesAutomatically = generalSettingsUserControl.GetManageBinariesAutomatically(); - if (!manageBinariesAutomatically) - { - this.SnykOptions.CurrentCliVersion = string.Empty; - this.SnykOptions.BinariesAutoUpdate = false; - serviceProvider.TasksService.CancelDownloadTask(); - // Language Server restart will happen on DownloadCancelled Event. - return; - } - if (this.SnykOptions.CliReleaseChannel != releaseChannel || this.SnykOptions.CliDownloadUrl != downloadUrl || this.SnykOptions.BinariesAutoUpdate != manageBinariesAutomatically) - { - this.SnykOptions.CliDownloadUrl = downloadUrl; - this.SnykOptions.CliReleaseChannel = releaseChannel; - this.SnykOptions.BinariesAutoUpdate = manageBinariesAutomatically; - serviceProvider.TasksService.CancelDownloadTask(); - this.serviceProvider.TasksService.Download(); - } - } - private void SnykGeneralOptionsDialogPage_SettingsChanged(object sender, SnykSettingsChangedEventArgs e) { ThreadHelper.JoinableTaskFactory.RunAsync(async () => diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.Designer.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.Designer.cs index 0de34f58..f540adb6 100644 --- a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.Designer.cs +++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.Designer.cs @@ -52,13 +52,6 @@ private void InitializeComponent() this.label2 = new System.Windows.Forms.Label(); this.OrganizationInfoLink = new System.Windows.Forms.LinkLabel(); this.OrgDescriptionText = new System.Windows.Forms.Label(); - this.richTextBox1 = new System.Windows.Forms.RichTextBox(); - this.resetCliPathToDefaultButton = new System.Windows.Forms.Button(); - this.CliPathBrowseButton = new System.Windows.Forms.Button(); - this.CliPathTextBox = new System.Windows.Forms.TextBox(); - this.CliPathLabel = new System.Windows.Forms.Label(); - this.ManageBinariesAutomaticallyCheckbox = new System.Windows.Forms.CheckBox(); - this.label1 = new System.Windows.Forms.Label(); this.productSelectionGroupBox = new System.Windows.Forms.GroupBox(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); @@ -80,19 +73,12 @@ private void InitializeComponent() this.snykCodeSecurityInfoToolTip = new System.Windows.Forms.ToolTip(this.components); this.snykCodeQualityInfoToolTip = new System.Windows.Forms.ToolTip(this.components); this.customCliPathFileDialog = new System.Windows.Forms.OpenFileDialog(); - this.ExecutablesGroupBox = new System.Windows.Forms.GroupBox(); - this.ReleaseChannelLink = new System.Windows.Forms.LinkLabel(); - this.releaseChannel = new System.Windows.Forms.ComboBox(); - this.cliReleaseChannelLabel = new System.Windows.Forms.Label(); - this.cliBaseDownloadUrl = new System.Windows.Forms.Label(); - this.cliDownloadUrlTextBox = new System.Windows.Forms.TextBox(); this.mainPanel = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); this.generalSettingsGroupBox.SuspendLayout(); this.productSelectionGroupBox.SuspendLayout(); this.ignoreGroupbox.SuspendLayout(); this.userExperienceGroupBox.SuspendLayout(); - this.ExecutablesGroupBox.SuspendLayout(); this.mainPanel.SuspendLayout(); this.SuspendLayout(); // @@ -304,77 +290,6 @@ private void InitializeComponent() this.OrgDescriptionText.Text = "Specify an organization slug name to run tests for that organization.\r\nIt must ma" + "tch the URL slug as displayed in the URL of your org in the Snyk UI:\r\nhttps://ap" + "p.snyk.io/org/[OrgSlugName]"; - // - // richTextBox1 - // - this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.richTextBox1.Location = new System.Drawing.Point(9, 155); - this.richTextBox1.Margin = new System.Windows.Forms.Padding(4); - this.richTextBox1.Name = "richTextBox1"; - this.richTextBox1.ReadOnly = true; - this.richTextBox1.Size = new System.Drawing.Size(684, 39); - this.richTextBox1.TabIndex = 18; - this.richTextBox1.Text = "Snyk will download, install and update the dependencies for you. If this option i" + - "s disabled, make sure valid paths to the dependencies are provided."; - // - // resetCliPathToDefaultButton - // - this.resetCliPathToDefaultButton.Location = new System.Drawing.Point(347, 65); - this.resetCliPathToDefaultButton.Margin = new System.Windows.Forms.Padding(4); - this.resetCliPathToDefaultButton.Name = "resetCliPathToDefaultButton"; - this.resetCliPathToDefaultButton.Size = new System.Drawing.Size(129, 28); - this.resetCliPathToDefaultButton.TabIndex = 17; - this.resetCliPathToDefaultButton.Text = "Reset to default"; - this.resetCliPathToDefaultButton.UseVisualStyleBackColor = true; - this.resetCliPathToDefaultButton.Click += new System.EventHandler(this.ClearCliCustomPathButton_Click); - // - // CliPathBrowseButton - // - this.CliPathBrowseButton.Location = new System.Drawing.Point(239, 65); - this.CliPathBrowseButton.Margin = new System.Windows.Forms.Padding(4); - this.CliPathBrowseButton.Name = "CliPathBrowseButton"; - this.CliPathBrowseButton.Size = new System.Drawing.Size(100, 28); - this.CliPathBrowseButton.TabIndex = 16; - this.CliPathBrowseButton.Text = "Browse"; - this.CliPathBrowseButton.UseVisualStyleBackColor = true; - this.CliPathBrowseButton.Click += new System.EventHandler(this.CliPathBrowseButton_Click); - // - // CliPathTextBox - // - this.CliPathTextBox.Location = new System.Drawing.Point(241, 96); - this.CliPathTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.CliPathTextBox.Name = "CliPathTextBox"; - this.CliPathTextBox.ReadOnly = true; - this.CliPathTextBox.Size = new System.Drawing.Size(399, 22); - this.CliPathTextBox.TabIndex = 15; - // - // CliPathLabel - // - this.CliPathLabel.AutoSize = true; - this.CliPathLabel.Location = new System.Drawing.Point(5, 71); - this.CliPathLabel.Name = "CliPathLabel"; - this.CliPathLabel.Size = new System.Drawing.Size(92, 16); - this.CliPathLabel.TabIndex = 14; - this.CliPathLabel.Text = "Snyk CLI Path:"; - // - // ManageBinariesAutomaticallyCheckbox - // - this.ManageBinariesAutomaticallyCheckbox.AutoSize = true; - this.ManageBinariesAutomaticallyCheckbox.Location = new System.Drawing.Point(16, 132); - this.ManageBinariesAutomaticallyCheckbox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.ManageBinariesAutomaticallyCheckbox.Name = "ManageBinariesAutomaticallyCheckbox"; - this.ManageBinariesAutomaticallyCheckbox.Size = new System.Drawing.Size(18, 17); - this.ManageBinariesAutomaticallyCheckbox.TabIndex = 13; - this.ManageBinariesAutomaticallyCheckbox.UseVisualStyleBackColor = true; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(41, 132); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(320, 16); - this.label1.TabIndex = 12; - this.label1.Text = "Update and install Snyk dependencies automatically"; // // productSelectionGroupBox // @@ -393,7 +308,7 @@ private void InitializeComponent() this.productSelectionGroupBox.Controls.Add(this.codeQualityEnabledCheckBox); this.productSelectionGroupBox.Controls.Add(this.ossEnabledCheckBox); this.productSelectionGroupBox.Controls.Add(this.codeSecurityEnabledCheckBox); - this.productSelectionGroupBox.Location = new System.Drawing.Point(29, 709); + this.productSelectionGroupBox.Location = new System.Drawing.Point(29, 424); this.productSelectionGroupBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.productSelectionGroupBox.Name = "productSelectionGroupBox"; this.productSelectionGroupBox.Padding = new System.Windows.Forms.Padding(11, 10, 11, 10); @@ -573,7 +488,7 @@ private void InitializeComponent() // userExperienceGroupBox // this.userExperienceGroupBox.Controls.Add(this.autoScanCheckBox); - this.userExperienceGroupBox.Location = new System.Drawing.Point(29, 955); + this.userExperienceGroupBox.Location = new System.Drawing.Point(29, 670); this.userExperienceGroupBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.userExperienceGroupBox.Name = "userExperienceGroupBox"; this.userExperienceGroupBox.Padding = new System.Windows.Forms.Padding(11, 10, 11, 10); @@ -615,88 +530,17 @@ private void InitializeComponent() // this.customCliPathFileDialog.SupportMultiDottedExtensions = true; // - // ExecutablesGroupBox - // - this.ExecutablesGroupBox.Controls.Add(this.ReleaseChannelLink); - this.ExecutablesGroupBox.Controls.Add(this.releaseChannel); - this.ExecutablesGroupBox.Controls.Add(this.cliReleaseChannelLabel); - this.ExecutablesGroupBox.Controls.Add(this.cliBaseDownloadUrl); - this.ExecutablesGroupBox.Controls.Add(this.richTextBox1); - this.ExecutablesGroupBox.Controls.Add(this.cliDownloadUrlTextBox); - this.ExecutablesGroupBox.Controls.Add(this.CliPathLabel); - this.ExecutablesGroupBox.Controls.Add(this.resetCliPathToDefaultButton); - this.ExecutablesGroupBox.Controls.Add(this.label1); - this.ExecutablesGroupBox.Controls.Add(this.CliPathBrowseButton); - this.ExecutablesGroupBox.Controls.Add(this.ManageBinariesAutomaticallyCheckbox); - this.ExecutablesGroupBox.Controls.Add(this.CliPathTextBox); - this.ExecutablesGroupBox.Location = new System.Drawing.Point(29, 426); - this.ExecutablesGroupBox.Margin = new System.Windows.Forms.Padding(4); - this.ExecutablesGroupBox.Name = "ExecutablesGroupBox"; - this.ExecutablesGroupBox.Padding = new System.Windows.Forms.Padding(4); - this.ExecutablesGroupBox.Size = new System.Drawing.Size(747, 277); - this.ExecutablesGroupBox.TabIndex = 19; - this.ExecutablesGroupBox.TabStop = false; - this.ExecutablesGroupBox.Text = "Executables Settings"; - // - // ReleaseChannelLink - // - this.ReleaseChannelLink.AutoSize = true; - this.ReleaseChannelLink.Location = new System.Drawing.Point(8, 241); - this.ReleaseChannelLink.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.ReleaseChannelLink.Name = "ReleaseChannelLink"; - this.ReleaseChannelLink.Size = new System.Drawing.Size(219, 16); - this.ReleaseChannelLink.TabIndex = 20; - this.ReleaseChannelLink.TabStop = true; - this.ReleaseChannelLink.Text = "Find out about our release channels"; - this.ReleaseChannelLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.ReleaseChannelLink_LinkClicked); - // - // releaseChannel - // - this.releaseChannel.FormattingEnabled = true; - this.releaseChannel.Location = new System.Drawing.Point(239, 208); - this.releaseChannel.Margin = new System.Windows.Forms.Padding(4); - this.releaseChannel.Name = "releaseChannel"; - this.releaseChannel.Size = new System.Drawing.Size(160, 24); - this.releaseChannel.TabIndex = 23; - // - // cliReleaseChannelLabel - // - this.cliReleaseChannelLabel.AutoSize = true; - this.cliReleaseChannelLabel.Location = new System.Drawing.Point(5, 212); - this.cliReleaseChannelLabel.Name = "cliReleaseChannelLabel"; - this.cliReleaseChannelLabel.Size = new System.Drawing.Size(128, 16); - this.cliReleaseChannelLabel.TabIndex = 22; - this.cliReleaseChannelLabel.Text = "CLI release channel:"; - // - // cliBaseDownloadUrl - // - this.cliBaseDownloadUrl.AutoSize = true; - this.cliBaseDownloadUrl.Location = new System.Drawing.Point(5, 27); - this.cliBaseDownloadUrl.Name = "cliBaseDownloadUrl"; - this.cliBaseDownloadUrl.Size = new System.Drawing.Size(194, 16); - this.cliBaseDownloadUrl.TabIndex = 20; - this.cliBaseDownloadUrl.Text = "Base URL to download the CLI: "; - // - // cliDownloadUrlTextBox - // - this.cliDownloadUrlTextBox.Location = new System.Drawing.Point(241, 23); - this.cliDownloadUrlTextBox.Margin = new System.Windows.Forms.Padding(4); - this.cliDownloadUrlTextBox.Name = "cliDownloadUrlTextBox"; - this.cliDownloadUrlTextBox.Size = new System.Drawing.Size(399, 22); - this.cliDownloadUrlTextBox.TabIndex = 21; - // // mainPanel // this.mainPanel.AutoScroll = true; this.mainPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mainPanel.Controls.Add(this.generalSettingsGroupBox); - this.mainPanel.Controls.Add(this.ExecutablesGroupBox); this.mainPanel.Controls.Add(this.productSelectionGroupBox); this.mainPanel.Controls.Add(this.userExperienceGroupBox); this.mainPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.mainPanel.Location = new System.Drawing.Point(0, 0); this.mainPanel.Name = "mainPanel"; - this.mainPanel.Size = new System.Drawing.Size(1060, 1041); + this.mainPanel.Size = new System.Drawing.Size(1060, 923); this.mainPanel.TabIndex = 20; // // SnykGeneralSettingsUserControl @@ -707,7 +551,7 @@ private void InitializeComponent() this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.MinimumSize = new System.Drawing.Size(1060, 923); this.Name = "SnykGeneralSettingsUserControl"; - this.Size = new System.Drawing.Size(1060, 1041); + this.Size = new System.Drawing.Size(1060, 923); ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); this.generalSettingsGroupBox.ResumeLayout(false); this.generalSettingsGroupBox.PerformLayout(); @@ -717,8 +561,6 @@ private void InitializeComponent() this.ignoreGroupbox.PerformLayout(); this.userExperienceGroupBox.ResumeLayout(false); this.userExperienceGroupBox.PerformLayout(); - this.ExecutablesGroupBox.ResumeLayout(false); - this.ExecutablesGroupBox.PerformLayout(); this.mainPanel.ResumeLayout(false); this.ResumeLayout(false); @@ -752,26 +594,13 @@ private void InitializeComponent() private System.Windows.Forms.ToolTip snykCodeQualityInfoToolTip; private LinkLabel OrganizationInfoLink; private Label OrgDescriptionText; - private Label label1; - private CheckBox ManageBinariesAutomaticallyCheckbox; - private Label CliPathLabel; - private TextBox CliPathTextBox; - private Button CliPathBrowseButton; private OpenFileDialog customCliPathFileDialog; - private Button resetCliPathToDefaultButton; - private RichTextBox richTextBox1; - private GroupBox ExecutablesGroupBox; private Label label2; private ComboBox authType; private RichTextBox authMethodDescription; private CheckBox autoScanCheckBox; private Label snykIacInfoLabel; private CheckBox iacEnabledCheckbox; - private ComboBox releaseChannel; - private Label cliReleaseChannelLabel; - private Label cliBaseDownloadUrl; - private TextBox cliDownloadUrlTextBox; - private LinkLabel ReleaseChannelLink; private GroupBox ignoreGroupbox; private CheckBox cbIgnoredIssues; private CheckBox cbOpenIssues; diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs index 0c4eb93e..55292410 100644 --- a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs +++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs @@ -56,7 +56,7 @@ private void Initialize() { Logger.Information("Enter Initialize method"); - this.UpdateViewFromOptionsDialog(); + this.UpdateViewFromOptions(); snykOptions.SettingsChanged += this.OptionsDialogPageOnSettingsChanged; this.Load += this.SnykGeneralSettingsUserControl_Load; @@ -81,7 +81,7 @@ private async Task OnOnLanguageClientNotInitializedAsync(object sender, SnykLang authenticateButton.Enabled = false; } - private void UpdateViewFromOptionsDialog() + private void UpdateViewFromOptions() { this.authenticateButton.Enabled = LanguageClientHelper.IsLanguageServerReady(); this.customEndpointTextBox.Text = snykOptions.CustomEndpoint; @@ -89,23 +89,11 @@ private void UpdateViewFromOptionsDialog() this.ignoreUnknownCACheckBox.Checked = snykOptions.IgnoreUnknownCA; this.ossEnabledCheckBox.Checked = snykOptions.OssEnabled; this.iacEnabledCheckbox.Checked = snykOptions.IacEnabled; - this.ManageBinariesAutomaticallyCheckbox.Checked = snykOptions.BinariesAutoUpdate; this.autoScanCheckBox.Checked = snykOptions.AutoScan; - this.cliDownloadUrlTextBox.Text = snykOptions.CliDownloadUrl; this.tokenTextBox.Text = snykOptions.ApiToken.ToString(); this.cbIgnoredIssues.Checked = snykOptions.IgnoredIssuesEnabled; this.cbOpenIssues.Checked = snykOptions.OpenIssuesEnabled; - var cliPath = string.IsNullOrEmpty(snykOptions.CliCustomPath) - ? SnykCli.GetSnykCliDefaultPath() - : snykOptions.CliCustomPath; - - this.CliPathTextBox.Text = cliPath; - if (releaseChannel.DataSource == null) - { - this.releaseChannel.DataSource = ReleaseChannelList(); - } - if (cbDelta.DataSource == null) { this.cbDelta.DataSource = DeltaOptionList(); @@ -117,8 +105,7 @@ private void UpdateViewFromOptionsDialog() this.authType.DisplayMember = "Description"; this.authType.ValueMember = "Value"; } - - this.releaseChannel.SelectedItem = snykOptions.CliReleaseChannel; + this.authType.SelectedValue = snykOptions.AuthenticationMethod; this.cbDelta.SelectedItem = snykOptions.EnableDeltaFindings ? "Net new issues" : "All issues"; } @@ -136,16 +123,6 @@ private IEnumerable AuthenticationMethodList() .ToList(); } - private IEnumerable ReleaseChannelList() - { - var defaultList = new List() { "stable", "rc", "preview" }; - if (!defaultList.Contains(snykOptions.CliReleaseChannel)) - { - defaultList.Add(snykOptions.CliReleaseChannel); - } - return defaultList; - } - private IEnumerable DeltaOptionList() { var defaultList = new List { "All issues", "Net new issues"}; @@ -156,7 +133,7 @@ private void OptionsDialogPageOnSettingsChanged(object sender, SnykSettingsChang ThreadHelper.JoinableTaskFactory.RunAsync(async () => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - this.UpdateViewFromOptionsDialog(); + this.UpdateViewFromOptions(); }).FireAndForget(); public async Task HandleAuthenticationSuccess(string apiToken, string apiUrl) @@ -434,28 +411,6 @@ private void OrganizationInfoLink_LinkClicked(object sender, LinkLabelLinkClicke Process.Start("https://docs.snyk.io/ide-tools/visual-studio-extension#organization-setting"); } - private void CliPathBrowseButton_Click(object sender, EventArgs e) - { - if (this.customCliPathFileDialog.ShowDialog() == DialogResult.OK) - { - var selectedCliPath = this.customCliPathFileDialog.FileName; - this.SetCliCustomPathValue(selectedCliPath); - } - } - - private void SetCliCustomPathValue(string selectedCliPath) - { - snykOptions.CliCustomPath = selectedCliPath; - this.CliPathTextBox.Text = string.IsNullOrEmpty(snykOptions.CliCustomPath) - ? SnykCli.GetSnykCliDefaultPath() - : selectedCliPath; - } - - private void ClearCliCustomPathButton_Click(object sender, EventArgs e) - { - this.SetCliCustomPathValue(string.Empty); - } - private void authType_SelectionChangeCommitted(object sender, EventArgs e) { snykOptions.AuthenticationMethod = (AuthenticationType)authType.SelectedValue; @@ -472,26 +427,6 @@ private void iacEnabledCheckbox_CheckedChanged(object sender, EventArgs e) snykOptions.IacEnabled = iacEnabledCheckbox.Checked; } - public string GetReleaseChannel() - { - return releaseChannel.Text; - } - - public string GetCliDownloadUrl() - { - return cliDownloadUrlTextBox.Text; - } - - public bool GetManageBinariesAutomatically() - { - return ManageBinariesAutomaticallyCheckbox.Checked; - } - - private void ReleaseChannelLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - this.ReleaseChannelLink.LinkVisited = true; - Process.Start("https://docs.snyk.io/snyk-cli/releases-and-channels-for-the-snyk-cli"); - } private void cbOpenIssues_CheckedChanged(object sender, EventArgs e) { diff --git a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.resx b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.resx index e89510c3..86b2d89c 100644 --- a/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.resx +++ b/Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.resx @@ -133,9 +133,6 @@ 140, 17 - - 477, 17 - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO @@ -145,8 +142,8 @@ jZZtldeAJuTjx7SYAQYQKn7xnCU8ABJO2R9gGis+AAAAAElFTkSuQmCC - - 270, 17 + + 477, 17 @@ -157,6 +154,9 @@ jZZtldeAJuTjx7SYAQYQKn7xnCU8ABJO2R9gGis+AAAAAElFTkSuQmCC + + 270, 17 + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO @@ -166,12 +166,6 @@ jZZtldeAJuTjx7SYAQYQKn7xnCU8ABJO2R9gGis+AAAAAElFTkSuQmCC - - 270, 17 - - - 477, 17 - 680, 17 diff --git a/Snyk.VisualStudio.Extension.2022/Snyk.VisualStudio.Extension.2022.csproj b/Snyk.VisualStudio.Extension.2022/Snyk.VisualStudio.Extension.2022.csproj index cd30bc4d..5d230c1f 100644 --- a/Snyk.VisualStudio.Extension.2022/Snyk.VisualStudio.Extension.2022.csproj +++ b/Snyk.VisualStudio.Extension.2022/Snyk.VisualStudio.Extension.2022.csproj @@ -148,9 +148,19 @@ + + + Component + + + UserControl + + + SnykCliOptionsUserControl.cs + Component @@ -576,6 +586,9 @@ + + SnykCliOptionsUserControl.cs + SnykGeneralSettingsUserControl.cs Designer diff --git a/Snyk.VisualStudio.Extension.2022/SnykVSPackage.cs b/Snyk.VisualStudio.Extension.2022/SnykVSPackage.cs index 0f0d93b5..928a58e8 100644 --- a/Snyk.VisualStudio.Extension.2022/SnykVSPackage.cs +++ b/Snyk.VisualStudio.Extension.2022/SnykVSPackage.cs @@ -49,8 +49,9 @@ namespace Snyk.VisualStudio.Extension [ProvideService(typeof(ISnykService), IsAsyncQueryable = true)] [ProvideMenuResource("Menus.ctmenu", 1)] [ProvideToolWindow(typeof(SnykToolWindow), Style = VsDockStyle.Tabbed)] - [ProvideOptionPage(typeof(SnykGeneralOptionsDialogPage), "Snyk", "General settings", 1000, 1001, true)] + [ProvideOptionPage(typeof(SnykGeneralOptionsDialogPage), "Snyk", "General", 1000, 1001, true)] [ProvideOptionPage(typeof(SnykSolutionOptionsDialogPage), "Snyk", "Solution settings", 1000, 1002, true)] + [ProvideOptionPage(typeof(SnykCliOptionsDialogPage), "Snyk", "CLI settings", 1000, 1003, true)] public sealed class SnykVSPackage : AsyncPackage, ISnykOptionsProvider { /// @@ -100,6 +101,7 @@ public void SetServiceProvider(ISnykServiceProvider serviceProvider) /// public ISnykOptions Options { get; private set; } public ISnykGeneralOptionsDialogPage SnykGeneralOptionsDialogPage { get; private set; } + public ISnykCliOptionsDialogPage SnykCliOptionsDialogPage { get; private set; } /// /// Gets instance. @@ -300,6 +302,16 @@ private async Task InitializeGeneralOptionsAsync() Logger.Information("Call generalOptionsDialogPage.Initialize()"); SnykGeneralOptionsDialogPage.Initialize(this.serviceProvider); } + + if (SnykCliOptionsDialogPage == null) + { + await JoinableTaskFactory.SwitchToMainThreadAsync(); + + SnykCliOptionsDialogPage = + (SnykCliOptionsDialogPage)GetDialogPage(typeof(SnykCliOptionsDialogPage)); + Logger.Information("Call generalOptionsDialogPage.Initialize()"); + SnykCliOptionsDialogPage.Initialize(this.serviceProvider); + } } private async Task GetVsVersionAsync()