protected override void Initialize()
        {
            Application.Current.MainWindow.Loaded += (s, e) =>
            {
                _mainWindow = (System.Windows.Window)s;
                _settings   = Setting.Initialize(this);
                _settings.OnChanged.AddEventHandler(ReloadSettings);
                if (ProvidersHolder.Instance.Providers == null)
                {
                    ProvidersHolder.Initialize(_settings, new List <IImageProvider>
                    {
                        new SildeShowImageProvider(_settings),
                        new SingleImageProvider(_settings),
                        new GifProvider(_settings)
                    });
                }
                _imageProviders = ProvidersHolder.Instance.Providers;
                _imageProvider  = _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType);
                _imageProviders.ForEach(x => x.NewImageAvaliable += InvokeChangeImage);

                ReloadSettings(null, null);
            };
            Application.Current.MainWindow.Closing += (s, e) =>
            {
                _imageProviders.ForEach(x => x.NewImageAvaliable -= InvokeChangeImage);
                if (_settings != null)
                {
                    _settings.OnChanged.RemoveEventHandler(ReloadSettings);
                }
            };

            base.Initialize();
        }
        /// <summary>
        /// Instantiates a ClaudiaIDE manager when a textView is created.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> upon which the adornment should be placed</param>
        public void TextViewCreated(IWpfTextView textView)
        {
            var settings = Setting.Initialize(ServiceProvider);

            if (ImageProviders == null)
            {
                if (ProvidersHolder.Instance.Providers == null)
                {
                    ProvidersHolder.Initialize(settings, new List <IImageProvider>
                    {
                        new SildeShowImageProvider(settings),
                        new SingleImageProvider(settings)
                    });
                }
                ImageProviders = ProvidersHolder.Instance.Providers;
            }

            new ClaudiaIDE(textView, ImageProviders);
        }
Beispiel #3
0
        /// <summary>
        /// Instantiates a ClaudiaIDE manager when a textView is created.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> upon which the adornment should be placed</param>
        public void TextViewCreated(IWpfTextView textView)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var settings = Setting.Initialize((EnvDTE.DTE)ServiceProvider.GetService(typeof(EnvDTE.DTE)));
            var solution = VisualStudioUtility.GetSolutionSettingsFileFullPath();

            if (ImageProviders == null)
            {
                if (ProvidersHolder.Instance.Providers == null)
                {
                    if (string.IsNullOrEmpty(solution))
                    {
                        ProvidersHolder.Initialize(settings, new List <IImageProvider>
                        {
                            new SingleImageEachProvider(settings),
                            new SlideShowImageProvider(settings),
                            new SingleImageProvider(settings)
                        });
                    }
                    else
                    {
                        ProvidersHolder.Initialize(settings, new List <IImageProvider>());
                        switch (settings.ImageBackgroundType)
                        {
                        case ImageBackgroundType.Single:
                            ProvidersHolder.Instance.Providers.Add(new SingleImageProvider(settings, solution));
                            break;

                        case ImageBackgroundType.SingleEach:
                            ProvidersHolder.Instance.Providers.Add(new SingleImageEachProvider(settings, solution));
                            break;

                        case ImageBackgroundType.Slideshow:
                            ProvidersHolder.Instance.Providers.Add(new SlideShowImageProvider(settings, solution));
                            break;

                        default:
                            ProvidersHolder.Instance.Providers.Add(new SingleImageEachProvider(settings, solution));
                            break;
                        }
                    }
                }
                ImageProviders = ProvidersHolder.Instance.Providers;
            }

            if (!string.IsNullOrEmpty(solution))
            {
                if (!ImageProviders.Any(x => x.SolutionConfigFile == solution))
                {
                    switch (settings.ImageBackgroundType)
                    {
                    case ImageBackgroundType.Single:
                        ImageProviders.Add(new SingleImageProvider(settings, solution));
                        break;

                    case ImageBackgroundType.SingleEach:
                        ImageProviders.Add(new SingleImageEachProvider(settings, solution));
                        break;

                    case ImageBackgroundType.Slideshow:
                        ImageProviders.Add(new SlideShowImageProvider(settings, solution));
                        break;

                    default:
                        ImageProviders.Add(new SingleImageEachProvider(settings, solution));
                        break;
                    }
                }
            }

            new ClaudiaIDE(textView, ImageProviders);
        }
        protected override async Task InitializeAsync(System.Threading.CancellationToken cancellationToken,
                                                      IProgress <ServiceProgressData> progress)
        {
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            Application.Current.MainWindow.Loaded += (s, e) =>
            {
                _mainWindow = (System.Windows.Window)s;
                _settings   = Setting.Initialize(this);
                _settings.OnChanged.AddEventHandler(ReloadSettings);
                if (ProvidersHolder.Instance.Providers == null)
                {
                    ProvidersHolder.Initialize(_settings, new List <IImageProvider>
                    {
                        new SingleImageEachProvider(_settings),
                        new SlideShowImageProvider(_settings),
                        new SingleImageProvider(_settings)
                    });
                }

                _imageProviders = ProvidersHolder.Instance.Providers;
                _imageProvider  = _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType);
                _imageProviders.ForEach(x => x.NewImageAvaliable += InvokeChangeImage);

                NextImage.InitializeAsync(this, _settings)
                .FileAndForget("claudiaide/nextimage/initializeasync");
                PauseSlideshow.InitializeAsync(this, _settings).FileAndForget("claudiaide/pauseslideshow/initializeasync");
                ReloadSettings(null, null);
            };
            Application.Current.MainWindow.Closing += (s, e) =>
            {
                _imageProviders.ForEach(x => x.NewImageAvaliable -= InvokeChangeImage);
                if (_settings != null)
                {
                    _settings.OnChanged.RemoveEventHandler(ReloadSettings);
                }
            };
            Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
            {
                try
                {
                    await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
                    _settings = await Setting.InitializeAsync(this);
                    if (_settings == null)
                    {
                        return;
                    }
                    _mainWindow = (System.Windows.Window)Application.Current.MainWindow;
                    _settings.OnChanged.AddEventHandler(ReloadSettings);
                    if (ProvidersHolder.Instance.Providers == null)
                    {
                        ProvidersHolder.Initialize(_settings, new List <IImageProvider>
                        {
                            new SingleImageEachProvider(_settings),
                            new SlideShowImageProvider(_settings),
                            new SingleImageProvider(_settings)
                        });
                    }

                    _imageProviders = ProvidersHolder.Instance.Providers;
                    _imageProvider  =
                        _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType);
                    _imageProviders.ForEach(x => x.NewImageAvaliable += InvokeChangeImage);

                    await NextImage.InitializeAsync(this, _settings);
                    await PauseSlideshow.InitializeAsync(this, _settings);
                    ReloadSettings(null, null);
                }
                catch { }
            }).FileAndForget("claudiaide/initializeasync");
        }
