コード例 #1
0
        public void Reload()
        {
            MatchCase            = _settings.GetBool(SettingsSection.FindAndReplace, "MatchCase", false);
            MatchWholeWord       = _settings.GetBool(SettingsSection.FindAndReplace, "MatchWholeWord", false);
            SearchBackwards      = _settings.GetBool(SettingsSection.FindAndReplace, "SearchBackwards", false);
            SearchFromBegining   = _settings.GetBool(SettingsSection.FindAndReplace, "SearchFromBegining", false);
            UseRegularExpression = _settings.GetBool(SettingsSection.FindAndReplace, "UseRegularExpression", false);
            var searchIn = _settings.Get(SettingsSection.FindAndReplace, "SearchIn", null);

            SearchIn = EnumUtils.ParseEnum(searchIn, true, SearchInOptions.CurrentDocument);

            var findHistoryString = _settings.Get(SettingsSection.FindAndReplace, "FindHistory", null);

            FindHistory = DeserialiseList(findHistoryString);
            var replaceHistoryString = _settings.Get(SettingsSection.FindAndReplace, "ReplaceHistory", null);

            ReplaceHistory = DeserialiseList(replaceHistoryString);

            var windowSizeString = _settings.Get(SettingsSection.FindAndReplace, "WindowSize", null);

            WindowSize = DeserialiseSize(windowSizeString);
            var windowLocationString = _settings.Get(SettingsSection.FindAndReplace, "WindowLocation", null);

            WindowLocation = DeserialisePoint(windowLocationString);
        }
コード例 #2
0
        public void Reload()
        {
            MatchCase = _settings.GetBool(SettingsSection.FindAndReplace, "MatchCase", false);
            MatchWholeWord = _settings.GetBool(SettingsSection.FindAndReplace, "MatchWholeWord", false);
            SearchBackwards = _settings.GetBool(SettingsSection.FindAndReplace, "SearchBackwards", false);
            SearchFromBegining = _settings.GetBool(SettingsSection.FindAndReplace, "SearchFromBegining", false);
            UseRegularExpression = _settings.GetBool(SettingsSection.FindAndReplace, "UseRegularExpression", false);
            var searchIn = _settings.Get(SettingsSection.FindAndReplace, "SearchIn", null);
            SearchIn = EnumUtils.ParseEnum(searchIn, true, SearchInOptions.CurrentDocument);

            var findHistoryString = _settings.Get(SettingsSection.FindAndReplace, "FindHistory", null);
            FindHistory = DeserialiseList(findHistoryString);
            var replaceHistoryString = _settings.Get(SettingsSection.FindAndReplace, "ReplaceHistory", null);
            ReplaceHistory = DeserialiseList(replaceHistoryString);

            var windowSizeString = _settings.Get(SettingsSection.FindAndReplace, "WindowSize", null);
            WindowSize = DeserialiseSize(windowSizeString);
            var windowLocationString = _settings.Get(SettingsSection.FindAndReplace, "WindowLocation", null);
            WindowLocation = DeserialisePoint(windowLocationString);
        }
