def execute(self): self._oldCursorPos, self._oldSelections = archyState.mainText.getNonContentMemento( ) firstOccurance = self.findTarget(self._oldSelections[1][1] + 1) if firstOccurance == -1: if self._target == "": self._status = 0 raise commands.AbortCommandException("Leap to " + self._target + " failed.") else: self._status = -1 raise commands.AbortCommandException("Leap to " + self._target + " failed.") self._updateSelections(firstOccurance)
def addChar(self, newChar): self._target += newChar firstOccurance = self.findTarget(self._oldSelections[1][1] + 1) if firstOccurance == -1: if self._target == "": self._status = 0 self.undo() raise commands.AbortCommandException("Leap to " + self._target + " failed.") else: self._status = -1 self.undo() raise commands.AbortCommandException("Leap to " + self._target + " failed.") self._status = 1 self._updateSelections(firstOccurance)
def execute(self): mT = archyState.mainText self.origSel = mT.getSelection('selection') if mT.textArray.getSubString( *self.origSel).lower() <> FindNextCommand.searchTerm.lower(): raise commands.AbortCommandException( "Current selection is not \"%s\". Use command-tab to find the next instantance." % (FindNextCommand.searchTerm)) self.origSearchEnd = FindNextCommand.searchEnd FindNextCommand.searchEnd += len(self.replacement) - len( FindNextCommand.searchTerm) self.delText = DeleteTextCommand() self.addText = AddTextCommand(self.replacement) self.findNext = FindNextCommand() self.delText.execute() self.addText.execute() try: self.findNext.execute() except commands.AbortCommandException, e: self.findNext = None messages.queue(e.getExplanation())
def execute(self): mT = archyState.mainText foSel = mT.getSelection('first old selection') oSel = mT.getSelection('old selection') sel = mT.getSelection('selection') self.origSel = sel self.origCursor = mT.getCursorPos() searchTerm = mT.textArray.getSubString(*foSel) replacement = mT.textArray.getSubString(*oSel) pos = mT.textArray.find(searchTerm, sel[0]) if pos < sel[1] and pos > 0: mT.setSelection('selection', pos, pos+len(searchTerm)-1) mT.setCursor(pos+len(searchTerm)) FindNextCommand.searchEnd = sel[1] FindNextCommand.searchTerm = searchTerm AcceptReplaceCommand.replacement = replacement archyState.commandMap.unregisterCommand(AcceptReplaceCommand()) archyState.commandMap.unregisterCommand(FindNextCommand()) archyState.commandMap.unregisterCommand(EndReplaceCommand()) archyState.commandMap.registerCommand(AcceptReplaceCommand()) archyState.commandMap.registerCommand(FindNextCommand()) archyState.commandMap.registerCommand(EndReplaceCommand()) messages.queue("command-space: change\ncommand-tab: find next\nEND - Exit REPLACE", "persistant") else: raise commands.AbortCommandException('\"%s\" was not found in the selection.' % (searchTerm))
def delChar(self): if len(self._target) == 0: self._status = 0 return self._target = self._target[:-1] if len(self._target) == 0: self._status = 0 self.undo() return firstOccurance = self.findTarget(self._oldSelections[1][1] + 1) self.undo() if firstOccurance == -1: if self._target == "": self._status = 0 raise commands.AbortCommandException("Leap to " + self._target + " failed.") else: self._status = -1 raise commands.AbortCommandException("Leap to " + self._target + " failed.") self._status = 1 self._updateSelections(firstOccurance)
def execute(self): mT = archyState.mainText self.cursorPos = mT.getCursorPos() self.origSel = mT.getSelection('selection') pos = mT.textArray.find(self.searchTerm, self.cursorPos) if pos < self.searchEnd and pos > 0: mT.setSelection('selection', pos, pos+len(self.searchTerm)-1) mT.setCursor(pos+len(self.searchTerm)) else: messages.unqueue('persistant') archyState.commandMap.unregisterCommand(FindNextCommand()) archyState.commandMap.unregisterCommand(AcceptReplaceCommand()) raise commands.AbortCommandException("Last \"%s\" found within selected range." % (self.searchTerm))
def execute(self): self.saveSelectionInfo() newSelections = [] # If the selection is the cursor selection: if self._oldSelections[1][0] == self._oldSelections[1][1]: # - If the cursor is just to the right of the selection, collapse the cursor to the selection, do not change the selections, and move the appropriate preselection anchor: if self._oldCursorPos == (self._oldSelections[1][1] + 1): newCursorPos = self._oldCursorPos - 1 newSelections.append( self.dragPreselection(newCursorPos, self._oldSelections[0])) newSelections.append(self.collapseSelection(newCursorPos)) # - If the cursor is on the selection and both are on the initial character, then don't change anything: elif (self._oldCursorPos == 0) and (self._oldSelections[1][0] == 0): newCursorPos = self._oldCursorPos newSelections.append(self._oldSelections[0]) newSelections.append(self._oldSelections[1]) # - If the cursor is on the selection, then move cursor, selection, and the appropriate preselection anchor one character left, and copy the old selections: elif self._oldCursorPos == self._oldSelections[1][0]: newCursorPos = self._oldCursorPos - 1 newSelections.append( self.dragPreselection(newCursorPos, self._oldSelections[0])) newSelections.append(self.collapseSelection(newCursorPos)) else: newCursorPos = self._oldCursorPos newSelections = [[newCursorPos, newCursorPos], [newCursorPos, newCursorPos]] # If the selection is extended: elif self._oldSelections[1][0] < self._oldSelections[1][1]: # - collapse the cursor to the first character of the selection newCursorPos = self._oldSelections[1][0] # - set the preselection to the selection newSelections = [self._oldSelections[1]] # - recollapse the selection to the cursor (redundant, but that's okay) newSelections.append(self.collapseSelection(newCursorPos)) # - move the selection to the first old selection newSelections.append(self._oldSelections[1]) else: raise commands.AbortCommandException("Selection was invalid.") # Finally, append all the previous old selections for i in self._oldSelections[2:]: newSelections.append(i) archyState.mainText.setCursor(newCursorPos) archyState.mainText.setSelectionList(newSelections) archyState.commandHistory.setSelectionAnchor(newCursorPos)
def execute(self): self.saveSelectionInfo() newSelections = [] # If the selection is the cursor selection: if self._oldSelections[1][0] == self._oldSelections[1][1]: # - If the cursor is just to the right of the selection, then collapse the selection to the cursor, copy the preselection, and copy the selections: if self._oldCursorPos == (self._oldSelections[1][1] + 1): newCursorPos = self._oldCursorPos newSelections.append( self.dragPreselection(newCursorPos, self._oldSelections[0])) newSelections.append(self.collapseSelection(newCursorPos)) # - If the cursor and the selection are on the last character, then do nothing: elif (self._oldCursorPos == (archyState.mainText.getLength() - 1)) and (self._oldSelections[1][0] == (archyState.mainText.getLength() - 1)): newCursorPos = self._oldCursorPos newSelections.append(self._oldSelections[0]) newSelections.append(self._oldSelections[1]) # - If the cursor and the selection are on the same character (which isn't the last), the move the cursor, the selection, and the appropriate preselection anchor right one character: elif self._oldCursorPos == self._oldSelections[1][0]: newCursorPos = self._oldCursorPos + 1 newSelections.append( self.dragPreselection(newCursorPos, self._oldSelections[0])) newSelections.append(self.collapseSelection(newCursorPos)) else: newCursorPos = self._oldCursorPos newSelections.append(self.collapseSelection(newCursorPos)) newSelections.append(self.collapseSelection(newCursorPos)) # If there is an extended selection: elif self._oldSelections[1][0] < self._oldSelections[1][1]: # -collapse the cursor to the last character of the selection newCursorPos = self._oldSelections[1][1] # -make sure the preselection is set to the selection newSelections.append([self._oldSelections[1][0], newCursorPos]) newSelections.append(self.collapseSelection(newCursorPos)) # -move the selection to the first old selection newSelections.append(self._oldSelections[1]) else: raise commands.AbortCommandException("Selection was invalid.") for i in self._oldSelections[2:]: newSelections.append(i) archyState.mainText.setCursor(newCursorPos) archyState.mainText.setSelectionList(newSelections) archyState.commandHistory.setSelectionAnchor(newCursorPos)
def onClipboardNotCompatibleFormat(): raise commands.AbortCommandException("Clipboard does not contain text data.")
def execute(self): if pygame_run.get_fullscreen_mode() == 0: raise commands.AbortCommandException("Already in unfullscreen mode.") pygame_run.set_fullscreen_mode(0)