Skip to content

Commit

Permalink
First release-ready version imo
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Abt committed Jan 11, 2020
1 parent 063d4f2 commit b11a605
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 60 deletions.
14 changes: 8 additions & 6 deletions ClippyVSPackage/Clippy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Recoding.ClippyVSPackage.Configurations;
using Microsoft.VisualStudio.Shell;
using Recoding.ClippyVSPackage.Configurations;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -131,11 +132,11 @@ private void RegisterAnimations()
Uri uri = new Uri(animationsResourceUri, UriKind.RelativeOrAbsolute);
StreamResourceInfo info = Application.GetResourceStream(uri);

List<Animation> storedAnimations = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Animation>>(StreamToString(info.Stream));
List<ClippyAnimation> storedAnimations = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClippyAnimation>>(StreamToString(info.Stream));

Animations = new Dictionary<string, Tuple<DoubleAnimationUsingKeyFrames, DoubleAnimationUsingKeyFrames>>();

foreach (Animation animation in storedAnimations)
foreach (ClippyAnimation animation in storedAnimations)
{
DoubleAnimationUsingKeyFrames xDoubleAnimation = new DoubleAnimationUsingKeyFrames();
xDoubleAnimation.FillBehavior = FillBehavior.HoldEnd;
Expand Down Expand Up @@ -209,20 +210,21 @@ void WPFAnimationsDispatcher_Tick(object sender, EventArgs e)
/// <param name="animationType"></param>
public void StartAnimation(ClippyAnimations animationType, bool byPassCurrentAnimation = false)
{
Application.Current.MainWindow.Dispatcher.Invoke(new Action(() =>
Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.Run(async delegate
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

if (!IsAnimating || byPassCurrentAnimation)
{
IsAnimating = true;

clippedImage.BeginAnimation(Canvas.LeftProperty, Animations[animationType.ToString()].Item1);
clippedImage.BeginAnimation(Canvas.TopProperty, Animations[animationType.ToString()].Item2);
}
}), DispatcherPriority.Send);
});
}



/// <summary>
/// Reads the content of a stream into a string
/// </summary>
Expand Down
26 changes: 21 additions & 5 deletions ClippyVSPackage/ClippyVSPackage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.ComponentModelHost;
using EnvDTE;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
Expand Down Expand Up @@ -26,6 +27,7 @@ public sealed class ClippyVisualStudioPackage : AsyncPackage
public ClippyVisualStudioPackage()
{
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));

}

#region Package Members
Expand All @@ -36,21 +38,35 @@ public ClippyVisualStudioPackage()
/// </summary>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{

Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();

Application.Current.MainWindow.ContentRendered += MainWindow_ContentRendered;

await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
// Add our command handlers for menu (commands must exist in the .vsct file)
OleMenuCommandService mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
OleMenuCommandService mcs = await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(true) as OleMenuCommandService;
if (null != mcs)
{
// Create the command for the menu item.
CommandID menuCommandID = new CommandID(Constants.guidClippyVSCmdSet, (int)PkgCmdIDList.cmdShowClippy);
MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID);
mcs.AddCommand(menuItem);
}
await Command1.InitializeAsync(this);
await Command1.InitializeAsync(this).ConfigureAwait(true);
}

private void SolutionEvents_Opened()
{
var componentModel = (IComponentModel)(GetService(typeof(SComponentModel)));
IClippyVSSettings s = componentModel.DefaultExportProvider.GetExportedValue<IClippyVSSettings>();

SpriteContainer container = new SpriteContainer(this);

if (s.ShowAtStartup)
{
container.Show();
}
}

void MainWindow_ContentRendered(object sender, EventArgs e)
Expand Down
1 change: 1 addition & 0 deletions ClippyVSPackage/ClippyVSPackage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployExtension>False</DeployExtension>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
4 changes: 2 additions & 2 deletions ClippyVSPackage/ClippyVSSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Store()

