Add .razor icon

This commit is contained in:
Matt Parker
2025-11-28 23:26:26 +10:00
parent e75d1319ef
commit 576ade5bfc
11 changed files with 139 additions and 9 deletions

View File

@@ -143,7 +143,7 @@ public class SharpIdeSolutionModificationService(FileChangedService fileChangedS
public async Task<SharpIdeFile> CreateFile(IFolderOrProject parentNode, string newFilePath, string fileName, string contents)
{
var sharpIdeFile = new SharpIdeFile(newFilePath, fileName, parentNode, []);
var sharpIdeFile = new SharpIdeFile(newFilePath, fileName, Path.GetExtension(newFilePath), parentNode, []);
var correctInsertionPosition = GetInsertionPosition(parentNode, sharpIdeFile);

View File

@@ -12,6 +12,7 @@ public class SharpIdeFile : ISharpIdeNode, IChildSharpIdeNode, IFileOrFolder
public required IExpandableSharpIdeNode Parent { get; set; }
public required string Path { get; set; }
public required string Name { get; set; }
public required string Extension { get; set; }
public bool IsRazorFile => Path.EndsWith(".razor", StringComparison.OrdinalIgnoreCase);
public bool IsCsprojFile => Path.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase);
public bool IsCshtmlFile => Path.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase);
@@ -25,10 +26,11 @@ public class SharpIdeFile : ISharpIdeNode, IChildSharpIdeNode, IFileOrFolder
public EventWrapper<Task> FileDeleted { get; } = new(() => Task.CompletedTask);
[SetsRequiredMembers]
internal SharpIdeFile(string fullPath, string name, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
internal SharpIdeFile(string fullPath, string name, string extension, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
{
Path = fullPath;
Name = name;
Extension = extension;
Parent = parent;
IsDirty = new ReactiveProperty<bool>(false);
SuppressDiskChangeEvents = false;

View File

@@ -75,7 +75,7 @@ public static class TreeMapperV2
return [];
}
var sharpIdeFiles = fileInfos.Select(f => new SharpIdeFile(f.FullName, f.Name, parent, allFiles)
var sharpIdeFiles = fileInfos.Select(f => new SharpIdeFile(f.FullName, f.Name, f.Extension, parent, allFiles)
{
Path = f.FullName,
Name = f.Name,

View File

@@ -14,7 +14,7 @@ public static class IntermediateMapper
var serializer = SolutionSerializers.GetSerializerByMoniker(solutionFilePath);
Guard.Against.Null(serializer, nameof(serializer));
var vsSolution = await serializer.OpenAsync(solutionFilePath, cancellationToken);
// Remove any projects that aren't csproj, TODO: Instead of removing, display in the solution explorer that the project type isn't supported
foreach (var vsSolutionSolutionProject in vsSolution.SolutionProjects.Where(s => s.Extension is not ".csproj").ToList())
{
@@ -59,10 +59,15 @@ public static class IntermediateMapper
.ToList();
var filesInFolder = folder.Files?
.Select(f => new IntermediateSlnFolderFileModel
.Select(f =>
{
Name = Path.GetFileName(f),
FullPath = new FileInfo(Path.Join(Path.GetDirectoryName(solutionFilePath), f)).FullName
var fileInfo = new FileInfo(Path.Join(Path.GetDirectoryName(solutionFilePath), f));
return new IntermediateSlnFolderFileModel
{
Name = Path.GetFileName(f),
FullPath = fileInfo.FullName,
Extension = fileInfo.Extension
};
})
.ToList() ?? [];

View File

@@ -29,4 +29,5 @@ internal class IntermediateSlnFolderFileModel
{
public required string Name { get; set; }
public required string FullPath { get; set; }
public required string Extension { get; set; }
}

View File

@@ -90,7 +90,7 @@ public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IC
{
Name = intermediateModel.Model.Name;
Parent = parent;
Files = new ObservableHashSet<SharpIdeFile>(intermediateModel.Files.Select(s => new SharpIdeFile(s.FullPath, s.Name, this, allFiles)));
Files = new ObservableHashSet<SharpIdeFile>(intermediateModel.Files.Select(s => new SharpIdeFile(s.FullPath, s.Name, s.Extension, this, allFiles)));
Folders = new ObservableHashSet<SharpIdeSolutionFolder>(intermediateModel.Folders.Select(x => new SharpIdeSolutionFolder(x, allProjects, allFiles, allFolders, this)));
Projects = new ObservableHashSet<SharpIdeProjectModel>(intermediateModel.Projects.Select(x => new SharpIdeProjectModel(x, allProjects, allFiles, allFolders, this)));
}

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
class="mud-icon-root mud-svg-icon mud-error-text mud-icon-size-medium"
focusable="false"
viewBox="0 0 24 24"
aria-hidden="true"
role="img"
style="fill: rgb(40, 167, 69);"
version="1.1"
id="svg1"
sodipodi:docname="RazorFile.svg"
inkscape:version="1.4.2 (f4327f4, 2025-05-13)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1" />
<sodipodi:namedview
id="namedview1"
pagecolor="#505050"
bordercolor="#eeeeee"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#505050"
inkscape:zoom="8.5957668"
inkscape:cx="-15.472733"
inkscape:cy="0.058168167"
inkscape:window-width="2560"
inkscape:window-height="1369"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg1" />
<path
d="M 0,0 H 24 V 24 H 0 Z"
fill="none"
id="path1"
style="display:inline" />
<text
x="11.912748"
y="13.454205"
text-anchor="middle"
dominant-baseline="middle"
font-family="'Segoe UI', Roboto, Helvetica, Arial, sans-serif"
font-size="16px"
font-weight="700"
id="text1"
style="display:none">C#</text>
<path
d="m 11.49478,17.055767 c -0.817709,0.395833 -1.8854171,0.59375 -3.2031254,0.59375 -1.71875,0 -3.0703125,-0.505208 -4.0546875,-1.515625 -0.984375,-1.010417 -1.4765625,-2.356771 -1.4765625,-4.039062 0,-1.791667 0.5520833,-3.2447921 1.65625,-4.3593754 1.109375,-1.1145833 2.546875,-1.671875 4.3125,-1.671875 1.0937503,0 2.0156254,0.1380208 2.7656254,0.4140625 v 2.4296875 c -0.75,-0.4479167 -1.6041668,-0.671875 -2.5625004,-0.671875 -1.0520833,0 -1.9010417,0.3307292 -2.546875,0.9921875 -0.6458333,0.6614586 -0.96875,1.5572919 -0.96875,2.6874999 0,1.083333 0.3046875,1.947917 0.9140625,2.59375 0.609375,0.640625 1.4296875,0.960938 2.4609375,0.960938 0.9843749,0 1.8854164,-0.239583 2.7031254,-0.71875 z m 9.859375,-7.9531249 -0.304688,1.4062499 h -1.445312 l -0.429688,1.9375 h 1.617188 l -0.351563,1.40625 h -1.554687 l -0.609375,2.703125 h -1.5625 l 0.570312,-2.703125 H 15.49478 l -0.578125,2.703125 h -1.5625 l 0.554687,-2.703125 h -1.453125 l 0.289063,-1.40625 h 1.46875 l 0.414062,-1.9375 h -1.578125 l 0.265625,-1.4062499 h 1.601563 l 0.578125,-2.78125 h 1.601562 l -0.578125,2.78125 h 1.789063 l 0.59375,-2.78125 h 1.585937 l -0.578125,2.78125 z M 18.02603,10.508892 h -1.8125 l -0.429688,1.9375 h 1.804688 z"
id="text2"
style="font-weight:700;font-size:16px;font-family:'Segoe UI', Roboto, Helvetica, Arial, sans-serif;dominant-baseline:middle;text-anchor:middle;display:none"
aria-label="C#"
sodipodi:nodetypes="cssscsccssscscccccccccccccccccccccccccccccccccccc" />
<path
d="M 20.743389,4.7145968 20.488494,5.8910339 H 19.279378 L 18.919911,7.511903 h 1.352903 l -0.29411,1.1764369 h -1.300616 l -0.509789,2.2613741 h -1.307153 l 0.47711,-2.2613741 H 15.841567 L 15.357921,10.949714 H 14.050768 L 14.514807,8.6883399 H 13.299155 L 13.540979,7.511903 h 1.228723 l 0.346395,-1.6208691 h -1.320224 l 0.222216,-1.1764371 h 1.339832 l 0.483646,-2.3267314 h 1.339831 l -0.483646,2.3267314 h 1.49669 L 18.69116,2.3878654 h 1.326759 L 19.534272,4.7145968 Z M 17.959154,5.8910339 H 16.442857 L 16.08339,7.511903 h 1.509761 z"
style="font-weight:700;font-size:16px;font-family:'Segoe UI', Roboto, Helvetica, Arial, sans-serif;dominant-baseline:middle;text-anchor:middle;display:inline;stroke-width:0.836578"
id="path1-5" />
<path
d="m 11.49478,15.821834 c -0.817709,0.395833 -1.8854171,0.59375 -3.2031254,0.59375 -1.71875,0 -3.0703125,-0.505208 -4.0546871,-1.515625 -0.984375,-1.010417 -1.476563,-2.356771 -1.476563,-4.039062 0,-1.7916672 0.552083,-3.2447921 1.6562501,-4.3593751 1.109375,-1.114584 2.546875,-1.671875 4.3125,-1.671875 1.0937503,0 2.0156254,0.13802 2.7656254,0.414062 v 2.429688 c -0.75,-0.447917 -1.6041668,-0.671875 -2.5625004,-0.671875 -1.0520833,0 -1.9010417,0.330729 -2.546875,0.992187 -0.6458333,0.661459 -0.96875,1.5572919 -0.96875,2.6875001 0,1.083333 0.3046875,1.947917 0.9140625,2.59375 0.609375,0.640625 1.4296875,0.960938 2.4609375,0.960938 0.9843749,0 1.8854164,-0.239583 2.7031254,-0.71875 z"
style="font-weight:700;font-size:16px;font-family:'Segoe UI', Roboto, Helvetica, Arial, sans-serif;dominant-baseline:middle;text-anchor:middle;display:inline"
id="path1-1" />
<text
xml:space="preserve"
style="font-size:10.6667px;text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;display:none;fill:#6c4d93;fill-opacity:1;stroke:#6c4d93;stroke-width:0.3;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
x="10.72811"
y="21.502331"
id="text3"><tspan
sodipodi:role="line"
id="tspan3"
x="10.72811"
y="21.502331"
style="font-size:10.6667px;fill:#6c4d93;fill-opacity:1;stroke:#6c4d93;stroke-width:0.3;stroke-dasharray:none;stroke-opacity:1">@</tspan></text>
<path
d="m 21.322558,16.2176 q 0,0.72396 -0.213542,1.401046 -0.208334,0.677085 -0.59896,1.234379 h -2.291674 l -0.140626,-0.604169 q -0.385417,0.312501 -0.739585,0.479168 -0.354168,0.166668 -0.812503,0.166668 -0.875003,0 -1.401046,-0.661461 -0.520835,-0.66146 -0.520835,-1.848964 0,-1.182295 0.640627,-1.885423 0.640627,-0.703127 1.531255,-0.703127 0.38021,0 0.671877,0.08854 0.291668,0.08333 0.63021,0.255209 v -0.25 h 0.828128 v 4.38543 h 1.265629 q 0.218751,-0.390626 0.328126,-0.973961 0.114584,-0.588544 0.114584,-1.052087 0,-0.854169 -0.239584,-1.552088 -0.234376,-0.697919 -0.692711,-1.197921 -0.458335,-0.500001 -1.13542,-0.765627 -0.677085,-0.270834 -1.536463,-0.270834 -0.833336,0 -1.526047,0.302084 -0.687502,0.302084 -1.182295,0.812503 -0.500002,0.510418 -0.786461,1.223962 -0.281251,0.708335 -0.281251,1.510421 0,0.859378 0.270834,1.572922 0.270835,0.708335 0.765628,1.213545 0.515626,0.526044 1.208337,0.791669 0.69271,0.270835 1.510421,0.270835 0.447918,0 0.921878,-0.05729 0.479168,-0.05729 0.91667,-0.182292 v 0.739585 q -0.50521,0.109376 -0.942711,0.145834 -0.437502,0.04167 -0.901045,0.04167 -0.968753,0 -1.796881,-0.333335 -0.828127,-0.328126 -1.421879,-0.921877 -0.59896,-0.598961 -0.932295,-1.437505 -0.333334,-0.838544 -0.333334,-1.854173 0,-0.963544 0.348959,-1.791672 0.34896,-0.833336 0.953128,-1.442713 0.604169,-0.609377 1.432297,-0.958336 0.828127,-0.34896 1.770838,-0.34896 1.020837,0 1.822923,0.322918 0.802086,0.322918 1.354171,0.906253 0.552085,0.583335 0.843752,1.406254 0.296876,0.817711 0.296876,1.822923 z m -3.255218,1.328129 v -2.697925 q -0.328126,-0.151042 -0.588544,-0.213542 -0.260417,-0.06771 -0.557293,-0.06771 -0.671877,0 -1.052087,0.468751 -0.380209,0.468752 -0.380209,1.333338 0,0.848961 0.302084,1.286462 0.302084,0.432293 0.942711,0.432293 0.34896,0 0.697919,-0.161458 0.34896,-0.161459 0.635419,-0.38021 z"
id="text3-7"
style="font-size:10.6667px;fill:#7b55b1;fill-opacity:1;stroke:#7b55b1;stroke-width:0.3;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
aria-label="@" />
</svg>

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@@ -0,0 +1,18 @@
[remap]
importer="svg"
type="DPITexture"
uid="uid://cff7jlvj2tlg2"
path="res://.godot/imported/RazorFile.svg-08f0ff289353f8dee724d8123b417b7b.dpitex"
[deps]
source_file="res://Features/SolutionExplorer/Resources/FileExtensions/RazorFile.svg"
dest_files=["res://.godot/imported/RazorFile.svg-08f0ff289353f8dee724d8123b417b7b.dpitex"]
[params]
base_scale=1.0
saturation=1.0
color_map={}
compress=true

View File

@@ -0,0 +1,21 @@
using Godot;
namespace SharpIDE.Godot.Features.SolutionExplorer;
public partial class SolutionExplorerPanel
{
private readonly Texture2D _csIcon = ResourceLoader.Load<Texture2D>("uid://do0edciarrnp0");
private readonly Texture2D _razorIcon = ResourceLoader.Load<Texture2D>("uid://cff7jlvj2tlg2");
private Texture2D GetIconForFileExtension(string fileExtension)
{
var texture = fileExtension switch
{
".cs" => _csIcon,
".razor" or ".cshtml" => _razorIcon,
_ => _csIcon
};
return texture;
}
}

View File

@@ -0,0 +1 @@
uid://bwr8t3txvnnux

View File

@@ -299,7 +299,7 @@ public partial class SolutionExplorerPanel : MarginContainer
}
var fileItem = tree.CreateItem(parent, newStartingIndex);
fileItem.SetText(0, sharpIdeFile.Name);
fileItem.SetIcon(0, CsharpFileIcon);
fileItem.SetIcon(0, GetIconForFileExtension(sharpIdeFile.Extension));
fileItem.SetCustomColor(0, GetColorForGitStatus(sharpIdeFile.GitStatus));
fileItem.SetMetadata(0, new RefCountedContainer<SharpIdeFile>(sharpIdeFile));