<commit_before>﻿namespace ResXManager.VSIX
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Threading;
    using System.Windows;
    using System.Windows.Threading;

    using Microsoft.VisualStudio;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Shell.Interop;

    using Ninject;

    using ResXManager.Infrastructure;
    using ResXManager.Model;
    using ResXManager.View.Tools;
    using ResXManager.View.Visuals;
    using ResXManager.VSIX.Visuals;

    using Throttle;

    using TomsToolbox.Composition;
    using TomsToolbox.Composition.Ninject;
    using TomsToolbox.Essentials;
    using TomsToolbox.Wpf;

    /// <summary>
    /// This is the class that implements the package exposed by this assembly.
    /// </summary>
    // This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is a package.
    [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Package already handles this.")]
    [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
    // This attribute is used to register the informations needed to show the this package in the Help/About dialog of Visual Studio.
    [InstalledProductRegistration(@"#110", @"#112", Product.Version, IconResourceID = 400)]
    // This attribute is needed to let the shell know that this package exposes some menus.
    [ProvideMenuResource(@"Menus.ctmenu", 1)]
    // This attribute registers a tool window exposed by this package.
    [ProvideToolWindow(typeof(MyToolWindow))]
    [Guid(GuidList.guidResXManager_VSIXPkgString)]
    [ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
    [ProvideAutoLoad(UIContextGuids.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
    public sealed class VsPackage : AsyncPackage
    {
        private readonly CustomToolRunner _customToolRunner = new CustomToolRunner();
        private readonly IKernel _kernel = new StandardKernel();

        private EnvDTE.SolutionEvents? _solutionEvents;
        private EnvDTE.DocumentEvents? _documentEvents;
        private EnvDTE.ProjectItemsEvents? _projectItemsEvents;
        private EnvDTE.ProjectItemsEvents? _solutionItemsEvents;
        private EnvDTE.ProjectItemsEvents? _miscFilesEvents;
        private EnvDTE.ProjectsEvents? _projectsEvents;
        private PerformanceTracer? _performanceTracer;

        private static VsPackage? _instance;

        public VsPackage()
        {
            _instance = this;
            Tracer = new OutputWindowTracer(this);

            _kernel.Bind<ITracer>().ToConstant(Tracer);
            _kernel.Bind<IServiceProvider>().ToConstant(this).Named(nameof(VsPackage));
            ExportProvider = new ExportProvider(_kernel);
        }

        public static VsPackage Instance
        {
            get
            {
                if (_instance == null)
                    throw new InvalidOperationException("Package is the entry point and is the first class to be created.");

                return _instance;
            }
        }

        public IExportProvider ExportProvider { get; }

        private ITracer Tracer { get; }

        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(false);

            var loaderMessages = await System.Threading.Tasks.Task.Run(FillCatalog, cancellationToken).ConfigureAwait(false);

            _performanceTracer = ExportProvider.GetExportedValue<PerformanceTracer>();

            var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(false);

            await JoinableTaskFactory.SwitchToMainThreadAsync();

            ShowLoaderMessages(loaderMessages);

            ErrorProvider.Register(ExportProvider);

            ConnectEvents();

            // start background services
            ExportProvider
                .GetExportedValues<IService>()
                .ForEach(service => service.Start());

            // Add our command handlers for menu (commands must exist in the .vsct file)
            if (!(menuCommandService is IMenuCommandService mcs))
                return;

            // Create the command for the menu item.
            CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyCommand, ShowToolWindow);
            // Create the command for the tool window
            CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTool, ShowToolWindow);
            // Create the command for the solution explorer context menu
            CreateMenuCommand(mcs, PkgCmdIdList.cmdidMySolutionExplorerContextMenu, ShowSelectedResourceFiles).BeforeQueryStatus += SolutionExplorerContextMenuCommand_BeforeQueryStatus;
            // Create the command for the text editor context menu
            CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTextEditorContextMenu, MoveToResource).BeforeQueryStatus += TextEditorContextMenuCommand_BeforeQueryStatus;
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            _customToolRunner.Dispose();
            _kernel.Dispose();<commit_msg>Fix #367: Update of grid after editing in the top-right text box is broken<commit_after>﻿namespace ResXManager.VSIX
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Threading;

    using Microsoft.VisualStudio;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Shell.Interop;

    using Ninject;

    using ResXManager.Infrastructure;
    using ResXManager.Model;
    using ResXManager.View.Tools;
    using ResXManager.View.Visuals;
    using ResXManager.VSIX.Visuals;

    using Throttle;

    using TomsToolbox.Composition;
    using TomsToolbox.Composition.Ninject;
    using TomsToolbox.Essentials;
    using TomsToolbox.Wpf;

    /// <summary>
    /// This is the class that implements the package exposed by this assembly.
    /// </summary>
    // This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is a package.
    [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Package already handles this.")]
    [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
    // This attribute is used to register the informations needed to show the this package in the Help/About dialog of Visual Studio.
    [InstalledProductRegistration(@"#110", @"#112", Product.Version, IconResourceID = 400)]
    // This attribute is needed to let the shell know that this package exposes some menus.
    [ProvideMenuResource(@"Menus.ctmenu", 1)]
    // This attribute registers a tool window exposed by this package.
    [ProvideToolWindow(typeof(MyToolWindow))]
    [Guid(GuidList.guidResXManager_VSIXPkgString)]
    [ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
    [ProvideAutoLoad(UIContextGuids.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
    public sealed class VsPackage : AsyncPackage
    {
        private readonly CustomToolRunner _customToolRunner = new CustomToolRunner();
        private readonly IKernel _kernel = new StandardKernel();

        private EnvDTE.SolutionEvents? _solutionEvents;
        private EnvDTE.DocumentEvents? _documentEvents;
        private EnvDTE.ProjectItemsEvents? _projectItemsEvents;
        private EnvDTE.ProjectItemsEvents? _solutionItemsEvents;
        private EnvDTE.ProjectItemsEvents? _miscFilesEvents;
        private EnvDTE.ProjectsEvents? _projectsEvents;
        private PerformanceTracer? _performanceTracer;

        private static VsPackage? _instance;

        public VsPackage()
        {
            _instance = this;
            Tracer = new OutputWindowTracer(this);

            _kernel.Bind<ITracer>().ToConstant(Tracer);
            _kernel.Bind<IServiceProvider>().ToConstant(this).Named(nameof(VsPackage));
            ExportProvider = new ExportProvider(_kernel);
        }

        public static VsPackage Instance
        {
            get
            {
                if (_instance == null)
                    throw new InvalidOperationException("Package is the entry point and is the first class to be created.");

                return _instance;
            }
        }

        public IExportProvider ExportProvider { get; }

        private ITracer Tracer { get; }

        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(false);

            var loaderMessages = await System.Threading.Tasks.Task.Run(FillCatalog, cancellationToken).ConfigureAwait(false);

            _performanceTracer = ExportProvider.GetExportedValue<PerformanceTracer>();

            var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(false);

            await JoinableTaskFactory.SwitchToMainThreadAsync();

            SynchronizationContextThrottle.TaskFactory = new TaskFactory(TaskScheduler.FromCurrentSynchronizationContext());

            ShowLoaderMessages(loaderMessages);

            ErrorProvider.Register(ExportProvider);

            ConnectEvents();

            // start background services
            ExportProvider
                .GetExportedValues<IService>()
                .ForEach(service => service.Start());

            // Add our command handlers for menu (commands must exist in the .vsct file)
            if (!(menuCommandService is IMenuCommandService mcs))
                return;

            // Create the command for the menu item.
            CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyCommand, ShowToolWindow);
            // Create the command for the tool window
            CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTool, ShowToolWindow);
            // Create the command for the solution explorer context menu
            CreateMenuCommand(mcs, PkgCmdIdList.cmdidMySolutionExplorerContextMenu, ShowSelectedResourceFiles).BeforeQueryStatus += SolutionExplorerContextMenuCommand_BeforeQueryStatus;
            // Create the command for the text editor context menu
            CreateMenuCommand(mcs, PkgCmdIdList.cmdidMyTextEditorContextMenu, MoveToResource).BeforeQueryStatus += TextEditorContextMenuCommand_BeforeQueryStatus;
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            _customToolRunner.Dispose();
            _kernel.Dispose();
{'fraction_non_alphanumeric': 0.07243325191611219, 'fraction_numerical': 0.0026109660574412533, 'mean_word_length': 3.0278154681139755, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4918214', 'n_tokens_mistral': 3020, 'n_tokens_neox': 2900, 'n_words': 781}