writableSettingsStore.SetString(Constants.SettingsCollectionPath, nameof(ShowAtStartup), ShowAtStartup.ToString(CultureInfo.InvariantCulture));
}
catch (Exception ex)
catch (ArgumentException ex)
{
Debug.Fail(ex.Message);
}
Expand All @@ -87,7 +87,7 @@ private void LoadSettings()
this.ShowAtStartup = b;
}
}
catch (Exception ex)
catch (ArgumentException ex)
{
Debug.Fail(ex.Message);
}
Expand Down
4 changes: 2 additions & 2 deletions ClippyVSPackage/Configurations/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace Recoding.ClippyVSPackage.Configurations
/// <summary>
/// Represents a single animation, as it is directly mapped from the JSON
/// </summary>
public class Animation
public class ClippyAnimation
{
/// <summary>
/// Default ctor
/// </summary>
public Animation()
public ClippyAnimation()
{
Frames = new List<Frame>();
}
Expand Down
2 changes: 1 addition & 1 deletion ClippyVSPackage/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Eros Fratini
Eros Fratini / Denis Abt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion ClippyVSPackage/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ClippyVS")]
[assembly: AssemblyTitle("ClippyVS 2019")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Recoding")]
Expand Down
41 changes: 23 additions & 18 deletions ClippyVSPackage/SpriteContainer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -60,10 +61,13 @@ public SpriteContainer(AsyncPackage package)

InitializeComponent();

this.Owner = System.Windows.Application.Current.MainWindow;
this.Owner = Application.Current.MainWindow;
this.Topmost = false;

#region Register event handlers
if (package == null)
throw new ArgumentException("Package was null");

IVsActivityLog activityLog = package.GetServiceAsync(typeof(SVsActivityLog))
.ConfigureAwait(true).GetAwaiter().GetResult() as IVsActivityLog;
//if (activityLog == null) return;
Expand All @@ -74,7 +78,7 @@ public SpriteContainer(AsyncPackage package)
docEvents = dte.Events.DocumentEvents;
buildEvents = dte.Events.BuildEvents;

RegisterToDTEEvents();
_ = RegisterToDTEEventsAsync();

Owner.LocationChanged += Owner_LocationChanged;
Owner.StateChanged += Owner_StateOrSizeChanged;
Expand All @@ -100,9 +104,9 @@ public SpriteContainer(AsyncPackage package)
if (_userSettingsStore.PropertyExists(Constants.SettingsCollectionPath, nameof(RelativeLeft)))
storedRelativeLeft = Double.Parse(_userSettingsStore.GetString(Constants.SettingsCollectionPath, nameof(RelativeLeft)), CultureInfo.InvariantCulture);
}
catch
catch (Exception e)
{

Debug.Fail(e.Message);
}

if (!storedRelativeTop.HasValue || !storedRelativeLeft.HasValue)
Expand Down Expand Up @@ -160,20 +164,19 @@ public SpriteContainer(AsyncPackage package)
_clippy.StartAnimation(ClippyAnimations.Idle1_1);
}

private void RegisterToDTEEvents()
private async Task<bool> RegisterToDTEEventsAsync()
{
docEvents.DocumentOpening += DocumentEvents_DocumentOpening;
docEvents.DocumentSaved += DocumentEvents_DocumentSaved;
docEvents.DocumentClosing += DocEvents_DocumentClosing;

buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
buildEvents.OnBuildDone += BuildEvents_OnBuildDone;

ThreadHelper.ThrowIfNotOnUIThread();
DTE dte = _package.GetServiceAsync(typeof(DTE)).ConfigureAwait(true).GetAwaiter().GetResult() as EnvDTE.DTE;
if (findEvents != null)
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
DTE dte = await _package.GetServiceAsync(typeof(DTE)).ConfigureAwait(false) as DTE;
if (dte.Events.FindEvents != null)
{
findEvents.FindDone += FindEventsClass_FindDone;
dte.Events.FindEvents.FindDone += FindEventsClass_FindDone;
}

Events2 events2 = dte.Events as Events2;
Expand All @@ -192,6 +195,8 @@ private void RegisterToDTEEvents()
this.csharpProjectItemsEvents.ItemRemoved += ProjectItemsEvents_ItemRemoved;
this.csharpProjectItemsEvents.ItemRenamed += ProjectItemsEvents_ItemRenamed;
}

