//========================================================================================= /// <summary>Mock text in clipboard.</summary> void SetTextToClipboard(string text) { ClipboardProxy = MockRepository.GenerateStub<ClipboardProxyClass>(); ClipboardProxy.Stub(x => x.ContainsText()).Return(true); ClipboardProxy.Stub(x => x.GetText()).Return(text); this.EditController.ClipboardProxy = this.ClipboardProxy; }
//========================================================================================= internal bool CopyToClipboard(bool deleteSelection) { if (!this.HasSelection()) return false; //Determine start and end of selection TextPoint pStart, pEnd; if (this.SelectionStart > this.CurPos) { pStart = this.CurPos; pEnd = this.SelectionStart; } else { pStart = this.SelectionStart; pEnd = this.CurPos; } var sb = new StringBuilder(); if (pStart.Line == pEnd.Line) { string sLine = this.Doc[pStart.Line].Text; sb.Append(sLine.Substring(pStart.Char, pEnd.Char - pStart.Char)); } else { //first line sb.AppendLine(this.Doc[pStart.Line].Text.Substring(pStart.Char)); //intermediate lines for (int iLine = pStart.Line + 1; iLine < pEnd.Line; iLine++) sb.AppendLine(this.Doc[iLine].Text); //last line string sLastLine = this.Doc[pEnd.Line].Text; if (pEnd.Char < sLastLine.Length) sLastLine = sLastLine.Remove(pEnd.Char); sb.Append(sLastLine); } if (this.ClipboardProxy == null) this.ClipboardProxy = ClipboardProxyClass.Self; try { this.ClipboardProxy.SetText(sb.ToString()); } catch (System.Runtime.InteropServices.ExternalException) { } if (deleteSelection) this.DeleteSelection(); return true; }
//========================================================================================= internal bool PasteFromClipboard() { if (this.ClipboardProxy == null) this.ClipboardProxy = ClipboardProxyClass.Self; if (!this.ClipboardProxy.ContainsText()) return false; this.PasteText(this.ClipboardProxy.GetText()); this.InitTokens(); this.Viewer.Body.Invalidate(false); return true; }
//========================================================================================= void ExpectTextInClipboard(string text) { ClipboardProxy = MockRepository.GenerateMock<ClipboardProxyClass>(); ClipboardProxy.Expect(x => x.SetText(text)); this.EditController.ClipboardProxy = this.ClipboardProxy; }