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

Smorin4/edit multiple #4583

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3a2139a
added page style for theme switching
May 20, 2022
8c5e31a
Merge remote-tracking branch 'upstream/main'
May 23, 2022
4f4e065
Merge remote-tracking branch 'upstream/main'
mikebattista May 24, 2022
5d4d37a
Merge remote-tracking branch 'upstream/main'
May 24, 2022
1ecc273
Merge remote-tracking branch 'upstream/main'
May 26, 2022
ae029b7
Merge remote-tracking branch 'upstream/main'
mikebattista May 26, 2022
f79fedc
Merge remote-tracking branch 'upstream/main'
mikebattista May 30, 2022
1d5e98d
Merge remote-tracking branch 'upstream/main'
Jun 1, 2022
5bbebc7
Merge branch 'main' of https://github.com/smorin4/TemplateStudio
Jun 1, 2022
ab87257
Merge remote-tracking branch 'upstream/main'
Jun 2, 2022
41be6b6
Merge remote-tracking branch 'upstream/main'
Jun 3, 2022
41fd67d
Merge remote-tracking branch 'upstream/main'
Jun 6, 2022
75d41d2
Merge remote-tracking branch 'upstream/main'
Jun 7, 2022
c267b79
Merge remote-tracking branch 'upstream/main'
Jun 8, 2022
69efecb
Merge remote-tracking branch 'upstream/main'
Jun 15, 2022
b2b4ca3
Merge remote-tracking branch 'upstream/main'
Jun 16, 2022
849dd84
Merge remote-tracking branch 'upstream/main'
Jun 17, 2022
0e66e37
Merge remote-tracking branch 'upstream/main'
Jun 20, 2022
daacedb
Merge remote-tracking branch 'upstream/main'
Jun 22, 2022
17a6168
Merge branch 'microsoft:main' into main
mikebattista Jun 22, 2022
3bfda96
Merge remote-tracking branch 'upstream/main'
Jun 23, 2022
3ee0e36
Merge branch 'main' of https://github.com/smorin4/TemplateStudio
Jun 23, 2022
7abd2e1
Merge remote-tracking branch 'upstream/main'
Jun 27, 2022
df9731c
Merge remote-tracking branch 'upstream/main'
Jun 30, 2022
82a9825
Merge remote-tracking branch 'upstream/main'
Jul 1, 2022
db7c4f0
Merge remote-tracking branch 'upstream/main'
Jul 5, 2022
0b5912c
Merge branch 'microsoft:main' into main
mikebattista Jul 6, 2022
bf53769
Merge remote-tracking branch 'upstream/main'
Jul 7, 2022
e505a5c
Merge remote-tracking branch 'upstream/main'
Jul 11, 2022
c0a9247
Merge branch 'main' of https://github.com/smorin4/TemplateStudio
Jul 11, 2022
771a5a9
Merge remote-tracking branch 'upstream/main'
Jul 12, 2022
ba8fba2
Merge remote-tracking branch 'upstream/main'
Jul 13, 2022
bf36d8a
extra blank page hardcoded without adding in new project wizard
Jul 13, 2022
629a98e
adjusted new item flow [not functional]
Jul 14, 2022
a14d3af
naming fix
Jul 15, 2022
e93654f
idek
Jul 15, 2022
297cb69
Merge branch 'microsoft:main' into main
mikebattista Jul 16, 2022
4bde2c5
Merge remote-tracking branch 'upstream/main'
Jul 18, 2022
89d6466
Merge branch 'main' of https://github.com/smorin4/TemplateStudio
Jul 18, 2022
c7d5aad
Merge branch 'main' into smorin4/EditMultiple
Jul 18, 2022
84d57b7
persistent group
Jul 19, 2022
46fcbd4
recognizing multiple selections
Jul 19, 2022
a439fda
Merge remote-tracking branch 'upstream/main'
Jul 19, 2022
c3f55d6
MULTIPLE ADDITION!
Jul 20, 2022
81f91b2
generated app builds
Jul 20, 2022
4e680c8
new pages added to generated app - functional
Jul 20, 2022
6a32710
cleanup
Jul 20, 2022
e3eeb8b
-
Jul 21, 2022
467da7f
added to addAsync (dependencies, sdks, licenses)
Jul 21, 2022
cd65ddb
cleaning
Jul 21, 2022
e58220b
Merge remote-tracking branch 'upstream/main'
Jul 22, 2022
505bdc8
Merge branch 'main' of https://github.com/smorin4/TemplateStudio
Jul 22, 2022
96ba2e9
Merge branch 'main' into smorin4/EditMultiple
Jul 22, 2022
a30ab7c
dependencies added
Jul 22, 2022
5948850
cleanup
Jul 22, 2022
dd1a5f7
added common class file
Jul 22, 2022
9030d2e
Correct-UI pages, changes summary initializes on tempalte selection p…
Jul 22, 2022
0a47839
cleanup, common class functions
Jul 25, 2022
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
2 changes: 0 additions & 2 deletions code/SharedFunctionality.Core/Gen/GenComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static IEnumerable<GenInfo> Compose(UserSelection userSelection, bool add
{
return genQueue;
}

AddProject(userSelection, genQueue);
AddTemplates(userSelection.Pages, genQueue, userSelection, newItemGeneration: false);
AddTemplates(userSelection.Features, genQueue, userSelection, newItemGeneration: false);
Expand Down Expand Up @@ -53,7 +52,6 @@ public static IEnumerable<GenInfo> Compose(UserSelection userSelection, bool add
}

genQueue = AddInCompositionTemplates(genQueue, userSelection, false);

return genQueue;
}

