]> git.saurik.com Git - wxWidgets.git/commitdiff
Added clipboard cut and paste
authorRobin Dunn <robin@alldunn.com>
Sat, 8 Dec 2001 18:04:27 +0000 (18:04 +0000)
committerRobin Dunn <robin@alldunn.com>
Sat, 8 Dec 2001 18:04:27 +0000 (18:04 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12928 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/wxPython/lib/editor/editor.py

index 833d7678e5f5b3c4abd9a54b2041317d962fa2e4..7eb7edd60fb6c9d1832bd501bb935ca3a9bcbc23 100644 (file)
@@ -75,7 +75,6 @@ class wxEditor(wxScrolledWindow):
         self.InitDoubleBuffering()
         self.InitScrolling()
         self.SelectOff()
         self.InitDoubleBuffering()
         self.InitScrolling()
         self.SelectOff()
-        self.CopiedData = None
         self.SetFocus()
         self.SetText([""])
         self.SpacesPerTab = 4
         self.SetFocus()
         self.SetText([""])
         self.SpacesPerTab = 4
@@ -634,17 +633,21 @@ class wxEditor(wxScrolledWindow):
         self.CopySelection(event)
         self.SelectOff()
 
         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)
 
     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]
 
     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()
 
     def OnDeleteSelection(self, event):
         selection = self.FindSelection()
@@ -677,16 +680,22 @@ class wxEditor(wxScrolledWindow):
         self.lines[bRow:eRow + 1] = [ModLine]
 
     def OnPaste(self, event):
         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
             wxBell()
             return
-        elif len(self.CopiedData) == 0:
+        if len(pastedLines) == 0:
             wxBell()
             return
             wxBell()
             return
-        elif len(self.CopiedData) == 1:
-            self.SingleLineInsert(self.CopiedData[0])
+        elif len(pastedLines) == 1:
+            self.SingleLineInsert(pastedLines[0])
         else:
         else:
-            self.MultipleLinePaste()
+            self.MultipleLinePaste(pastedLines)
 
     def SingleLineInsert(self, newText):
         ModLine = self.GetTextLine(self.cy)
 
     def SingleLineInsert(self, newText):
         ModLine = self.GetTextLine(self.cy)
@@ -696,18 +705,18 @@ class wxEditor(wxScrolledWindow):
         self.TouchBuffer()
         self.UpdateView()
 
         self.TouchBuffer()
         self.UpdateView()
 
-    def MultipleLinePaste(self):
+    def MultipleLinePaste(self, pastedLines):
         FirstLine = LastLine = self.GetTextLine(self.cy)
         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 = [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
 
         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()
 
         self.TouchBuffer()
         self.UpdateView()