Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reference folder for delta scan [IDE-953] #345

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 48 additions & 14 deletions Snyk.VisualStudio.Extension.2022/BranchSelectorDialogWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,75 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
xmlns:ui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
IsCloseButtonEnabled="True"
HasHelpButton="False"
MinHeight="150" Height="150"
MinHeight="250" Height="250"
MinWidth="400" Width="400"
BorderBrush="{x:Static SystemColors.WindowFrameBrush}" BorderThickness="1"
WindowStyle="None" ResizeMode="NoResize" AllowsTransparency="True"
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
toolkit:Themes.UseVsTheme="True"
Title="Choose base branch for net-new issue scanning"
MouseDown="BranchSelectorDialogWindow_OnMouseDown">

<DockPanel Margin="10">
<Button DockPanel.Dock="Top" HorizontalAlignment="Right" Click="CancelButton_OnClick" MinWidth="1"
MinHeight="1" Width="35" Margin="0" Padding="0">
<!-- Top: Close Button -->
<Button DockPanel.Dock="Top"
HorizontalAlignment="Right"
Click="CancelButton_OnClick"
MinWidth="1"
MinHeight="1"
Width="35"
Margin="0"
Padding="0">
<imaging:CrispImage Moniker="{x:Static catalog:KnownMonikers.Close}" />
</Button>

<!-- Bottom: OK Button -->
<DockPanel DockPanel.Dock="Bottom">
<Button x:Name="OkButton" Content="Ok" Click="OkButton_OnClick" Width="78" HorizontalAlignment="Left" />
<Button x:Name="OkButton"
Content="Ok"
Click="OkButton_OnClick"
Width="78"
HorizontalAlignment="Left" />
</DockPanel>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<StackPanel Grid.Row="1" HorizontalAlignment="Left">
<TextBlock x:Name="ProjectNameLabel" TextWrapping="Wrap">
Base Branch for:
</TextBlock>
<TextBlock x:Name="LblFolderPath" TextWrapping="Wrap" />
<TextBlock TextWrapping="Wrap" />
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="ProjectNameLabel" TextWrapping="Wrap" Text="Base Branch for: " />
<TextBlock x:Name="LblFolderPathForBranch" TextWrapping="Wrap" />
</StackPanel>
<ComboBox x:Name="CbBranchList" />
</StackPanel>

<StackPanel Grid.Row="2" Margin="0,10,0,0" ToolTip="Optional. Here you can specify a reference directory to be used for scanning.">
<TextBlock>
<LineBreak />
</TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="Reference folder for: " />
<TextBlock x:Name="LblFolderPathForReferenceFolder" TextWrapping="Wrap" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox x:Name="SelectedFolderPath"
Width="250"
Margin="0,0,5,0" HorizontalAlignment="Left" />
<Button Content="Browse..."
Click="BrowseButton_Click"
Width="80" HorizontalAlignment="Left"/>
</StackPanel>

</StackPanel>
</Grid>
</DockPanel>
</ui:DialogWindow>
</ui:DialogWindow>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
Expand All @@ -26,9 +27,11 @@ public BranchSelectorDialogWindow(ISnykServiceProvider serviceProvider)
this.serviceProvider.Options?.FolderConfigs?.SingleOrDefault(x => x.FolderPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) == currentFolder);
if (FolderConfig == null)
return;
LblFolderPath.Text = FolderConfig.FolderPath;
LblFolderPathForBranch.Text = FolderConfig.FolderPath;
LblFolderPathForReferenceFolder.Text = FolderConfig.FolderPath;
CbBranchList.ItemsSource = FolderConfig.LocalBranches;
CbBranchList.SelectedItem = FolderConfig.BaseBranch;
SelectedFolderPath.Text = FolderConfig.ReferenceFolderPath;
IsOpen = true;
}

Expand All @@ -47,14 +50,20 @@ private void OkButton_OnClick(object sender, RoutedEventArgs e)
return;
}
FolderConfig.BaseBranch = CbBranchList.SelectedItem.ToString();
FolderConfig.ReferenceFolderPath = SelectedFolderPath.Text;

var folderConfigList = this.serviceProvider.Options.FolderConfigs;
var currentList = folderConfigList.Where(x => x.FolderPath != FolderConfig.FolderPath).ToList();
currentList.Add(FolderConfig);

var options = SnykVSPackage.ServiceProvider.Options;
options.FolderConfigs = currentList;
SnykVSPackage.ServiceProvider.SnykOptionsManager.Save(options);
this.CloseDialog();
if (SnykVSPackage.Instance.Options.AutoScan)
{
ThreadHelper.JoinableTaskFactory.RunAsync(serviceProvider.TasksService.ScanAsync).FireAndForget();
}
this.CloseDialog();
}

private void CancelButton_OnClick(object sender, RoutedEventArgs e)
Expand All @@ -67,5 +76,19 @@ private void CloseDialog()
IsOpen = false;
this.Close();
}

private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
using (var dialog = new FolderBrowserDialog())
{
dialog.ShowNewFolderButton = false;

var result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
SelectedFolderPath.Text = dialog.SelectedPath;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class SnykLsInitializationOptions
public class FolderConfig
{
public string BaseBranch { get; set; }
public string ReferenceFolderPath { get; set; }
public string FolderPath { get; set; }
public List<string> LocalBranches { get; set; }
public List<string> AdditionalParameters { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void EnableDelta(bool isEnabled)
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
this.serviceProvider.Options.EnableDeltaFindings = isEnabled;
this.serviceProvider.SnykOptionsManager.Save(this.serviceProvider.Options, false);
this.serviceProvider.SnykOptionsManager.Save(this.serviceProvider.Options);
await LanguageClientHelper.LanguageClientManager().DidChangeConfigurationAsync(SnykVSPackage.Instance.DisposalToken);

}).FireAndForget();
Expand Down
Loading