<commit_before>﻿using GitHub.Settings;
using GitHub.VisualStudio.UI;
using Microsoft.VisualStudio.Shell;
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows;

namespace GitHub.VisualStudio
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComVisible(true)]
    [Guid("68C87C7B-0212-4256-BB6D-6A6BB847A3A7")]
    public class OptionsPage : UIElementDialogPage
    {
        OptionsControl child;
        IPackageSettings packageSettings;

        protected override UIElement Child
        {
            get { return child ?? (child = new OptionsControl()); }
        }

        protected override void OnActivate(CancelEventArgs e)
        {
            base.OnActivate(e);
            packageSettings = Services.DefaultExportProvider.GetExportedValue<IPackageSettings>();
            LoadSettings();
        }

        void LoadSettings()
        {
            child.CollectMetrics = packageSettings.CollectMetrics;
            child.EditorComments = packageSettings.EditorComments;
            child.EnableTraceLogging = packageSettings.EnableTraceLogging;
        }

        void SaveSettings()
        {
            packageSettings.CollectMetrics = child.CollectMetrics;
            packageSettings.EditorComments = child.EditorComments;
            packageSettings.EnableTraceLogging = child.EnableTraceLogging;
            packageSettings.Save();
        }

        protected override void OnApply(PageApplyEventArgs args)
        {
            if (args.ApplyBehavior == ApplyKind.Apply)
            {
                SaveSettings();
            }

            base.OnApply(args);
        }
    }
}<commit_msg>Disable options when not executing in VS<commit_after>﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Runtime.InteropServices;
using GitHub.Exports;
using GitHub.Logging;
using GitHub.Settings;
using GitHub.VisualStudio.UI;
using Microsoft.VisualStudio.Shell;
using Serilog;

namespace GitHub.VisualStudio
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ComVisible(true)]
    [Guid("68C87C7B-0212-4256-BB6D-6A6BB847A3A7")]
    public class OptionsPage : UIElementDialogPage
    {
        static readonly ILogger log = LogManager.ForContext<OptionsPage>();

        OptionsControl child;
        IPackageSettings packageSettings;

        protected override UIElement Child
        {
            get
            {
                if (!ExportForVisualStudioProcessAttribute.IsVisualStudioProcess())
                {
                    return new Grid(); // Show blank page
                }

                return child ?? (child = new OptionsControl());
            }
        }

        protected override void OnActivate(CancelEventArgs e)
        {
            if (!ExportForVisualStudioProcessAttribute.IsVisualStudioProcess())
            {
                log.Warning("Don't activate options for non-Visual Studio process");
                return;
            }

            base.OnActivate(e);
            packageSettings = Services.DefaultExportProvider.GetExportedValue<IPackageSettings>();
            LoadSettings();
        }

        void LoadSettings()
        {
            child.CollectMetrics = packageSettings.CollectMetrics;
            child.EditorComments = packageSettings.EditorComments;
            child.EnableTraceLogging = packageSettings.EnableTraceLogging;
        }

        void SaveSettings()
        {
            packageSettings.CollectMetrics = child.CollectMetrics;
            packageSettings.EditorComments = child.EditorComments;
            packageSettings.EnableTraceLogging = child.EnableTraceLogging;
            packageSettings.Save();
        }

        protected override void OnApply(PageApplyEventArgs args)
        {
            if (!ExportForVisualStudioProcessAttribute.IsVisualStudioProcess())
            {
                log.Warning("Don't apply options for non-Visual Studio process");
                return;
            }

            if (args.ApplyBehavior == ApplyKind.Apply)
            {
                SaveSettings();
            }

            base.OnApply(args);
        }
    }
}
{'fraction_non_alphanumeric': 0.07824427480916031, 'fraction_numerical': 0.010019083969465648, 'mean_word_length': 2.1717095310136156, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '5317738', 'n_tokens_mistral': 1065, 'n_tokens_neox': 989, 'n_words': 193}