Created
October 27, 2010 23:50
-
-
Save aalvarado/650263 to your computer and use it in GitHub Desktop.
Snippet from my record line file for pythonscript plugin in n++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FilePosition: | |
def __init__(self, bufferId): | |
self.bufferId = bufferId #sets the bufferId | |
self.filePositions = [] # where the modified lines will be stored | |
self.lastPos = 0 | |
self.counter = 0 | |
def addFilePosition(self, pos): | |
self._findDelete(pos) # checks if the line number is already in the list | |
if editor.getLineCount() < pos: | |
pos = editor.getLineCount() | |
self.filePositions.append(pos) # adds the line number | |
self.lastPos = pos | |
def getBufferId(self): #returns buffer id | |
return self.bufferId | |
def printAll(self): # prints all the positions stored in the object | |
for i,j in enumerate(self.filePositions): | |
console.write(str(j) + '\n') | |
console.write('end \n') | |
def getPrev(self): | |
pass | |
def getNext(self): | |
pass | |
def getLastPos(self): | |
return self.lastPos | |
def _findDelete(self, pos): | |
self.maxPos = editor.getLineCount()-1 | |
for i,j in enumerate(self.filePositions): | |
if j == pos or j > self.maxPos: | |
self.filePositions.remove(j) | |
class FilePositionCollection: | |
_fpc = [] | |
#adding(1040) or deleting (2064) adds a line position | |
_modificationTypes = [1040,2064] | |
def modified(self,args): | |
# if the arguments contain a valid modification type add it to positions | |
if args['modificationType'] in self._modificationTypes: | |
self.fp1 = self.fpcExists(notepad.getCurrentBufferID()) | |
self.pos = editor.lineFromPosition(args['position']) | |
if self.fp1.getLastPos() != self.pos: | |
self.fp1.addFilePosition(self.pos) | |
self.fp1.printAll() | |
def getNext(self): | |
self.fp1 = self.fpcExists(notepad.getCurrentBufferID()) | |
pass | |
def getPrev(self): | |
self.fp1 = self.fpcExists(notepad.getCurrentBufferID()) | |
pass | |
def fpcExists(self, bufferId): | |
''' | |
If the object doesn't exist with the specified | |
bufferId | |
create it. | |
''' | |
for i, o in enumerate(FilePositionCollection._fpc): | |
if o.getBufferId() == bufferId: | |
return o | |
else: | |
FilePositionCollection._fpc.append(FilePosition(bufferId)) | |
return FilePositionCollection._fpc[len(FilePositionCollection._fpc)-1] | |
fpc = FilePositionCollection() | |
editor.callback(fpc.modified, [SCINTILLANOTIFICATION.MODIFIED]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
editor.callback(fpc.modified, [SCINTILLANOTIFICATION.MODIFIED]) -- this binds a method if a change in the active tab is detected