From: Robin Dunn Date: Sat, 8 Dec 2001 18:04:27 +0000 (+0000) Subject: Added clipboard cut and paste X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/51dc95a4c8ccb00741be48f6353749ada3e9f39a Added clipboard cut and paste git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12928 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/wxPython/wxPython/lib/editor/editor.py b/wxPython/wxPython/lib/editor/editor.py index 833d7678e5..7eb7edd60f 100644 --- a/wxPython/wxPython/lib/editor/editor.py +++ b/wxPython/wxPython/lib/editor/editor.py @@ -75,7 +75,6 @@ class wxEditor(wxScrolledWindow): self.InitDoubleBuffering() self.InitScrolling() self.SelectOff() - self.CopiedData = None self.SetFocus() self.SetText([""]) self.SpacesPerTab = 4 @@ -634,17 +633,21 @@ class wxEditor(wxScrolledWindow): self.CopySelection(event) self.SelectOff() - def CopyData(self, data): - self.CopiedData = data + def CopyToClipboard(self, linesOfText): + do = wxTextDataObject() + do.SetText(string.join(linesOfText, os.linesep)) + wxTheClipboard.Open() + wxTheClipboard.SetData(do) + wxTheClipboard.Close() def SingleLineCopy(self, Row, bCol, eCol): Line = self.GetTextLine(Row) - self.CopyData([Line[bCol:eCol]]) + self.CopyToClipboard([Line[bCol:eCol]]) def MultipleLineCopy(self, bRow, bCol, eRow, eCol): bLine = self.GetTextLine(bRow)[bCol:] eLine = self.GetTextLine(eRow)[:eCol] - self.CopyData([bLine] + [l for l in self.lines[bRow + 1:eRow]] + [eLine]) + self.CopyToClipboard([bLine] + [l for l in self.lines[bRow + 1:eRow]] + [eLine]) def OnDeleteSelection(self, event): selection = self.FindSelection() @@ -677,16 +680,22 @@ class wxEditor(wxScrolledWindow): self.lines[bRow:eRow + 1] = [ModLine] def OnPaste(self, event): - if self.CopiedData is None: + do = wxTextDataObject() + wxTheClipboard.Open() + success = wxTheClipboard.GetData(do) + wxTheClipboard.Close() + if success: + pastedLines = string.split(do.GetText(), '\n') + else: wxBell() return - elif len(self.CopiedData) == 0: + if len(pastedLines) == 0: wxBell() return - elif len(self.CopiedData) == 1: - self.SingleLineInsert(self.CopiedData[0]) + elif len(pastedLines) == 1: + self.SingleLineInsert(pastedLines[0]) else: - self.MultipleLinePaste() + self.MultipleLinePaste(pastedLines) def SingleLineInsert(self, newText): ModLine = self.GetTextLine(self.cy) @@ -696,18 +705,18 @@ class wxEditor(wxScrolledWindow): self.TouchBuffer() self.UpdateView() - def MultipleLinePaste(self): + def MultipleLinePaste(self, pastedLines): FirstLine = LastLine = self.GetTextLine(self.cy) - FirstLine = FirstLine[:self.cx] + self.CopiedData[0] - LastLine = self.CopiedData[-1] + LastLine[self.cx:] + FirstLine = FirstLine[:self.cx] + pastedLines[0] + LastLine = pastedLines[-1] + LastLine[self.cx:] NewSlice = [FirstLine] - NewSlice += [l for l in self.CopiedData[1:-1]] + NewSlice += [l for l in pastedLines[1:-1]] NewSlice += [LastLine] self.lines[self.cy:self.cy + 1] = NewSlice - self.cy = self.cy + len(self.CopiedData)-1 - self.cx = len(self.CopiedData[-1]) + self.cy = self.cy + len(pastedLines)-1 + self.cx = len(pastedLines[-1]) self.TouchBuffer() self.UpdateView()