Skip to content

Commit

Permalink
Renamed project and updated codebase
Browse files Browse the repository at this point in the history
The project has been renamed from 'MemefulComments' to 'IlluminatedComments'. The solution file, .csproj file, and all related files have been updated accordingly. Code changes include improved error handling, refactoring for better readability, and updates to the Visual Studio version in the .csproj file. Also, the target framework version has been upgraded from v4.7.2 to v4.8.1 and copyright information in AssemblyInfo.cs has been updated.
  • Loading branch information
Ris Adams committed Aug 6, 2024
1 parent 55bb225 commit d3f9e64
Show file tree
Hide file tree
Showing 26 changed files with 147 additions and 133 deletions.
59 changes: 25 additions & 34 deletions MemefulComments.sln → IlluminatedComments.sln
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MemefulComments", "MemefulComments\MemefulComments.csproj", "{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {777967B1-5B02-4D5D-84D2-FCF09E8E1B4C}
EndGlobalSection
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 2
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://mariusbancila.visualstudio.com/
SccLocalPath0 = .
SccProjectUniqueName1 = MemefulComments\\MemefulComments.csproj
SccProjectName1 = MemefulComments
SccLocalPath1 = MemefulComments
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IlluminatedComments", "IlluminatedComments\IlluminatedComments.csproj", "{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6DA3013-4F85-4967-A7B9-F8AF9CC42B01}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {777967B1-5B02-4D5D-84D2-FCF09E8E1B4C}
EndGlobalSection
EndGlobal
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.IO;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using WpfAnimatedGif;

namespace IlluminatedComments
Expand Down Expand Up @@ -71,6 +73,7 @@ public void Dispose()
public bool TrySet(string imageUrl, string originalUrl, double scale, string filepath, out Exception exception)
{
exception = null;
if (string.IsNullOrEmpty(filepath)) return false;
try
{
imageUrl = _variableExpander.ProcessText(imageUrl);
Expand All @@ -88,11 +91,17 @@ public bool TrySet(string imageUrl, string originalUrl, double scale, string fil
}
}

private bool IsAbsoluteUri(string uri) => Uri.TryCreate(uri, UriKind.Absolute, out var result);
private bool IsAbsoluteUri(string uri) => Uri.TryCreate(uri, UriKind.Absolute, out _);

private BitmapImage LoadImage(string uri, string filepath)
{
if (!IsAbsoluteUri(uri)) uri = Path.Combine(Path.GetDirectoryName(filepath), uri);
// fail early if file or path is not found.
if(string.IsNullOrEmpty(filepath)) return null;

var dirPath = Path.GetDirectoryName(filepath);
if(string.IsNullOrEmpty(dirPath)) return null;

if (!IsAbsoluteUri(uri)) uri = Path.Combine(dirPath, uri);

fileSystemWatcher.EnableRaisingEvents = false;
fileSystemWatcher.Path = Path.GetDirectoryName(uri);
Expand Down Expand Up @@ -132,11 +141,17 @@ private BitmapImage LoadImage(string uri, string filepath)

public override string ToString() => Url;

private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e) => Dispatcher.Invoke(() =>
private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
Source = LoadImage(e.FullPath, string.Empty);
Scale = _scale;
InvalidateVisual();
});
ThreadHelper.JoinableTaskFactory.Run(async delegate
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (string.IsNullOrEmpty(e.FullPath)) return;
Source = LoadImage(e.FullPath, string.Empty);
Scale = _scale;
InvalidateVisual();
});

}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ internal sealed class CommentsAdornment : ITagger<ErrorTag>, IDisposable
private string _contentTypeName;
private readonly ConcurrentDictionary<int, ITextViewLine> _editedLines = new ConcurrentDictionary<int, ITextViewLine>();
private readonly List<ITagSpan<ErrorTag>> _errorTags;
private bool _initialised1;
private bool _initialised2;
private bool _initialized1;
private bool _initialized2;

private readonly IAdornmentLayer _layer;

private readonly List<string> _processingUris = new List<string>();
private readonly ITextDocumentFactoryService _textDocumentFactory;

private readonly Timer _timer = new Timer(200);
private readonly ConcurrentDictionary<WebClient, ImageParameters> _toaddImages = new ConcurrentDictionary<WebClient, ImageParameters>();
private readonly ConcurrentDictionary<WebClient, ImageParameters> _toAddImages = new ConcurrentDictionary<WebClient, ImageParameters>();
private readonly VariableExpander _variableExpander;
private readonly IWpfTextView _view;

Expand All @@ -58,7 +58,7 @@ public CommentsAdornment(IWpfTextView view, ITextDocumentFactoryService textDocu
_errorTags = new List<ITagSpan<ErrorTag>>();
_variableExpander = new VariableExpander(_view, serviceProvider);

_timer.Elapsed += _timer_Elapsed;
_timer.Elapsed += On_Timer_Elapsed;
}

public static bool Enabled { get; set; }
Expand Down Expand Up @@ -105,16 +105,16 @@ internal void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
// have been added, so the lines don't resize to the image height. So here's a workaround:
// Changing the zoom level triggers the required update.
// Need to do it twice - once to trigger the event, and again to change it back to the user's expected level.
if (!_initialised1)
if (!_initialized1)
{
_view.ZoomLevel++;
_initialised1 = true;
_initialized1 = true;
}

if (!_initialised2)
if (!_initialized2)
{
_view.ZoomLevel--;
_initialised2 = true;
_initialized2 = true;
}
}
catch (Exception ex)
Expand All @@ -129,10 +129,11 @@ private void ResetTimer()
_timer.Start();
}

