Skip to content

Commit

Permalink
Mark package content items as "user read-only"
Browse files Browse the repository at this point in the history
Fixes: #2141

This marks package content items as user read-only, which causes them to be opened read-only in the editor.
  • Loading branch information
davkean committed Aug 10, 2020
1 parent 484014c commit 89723dc
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="NuGetPackageId"
Visible="false">
<StringProperty.Metadata>
<NameValuePair Name="DoNotCopyAcrossProjects"
Value="true" />
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="SubType"
Visible="false">
<StringProperty.DataSource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="NuGetPackageId"
Visible="false">
<StringProperty.Metadata>
<NameValuePair Name="DoNotCopyAcrossProjects"
Value="true" />
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="SubType"
Visible="false">
<StringProperty.DataSource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="NuGetPackageId"
Visible="false">
<StringProperty.Metadata>
<NameValuePair Name="DoNotCopyAcrossProjects"
Value="true" />
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="SubType"
Visible="false">
<StringProperty.DataSource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="NuGetPackageId"
Visible="false">
<StringProperty.Metadata>
<NameValuePair Name="DoNotCopyAcrossProjects"
Value="true" />
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="SubType"
Visible="false">
<StringProperty.DataSource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="NuGetPackageId"
Visible="false">
<StringProperty.Metadata>
<NameValuePair Name="DoNotCopyAcrossProjects"
Value="true" />
</StringProperty.Metadata>
</StringProperty>

<StringProperty Name="SubType"
Visible="false">
<StringProperty.DataSource>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.md file in the project root for more information.

using System.ComponentModel.Composition;

namespace Microsoft.VisualStudio.ProjectSystem.Tree
{
/// <summary>
/// Marks content items that come from packages as "user read-only".
/// </summary>
[Export(typeof(IProjectTreePropertiesProvider))]
[AppliesTo(ProjectCapability.PackageReferences)]
internal class PackageContentProjectTreePropertiesProvider : IProjectTreePropertiesProvider
{
public void CalculatePropertyValues(IProjectTreeCustomizablePropertyContext propertyContext, IProjectTreeCustomizablePropertyValues propertyValues)
{
// Package content items always come in as linked items, so to reduce
// the number of items we look at, we limit ourselves to them
if (propertyValues.Flags.Contains(ProjectTreeFlags.LinkedItem) &&
propertyContext.Metadata != null &&
propertyContext.Metadata.TryGetValue(None.NuGetPackageIdProperty, out string packageId) && packageId.Length > 0)
{
// TODO: Replace this with strongly typed value when we next update
propertyValues.Flags |= ProjectTreeFlags.Create("UserReadOnly");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public string NuGetPackageFolders
if (!string.Equals(_nuGetPackageFoldersString, value, StringComparisons.Paths))
{
_nuGetPackageFoldersString = value;
_nuGetPackageFolders = value.Split(';');
_nuGetPackageFolders = value.Split(Delimiter.Semicolon);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

using System;

namespace Microsoft
namespace Microsoft.VisualStudio
{
internal static class StringExtensions
{
public static string[] SplitReturningEmptyIfEmpty(this string value, char separator)
public static string[] SplitReturningEmptyIfEmpty(this string value, params char[] separator)
{
string[] values = value.Split(separator);

if (values.Length == 1 && string.IsNullOrEmpty(value))
if (values.Length == 1 && string.IsNullOrEmpty(values[0]))
return Array.Empty<string>();

return values;
Expand Down

0 comments on commit 89723dc

Please sign in to comment.