Beispiel #5
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken,
                                                      IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            Application.Current.MainWindow.Loaded += (s, e) =>
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                _mainWindow = (Window)s;
                _settings   = Setting.Initialize((DTE)GetService(typeof(DTE)));
                _settings.OnChanged.AddEventHandler(ReloadSettings);
                if (ProvidersHolder.Instance.Providers == null)
                {
                    ProvidersHolder.Initialize(_settings, new List <ImageProvider>
                    {
                        new SingleImageEachProvider(_settings),
                        new SlideShowImageProvider(_settings),
                        new SingleImageProvider(_settings),
                        new SingleImageWebProvider(_settings),
                        new WebApiImageProvider(_settings)
                    });
                }

                _imageProviders         = ProvidersHolder.Instance.Providers;
                _imageProvider          = _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType);
                _imageProvider.IsActive = true;
                _imageProviders.ForEach(x => x.NewImageAvailable += InvokeChangeImage);

                NextImage.InitializeAsync(this)
                .FileAndForget("claudiaide/nextimage/initializeasync");
                PauseSlideshow.InitializeAsync(this).FileAndForget("claudiaide/pauseslideshow/initializeasync");
                SaveSolutionSettings.InitializeAsync(this, _settings)
                .FileAndForget("claudiaide/saveSolutionSettings/initializeasync");
                ;
                ReloadSettings(null, null);
            };
            Application.Current.MainWindow.Closing += (s, e) =>
            {
                _imageProviders.ForEach(x => x.NewImageAvailable -= InvokeChangeImage);
                if (_settings != null)
                {
                    _settings.OnChanged.RemoveEventHandler(ReloadSettings);
                }
            };
            ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
            {
                try
                {
                    await JoinableTaskFactory.SwitchToMainThreadAsync(true, cancellationToken);
                    _settings = Setting.Initialize((DTE)await GetServiceAsync(typeof(DTE)));
                    if (_settings == null)
                    {
                        return;
                    }
                    _mainWindow = Application.Current.MainWindow;
                    _settings.OnChanged.AddEventHandler(ReloadSettings);
                    if (ProvidersHolder.Instance.Providers == null)
                    {
                        ProvidersHolder.Initialize(_settings, new List <ImageProvider>
                        {
                            new SingleImageEachProvider(_settings),
                            new SlideShowImageProvider(_settings),
                            new SingleImageProvider(_settings),
                            new SingleImageWebProvider(_settings),
                            new WebApiImageProvider(_settings)
                        });
                    }

                    _imageProviders = ProvidersHolder.Instance.Providers;
                    _imageProvider  =
                        _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType);
                    _imageProvider.IsActive = true;
                    _imageProviders.ForEach(x => x.NewImageAvailable += InvokeChangeImage);

                    await NextImage.InitializeAsync(this);
                    await PauseSlideshow.InitializeAsync(this);
                    await SaveSolutionSettings.InitializeAsync(this, _settings);
                    ReloadSettings(null, null);
                }
                catch
                {
                }
            }).FileAndForget("claudiaide/initializeasync");
        }