private void ShowGotoLineDialog() { EdiViewModel f = this.ActiveDocument as EdiViewModel; if (f != null) { Window dlg = null; Edi.View.Dialogs.GotoLine.GotoLineViewModel dlgVM = null; try { int iCurrLine = Workspace.GetCurrentEditorLine(f); dlgVM = new Edi.View.Dialogs.GotoLine.GotoLineViewModel(1, f.Document.LineCount, iCurrLine); dlg = ViewSelector.GetDialogView((object)dlgVM); // 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) dlgVM.InitDialogInputData(); dlg.DataContext = dlgVM; dlg.Closing += dlgVM.OpenCloseView.OnClosing; dlg.Owner = Application.Current.MainWindow; // Make sure that dialog window appears in front of main window dlg.ShowDialog(); // Copy input if user OK'ed it. This could also be done by a method, equality operator, or copy constructor if (((Edi.View.Dialogs.GotoLine.GotoLineViewModel)dlg.DataContext).OpenCloseView.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) { Edi.Msg.Box.Show(exc, "An unexpected error occured.", MsgBoxButtons.OK, MsgBoxImage.Error); } finally { if (dlg != null) { dlg.Closing -= dlgVM.OpenCloseView.OnClosing; dlg.Close(); } } } }
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(); } } } }