return true;
}

#region -- IDE Event Handlers --
Expand Down Expand Up @@ -303,13 +308,13 @@ private void cmdClose_Click(object sender, RoutedEventArgs e)
{
while (_clippy.IsAnimating) { }

Dispatcher.Invoke(new Action(() =>
{
window.Owner.Focus();
ThreadHelper.JoinableTaskFactory.Run(async delegate {
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

window.Owner.Focus();
window.Close();

}), DispatcherPriority.Send);
});

};
bgWorker.RunWorkerAsync();
Expand Down Expand Up @@ -371,9 +376,9 @@ private void SpriteContainer_LocationChanged(object sender, EventArgs e)
{
storeRelativeSpritePosition(relativeTop, relativeLeft);
}
catch
catch (Exception ex)
{

Debug.Fail(ex.Message);
}
}

Expand Down Expand Up @@ -434,9 +439,9 @@ private void storeRelativeSpritePosition(double relativeTop, double relativeLeft
_userSettingsStore.SetString(Constants.SettingsCollectionPath, nameof(RelativeTop), relativeTop.ToString(CultureInfo.InvariantCulture));
_userSettingsStore.SetString(Constants.SettingsCollectionPath, nameof(RelativeLeft), relativeLeft.ToString(CultureInfo.InvariantCulture));
}
catch
catch (ArgumentException ae)
{

Debug.Fail(ae.Message);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ClippyVSPackage/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ClippyVS - Changelog
--------------------

0.4 - Ported to VS 2019 and some code cleanup after migration
0.3 - Multimonitor support
0.2.2 - Fixed compatibility with Visual Studio 2015
0.2.1 - Removed the MPF dependency
Expand Down
50 changes: 25 additions & 25 deletions ClippyVSPackage/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="6aae52ac-8840-421f-bb35-60b52ab431e2" Version="0.3" Language="en-US" Publisher="Eros Fratini" />
<DisplayName>ClippyVS</DisplayName>
<Description xml:space="preserve">Clippy is back!</Description>
<License>LICENSE.txt</License>
<ReleaseNotes>changelog.txt</ReleaseNotes>
<Icon>Resources\Package.ico</Icon>
<PreviewImage>Resources\preview.png</PreviewImage>
<Tags>adornment, vintage, nostalgia</Tags>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Version="[14.0,17.0)" Id="Microsoft.VisualStudio.Community" />
<InstallationTarget Version="[14.0,17.0)" Id="Microsoft.VisualStudio.Enterprise" />
<InstallationTarget Version="[14.0,17.0)" Id="Microsoft.VisualStudio.Pro" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.Net.Component.4.5.TargetingPack" Version="[14.0.26208.0,)" DisplayName=".NET Framework 4.5 targeting pack" />
</Prerequisites>
<Metadata>
<Identity Id="6aae52ac-8840-421f-bb35-60b52ab431e2" Version="0.4" Language="en-US" Publisher="Denis Abt " />
<DisplayName>ClippyVS 2019</DisplayName>
<Description xml:space="preserve">Clippy is back! Now in VS 2019. Thanks Eros Fratini for getting Clippy alive and back, and for letting me port it to Visual Studio 2019.</Description>
<License>LICENSE.txt</License>
<ReleaseNotes>changelog.txt</ReleaseNotes>
<Icon>Resources\Package.ico</Icon>
<PreviewImage>Resources\preview.png</PreviewImage>
<Tags>adornment, vintage, nostalgia</Tags>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Version="[14.0,17.0)" Id="Microsoft.VisualStudio.Community" />
<InstallationTarget Version="[14.0,17.0)" Id="Microsoft.VisualStudio.Enterprise" />
<InstallationTarget Version="[14.0,17.0)" Id="Microsoft.VisualStudio.Pro" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.Net.Component.4.5.TargetingPack" Version="[14.0.26208.0,)" DisplayName=".NET Framework 4.5 targeting pack" />
</Prerequisites>
</PackageManifest>

0 comments on commit b11a605

Please sign in to comment.