Example #1
0
        /// <summary>
        /// Default ctor
        /// </summary>
        /// <param name="package"></param>
        public SpriteContainer(Package package)
        {
            _package = package;

            SettingsManager settingsManager = new ShellSettingsManager(_package);

            _userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

            InitializeComponent();

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

            #region Register event handlers

            dte         = (EnvDTE80.DTE2)Package.GetGlobalService(typeof(SDTE));
            events      = dte.Events;
            docEvents   = (EnvDTE.DocumentEventsClass)dte.Events.DocumentEvents;
            buildEvents = (EnvDTE.BuildEventsClass)dte.Events.BuildEvents;

            RegisterToDTEEvents();

            this.Owner.LocationChanged += Owner_LocationChanged;
            this.Owner.StateChanged    += Owner_StateOrSizeChanged;
            this.Owner.SizeChanged     += Owner_StateOrSizeChanged;

            this.LocationChanged += SpriteContainer_LocationChanged;

            #endregion

            #region -- Restore Sprite postion --

            double?storedRelativeTop  = null;
            double?storedRelativeLeft = null;

            double relativeTop  = 0;
            double relativeLeft = 0;

            try
            {
                if (_userSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "RelativeTop"))
                {
                    storedRelativeTop = Double.Parse(_userSettingsStore.GetString(Constants.SettingsCollectionPath, "RelativeTop"));
                }

                if (_userSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "RelativeLeft"))
                {
                    storedRelativeLeft = Double.Parse(_userSettingsStore.GetString(Constants.SettingsCollectionPath, "RelativeLeft"));
                }
            }
            catch
            {
            }

            if (!storedRelativeTop.HasValue || !storedRelativeLeft.HasValue)
            {
                recalculateSpritePosition(out relativeTop, out relativeLeft, true);
                storedRelativeTop  = relativeTop;
                storedRelativeLeft = relativeLeft;

                this.RelativeLeft = relativeLeft;
                this.RelativeTop  = relativeTop;

                storeRelativeSpritePosition(storedRelativeTop.Value, storedRelativeLeft.Value);
            }
            else
            {
                recalculateSpritePosition(out relativeTop, out relativeLeft);

                this.RelativeLeft = relativeLeft;
                this.RelativeTop  = relativeTop;
            }

            double ownerTop  = this.Owner.Top;
            double ownerLeft = this.Owner.Left;

            if (this.Owner.WindowState == WindowState.Maximized)
            {
                ownerTop  = 0;
                ownerLeft = 0;
            }

            this.Top  = ownerTop + storedRelativeTop.Value;
            this.Left = ownerLeft + storedRelativeLeft.Value;

            #endregion

            var values = Enum.GetValues(typeof(ClippyAnimations));

            //// TEMP: create a voice for each animation in the context menu
            //var pMenu = (ContextMenu)this.Resources["cmButton"];

            //foreach (ClippyAnimations val in values)
            //{
            //    var menuItem = new MenuItem()
            //    {
            //        Header = val.ToString(),
            //        Name = "cmd" + val.ToString()
            //    };
            //    menuItem.Click += cmdTestAnimation_Click;
            //    pMenu.Items.Add(menuItem);
            //}
            //// /TEMP

            _clippy = new Clippy((Canvas)this.FindName("ClippyCanvas"));

            _clippy.StartAnimation(ClippyAnimations.Idle1_1);
        }
        /// <summary>
        /// Default ctor
        /// </summary>
        /// <param name="package"></param>
        public SpriteContainer(AsyncPackage package)
        {
            _package = package;

            ThreadHelper.ThrowIfNotOnUIThread();
            var settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);

            _userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

            InitializeComponent();

            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;
            //System.Windows.Forms.MessageBox.Show("Found the activity log service.");
            ThreadHelper.ThrowIfNotOnUIThread();
            DTE dte = (DTE)package.GetServiceAsync(typeof(DTE)).ConfigureAwait(true).GetAwaiter().GetResult();
            events      = dte.Events;
            docEvents   = dte.Events.DocumentEvents;
            buildEvents = dte.Events.BuildEvents;

            RegisterToDTEEvents();

            Owner.LocationChanged += Owner_LocationChanged;
            Owner.StateChanged    += Owner_StateOrSizeChanged;
            Owner.SizeChanged     += Owner_StateOrSizeChanged;

            LocationChanged += SpriteContainer_LocationChanged;

            #endregion

            #region -- Restore Sprite postion --

            double?storedRelativeTop  = null;
            double?storedRelativeLeft = null;

            double relativeTop  = 0;
            double relativeLeft = 0;

            try
            {
                if (_userSettingsStore.PropertyExists(Constants.SettingsCollectionPath, nameof(RelativeTop)))
                {
                    storedRelativeTop = double.Parse(_userSettingsStore.GetString(Constants.SettingsCollectionPath, nameof(RelativeTop)), CultureInfo.InvariantCulture);
                }

                if (_userSettingsStore.PropertyExists(Constants.SettingsCollectionPath, nameof(RelativeLeft)))
                {
                    storedRelativeLeft = Double.Parse(_userSettingsStore.GetString(Constants.SettingsCollectionPath, nameof(RelativeLeft)), CultureInfo.InvariantCulture);
                }
            }
            catch (Exception e)
            {
                Debug.Fail(e.Message);
            }

            if (!storedRelativeTop.HasValue || !storedRelativeLeft.HasValue)
            {
                recalculateSpritePosition(out relativeTop, out relativeLeft, true);
                storedRelativeTop  = relativeTop;
                storedRelativeLeft = relativeLeft;

                this.RelativeLeft = relativeLeft;
                this.RelativeTop  = relativeTop;

                storeRelativeSpritePosition(storedRelativeTop.Value, storedRelativeLeft.Value);
            }
            else
            {
                recalculateSpritePosition(out relativeTop, out relativeLeft);

                this.RelativeLeft = relativeLeft;
                this.RelativeTop  = relativeTop;
            }

            double ownerTop  = this.Owner.Top;
            double ownerLeft = this.Owner.Left;

            if (this.Owner.WindowState == WindowState.Maximized)
            {
                ownerTop  = 0;
                ownerLeft = 0;
            }

            this.Top  = ownerTop + storedRelativeTop.Value;
            this.Left = ownerLeft + storedRelativeLeft.Value;

            #endregion

            var values = Enum.GetValues(typeof(ClippyAnimation));

            //// TEMP: create a voice for each animation in the context menu
            //var pMenu = (ContextMenu)this.Resources["cmButton"];

            //foreach (ClippySingleAnimation val in values)
            //{
            //    var menuItem = new MenuItem()
            //    {
            //        Header = val.ToString(),
            //        Name = "cmd" + val.ToString()
            //    };
            //    menuItem.Click += cmdTestAnimation_Click;
            //    pMenu.Items.Add(menuItem);
            //}
            //// /TEMP

            _clippy = new Clippy((Canvas)FindName("ClippyCanvas"));
            _clippy.StartAnimation(ClippyAnimation.Idle1_1);
        }