Exemplo n.º 1
0
        protected override void OnOpen(object parameter = null)
        {
            _findReplaceViewModel = new FindReplaceViewModel(_findReplaceSettings, _findReplaceService);

            _uiVisualizerService.ShowAsync(_findReplaceViewModel);

            _findReplaceViewModel.ClosedAsync += OnClosedAsync;
        }
Exemplo n.º 2
0
        private void ShowFindReplaceDialog(bool showFind = true)
        {
            if (ActiveDocument is EdiViewModel)
            {
                EdiViewModel f   = ActiveDocument as EdiViewModel;
                Window       dlg = null;

                try
                {
                    if (FindReplaceVm == null)
                    {
                        FindReplaceVm = new FindReplaceViewModel(_SettingsManager, _MsgBox);
                    }

                    FindReplaceVm.FindNext = FindNext;

                    // determine whether Find or Find/Replace is to be executed
                    FindReplaceVm.ShowAsFind = showFind;

                    if (f.TxtControl != null)                          // Search by default for currently selected text (if any)
                    {
                        string textToFind;
                        f.TxtControl.GetSelectedText(out textToFind);

                        if (textToFind.Length > 0)
                        {
                            FindReplaceVm.TextToFind = textToFind;
                        }
                    }

                    FindReplaceVm.CurrentEditor = f;

                    dlg = ViewSelector.GetDialogView(FindReplaceVm, Application.Current.MainWindow);

                    dlg.Closing += FindReplaceVm.OnClosing;

                    dlg.ShowDialog();
                }
                catch (Exception exc)
                {
                    _MsgBox.Show(exc, Util.Local.Strings.STR_MSG_FIND_UNEXPECTED_ERROR,
                                 MsgBoxButtons.OK, MsgBoxImage.Error);
                }
                finally
                {
                    if (dlg != null)
                    {
                        dlg.Closing -= FindReplaceVm.OnClosing;
                        dlg.Close();
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ShowFindReplaceDialog(bool ShowFind = true)
        {
            if (this.ActiveDocument is EdiViewModel f)
            {
                Window dlg = null;

                try
                {
                    if (this.FindReplaceVM == null)
                    {
                        this.FindReplaceVM = new Edi.Dialogs.FindReplace.ViewModel.FindReplaceViewModel(this.mSettingsManager);
                    }

                    this.FindReplaceVM.FindNext = this.FindNext;

                    // determine whether Find or Find/Replace is to be executed
                    this.FindReplaceVM.ShowAsFind = ShowFind;

                    if (f.TxtControl != null)      // Search by default for currently selected text (if any)
                    {
                        string textToFind;
                        f.TxtControl.GetSelectedText(out textToFind);

                        if (textToFind.Length > 0)
                        {
                            this.FindReplaceVM.TextToFind = textToFind;
                        }
                    }

                    this.FindReplaceVM.CurrentEditor = f;

                    dlg = ViewSelector.GetDialogView((object)this.FindReplaceVM, Application.Current.MainWindow);

                    dlg.Closing += this.FindReplaceVM.OnClosing;

                    dlg.ShowDialog();
                }
                catch (Exception exc)
                {
                    _MsgBox.Show(exc, Edi.Util.Local.Strings.STR_MSG_FIND_UNEXPECTED_ERROR,
                                 MsgBoxButtons.OK, MsgBoxImage.Error);
                }
                finally
                {
                    if (dlg != null)
                    {
                        dlg.Closing -= this.FindReplaceVM.OnClosing;
                        dlg.Close();
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Find a match in a given peace of string
        /// </summary>
        /// <param name="selectionStart"></param>
        /// <param name="selectionLength"></param>
        /// <param name="invertLeftRight"></param>
        /// <param name="text"></param>
        /// <param name="f"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        Match FindNextMatchInText(int selectionStart,             // CE.SelectionStart
                                  int selectionLength,            // CE.SelectionLength
                                  bool invertLeftRight,           // CE.Text
                                  string text,                    // InvertLeftRight
                                  ref FindReplaceViewModel f,
                                  out Regex r)
        {
            if (invertLeftRight)
            {
                f.SearchUp = !f.SearchUp;
                r          = f.GetRegEx();
                f.SearchUp = !f.SearchUp;
            }
            else
            {
                r = f.GetRegEx();
            }

            return(r.Match(text, r.Options.HasFlag(RegexOptions.RightToLeft) ? selectionStart : selectionStart + selectionLength));
        }
Exemplo n.º 5
0
        private IEditor GetNextEditor(FindReplaceViewModel f,
                                      bool previous = false
                                      )
        {
            // There is no next open document if there is none or only one open
            if (this.Files.Count <= 1)
            {
                return(f.GetCurrentEditor());
            }

            // There is no next open document If the user wants to search the current document only
            if (f.SearchIn == Edi.Dialogs.FindReplace.SearchScope.CurrentDocument)
            {
                return(f.GetCurrentEditor());
            }

            var l = new List <object>(this.Files.Cast <object>());

            int idxStart = l.IndexOf(f.CurrentEditor);
            int i        = idxStart;

            if (i >= 0)
            {
                Match m = null;

                bool textSearchSuccess = false;
                do
                {
                    if (previous == true)                  // Get next/previous document
                    {
                        i = (i < 1 ? l.Count - 1 : i - 1);
                    }
                    else
                    {
                        i = (i >= l.Count - 1 ? 0 : i + 1);
                    }

                    //// i = (i + (previous ? l.Count - 1 : +1)) % l.Count;

                    // Search text in document
                    if (l[i] is EdiViewModel)
                    {
                        EdiViewModel fTmp = l[i] as EdiViewModel;

                        Regex r;
                        m = this.FindNextMatchInText(0, 0, false, fTmp.Text, ref f, out r);

                        textSearchSuccess = m.Success;
                    }
                }while (i != idxStart && textSearchSuccess != true);

                // Found a match so activate the corresponding document and select the text with scroll into view
                if (textSearchSuccess == true && m != null)
                {
                    var doc = l[i] as EdiViewModel;

                    if (doc != null)
                    {
                        this.ActiveDocument = doc;
                    }

                    // Ensure that no pending calls are in the dispatcher queue
                    // This makes sure that we are blocked until bindings are re-established
                    // Bindings are required to scroll a selection into view
                    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) delegate
                    {
                        if (this.ActiveDocument != null && doc != null)
                        {
                            doc.TextEditorSelectionStart  = m.Index;
                            doc.TextEditorSelectionLength = m.Length;

                            // Reset cursor position to make sure we search a document from its beginning
                            doc.TxtControl.SelectText(m.Index, m.Length);

                            f.CurrentEditor = l[i] as IEditor;

                            IEditor edi = f.GetCurrentEditor();

                            if (edi != null)
                            {
                                edi.Select(m.Index, m.Length);
                            }
                        }
                    });

                    return(f.GetCurrentEditor());
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        private bool FindNext(FindReplaceViewModel f,
                              bool invertLeftRight = false)
        {
            IEditor ce = f.GetCurrentEditor();

            if (ce == null)
            {
                return(false);
            }

            Regex r;
            Match m = FindNextMatchInText(ce.SelectionStart, ce.SelectionLength,
                                          invertLeftRight, ce.Text, ref f, out r);

            if (m.Success)
            {
                ce.Select(m.Index, m.Length);

                return(true);
            }
            else
            {
                if (f.SearchIn == Dialogs.FindReplace.SearchScope.CurrentDocument)
                {
                    _MsgBox.Show(Util.Local.Strings.STR_MSG_FIND_NO_MORE_ITEMS_FOUND);

                    return(false);
                }

                // we have reached the end of the document
                // start again from the beginning/end,
                object oldEditor = f.CurrentEditor;
                do
                {
                    if (f.SearchIn == Dialogs.FindReplace.SearchScope.AllDocuments)
                    {
                        ce = GetNextEditor(f, r.Options.HasFlag(RegexOptions.RightToLeft));

                        if (ce == null)
                        {
                            return(false);
                        }

                        f.CurrentEditor = ce;

                        return(true);
                    }

                    m = r.Options.HasFlag(RegexOptions.RightToLeft) ? r.Match(ce.Text, ce.Text.Length - 1) : r.Match(ce.Text, 0);

                    if (m.Success)
                    {
                        ce.Select(m.Index, m.Length);
                        break;
                    }
                    else
                    {
                        _MsgBox.Show(Util.Local.Strings.STR_MSG_FIND_NO_MORE_ITEMS_FOUND2,
                                     Util.Local.Strings.STR_MSG_FIND_Caption);
                    }
                } while (f.CurrentEditor != oldEditor);
            }

            return(false);
        }
Exemplo n.º 7
0
 public FindReplacePage()
 {
     viewModel = new FindReplaceViewModel();
     this.InitializeComponent();
 }
Exemplo n.º 8
0
        private void ShowFindReplaceDialog(bool ShowFind = true)
        {
            EdiViewModel f = this.ActiveDocument as EdiViewModel;

            if (f != null)
            {
                Window dlg = null;

                try
                {
                    if (this.FindReplaceVM == null)
                    {
                        this.FindReplaceVM = new Edi.View.Dialogs.FindReplace.FindReplaceViewModel();
                    }

                    this.FindReplaceVM.FindNext = this.FindNext;

                    // determine whether Find or Find/Replace is to be executed
                    this.FindReplaceVM.ShowAsFind = ShowFind;

                    if (f.TxtControl != null) // Search by default for currently selected text (if any)
                    {
                        string textToFind;
                        f.TxtControl.GetSelectedText(out textToFind);

                        if (textToFind.Length > 0)
                        {
                            this.FindReplaceVM.TextToFind = textToFind;
                        }
                    }

                    this.FindReplaceVM.CurrentEditor = f;

                    dlg = ViewSelector.GetDialogView((object)this.FindReplaceVM);

                    // It is important to either:
                    // 1> Use the InitDialogInputData methode here or
                    // 2> Reset the WindowCloseResult=null property
                    // because otherwise ShowDialog will not work twice
                    // (Symptom: The dialog is closed immeditialy by the attached behaviour)
                    this.FindReplaceVM.InitDialogInputData();

                    dlg.DataContext = this.FindReplaceVM;

                    dlg.Closing += this.FindReplaceVM.OpenCloseView.OnClosing;

                    dlg.Owner = Application.Current.MainWindow; // Make sure that dialog window appears in front of main window

                    dlg.ShowDialog();
                }
                catch (Exception exc)
                {
                    Edi.Msg.Box.Show(exc, "An unexpected error occured.", MsgBoxButtons.OK, MsgBoxImage.Error);
                }
                finally
                {
                    if (dlg != null)
                    {
                        dlg.Closing -= this.FindReplaceVM.OpenCloseView.OnClosing;
                        dlg.Close();
                    }
                }
            }
        }
Exemplo n.º 9
0
        private bool FindNext(FindReplaceViewModel f,
                              bool InvertLeftRight = false)
        {
            IEditor CE = f.GetCurrentEditor();

            if (CE == null)
            {
                return(false);
            }

            Regex r;
            Match m = this.FindNextMatchInText(CE.SelectionStart, CE.SelectionLength,
                                               InvertLeftRight, CE.Text, ref f, out r);

            if (m.Success)
            {
                CE.Select(m.Index, m.Length);

                return(true);
            }
            else
            {
                if (f.SearchIn == EdiViews.FindReplace.SearchScope.CurrentDocument)
                {
                    Edi.Msg.Box.Show("There are no more search results to display.");

                    return(false);
                }

                // we have reached the end of the document
                // start again from the beginning/end,
                object OldEditor = f.CurrentEditor;
                do
                {
                    if (f.SearchIn == EdiViews.FindReplace.SearchScope.AllDocuments)
                    {
                        CE = this.GetNextEditor(f, r.Options.HasFlag(RegexOptions.RightToLeft));

                        if (CE == null)
                        {
                            return(false);
                        }

                        f.CurrentEditor = CE;

                        return(true);
                    }

                    if (r.Options.HasFlag(RegexOptions.RightToLeft))
                    {
                        m = r.Match(CE.Text, CE.Text.Length - 1);
                    }
                    else
                    {
                        m = r.Match(CE.Text, 0);
                    }

                    if (m.Success)
                    {
                        CE.Select(m.Index, m.Length);
                        break;
                    }
                    else
                    {
                        Edi.Msg.Box.Show("No further occurence found.", "Search");
                    }
                } while (f.CurrentEditor != OldEditor);
            }

            return(false);
        }