80 language is passed as a parameter. |
80 language is passed as a parameter. |
81 @signal eolChanged(str) emitted when the editors eol type was set. The eol string |
81 @signal eolChanged(str) emitted when the editors eol type was set. The eol string |
82 is passed as a parameter. |
82 is passed as a parameter. |
83 @signal encodingChanged(str) emitted when the editors encoding was set. The |
83 @signal encodingChanged(str) emitted when the editors encoding was set. The |
84 encoding name is passed as a parameter. |
84 encoding name is passed as a parameter. |
|
85 @signal lastEditPositionAvailable() emitted when a last edit position is available |
85 """ |
86 """ |
86 modificationStatusChanged = pyqtSignal(bool, QsciScintillaCompat) |
87 modificationStatusChanged = pyqtSignal(bool, QsciScintillaCompat) |
87 undoAvailable = pyqtSignal(bool) |
88 undoAvailable = pyqtSignal(bool) |
88 redoAvailable = pyqtSignal(bool) |
89 redoAvailable = pyqtSignal(bool) |
89 cursorChanged = pyqtSignal(str, int, int) |
90 cursorChanged = pyqtSignal(str, int, int) |
99 taskMarkersUpdated = pyqtSignal(QsciScintillaCompat) |
100 taskMarkersUpdated = pyqtSignal(QsciScintillaCompat) |
100 showMenu = pyqtSignal(str, QMenu, QsciScintillaCompat) |
101 showMenu = pyqtSignal(str, QMenu, QsciScintillaCompat) |
101 languageChanged = pyqtSignal(str) |
102 languageChanged = pyqtSignal(str) |
102 eolChanged = pyqtSignal(str) |
103 eolChanged = pyqtSignal(str) |
103 encodingChanged = pyqtSignal(str) |
104 encodingChanged = pyqtSignal(str) |
|
105 lastEditPositionAvailable = pyqtSignal() |
104 |
106 |
105 # Autocompletion icon definitions |
107 # Autocompletion icon definitions |
106 ClassID = 1 |
108 ClassID = 1 |
107 ClassProtectedID = 2 |
109 ClassProtectedID = 2 |
108 ClassPrivateID = 3 |
110 ClassPrivateID = 3 |
220 self.__savedText = "" |
224 self.__savedText = "" |
221 self.__inSharedEdit = False |
225 self.__inSharedEdit = False |
222 self.__isShared = False |
226 self.__isShared = False |
223 self.__inRemoteSharedEdit = False |
227 self.__inRemoteSharedEdit = False |
224 |
228 |
|
229 # connect signals before loading the text |
225 self.modificationChanged.connect(self.__modificationChanged) |
230 self.modificationChanged.connect(self.__modificationChanged) |
226 self.cursorPositionChanged.connect(self.__cursorPositionChanged) |
231 self.cursorPositionChanged.connect(self.__cursorPositionChanged) |
227 self.modificationAttempted.connect(self.__modificationReadOnly) |
232 self.modificationAttempted.connect(self.__modificationReadOnly) |
228 self.userListActivated.connect(self.__completionListSelected) |
233 self.userListActivated.connect(self.__completionListSelected) |
229 |
234 |
397 self.addActions(self.vm.copyActGrp.actions()) |
402 self.addActions(self.vm.copyActGrp.actions()) |
398 self.addActions(self.vm.viewActGrp.actions()) |
403 self.addActions(self.vm.viewActGrp.actions()) |
399 |
404 |
400 # register images to be shown in autocompletion lists |
405 # register images to be shown in autocompletion lists |
401 self.__registerImages() |
406 self.__registerImages() |
|
407 |
|
408 # connect signals after loading the text |
|
409 self.textChanged.connect(self.__textChanged) |
402 |
410 |
403 def __registerImages(self): |
411 def __registerImages(self): |
404 """ |
412 """ |
405 Private method to register images for autocompletion lists. |
413 Private method to register images for autocompletion lists. |
406 """ |
414 """ |
3234 @keyparam pos position in line to go to (integer) |
3242 @keyparam pos position in line to go to (integer) |
3235 """ |
3243 """ |
3236 self.setCursorPosition(line - 1, pos - 1) |
3244 self.setCursorPosition(line - 1, pos - 1) |
3237 self.ensureVisible(line) |
3245 self.ensureVisible(line) |
3238 |
3246 |
|
3247 def __textChanged(self): |
|
3248 """ |
|
3249 Private slot to handle a change of the editor text. |
|
3250 |
|
3251 This slot defers the handling to the next time the event loop |
|
3252 is run in order to ensure, that cursor position has been updated |
|
3253 by the underlying Scintilla editor. |
|
3254 """ |
|
3255 QTimer.singleShot(0, self.__saveLastEditPosition) |
|
3256 |
|
3257 def __saveLastEditPosition(self): |
|
3258 """ |
|
3259 Private slot to record the last edit position. |
|
3260 """ |
|
3261 self.__lastEditPosition = self.getCursorPosition() |
|
3262 self.lastEditPositionAvailable.emit() |
|
3263 |
|
3264 def isLastEditPositionAvailable(self): |
|
3265 """ |
|
3266 Public method to check, if a last edit position is available. |
|
3267 |
|
3268 @return flag indicating availability (boolean) |
|
3269 """ |
|
3270 return self.__lastEditPosition is not None |
|
3271 |
|
3272 def gotoLastEditPosition(self): |
|
3273 """ |
|
3274 Public method to move the cursor to the last edit position. |
|
3275 """ |
|
3276 self.setCursorPosition(*self.__lastEditPosition) |
|
3277 self.ensureVisible(self.__lastEditPosition[0]) |
|
3278 |
|
3279 def gotoMethodClass(self, goUp=False): |
|
3280 """ |
|
3281 Public method to go to the next Python method or class definition. |
|
3282 """ |
|
3283 if self.isPy3File() or self.isPy2File() or self.isRubyFile(): |
|
3284 lineNo = self.getCursorPosition()[0] |
|
3285 line = self.text(lineNo) |
|
3286 if line.strip().startswith(("class ", "def ", "module ")): |
|
3287 if goUp: |
|
3288 lineNo -= 1 |
|
3289 else: |
|
3290 lineNo += 1 |
|
3291 while True: |
|
3292 if goUp and lineNo < 0: |
|
3293 self.setCursorPosition(0, 0) |
|
3294 self.ensureVisible(0) |
|
3295 return |
|
3296 elif not goUp and lineNo == self.lines(): |
|
3297 lineNo = self.lines() - 1 |
|
3298 self.setCursorPosition(lineNo, self.lineLength(lineNo)) |
|
3299 self.ensureVisible(lineNo) |
|
3300 return |
|
3301 |
|
3302 line = self.text(lineNo) |
|
3303 if line.strip().startswith(("class ", "def ", "module ")): |
|
3304 # try 'def ' first because it occurs more often |
|
3305 first = line.find("def ") |
|
3306 if first > -1: |
|
3307 first += 4 |
|
3308 else: |
|
3309 first = line.find("class ") |
|
3310 if first > -1: |
|
3311 first += 6 |
|
3312 else: |
|
3313 first = line.find("module ") + 7 |
|
3314 match = re.search("[:(]", line) |
|
3315 if match: |
|
3316 end = match.start() |
|
3317 else: |
|
3318 end = self.lineLength(lineNo) - 1 |
|
3319 self.setSelection(lineNo, first, lineNo, end) |
|
3320 self.ensureVisible(lineNo) |
|
3321 return |
|
3322 |
|
3323 if goUp: |
|
3324 lineNo -= 1 |
|
3325 else: |
|
3326 lineNo += 1 |
|
3327 |
|
3328 |
3239 ############################################################################ |
3329 ############################################################################ |
3240 ## Setup methods below |
3330 ## Setup methods below |
3241 ############################################################################ |
3331 ############################################################################ |
3242 |
3332 |
3243 def readSettings(self): |
3333 def readSettings(self): |