QScintilla/Editor.py

changeset 6306
af71f34a0cfb
parent 6305
7652b925c25e
child 6319
df201b9fbad4
child 6426
f072dd2edb0f
equal deleted inserted replaced
6305:7652b925c25e 6306:af71f34a0cfb
408 self.__acWatchdog.setInterval( 408 self.__acWatchdog.setInterval(
409 Preferences.getEditor("AutoCompletionWatchdogTime")) 409 Preferences.getEditor("AutoCompletionWatchdogTime"))
410 self.__acWatchdog.timeout.connect(self.autoCompleteQScintilla) 410 self.__acWatchdog.timeout.connect(self.autoCompleteQScintilla)
411 411
412 self.userListActivated.connect(self.__completionListSelected) 412 self.userListActivated.connect(self.__completionListSelected)
413 self.SCN_CHARADDED.connect(self.__charAddedPermanent) 413 self.SCN_CHARADDED.connect(self.__charAdded)
414 self.SCN_AUTOCCANCELLED.connect(self.__autocompletionCancelled)
414 415
415 self.__completionListHookFunctions = {} 416 self.__completionListHookFunctions = {}
416 self.__completionListAsyncHookFunctions = {} 417 self.__completionListAsyncHookFunctions = {}
417 self.__setAutoCompletion() 418 self.__setAutoCompletion()
418 419
4418 Preferences.getEditor("AutoCompletionFillups")) 4419 Preferences.getEditor("AutoCompletionFillups"))
4419 self.setAutoCompletionCaseSensitivity( 4420 self.setAutoCompletionCaseSensitivity(
4420 Preferences.getEditor("AutoCompletionCaseSensitivity")) 4421 Preferences.getEditor("AutoCompletionCaseSensitivity"))
4421 self.setAutoCompletionReplaceWord( 4422 self.setAutoCompletionReplaceWord(
4422 Preferences.getEditor("AutoCompletionReplaceWord")) 4423 Preferences.getEditor("AutoCompletionReplaceWord"))
4424 self.setAutoCompletionThreshold(0)
4423 try: 4425 try:
4424 self.setAutoCompletionUseSingle( 4426 self.setAutoCompletionUseSingle(
4425 Preferences.getEditor("AutoCompletionShowSingle")) 4427 Preferences.getEditor("AutoCompletionShowSingle"))
4426 except AttributeError: 4428 except AttributeError:
4427 self.setAutoCompletionShowSingle( 4429 self.setAutoCompletionShowSingle(
4431 self.setAutoCompletionSource(QsciScintilla.AcsDocument) 4433 self.setAutoCompletionSource(QsciScintilla.AcsDocument)
4432 elif autoCompletionSource == QsciScintilla.AcsAPIs: 4434 elif autoCompletionSource == QsciScintilla.AcsAPIs:
4433 self.setAutoCompletionSource(QsciScintilla.AcsAPIs) 4435 self.setAutoCompletionSource(QsciScintilla.AcsAPIs)
4434 else: 4436 else:
4435 self.setAutoCompletionSource(QsciScintilla.AcsAll) 4437 self.setAutoCompletionSource(QsciScintilla.AcsAll)
4436 if Preferences.getEditor("AutoCompletionEnabled"):
4437 if not self.__completionListHookFunctions and \
4438 not self.__completionListAsyncHookFunctions:
4439 self.setAutoCompletionThreshold(
4440 Preferences.getEditor("AutoCompletionThreshold"))
4441 else:
4442 self.setAutoCompletionThreshold(0)
4443 else:
4444 self.setAutoCompletionThreshold(-1)
4445 self.setAutoCompletionSource(QsciScintilla.AcsNone)
4446 4438
4447 self.maxLines = Preferences.getEditor("AutoCompletionMaxLines") 4439 self.maxLines = Preferences.getEditor("AutoCompletionMaxLines")
4448 self.maxChars = Preferences.getEditor("AutoCompletionMaxChars") 4440 self.maxChars = Preferences.getEditor("AutoCompletionMaxChars")
4449 4441
4450 def __setCallTips(self): 4442 def __setCallTips(self):
4515 4507
4516 @param enable flag indicating the desired autocompletion status 4508 @param enable flag indicating the desired autocompletion status
4517 (boolean) 4509 (boolean)
4518 """ 4510 """
4519 if enable: 4511 if enable:
4520 self.setAutoCompletionThreshold(
4521 Preferences.getEditor("AutoCompletionThreshold"))
4522 autoCompletionSource = \ 4512 autoCompletionSource = \
4523 Preferences.getEditor("AutoCompletionSource") 4513 Preferences.getEditor("AutoCompletionSource")
4524 if autoCompletionSource == QsciScintilla.AcsDocument: 4514 if autoCompletionSource == QsciScintilla.AcsDocument:
4525 self.setAutoCompletionSource(QsciScintilla.AcsDocument) 4515 self.setAutoCompletionSource(QsciScintilla.AcsDocument)
4526 elif autoCompletionSource == QsciScintilla.AcsAPIs: 4516 elif autoCompletionSource == QsciScintilla.AcsAPIs:
4527 self.setAutoCompletionSource(QsciScintilla.AcsAPIs) 4517 self.setAutoCompletionSource(QsciScintilla.AcsAPIs)
4528 else: 4518 else:
4529 self.setAutoCompletionSource(QsciScintilla.AcsAll) 4519 self.setAutoCompletionSource(QsciScintilla.AcsAll)
4530 else: 4520
4531 self.setAutoCompletionThreshold(-1)
4532 self.setAutoCompletionSource(QsciScintilla.AcsNone)
4533
4534 def __toggleAutoCompletionEnable(self): 4521 def __toggleAutoCompletionEnable(self):
4535 """ 4522 """
4536 Private slot to handle the Enable Autocompletion context menu entry. 4523 Private slot to handle the Enable Autocompletion context menu entry.
4537 """ 4524 """
4538 if self.menuActs["AutoCompletionEnable"].isChecked(): 4525 if self.menuActs["AutoCompletionEnable"].isChecked():
4548 """ 4535 """
4549 Private slot called to handle the user entering a character. 4536 Private slot called to handle the user entering a character.
4550 4537
4551 @param charNumber value of the character entered (integer) 4538 @param charNumber value of the character entered (integer)
4552 """ 4539 """
4540 char = chr(charNumber)
4541 # update code documentation viewer
4542 if char == "(" and \
4543 Preferences.getDocuViewer("ShowInfoOnOpenParenthesis"):
4544 self.vm.showEditorInfo(self)
4545
4553 if self.isListActive(): 4546 if self.isListActive():
4554 char = chr(charNumber)
4555 if self.__isStartChar(char): 4547 if self.__isStartChar(char):
4556 self.cancelList() 4548 self.cancelList()
4557 self.autoComplete(auto=True, context=True) 4549 self.autoComplete(auto=True, context=True)
4558 return 4550 return
4559 elif char == '(': 4551 elif char == '(':
4632 self.tr("""The completion list provider '{0}' was already""" 4624 self.tr("""The completion list provider '{0}' was already"""
4633 """ registered. Ignoring duplicate request.""") 4625 """ registered. Ignoring duplicate request.""")
4634 .format(key)) 4626 .format(key))
4635 return 4627 return
4636 4628
4637 if not self.__completionListHookFunctions and \
4638 not self.__completionListAsyncHookFunctions:
4639 if self.autoCompletionThreshold() > 0:
4640 self.setAutoCompletionThreshold(0)
4641 self.SCN_CHARADDED.connect(self.__charAdded)
4642 self.SCN_AUTOCCANCELLED.connect(self.__autocompletionCancelled)
4643
4644 if asynchroneous: 4629 if asynchroneous:
4645 self.__completionListAsyncHookFunctions[key] = func 4630 self.__completionListAsyncHookFunctions[key] = func
4646 else: 4631 else:
4647 self.__completionListHookFunctions[key] = func 4632 self.__completionListHookFunctions[key] = func
4648 4633
4656 """ 4641 """
4657 if key in self.__completionListHookFunctions: 4642 if key in self.__completionListHookFunctions:
4658 del self.__completionListHookFunctions[key] 4643 del self.__completionListHookFunctions[key]
4659 elif key in self.__completionListAsyncHookFunctions: 4644 elif key in self.__completionListAsyncHookFunctions:
4660 del self.__completionListAsyncHookFunctions[key] 4645 del self.__completionListAsyncHookFunctions[key]
4661
4662 if not self.__completionListHookFunctions and \
4663 not self.__completionListAsyncHookFunctions:
4664 self.SCN_CHARADDED.disconnect(self.__charAdded)
4665 self.SCN_AUTOCCANCELLED.disconnect(self.__autocompletionCancelled)
4666 if self.autoCompletionThreshold() == 0:
4667 self.setAutoCompletionThreshold(
4668 Preferences.getEditor("AutoCompletionThreshold"))
4669 4646
4670 def getCompletionListHook(self, key): 4647 def getCompletionListHook(self, key):
4671 """ 4648 """
4672 Public method to get the registered completion list provider. 4649 Public method to get the registered completion list provider.
4673 4650
4685 4662
4686 @keyparam auto flag indicating a call from the __charAdded method 4663 @keyparam auto flag indicating a call from the __charAdded method
4687 (boolean) 4664 (boolean)
4688 @keyparam context flag indicating to complete a context (boolean) 4665 @keyparam context flag indicating to complete a context (boolean)
4689 """ 4666 """
4690 if auto and self.autoCompletionThreshold() == -1: 4667 if auto and not Preferences.getEditor("AutoCompletionEnabled"):
4691 # auto-completion is disabled 4668 # auto-completion is disabled
4692 return 4669 return
4693 4670
4694 if self.isListActive(): 4671 if self.isListActive():
4695 self.cancelList() 4672 self.cancelList()
5061 return ct 5038 return ct
5062 5039
5063 ################################################################# 5040 #################################################################
5064 ## Methods needed by the code documentation viewer 5041 ## Methods needed by the code documentation viewer
5065 ################################################################# 5042 #################################################################
5066
5067 def __charAddedPermanent(self, charNumber):
5068 """
5069 Private slot called to handle the user entering a character.
5070
5071 Note: This slot is always connected independent of the auto-completion
5072 and calltips handling __charAdded() slot.
5073
5074 @param charNumber value of the character entered (integer)
5075 """
5076 char = chr(charNumber)
5077 if char == "(" and \
5078 Preferences.getDocuViewer("ShowInfoOnOpenParenthesis"):
5079 self.vm.showEditorInfo(self)
5080 5043
5081 def __showCodeInfo(self): 5044 def __showCodeInfo(self):
5082 """ 5045 """
5083 Private slot to handle the context menu action to show code info. 5046 Private slot to handle the context menu action to show code info.
5084 """ 5047 """

eric ide

mercurial