Skip to content

Commit

Permalink
minor fixes - started on checkbox token input form
Browse files Browse the repository at this point in the history
  • Loading branch information
anderslaub committed Jun 19, 2017
1 parent ae29408 commit d545b2a
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Foundation/HelixTemplating/Tokens/TokenInputForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum TokenInputForm
{
Text,
Folder,
Selection
Selection,
Checkbox
}
}
2 changes: 1 addition & 1 deletion VisualStudio/Dialogs/Dialogs/ManifestDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<Grid VerticalAlignment="Center" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="1" Margin="10,0,10,10">
<StackPanel HorizontalAlignment="Stretch">
<Label>Available Helix Templates</Label>
<ComboBox HorizontalAlignment="Left" Width="Auto" MaxWidth="550" MinWidth="450" Height="25" Name="AvailableManifests" ItemsSource="{Binding AvailableManifestsCollection}" SelectedItem="{Binding SelectedManifestComboItem}" >
<ComboBox HorizontalAlignment="Left" Width="Auto" MaxWidth="550" MinWidth="450" Height="25" Name="AvailableManifestsComboBox" ItemsSource="{Binding AvailableManifestsCollection}" SelectedItem="{Binding SelectedManifestComboItem}" >
</ComboBox>
<TextBlock FontSize="10" HorizontalAlignment="Left" Name="TemplateDescription" Width="Auto" MaxWidth="450" TextWrapping="WrapWithOverflow" Margin="0,0,10,5"></TextBlock>
<TextBlock FontStyle="Italic" HorizontalAlignment="Left" FontSize="10" Name="TemplateAuthor" MaxWidth="450" Width="Auto" TextWrapping="WrapWithOverflow"></TextBlock>
Expand Down
14 changes: 8 additions & 6 deletions VisualStudio/Dialogs/Dialogs/ManifestDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void Initialize(string rootDirectory, string solutionRoot, IDictionary<st
return;
}
SetAvailableManifestsCollection(_manifests);
AvailableManifests.SelectedIndex = 0;
AvailableManifestsComboBox.Items.Refresh();
AvailableManifestsComboBox.SelectedIndex = 0;
}

protected void SetAvailableManifestsCollection(IEnumerable<HelixTemplateManifest> helixTemplateManifests)
Expand All @@ -73,13 +74,13 @@ protected void SetAvailableManifestsCollection(IEnumerable<HelixTemplateManifest
{
Content = helixTemplateManifest.Name + " " + helixTemplateManifest.Version
});
AvailableManifests.SelectionChanged += SelectionChanged;
AvailableManifestsComboBox.SelectionChanged += SelectionChanged;
}

protected void SelectionChanged(object sender, SelectionChangedEventArgs selectionChangedEventArgs)
{
SelectedManifestComboItem = AvailableManifestsCollection[AvailableManifests.SelectedIndex];
_selectedManifest = _manifests[AvailableManifests.SelectedIndex];
SelectedManifestComboItem = AvailableManifestsCollection[AvailableManifestsComboBox.SelectedIndex];
_selectedManifest = _manifests[AvailableManifestsComboBox.SelectedIndex];
SetSelectedManifest();
}

Expand Down Expand Up @@ -125,9 +126,10 @@ protected void SettingsButton_Clicked(object sender, RoutedEventArgs e)
var settingsUpdated = settingsDialog.ShowDialog();
if (!settingsUpdated.HasValue || !settingsUpdated.Value)
return;

var rootDirectory = settingsDialog.RootDirectory;
Initialize(rootDirectory, SolutionRoot, _initialTokens, _isSolutionCreation);
_selectedManifest = _manifests[AvailableManifests.SelectedIndex];
_selectedManifest = _manifests[AvailableManifestsComboBox.SelectedIndex];
SetSelectedManifest();
}

Expand Down Expand Up @@ -179,7 +181,7 @@ private void HelixLogo_Clicked(object sender, RoutedEventArgs e)

private void LaubLogo_Clicked(object sender, RoutedEventArgs e)
{
Process.Start(new ProcessStartInfo("https://laubplusco.net"));
Process.Start(new ProcessStartInfo("https://laubplusco.net/?origin=vstemplates"));
e.Handled = true;
}

Expand Down
2 changes: 1 addition & 1 deletion VisualStudio/Dialogs/Dialogs/SettingsDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<Label Margin="5,5,5,0" FontWeight="DemiBold">Helix Templates root folder</Label>
<TextBox Height="25" Width="350" Name="RootDirectoryPath" Margin="5" />
<Button Content="OK" IsDefault="True" Click="SaveSettings_Click" Margin="5" />
<Button Style="{StaticResource ImageButton}" Background="{StaticResource UnpackButtonImage}" BorderThickness="0" MinHeight="80" MinWidth="81" HorizontalAlignment="Center" Margin="0,20,0,0" Click="UnpackTemplates_Clicked" />
<Button Style="{StaticResource ImageButton}" Background="{StaticResource UnpackButtonImage}" BorderThickness="0" MinHeight="80" MinWidth="81" HorizontalAlignment="Center" Margin="0,20,0,0" Click="UnpackTemplates_Clicked" Name="UnpackBuiltInButton" />
<Label HorizontalAlignment="Center" FontSize="10" Margin="0" >
<TextBlock FontWeight="DemiBold" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center">Install/re-install<LineBreak/> built-in templates</TextBlock>
</Label>
Expand Down
15 changes: 8 additions & 7 deletions VisualStudio/Dialogs/Dialogs/SettingsDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,28 @@ private bool RootHasTemplateManifests(string selectedRootpath)
return new DirectoryInfo(selectedRootpath).EnumerateFiles("template.manifest.xml", SearchOption.AllDirectories).Any();
}

private void Cancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}

