Exemple #1
0
        private void ShowFindReplaceDialog(bool ShowFind = true)
        {
            if (this.ActiveDocument is EdiViewModel f)
            {
                Window dlg = null;

                try
                {
                    if (this.FindReplaceVM == null)
                    {
                        this.FindReplaceVM = new EdiDialogs.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.Msg.Show(exc, Util.Local.Strings.STR_MSG_FIND_UNEXPECTED_ERROR,
                                    MsgBoxButtons.OK, MsgBoxImage.Error);
                }
                finally
                {
                    if (dlg != null)
                    {
                        dlg.Closing -= this.FindReplaceVM.OnClosing;
                        dlg.Close();
                    }
                }
            }
        }
Exemple #2
0
        private void ShowGotoLineDialog()
        {
            if (this.ActiveDocument is EdiViewModel f)
            {
                Window dlg = null;
                EdiDialogs.GotoLine.GotoLineViewModel dlgVM = null;

                try
                {
                    int iCurrLine = ApplicationViewModel.GetCurrentEditorLine(f);

                    dlgVM = new EdiDialogs.GotoLine.GotoLineViewModel(1, f.Document.LineCount, iCurrLine);
                    dlg   = ViewSelector.GetDialogView((object)dlgVM, Application.Current.MainWindow);

                    dlg.Closing += dlgVM.OnClosing;

                    dlg.ShowDialog();

                    // Copy input if user OK'ed it. This could also be done by a method, equality operator, or copy constructor
                    if (dlgVM.WindowCloseResult == true)
                    {
                        DocumentLine line = f.Document.GetLineByNumber(dlgVM.LineNumber);

                        f.TxtControl.SelectText(line.Offset, 0);     // Select text with length 0 and scroll to where
                        f.TxtControl.ScrollToLine(dlgVM.LineNumber); // we are supposed to be at
                    }
                }
                catch (Exception exc)
                {
                    MsgBox.Msg.Show(exc, Util.Local.Strings.STR_MSG_FIND_UNEXPECTED_ERROR,
                                    MsgBoxButtons.OK, MsgBoxImage.Error);
                }
                finally
                {
                    if (dlg != null)
                    {
                        dlg.Closing -= dlgVM.OnClosing;
                        dlg.Close();
                    }
                }
            }
        }