Beispiel #1
0
 public FindReplaceDialog(FindReplaceSettings findReplaceSettings)
 {
     InitializeComponent();
     DataContext = findReplaceSettings;
     Closed     += (s, e) => findReplaceSettings.Save();
     Closing    += (s, e) => { e.Cancel = true; Hide(); };
 }
 public FindReplaceDialog(FindReplaceSettings findReplaceSettings)
 {
     InitializeComponent();
     DataContext = findReplaceSettings;
     Closed += (s, e) => findReplaceSettings.Save();
     Closing += (s, e) => { e.Cancel = true; Hide(); };
 }
Beispiel #3
0
        public FindReplaceViewModel(FindReplaceSettings findReplaceSettings, IFindReplaceService findReplaceService)
        {
            Argument.IsNotNull(() => findReplaceSettings);
            Argument.IsNotNull(() => findReplaceService);

            _findReplaceService = findReplaceService;

            FindNext   = new Command <string>(OnFindNext);
            Replace    = new Command <object>(OnReplace);
            ReplaceAll = new Command <object>(OnReplaceAll);

            FindReplaceSettings = findReplaceSettings;

            var initialText = _findReplaceService.GetInitialFindText();

            TextToFind           = initialText;
            TextToFindForReplace = initialText;
        }
Beispiel #4
0
        public static Regex GetRegEx(this FindReplaceSettings settings, string textToFind, bool isLeftToRight = false)
        {
            Argument.IsNotNull(() => textToFind);
            Argument.IsNotNull(() => settings);

            var options = RegexOptions.None;

            if (settings.IsSearchUp && !isLeftToRight)
            {
                options |= RegexOptions.RightToLeft;
            }

            if (!settings.CaseSensitive)
            {
                options |= RegexOptions.IgnoreCase;
            }

            if (settings.UseRegex)
            {
                return(new Regex(textToFind, options));
            }

            var pattern = Regex.Escape(textToFind);

            if (settings.UseWildcards)
            {
                pattern = pattern.Replace("\\*", ".*").Replace("\\?", ".");
            }

            if (settings.WholeWord)
            {
                pattern = "\\b" + pattern + "\\b";
            }

            return(new Regex(pattern, options));
        }