<commit_before>﻿/*
 @ <NAME>
*/

using System.Windows;
using System.Windows.Controls;

namespace EasyKeeper {
    public class WaterMarkText : DependencyObject {
        public static readonly DependencyProperty IsMonitoringProperty =
            DependencyProperty.RegisterAttached("IsMonitoring",
                                                typeof(bool),
                                                typeof(WaterMarkText),
                                                new UIPropertyMetadata(false, IsMonitoringChanged));

        public static bool GetIsMonitoring(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsMonitoringProperty);
        }

        public static void SetIsMonitoring(DependencyObject obj, bool value)
        {
            obj.SetValue(IsMonitoringProperty, value);
        }

        public static readonly DependencyProperty TextLengthProperty =
            DependencyProperty.RegisterAttached("TextLength",
                                                typeof(int),
                                                typeof(WaterMarkText),
                                                new UIPropertyMetadata(0, TextLengthChanged));

        public static int GetTextLength(DependencyObject obj)
        {
            return (int)obj.GetValue(TextLengthProperty);
        }

        public static void SetTextLength(DependencyObject obj, int value)
        {
            obj.SetValue(TextLengthProperty, value);
        }

        public static readonly DependencyProperty HasTextProperty =
            DependencyProperty.RegisterAttached("HasText",
                                                typeof(bool),
                                                typeof(WaterMarkText),
                                                new UIPropertyMetadata(false));

        public static bool GetHasText(DependencyObject obj)
        {
            return (bool)obj.GetValue(HasTextProperty);
        }

        public static void SetHasText(DependencyObject obj, bool value)
        {
            obj.SetValue(HasTextProperty, value);
        }

        public static readonly DependencyProperty TextProperty =
            DependencyProperty.RegisterAttached("Text",
                                                typeof(string),
                                                typeof(WaterMarkText),
                                                new UIPropertyMetadata(string.Empty));

        public static string GetText(DependencyObject obj)
        {
            return (string)obj.GetValue(TextProperty);
        }

        public static void SetText(DependencyObject obj, string value)
        {
            obj.SetValue(TextProperty, value);
        }

        private static void IsMonitoringChanged(DependencyObject obj,
                                                DependencyPropertyChangedEventArgs args)
        {
            var passwordBox = obj as PasswordBox;
            if (passwordBox != null) {
                if ((bool)args.NewValue) {
                    passwordBox.PasswordChanged += PasswordChanged;
                } else {
                    passwordBox.PasswordChanged -= PasswordChanged;
                }
            }
        }

        private static void TextLengthChanged(DependencyObject obj,
                                              DependencyPropertyChangedEventArgs args)
        {
            var hasText = (int)args.NewValue > 0;
            SetHasText(obj, hasText);
        }

        private static void PasswordChanged(object sender, RoutedEventArgs args)
        {
            PasswordBox passwordBox = sender as PasswordBox;
            if (passwordBox != null) {
                SetTextLength(passwordBox, passwordBox.Password.Length);
            }
        }
    }
}<commit_msg>Add class documentation. also use `var` for one  variable declaration.<commit_after>﻿/*
 @ <NAME>
*/

using System.Windows;
using System.Windows.Controls;

namespace EasyKeeper {
    // This class adds watermark text in PasswordBox controls.
    // However, it is literally plausible to use this class for normal TextBox controls,
    // though there might be another more simpler approach.
    public class WaterMarkText : DependencyObject {
        public static readonly DependencyProperty IsMonitoringProperty =
            DependencyProperty.RegisterAttached("IsMonitoring",
                                                typeof(bool),
                                                typeof(WaterMarkText),
                                                new UIPropertyMetadata(false, IsMonitoringChanged));

        public static bool GetIsMonitoring(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsMonitoringProperty);
        }

        public static void SetIsMonitoring(DependencyObject obj, bool value)
        {
            obj.SetValue(IsMonitoringProperty, value);
        }

        public static readonly DependencyProperty TextLengthProperty =
            DependencyProperty.RegisterAttached("TextLength",
                                                typeof(int),
                                                typeof(WaterMarkText),
                                                new UIPropertyMetadata(0, TextLengthChanged));

        public static int GetTextLength(DependencyObject obj)
        {
            return (int)obj.GetValue(TextLengthProperty);
        }

        public static void SetTextLength(DependencyObject obj, int value)
        {
            obj.SetValue(TextLengthProperty, value);
        }

        public static readonly DependencyProperty HasTextProperty =
            DependencyProperty.RegisterAttached("HasText",
                                                typeof(bool),
                                                typeof(WaterMarkText),
                                                new UIPropertyMetadata(false));

        public static bool GetHasText(DependencyObject obj)
        {
            return (bool)obj.GetValue(HasTextProperty);
        }

        public static void SetHasText(DependencyObject obj, bool value)
        {
            obj.SetValue(HasTextProperty, value);
        }

        public static readonly DependencyProperty TextProperty =
            DependencyProperty.RegisterAttached("Text",
                                                typeof(string),
                                                typeof(WaterMarkText),
                                                new UIPropertyMetadata(string.Empty));

        public static string GetText(DependencyObject obj)
        {
            return (string)obj.GetValue(TextProperty);
        }

        public static void SetText(DependencyObject obj, string value)
        {
            obj.SetValue(TextProperty, value);
        }

        private static void IsMonitoringChanged(DependencyObject obj,
                                                DependencyPropertyChangedEventArgs args)
        {
            var passwordBox = obj as PasswordBox;
            if (passwordBox != null) {
                if ((bool)args.NewValue) {
                    passwordBox.PasswordChanged += PasswordChanged;
                } else {
                    passwordBox.PasswordChanged -= PasswordChanged;
                }
            }
        }

        private static void TextLengthChanged(DependencyObject obj,
                                              DependencyPropertyChangedEventArgs args)
        {
            var hasText = (int)args.NewValue > 0;
            SetHasText(obj, hasText);
        }

        private static void PasswordChanged(object sender, RoutedEventArgs args)
        {
            var passwordBox = sender as PasswordBox;
            if (passwordBox != null) {
                SetTextLength(passwordBox, passwordBox.Password.Length);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06082198753022013, 'fraction_numerical': 0.0005089706069474488, 'mean_word_length': 1.440235951567836, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5168585', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1516, 'n_words': 378}