コード例 #3
0
        private void OnDoAction(object sender, DoActionEventArgs doActionEventArgs)
        {
            var window = sender as FindAndReplaceForm;
            if (window == null) return;

            // Set options
            MatchCase = window.MatchCase;
            MatchWholeWord = window.MatchWholeWord;
            UseRegularExpression = window.UseRegularExpression;
            SearchBackwards = window.SearchBackwards;
            SearchFromBegining = window.SearchFromBegining;

            var findText = window.FindText;
            var replaceText = window.ReplaceText;
            // Check find text is not null or empty. Replace text can be.
            if (string.IsNullOrEmpty(findText)) return;
            // Update history
            if (SaveFindHistory(findText))
                window.FindHistory = FindHistory.ToArray();
            // Get search scope if required.
            _searchIn = window.SearchIn;
            if (_searchIn == SearchInOptions.SelectedText)
            {
                var sel = _editor.GetSelection();
                // Check if user has changed selection - if so reset search scope. Selection should either be initial selection or last found match.
                if (_searchScope.HasValue &&
                    !sel.Equals(_searchScope.Value) &&
                    _lastMatch.HasValue &&
                    !sel.Equals(_lastMatch.Value) &&
                    sel.cpMin != sel.cpMax)
                    _searchScope = null;

                if (!_searchScope.HasValue)
                {
                    _searchScope = sel;
                    // Check we have a selection
                    if (_searchScope.Value.cpMin == _searchScope.Value.cpMax)
                    {
                        MessageBox.Show(_owner, "No text selected", window.Text);
                        return;
                    }
                    SearchFromBegining = true;
                }
            }

            switch (doActionEventArgs.Action)
            {
                case Action.FindNext:
                    var posFound = FindNext(findText);
                    if (posFound == -1)
                    {
                        MessageBox.Show(
                            _owner,
                            string.Format(
                                "{0} of {1} reached. No match found",
                                SearchBackwards ? "Start" : "End",
                                _searchIn == SearchInOptions.SelectedText ? "scope" : "document(s)"),
                            window.Text);
                        // If we haven't started from begining of document, turn that option on.
                        if (!SearchFromBegining)
                            window.SearchFromBegining = true;
                        // Reset search in selection
                        if (_searchIn == SearchInOptions.SelectedText)
                            _editor.SetSelection(_searchScope.Value.cpMin, _searchScope.Value.cpMax);
                        // Clear search scope
                        _searchScope = null;
                    }
                    else
                    {
                        // Turn off search from beining otherwise we'll only ever find the first match.
                        window.SearchFromBegining = false;
                    }
                    break;
                case Action.FindAll:
                    MessageBox.Show(
                        _owner,
                        string.Format("{0} matches found", MarkAll(findText, false)),
                        window.Text);
                    _searchScope = null;
                    break;
                case Action.Count:
                    MessageBox.Show(
                        _owner,
                        string.Format("{0} matches found", MarkAll(findText, true)),
                        window.Text);
                    _searchScope = null;
                    break;
                case Action.Replace:
                    // Todo: Check if readonly
                    // if ((*_ppEditView)->getCurrentBuffer()->isReadOnly()) return false;
                    if (SaveReplaceHistory(replaceText))
                        window.ReplaceHistory = ReplaceHistory.ToArray();
                    var posFoundReplace = Replace(findText, replaceText);
                    if (posFoundReplace == -1)
                    {
                        MessageBox.Show(
                            _owner,
                            string.Format(
                                "{0} of {1} reached. No match found",
                                SearchBackwards ? "Start" : "End",
                                _searchIn == SearchInOptions.SelectedText ? "scope" : "document"),
                            window.Text);
                        // If we haven't started from begining of document, turn that option on.
                        if (!SearchFromBegining)
                            window.SearchFromBegining = true;
                        // Reset search in selection
                        if (_searchIn == SearchInOptions.SelectedText)
                            _editor.SetSelection(_searchScope.Value.cpMin, _searchScope.Value.cpMax);
                        // Clear search scope
                        _searchScope = null;
                    }
                    else
                    {
                        // Turn off search from beining otherwise we'll only ever find the first match.
                        window.SearchFromBegining = false;
                    }
                    break;
                case Action.ReplaceAll:
                    // Todo: Check if readonly
                    // if ((*_ppEditView)->getCurrentBuffer()->isReadOnly()) return false;
                    if (SaveReplaceHistory(replaceText))
                        window.ReplaceHistory = ReplaceHistory.ToArray();
                    MessageBox.Show(
                        _owner,
                        string.Format("{0} matches replaced", ReplaceAll(findText, replaceText)),
                        window.Text);
                    _searchScope = null;
                    break;
            }
        }