- if self.CanPaste():
- if wxTheClipboard.Open():
- if wxTheClipboard.IsSupported(wxDataFormat(wxDF_TEXT)):
- data = wxTextDataObject()
- if wxTheClipboard.GetData(data):
- command = data.GetText()
- command = command.rstrip()
- command = self.fixLineEndings(command)
- command = self.lstripPrompt(text=command)
- command = command.replace(os.linesep + sys.ps2, '\n')
- command = command.replace(os.linesep, '\n')
+ if self.CanPaste() and wxTheClipboard.Open():
+ if wxTheClipboard.IsSupported(wxDataFormat(wxDF_TEXT)):
+ data = wxTextDataObject()
+ if wxTheClipboard.GetData(data):
+ self.ReplaceSelection('')
+ command = data.GetText()
+ command = command.rstrip()
+ command = self.fixLineEndings(command)
+ command = self.lstripPrompt(text=command)
+ command = command.replace(os.linesep + sys.ps2, '\n')
+ command = command.replace(os.linesep, '\n')
+ command = command.replace('\n', os.linesep + sys.ps2)
+ self.write(command)
+ wxTheClipboard.Close()
+
+ def PasteAndRun(self):
+ """Replace selection with clipboard contents, run commands."""
+ if wxTheClipboard.Open():
+ if wxTheClipboard.IsSupported(wxDataFormat(wxDF_TEXT)):
+ data = wxTextDataObject()
+ if wxTheClipboard.GetData(data):
+ endpos = self.GetTextLength()
+ self.SetCurrentPos(endpos)
+ startpos = self.promptPosEnd
+ self.SetSelection(startpos, endpos)
+ self.ReplaceSelection('')
+ text = data.GetText()
+ text = text.strip()
+ text = self.fixLineEndings(text)
+ text = self.lstripPrompt(text=text)
+ text = text.replace(os.linesep + sys.ps1, '\n')
+ text = text.replace(os.linesep + sys.ps2, '\n')
+ text = text.replace(os.linesep, '\n')
+ lines = text.split('\n')
+ commands = []
+ command = ''
+ for line in lines:
+ if line.strip() != '' and line.lstrip() == line:
+ # New command.
+ if command:
+ # Add the previous command to the list.
+ commands.append(command)
+ # Start a new command, which may be multiline.
+ command = line
+ else:
+ # Multiline command. Add to the command.
+ command += '\n'
+ command += line
+ commands.append(command)
+ for command in commands: