Skip to content
Permalink
Browse files

[Assets] Fix view models to allow selection as current project

  • Loading branch information
xen2 committed Sep 10, 2018
1 parent afae09c commit 0e1ad23e3216247a4d9a0b82c54a360d5786f984
@@ -42,18 +42,19 @@ public class PackageViewModel : SessionObjectViewModel, IComparable<PackageViewM
private ProfileViewModel selectedProfile;
private readonly List<AssetViewModel> deletedAssetsSinceLastSave = new List<AssetViewModel>();

public PackageViewModel(SessionViewModel session, Package package, bool packageAlreadyInSession)
public PackageViewModel(SessionViewModel session, PackageContainer packageContainer, bool packageAlreadyInSession)
: base(session)
{
Package = package;
HasBeenUpgraded = package.IsDirty;
PackageContainer = packageContainer;
Package = PackageContainer.Package;
HasBeenUpgraded = Package.IsDirty;
DependentProperties.Add(nameof(PackagePath), new[] { nameof(Name), nameof(RootDirectory) });
Dependencies = new DependencyCategoryViewModel(nameof(Dependencies), this, session, package.RootAssets);
Dependencies = new DependencyCategoryViewModel(nameof(Dependencies), this, session, Package.RootAssets);
AssetMountPoint = new AssetMountPointViewModel(this);
content.Add(AssetMountPoint);
content.Add(Dependencies);
RenameCommand = new AnonymousCommand(ServiceProvider, () => IsEditing = true);
IsLoaded = package.State >= PackageState.AssetsReady;
IsLoaded = Package.State >= PackageState.AssetsReady;

// IsDeleted will make the package added to Session.LocalPackages, so let's do it last
InitialUndelete(!packageAlreadyInSession);
@@ -74,6 +75,8 @@ public PackageViewModel(SessionViewModel session, Package package, bool packageA
/// </summary>
public Guid Id => Package.Id;

public PackageContainer PackageContainer { get; }

/// <summary>
/// Gets the underlying <see cref="Package"/> used as a model for this view.
/// </summary>
@@ -49,29 +49,27 @@ protected override void UpdateIsDeletedStatus()
// TODO: For the moment we consider that a project has only a single parent profile. Sharing project in several profile is not supported.
public class ProjectViewModel : PackageViewModel
{
private readonly SolutionProject project;
private bool isCurrentProject;
private PackageViewModel package;

public ProjectViewModel(SessionViewModel session, SolutionProject project, bool packageAlreadyInSession)
: base(session, project.Package, packageAlreadyInSession)
: base(session, project, packageAlreadyInSession)
{
this.project = project;
content.Add(Code = new ProjectCodeViewModel(this));
}

public SolutionProject Project => project;
public SolutionProject Project => (SolutionProject)PackageContainer;

public ProjectCodeViewModel Code { get; }

public override string Name { get { return project.Name; } set { if (value != Name) throw new InvalidOperationException("The name of a project cannot be set"); } }
public override string Name { get { return Project.Name; } set { if (value != Name) throw new InvalidOperationException("The name of a project cannot be set"); } }

public UFile ProjectPath => project.FullPath;
public UFile ProjectPath => Project.FullPath;

// TODO CSPROJ=XKPKG
public ProjectType Type => project.Type;
public ProjectType Type => Project.Type;

public PlatformType Platform => project.Platform;
public PlatformType Platform => Project.Platform;

/// <summary>
/// Gets the generic type (either PlatformType or ProjectType)
@@ -87,7 +85,7 @@ internal set
SetValueUncancellable(ref isCurrentProject, value);

// TODO: Check with Ben if this is the property place to put this?
Package.Session.CurrentProject = isCurrentProject ? project : null;
Package.Session.CurrentProject = isCurrentProject ? Project : null;
}
}

@@ -1062,7 +1062,7 @@ private PackageViewModel CreateProjectViewModel(PackageContainer packageContaine
}
case StandalonePackage standalonePackage:
{
var packageContainerViewModel = new PackageViewModel(this, standalonePackage.Package, packageAlreadyInSession);
var packageContainerViewModel = new PackageViewModel(this, standalonePackage, packageAlreadyInSession);
packageMap.Add(packageContainerViewModel, standalonePackage);
if (!packageAlreadyInSession)
session.Projects.Add(standalonePackage);
@@ -1445,7 +1445,7 @@ private void DoUpdateSessionState()
return;

var packageSelected = false;
var packageHasExecutables = false;
var projectSelected = false;
var dependenciesSelected = false;
var directorySelected = false;
var canDelete = ActiveAssetView.SelectedLocations.Count > 0;
@@ -1455,12 +1455,11 @@ private void DoUpdateSessionState()
if (location is PackageViewModel package && package.IsEditable)
{
packageSelected = true;
packageHasExecutables = (package as ProjectViewModel)?.Type == ProjectType.Executable;
projectSelected = package is ProjectViewModel;
}
if (location is DirectoryBaseViewModel)
{
var project = location as ProjectViewModel;
directorySelected = project == null || project.Type != ProjectType.Executable;
directorySelected = true;
}
if (location is DependencyCategoryViewModel)
{
@@ -1482,9 +1481,9 @@ private void DoUpdateSessionState()

NewPackageCommand.IsEnabled = !string.IsNullOrWhiteSpace(SolutionPath);
AddExistingProjectCommand.IsEnabled = packageSelected;
IsUpdatePackageEnabled = packageSelected && packageHasExecutables;
IsUpdatePackageEnabled = projectSelected;
AddDependencyCommand.IsEnabled = packageSelected || dependenciesSelected;
SetCurrentProjectCommand.IsEnabled = packageHasExecutables;
SetCurrentProjectCommand.IsEnabled = projectSelected;
DeleteSelectedSolutionItemsCommand.IsEnabled = canDelete;
ExploreCommand.IsEnabled = ActiveAssetView.SelectedContent.Count > 0 || ActiveAssetView.SelectedLocations.Count == 1;
RenameDirectoryOrPackageCommand.IsEnabled = canRename;
@@ -230,7 +230,7 @@
</MenuItem>
<MenuItem Header="{xk:Localize Add existing project..., Context=Menu}" Command="{Binding Session.AddExistingProjectCommand}" Icon="{xk:Image {StaticResource ImageAddExistingProject}}"/>
<MenuItem Header="{xk:Localize Add dependency..., Context=Menu}" Command="{Binding Session.AddDependencyCommand}" Icon="{xk:Image {StaticResource ImageAddDependency}}"/>
<MenuItem Header="{xk:Localize Set as current package, Context=Menu}" Command="{Binding Session.SetCurrentPackageCommand}" CommandParameter="{Binding}" Icon="{xk:Image {StaticResource ImageStartupProject}}"/>
<MenuItem Header="{xk:Localize Set as current project, Context=Menu}" Command="{Binding Session.SetCurrentProjectCommand}" CommandParameter="{Binding}" Icon="{xk:Image {StaticResource ImageStartupProject}}"/>
<MenuItem Header="{xk:Localize Package properties, Context=Menu}" Command="{Binding Session.ActivatePackagePropertiesCommand}" Icon="{xk:Image {StaticResource ImagePackageProperties}}"/>

<MenuItem Header="{xk:Localize Solution, Context=Menu}" Style="{StaticResource MenuGroupSeparatorStyle}"/>
@@ -489,7 +489,7 @@
<MenuItem Header="{xk:Localize Folder, Context=Menu}" Style="{StaticResource MenuGroupSeparatorStyle}" Visibility="{Binding Session.NewDirectoryCommand.IsEnabled, Converter={xk:VisibleOrCollapsed}}"/>
<MenuItem Header="{xk:Localize Create folder, Context=Menu}" Command="{Binding Session.NewDirectoryCommand}" CommandParameter="{Binding Session.ActiveAssetView.SelectedLocations}" Icon="{xk:Image {StaticResource ImageNewFolder}}" Visibility="{Binding Session.NewDirectoryCommand.IsEnabled, Converter={xk:VisibleOrCollapsed}}"/>

<MenuItem Header="{xk:Localize Package, Context=Menu}" Style="{StaticResource MenuGroupSeparatorStyle}" Visibility="{xk:MultiBinding {Binding Session.IsUpdatePackageEnabled}, {Binding Session.AddExistingProjectCommand.IsEnabled}, {Binding Session.AddDependencyCommand.IsEnabled}, {Binding Session.SetCurrentPackageCommand.IsEnabled}, Converter={xk:MultiChained {xk:OrMultiConverter}, {xk:VisibleOrCollapsed}}}"/>
<MenuItem Header="{xk:Localize Package, Context=Menu}" Style="{StaticResource MenuGroupSeparatorStyle}" Visibility="{xk:MultiBinding {Binding Session.IsUpdatePackageEnabled}, {Binding Session.AddExistingProjectCommand.IsEnabled}, {Binding Session.AddDependencyCommand.IsEnabled}, {Binding Session.SetCurrentProjectCommand.IsEnabled}, Converter={xk:MultiChained {xk:OrMultiConverter}, {xk:VisibleOrCollapsed}}}"/>
<MenuItem Header="{xk:Localize Update package, Context=Menu}" ItemsSource="{Binding Session.UpdatePackageViewModel.Templates}" Icon="{xk:Image {StaticResource ImageAddNewProject}}" Visibility="{Binding Session.IsUpdatePackageEnabled, Converter={xk:VisibleOrCollapsed}}">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}" d:DataContext="{d:DesignInstance viewModels1:TemplateDescriptionViewModel}">
@@ -510,7 +510,7 @@
</MenuItem>
<MenuItem Header="{xk:Localize Add existing project..., Context=Menu}" Command="{Binding Session.AddExistingProjectCommand}" Icon="{xk:Image {StaticResource ImageAddExistingProject}}" Visibility="{Binding Session.AddExistingProjectCommand.IsEnabled, Converter={xk:VisibleOrCollapsed}}"/>
<MenuItem Header="{xk:Localize Add dependency..., Context=Menu}" Command="{Binding Session.AddDependencyCommand}" Icon="{xk:Image {StaticResource ImageAddDependency}}" Visibility="{Binding Session.AddDependencyCommand.IsEnabled, Converter={xk:VisibleOrCollapsed}}"/>
<MenuItem Header="{xk:Localize Set as current package, Context=Menu}" Command="{Binding Session.SetCurrentPackageCommand}" CommandParameter="{Binding}" Icon="{xk:Image {StaticResource ImageStartupProject}}" Visibility="{Binding Session.SetCurrentPackageCommand.IsEnabled, Converter={xk:VisibleOrCollapsed}}"/>
<MenuItem Header="{xk:Localize Set as current project, Context=Menu}" Command="{Binding Session.SetCurrentProjectCommand}" CommandParameter="{Binding}" Icon="{xk:Image {StaticResource ImageStartupProject}}" Visibility="{Binding Session.SetCurrentProjectCommand.IsEnabled, Converter={xk:VisibleOrCollapsed}}"/>
<MenuItem Header="{xk:Localize Package properties, Context=Menu}" Command="{Binding Session.ActivatePackagePropertiesCommand}" Icon="{xk:Image {StaticResource ImagePackageProperties}}" Visibility="{Binding Session.ActivatePackagePropertiesCommand.IsEnabled, Converter={xk:VisibleOrCollapsed}}"/>

<MenuItem Header="{xk:Localize Solution, Context=Menu}" Style="{StaticResource MenuGroupSeparatorStyle}" Visibility="{xk:MultiBinding {Binding Session.NewPackageCommand.IsEnabled}, {Binding Session.AddExistingPackageCommand.IsEnabled}, {Binding Session.OpenInIDECommand.IsEnabled}, Converter={xk:MultiChained {xk:OrMultiConverter}, {xk:VisibleOrCollapsed}}}"/>
@@ -118,6 +118,8 @@ public static void UpdatePackagePlatforms(TemplateGeneratorParameters parameters

package.Session.Projects.Add(newExeProject);

package.Session.LoadMissingReferences(logger);

package.IsDirty = true;
}
}
@@ -420,8 +420,8 @@ msgstr "依存関係の追加..."
#: ../editor/Xenko.GameStudio/GameStudioWindow.xaml:210
#: ../editor/Xenko.GameStudio/GameStudioWindow.xaml:490
msgctxt "Menu"
msgid "Set as current package"
msgstr "現在のパッケージに設定"
msgid "Set as current project"
msgstr "現在のプロジェクトに設定"

#: ../editor/Xenko.GameStudio/GameStudioWindow.xaml:211
#: ../editor/Xenko.GameStudio/GameStudioWindow.xaml:491

0 comments on commit 0e1ad23

Please sign in to comment.
You can’t perform that action at this time.