Expand Down
3 changes: 3 additions & 0 deletions code/SharedFunctionality.UI/Launcher/WizardLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Templates.UI.ViewModels.NewItem;
using Microsoft.Templates.UI.Views;
using Microsoft.Templates.UI.Views.Common;
using Microsoft.Templates.UI.Views.NewItem;
using Microsoft.Templates.UI.VisualStudio.GenShell;
using Microsoft.VisualStudio.TemplateWizard;

Expand Down Expand Up @@ -83,6 +84,8 @@ private UserSelection StartWizard(IWizardShell wizardShell, WizardTypeEnum wizar
private static UserSelection LaunchWizardShell(IWizardShell wizardShell)
{
GenContext.ToolBox.Shell.UI.ShowModal(wizardShell as IWindow);
//UserSelectionItem newBlank = new UserSelectionItem() { Name = "NewMain", TemplateId = "ts.WinUI.Page.Blank" };
//wizardShell.Result.Pages.Add(newBlank);
return wizardShell.Result;
}

Expand Down
2 changes: 2 additions & 0 deletions code/SharedFunctionality.UI/Services/ValidationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public static string InferTemplateName(string templateName)

public static bool HasAllPagesViewSuffix(bool fromNewTemplate, string newName)
{

// in new item instance, throws because names = null after this line (cannot be null)
var names = _getPageNames?.Invoke();
if (!names.Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Validators\HasPivotValidator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Validators\IBreakingChangeValidator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Common\BaseDialogViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Common\BaseSelectionViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Common\BaseMainViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Common\CompositionTool\CompositionFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Common\CompositionTool\CompositionToolViewModel.cs" />
Expand Down Expand Up @@ -147,7 +148,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Compile Include="$(MSBuildThisFileDirectory)Controls\CodeViewer.xaml.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)Controls\CodeViewer.xaml.cs" />
<Page Include="$(MSBuildThisFileDirectory)Controls\MarkdownBlock.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Templates.Core;
using Microsoft.Templates.Core.Gen;
using Microsoft.Templates.UI.Mvvm;
using Microsoft.Templates.UI.ViewModels.NewProject;

namespace Microsoft.Templates.UI.ViewModels.Common
{
public class BaseSelectionViewModel
{
/*
Initialize
UpdateHasItemsAddedByUser
AllTemplates
GetUserSelection
*/

public static IEnumerable<string> GetNames(ObservableCollection<UserSelectionGroup> groups)
{
var names = new List<string>();
groups.ToList().ForEach(g => names.AddRange(g.GetNames()));
return names;
}

public static IEnumerable<string> GetPageNames(ObservableCollection<UserSelectionGroup> groups) => groups.First(g => g.TemplateType == TemplateType.Page).GetNames(p => p.ItemNameEditable);
public static ObservableCollection<SavedTemplateViewModel> GetCollection(TemplateType templateType, ObservableCollection<UserSelectionGroup> groups)
{
return groups.First(g => g.TemplateType == templateType).Items;
}
public static bool IsTemplateAdded(TemplateInfoViewModel template, ObservableCollection<UserSelectionGroup> groups) => GetCollection(template.TemplateType, groups).Any(t => t.Equals(template));

public static UserSelectionGroup GetGroup(TemplateType templateType, ObservableCollection<UserSelectionGroup> groups) => groups.First(t => t.TemplateType == templateType);

public static void AddToGroup(TemplateType templateType, SavedTemplateViewModel savedTemplate, ObservableCollection<UserSelectionGroup> groups)
{
bool GenGroupEqual(SavedTemplateViewModel st) => st.GenGroup == savedTemplate.GenGroup;
bool GenGroupPrevious(SavedTemplateViewModel st) => st.GenGroup < savedTemplate.GenGroup;

int index = 0;
var group = GetGroup(templateType, groups);
if (group.Items.Any(GenGroupEqual))
{
index = group.Items.IndexOf(group.Items.Last(GenGroupEqual)) + 1;
}
else if (group.Items.Any())
{
index = group.Items.IndexOf(group.Items.Last(GenGroupPrevious)) + 1;
}

group.Insert(index, savedTemplate);
}
public static UserSelection GetUserSelection(ObservableCollection<UserSelectionGroup> groups, UserSelectionContext _context) // creates user selection list
{
var selection = new UserSelection(_context);
var pages = groups.First(g => g.TemplateType == TemplateType.Page).Items;
selection.HomeName = pages.FirstOrDefault()?.Name ?? string.Empty;
selection.Pages.AddRange(pages.Select(i => i.ToUserSelectionItem()));

var features = groups.First(g => g.TemplateType == TemplateType.Feature).Items;
selection.Features.AddRange(features.Select(i => i.ToUserSelectionItem()));

var services = groups.First(g => g.TemplateType == TemplateType.Service).Items;
selection.Services.AddRange(services.Select(i => i.ToUserSelectionItem()));

var tests = groups.First(g => g.TemplateType == TemplateType.Testing).Items;
selection.Testing.AddRange(tests.Select(i => i.ToUserSelectionItem()));
return selection;
}
}
}
98 changes: 68 additions & 30 deletions code/SharedFunctionality.UI/ViewModels/NewItem/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
using Microsoft.Templates.Core.Gen;
using Microsoft.Templates.SharedResources;
using Microsoft.Templates.UI.Controls;
using Microsoft.Templates.UI.Extensions;
using Microsoft.Templates.UI.Mvvm;
using Microsoft.Templates.UI.Services;
using Microsoft.Templates.UI.Threading;
using Microsoft.Templates.UI.ViewModels.Common;
using Microsoft.Templates.UI.ViewModels.NewProject;
using Microsoft.Templates.UI.Views.NewItem;
using Microsoft.Templates.UI.Views.NewProject;

namespace Microsoft.Templates.UI.ViewModels.NewItem
{
Expand All @@ -36,6 +39,7 @@ public class MainViewModel : BaseMainViewModel
public TemplateType TemplateType { get; set; }

public static MainViewModel Instance { get; private set; }
public Dictionary<TemplateType, TemplatesStepViewModel> StepsViewModels { get; } = new Dictionary<TemplateType, TemplatesStepViewModel>();

public TemplateSelectionViewModel TemplateSelection { get; } = new TemplateSelectionViewModel();

Expand Down Expand Up @@ -75,10 +79,10 @@ public override void UnsubscribeEventHandlers()
}

private static IEnumerable<StepData> NewItemSteps
{
{
get
{
yield return StepData.MainStep(NewItemStepTemplateSelection, "1", Resources.NewItemStepOne, () => new TemplateSelectionPage(), true, true);
//yield return StepData.MainStep(NewItemStepTemplateSelection, "1", Resources.NewItemStepOne, () => new TemplateSelectionPage(), true, true);
yield return StepData.MainStep(NewItemStepChangesSummary, "2", Resources.NewItemStepTwo, () => new ChangesSummaryPage(_output));
}
}
Expand All @@ -87,8 +91,40 @@ public void Initialize(TemplateType templateType, UserSelectionContext context)
{
TemplateType = templateType;
WizardStatus.Title = GetNewItemTitle(templateType);

TemplateSelection.Initialize(context);
Initialize(context);
BuildStepViewModelAsync(templateType);
}

private async Task BuildStepViewModelAsync(TemplateType templateType)
{
var hasTemplates = DataService.HasTemplatesFromType(templateType, Context);
var stepId = templateType.GetNewProjectStepId();
var isStepAdded = StepsViewModels.ContainsKey(templateType);
if (hasTemplates)
{
if (!isStepAdded)
{
var stepTitle = templateType.GetNewProjectStepTitle();
var pageTitle = templateType.GetStepPageTitle();
var step = new TemplatesStepViewModel(templateType, Context, pageTitle);
step.LoadData();
StepsViewModels.Add(templateType, step);
WizardNavigation.Current.AddNewStep(stepId, stepTitle, () => new TemplatesStepPage(templateType));
}
else
{
var step = StepsViewModels[templateType];
step.ResetData();
}
}

// if we want multiple selection pages in the edit menu
/*else if (!hasTemplates && isStepAdded)
{
StepsViewModels.Remove(templateType);
await WizardNavigation.Current.RemoveStepAsync(stepId);
}*/
}

private string GetNewItemTitle(TemplateType templateType)
Expand Down Expand Up @@ -160,36 +196,13 @@ private string GetNewItemHasNoChangesMessage(TemplateType templateType)
private async Task<NewItemGenerationResult> CleanupAndGenerateNewItemAsync()
{
NewItemGenController.Instance.CleanupTempGeneration();
var userSelection = CreateUserSelection();
var userSelection = TemplateSelection.GetUserSelection();
await _generationService.GenerateNewItemAsync(TemplateSelection.Template.TemplateType, userSelection);
return NewItemGenController.Instance.CompareOutputAndProject();
}

private UserSelection CreateUserSelection()
{
var userSelection = new UserSelection(Context) { HomeName = string.Empty };
var selectedTemplate = new UserSelectionItem { Name = TemplateSelection.Name, TemplateId = TemplateSelection.Template.TemplateId };
userSelection.Add(selectedTemplate, TemplateSelection.Template.TemplateType);

foreach (var dependencyTemplate in TemplateSelection.Template.Dependencies)
{
var selectedTemplateDependency = new UserSelectionItem { Name = dependencyTemplate.DefaultName, TemplateId = dependencyTemplate.TemplateId };
userSelection.Add(selectedTemplateDependency, dependencyTemplate.TemplateType);
}

return userSelection;
}

private void OnFinish(object sender, EventArgs e)
{
var userSelection = new UserSelection(Context);
userSelection.Add(
new UserSelectionItem()
{
Name = TemplateSelection.Name,
TemplateId = TemplateSelection.Template.TemplateId,
}, TemplateType);
NewItemWizardShell.Current.Result = userSelection;
NewItemWizardShell.Current.Result = TemplateSelection.GetUserSelection();
NewItemWizardShell.Current.Result.ItemGenerationType = ChangesSummary.DoNotMerge ? ItemGenerationType.Generate : ItemGenerationType.GenerateAndMerge;
}

Expand All @@ -198,9 +211,26 @@ public IEnumerable<string> GetNames()
return TemplateSelection.Dependencies.Select(i => i.DefaultName);
}

public TemplateInfoViewModel GetTemplate(TemplateInfo templateInfo)
{
StepsViewModels[templateInfo.TemplateType].LoadData();
var groups = StepsViewModels[templateInfo.TemplateType].Groups;
foreach (var group in groups)
{
var template = group.GetTemplate(templateInfo);
if (template != null)
{
return template;
}
}

return null;
}

public override async Task OnTemplatesAvailableAsync()
{
ValidationService.Initialize(GetNames, null);
//ValidationService.Initialize(GetNames, null);
ValidationService.Initialize(TemplateSelection.GetNames, TemplateSelection.GetPageNames);
TemplateSelection.LoadData(TemplateType, Context);
WizardStatus.IsLoading = false;

Expand Down Expand Up @@ -257,12 +287,20 @@ public override async Task ProcessItemAsync(object item)
{
if (item is TemplateInfoViewModel template)
{
TemplateSelection.SelectTemplate(template);
await AddTemplateAsync(template);
}

await Task.CompletedTask;
}

private async Task AddTemplateAsync(TemplateInfoViewModel selectedTemplate)
{
if (!selectedTemplate.Disabled && selectedTemplate.CanBeAdded)
{
await TemplateSelection.AddAsync(TemplateOrigin.UserSelection, selectedTemplate);
}
}

public override bool IsSelectionEnabled(MetadataType metadataType) => true;
}
}
Loading