Skip to content

Commit

Permalink
Merge pull request #1 from denisabt/abde/vs_2019_update
Browse files Browse the repository at this point in the history
Abde/vs 2019 update - works on 2019 now
  • Loading branch information
denisabt authored May 12, 2021
2 parents b11a605 + 9bdc8c3 commit 2a544d2
Show file tree
Hide file tree
Showing 13 changed files with 573 additions and 622 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,4 @@ paket-files/
# JetBrains Rider
.idea/
*.sln.iml
/MigrationBackup/53daca6d/ClippyVSPackage
33 changes: 20 additions & 13 deletions ClippyVSPackage/Clippy.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Microsoft.VisualStudio.Shell;

using Microsoft.VisualStudio.Shell;
using Recoding.ClippyVSPackage.Configurations;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
Expand Down Expand Up @@ -75,7 +77,7 @@ public class Clippy
/// <summary>
/// All the animations that represents an Idle state
/// </summary>
private static List<ClippyAnimations> IdleAnimations = new List<ClippyAnimations>() {
public static List<ClippyAnimations> IdleAnimations = new List<ClippyAnimations>() {
ClippyAnimations.Idle1_1,
ClippyAnimations.IdleRopePile,
ClippyAnimations.IdleAtom,
Expand Down Expand Up @@ -204,26 +206,31 @@ void WPFAnimationsDispatcher_Tick(object sender, EventArgs e)
StartAnimation(IdleAnimations[random_int]);
}

public void StartAnimation(ClippyAnimations animations, bool byPassCurrentAnimation = false)
{
ThreadHelper.JoinableTaskFactory.Run(
async delegate {
await StartAnimationAsync(ClippyAnimations.Idle1_1,byPassCurrentAnimation);
});
}

/// <summary>
/// Start a specific animation
/// </summary>
/// <param name="animationType"></param>
public void StartAnimation(ClippyAnimations animationType, bool byPassCurrentAnimation = false)
public async System.Threading.Tasks.Task StartAnimationAsync(ClippyAnimations animationType, bool byPassCurrentAnimation = false)
{
Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.Run(async delegate
if (!IsAnimating || byPassCurrentAnimation)
{
IsAnimating = true;
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);
}
});
clippedImage.BeginAnimation(Canvas.LeftProperty, Animations[animationType.ToString()].Item1);
clippedImage.BeginAnimation(Canvas.TopProperty, Animations[animationType.ToString()].Item2);
}

}



/// <summary>
/// Reads the content of a stream into a string
Expand Down
71 changes: 38 additions & 33 deletions ClippyVSPackage/ClippyVSPackage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using EnvDTE;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Settings;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell.Settings;
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
Expand All @@ -15,8 +15,14 @@
namespace Recoding.ClippyVSPackage
{
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#110", "#112", "0.3", IconResourceID = 400)]
[InstalledProductRegistration("#110", "#112", "0.4", IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideService(typeof(OleMenuCommandService))]
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasSingleProject_string, PackageAutoLoadFlags.BackgroundLoad)]

[Guid(Constants.guidClippyVSPkgString)]
[ProvideOptionPageAttribute(typeof(OptionsPage), "Clippy VS", "General", 0, 0, supportsAutomation: true)]
public sealed class ClippyVisualStudioPackage : AsyncPackage
Expand All @@ -38,48 +44,47 @@ 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();

await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

// Add our command handlers for menu (commands must exist in the .vsct file)
OleMenuCommandService mcs = await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(true) as OleMenuCommandService;
if (null != mcs)
try
{
// 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).ConfigureAwait(true);
}
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();

private void SolutionEvents_Opened()
{
var componentModel = (IComponentModel)(GetService(typeof(SComponentModel)));
IClippyVSSettings s = componentModel.DefaultExportProvider.GetExportedValue<IClippyVSSettings>();
OleMenuCommandService mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

SpriteContainer container = new SpriteContainer(this);
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(this.DisposalToken);
Application.Current.MainWindow.ContentRendered += MainWindow_ContentRendered;

// Add our command handlers for menu (commands must exist in the .vsct file)

if (s.ShowAtStartup)
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);
}
catch (Exception e)
{
container.Show();
MessageBox.Show("Exception !");
}
await Recoding.ClippyVSPackage.Command1.InitializeAsync(this);
}

void MainWindow_ContentRendered(object sender, EventArgs e)
async void MainWindow_ContentRendered(object sender, EventArgs e)
{
var componentModel = (IComponentModel)(GetService(typeof(SComponentModel)));
IClippyVSSettings s = componentModel.DefaultExportProvider.GetExportedValue<IClippyVSSettings>();
var token = new CancellationToken();
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(token);
var shellSettingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
var writableSettingsStore = shellSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

IClippyVSSettings settings = new ClippyVSSettings(writableSettingsStore);
SpriteContainer container = new SpriteContainer(this);

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

}

#endregion
Expand Down
Loading

0 comments on commit 2a544d2

Please sign in to comment.