private void UnpackTemplates_Clicked(object sender, RoutedEventArgs e)
{
var rootDirectory = TemplatesRootDirectoryPathRepository.Get();
if (string.IsNullOrEmpty(rootDirectory) || !Directory.Exists(rootDirectory))
MessageBox.Show(this, "You need to select a valid root directory.", "Error", MessageBoxButton.OK);
{
MessageBox.Show(this, "You need to set a valid root directory.", "Error", MessageBoxButton.OK);
return;
}
UnpackBuiltInButton.IsEnabled = false;
if (Directory.EnumerateDirectories(rootDirectory).Any())
{
var overwriteConfirmResult = MessageBox.Show("This will overwrite changes made to built-in templates in this root folder.\nAre you sure you want to continue?\n\nNote: Always make your modifications changes in copies and never directly in the built-in example templates.", "Confirm", MessageBoxButton.YesNo);
if (overwriteConfirmResult != MessageBoxResult.Yes)
{
UnpackBuiltInButton.IsEnabled = true;
return;
}
DeleteExistingBuiltInTemplates(rootDirectory);
}
UnzipTemplatesArchive(rootDirectory);
MessageBox.Show("Built-in templates updated", "", MessageBoxButton.OK);
UnpackBuiltInButton.IsEnabled = true;
}

private void DeleteExistingBuiltInTemplates(string rootDirectory)
Expand Down
21 changes: 21 additions & 0 deletions VisualStudio/Dialogs/Dialogs/TokenCheckboxInput.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<local:TokenInputControl x:Class="LaubPlusCo.VisualStudio.HelixTemplates.Dialogs.Dialogs.TokenCheckboxInput"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LaubPlusCo.VisualStudio.HelixTemplates.Dialogs.Dialogs"
mc:Ignorable="d" d:DesignWidth="400">
<Grid Margin="0,5,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Left" Name="TokenInputCheckbox" />
<Label FontWeight="DemiBold" Width="Auto" HorizontalAlignment="Left" MaxWidth="430" Name="TokenDisplayNameLabel" />
</StackPanel>
</Grid>
</local:TokenInputControl>
39 changes: 39 additions & 0 deletions VisualStudio/Dialogs/Dialogs/TokenCheckboxInput.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using LaubPlusCo.Foundation.HelixTemplating.Manifest;

namespace LaubPlusCo.VisualStudio.HelixTemplates.Dialogs.Dialogs
{
/// <summary>
/// Interaction logic for TokenCheckboxInput.xaml
/// </summary>
public partial class TokenCheckboxInput : TokenInputControl
{
public TokenCheckboxInput(TokenDescription tokenDescription)
{
InitializeComponent();
TokenDescription = tokenDescription;
}

public override string TokenValue
{
get => TokenInputCheckbox.IsChecked.HasValue && TokenInputCheckbox.IsChecked.Value ? bool.TrueString : bool.FalseString;
set => TokenInputCheckbox.IsChecked = bool.TryParse(value, out bool val) && val;
}

public override Label DisplayNameLabel => TokenDisplayNameLabel;
public override Control InputControl => TokenInputCheckbox;
}
}
5 changes: 5 additions & 0 deletions VisualStudio/Dialogs/Dialogs/TokenInputControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace LaubPlusCo.VisualStudio.HelixTemplates.Dialogs.Dialogs
{
public abstract class TokenInputControl : UserControl
{
protected TokenInputControl()
{

}

public TokenInputControl[] DependendTokenInputs;

public TokenDescription TokenDescription { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\TokenCheckboxInput.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\TokenFolderInput.xaml">
<SubType>Designer</SubType>
<Generator>XamlIntelliSenseFileGenerator</Generator>
Expand Down Expand Up @@ -102,6 +106,9 @@
<Compile Include="Dialogs\SettingsDialog.xaml.cs">
<DependentUpon>SettingsDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\TokenCheckboxInput.xaml.cs">
<DependentUpon>TokenCheckboxInput.xaml</DependentUpon>
</Compile>
<Compile Include="Dialogs\TokenFolderInput.xaml.cs">
<DependentUpon>TokenFolderInput.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
Binary file modified VisualStudio/Dialogs/Resources/StandardTemplates.zip
Binary file not shown.
14 changes: 14 additions & 0 deletions VisualStudio/Wizard/HelixTemplateWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Principal;
using System.Windows;
using EnvDTE;
using EnvDTE80;
using LaubPlusCo.Foundation.HelixTemplating.TemplateEngine;
Expand All @@ -35,6 +37,12 @@ public class HelixTemplateWizard : IWizard
private bool? _isExclusive;
public void RunStarted(object automationObject, Dictionary<string, string> replacementTokens, WizardRunKind runKind, object[] customParams)
{
if (!IsAdministrator())
{
MessageBox.Show("You need to run Visual Studio as administrator to use these templates.\n\nPlease close Visual Studio and start as Administrator.", "Security", MessageBoxButton.OK);
DeleteAutoCreatedDirectory();
}

_dte = automationObject as DTE2;
_replacementTokens = replacementTokens;
_destinationDirectory = replacementTokens["$destinationdirectory$"];
Expand All @@ -48,6 +56,12 @@ public void RunStarted(object automationObject, Dictionary<string, string> repla
ShowManifestDialog();
}

private static bool IsAdministrator()
{
return (new WindowsPrincipal(WindowsIdentity.GetCurrent()))
.IsInRole(WindowsBuiltInRole.Administrator);
}

public bool IsFirstRun => string.IsNullOrEmpty(TemplatesRootDirectoryPathRepository.Get()) || !Directory.Exists(TemplatesRootDirectoryPathRepository.Get());

private void ShowInitSetupDialog()
Expand Down

0 comments on commit d545b2a

Please sign in to comment.