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(); } } } }
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(); } } } }
private void ShowGotoLineDialog() { if (ActiveDocument is EdiViewModel) { EdiViewModel f = ActiveDocument as EdiViewModel; Window dlg = null; Dialogs.GotoLine.GotoLineViewModel dlgVm = null; try { int iCurrLine = GetCurrentEditorLine(f); dlgVm = new Dialogs.GotoLine.GotoLineViewModel(1, f.Document.LineCount, iCurrLine); dlg = ViewSelector.GetDialogView(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.Show(exc, Util.Local.Strings.STR_MSG_FIND_UNEXPECTED_ERROR, MsgBoxButtons.OK, MsgBoxImage.Error); } finally { if (dlg != null) { dlg.Closing -= dlgVm.OnClosing; dlg.Close(); } } } }