private void _timer_Elapsed(object sender, ElapsedEventArgs e)
private async void On_Timer_Elapsed(object sender, ElapsedEventArgs e)
{
_timer.Stop();

await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Application.Current.Dispatcher.Invoke(() =>
{
string filepath = null;
Expand Down Expand Up @@ -182,8 +183,7 @@ private void CreateVisuals(ITextViewLine line, int lineNumber, string filepath)

if (xmlParseException != null)
{
CommentImage commentImage;
if (Images.TryRemove(lineNumber, out commentImage))
if (Images.TryRemove(lineNumber, out var commentImage))
{
_layer.RemoveAdornment(commentImage);
commentImage.Dispose();
Expand All @@ -204,7 +204,7 @@ private void CreateVisuals(ITextViewLine line, int lineNumber, string filepath)
return new CommentImage(_variableExpander);
}, (ln, img) =>
{
if (img.OriginalUrl == imageUrl && img.Scale != scale)
if (img.OriginalUrl == imageUrl && (Math.Abs(img.Scale - scale) > float.Epsilon))
{
// URL same but scale changed
img.Scale = scale;
Expand Down Expand Up @@ -237,7 +237,7 @@ private void CreateVisuals(ITextViewLine line, int lineNumber, string filepath)
var client = new WebClient();
client.DownloadDataCompleted += Client_DownloadDataCompleted;

_toaddImages.TryAdd(
_toAddImages.TryAdd(
client,
new ImageParameters
{
Expand Down Expand Up @@ -266,7 +266,7 @@ private void CreateVisuals(ITextViewLine line, int lineNumber, string filepath)
else
{
Images.TryRemove(lineNumber, out var commentImage);
commentImage.Dispose();
commentImage?.Dispose();
}
}
catch (Exception ex)
Expand All @@ -279,27 +279,28 @@ private void Client_DownloadDataCompleted(object sender, DownloadDataCompletedEv
{
try
{
var client = sender as WebClient;

client.DownloadDataCompleted -= Client_DownloadDataCompleted;

if (_toaddImages.TryGetValue(client, out var item))
if (sender is WebClient client)
{
var data = e.Result;
File.WriteAllBytes(item.LocalPath, data);
ImageCache.Instance.Add(item.Uri, item.LocalPath);
_processingUris.Remove(item.Uri);

ProcessImage(item.Image,
item.LocalPath,
item.Uri,
item.Line,
item.LineNumber,
item.Span,
item.Scale,
item.Filepath);

_toaddImages.TryRemove(client, out var value);
client.DownloadDataCompleted -= Client_DownloadDataCompleted;

if (_toAddImages.TryGetValue(client, out var item))
{
var data = e.Result;
File.WriteAllBytes(item.LocalPath, data);
ImageCache.Instance.Add(item.Uri, item.LocalPath);
_processingUris.Remove(item.Uri);

ProcessImage(item.Image,
item.LocalPath,
item.Uri,
item.Line,
item.LineNumber,
item.Span,
item.Scale,
item.Filepath);

_toAddImages.TryRemove(client, out var value);
}
}
}
catch (Exception ex)
Expand All @@ -322,7 +323,7 @@ private void ProcessImage(CommentImage image, string imageUrl, string originalUr
// Position image and add as adornment
if (imageLoadingException == null)
{
AddAdorment(image, line, lineNumber, span);
AddAdornment(image, line, span);
}
else
{
Expand All @@ -341,7 +342,7 @@ private void ProcessImage(CommentImage image, string imageUrl, string originalUr
}
}

private void AddAdorment(UIElement element, ITextViewLine line, int lineNumber, SnapshotSpan span)
private void AddAdornment(UIElement element, ITextViewLine line, SnapshotSpan span)
{
Geometry geometry = null;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal sealed class CommentsAdornmentTextViewCreationListener : IWpfTextViewCr
/// after the selection layer in the Z-order
/// </summary>
[Export(typeof(AdornmentLayerDefinition))] [Name("CommentImageAdornmentLayer")] [Order(After = PredefinedAdornmentLayers.Selection, Before = PredefinedAdornmentLayers.Text)]
private AdornmentLayerDefinition editorAdornmentLayer;
private readonly AdornmentLayerDefinition editorAdornmentLayer;

#pragma warning restore 649, 169

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<TargetFrameworkProfile />
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
Expand All @@ -22,7 +26,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IlluminatedComments</RootNamespace>
<AssemblyName>IlluminatedComments</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<GeneratePkgDefFile>false</GeneratePkgDefFile>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>true</IncludeDebugSymbolsInVSIXContainer>
Expand Down Expand Up @@ -104,25 +108,25 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.CoreUtility">
<Version>17.0.487</Version>
<Version>17.10.191</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Framework">
<Version>17.0.31902.203</Version>
<Version>17.10.40170</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Text.Data">
<Version>17.0.487</Version>
<Version>17.10.191</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Text.Logic">
<Version>17.0.487</Version>
<Version>17.10.191</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Text.UI">
<Version>17.0.487</Version>
<Version>17.10.191</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf">
<Version>17.0.487</Version>
<Version>17.10.191</Version>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
<Version>17.0.5232</Version>
<Version>17.11.414</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Marius Bancila, Ris Adams")]
[assembly: AssemblyProduct("Illuminated Comments")]
[assembly: AssemblyCopyright("Marius Bancila (c) 2017 - 2019, Ris Adams (c) 2021")]
[assembly: AssemblyCopyright("Marius Bancila (c) 2017 - 2019, Ris Adams (c) 2021 - 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -28,5 +28,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
File renamed without changes.
Loading

0 comments on commit d3f9e64

Please sign in to comment.