Example #1
0
void FileEditorWnd::OnCharacterAdded(wxStyledTextEvent& event)
{
	char chr = (char)event.GetKey();
	int currentLine = m_textCtrl->GetCurrentLine();
	if (chr== '\n')
	{
		int lineInd = 0;
		if (currentLine>0)
			lineInd = m_textCtrl->GetLineIndentation(currentLine-1);
		if (lineInd==0)
			return;

		m_textCtrl->SetLineIndentation(currentLine, lineInd);
		m_textCtrl->LineEnd();
		return;
	}

	char previousChr = m_textCtrl->GetCharAt(m_textCtrl->GetCurrentPos() - 2 );
	if (chr == '.' || (chr == '>' && previousChr == '-'))
		showAutoComplete();
	else if (chr == '(')
		showCallTip(true);
	else if (chr == ')')
	{
		if (m_textCtrl->CallTipActive())
			m_textCtrl->CallTipCancel();
	}
	else if (m_textCtrl->CallTipActive())
		showCallTip(false);
}
void AutoCompletion::update(int character)
{
	const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI();
	if (!_funcCompletionActive && nppGUI._autocStatus == nppGUI.autoc_func)
		return;

	if (nppGUI._funcParams || _funcCalltip.isVisible()) {
		if (_funcCalltip.updateCalltip(character)) {	//calltip visible because triggered by autocomplete, set mode
			_activeCompletion = CompletionFunc;
			return;	//only return in case of success, else autocomplete
		}
	}

	if (!character)
		return;

	//If autocomplete already active, let Scintilla handle it
	if (_pEditView->execute(SCI_AUTOCACTIVE) != 0)
		return;

	const int wordSize = 64;
	TCHAR s[wordSize];
	_pEditView->getWordToCurrentPos(s, wordSize);
	
	if (lstrlen(s) >= int(nppGUI._autocFromLen))
	{
		if (nppGUI._autocStatus == nppGUI.autoc_word)
			showWordComplete(false);
		else if (nppGUI._autocStatus == nppGUI.autoc_func)
			showAutoComplete();
		else if (nppGUI._autocStatus == nppGUI.autoc_func_and_word)
			showWordAndFuncComplete();	// 新增的函数和单词自动完成
	}
}
void AutoCompletion::update(int character)
{
    const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI();
    if (!_funcCompletionActive && nppGUI._autocStatus == nppGUI.autoc_func)
        return;

    if (nppGUI._funcParams || _funcCalltip.isVisible())
    {
        if (_funcCalltip.updateCalltip(character)) // calltip visible because triggered by autocomplete, set mode
        {
            _activeCompletion = CompletionFunc;
            return; // Only return in case of success, else autocomplete
        }
    }

    if (!character)
        return;

    //If autocomplete already active, let Scintilla handle it
    if (_pEditView->execute(SCI_AUTOCACTIVE) != 0)
        return;

    const int wordSize = 64;
    TCHAR s[wordSize];
    _pEditView->getWordToCurrentPos(s, wordSize);

    if (lstrlen(s) >= int(nppGUI._autocFromLen))
    {
        if (nppGUI._autocStatus == nppGUI.autoc_word)
        {
            // Walk around - to avoid the crash under Chinese Windows7 ANSI doc mode
            if (!_pEditView->isCJK())
            {
                showWordComplete(false);
            }
            else
            {
                if ((_pEditView->getCurrentBuffer())->getUnicodeMode() != uni8Bit)
                    showWordComplete(false);
            }
        }
        else if (nppGUI._autocStatus == nppGUI.autoc_func)
            showAutoComplete();

        /*
        if (nppGUI._autocStatus == nppGUI.autoc_word)
        	showWordComplete(false);
        else if (nppGUI._autocStatus == nppGUI.autoc_func)
        	showAutoComplete();
        */
    }
}
Example #4
0
void MLScriptEditor::keyPressEvent( QKeyEvent * e )
{
	switch(e->key())
	{
		case (Qt::Key_Return):
		case (Qt::Key_Enter):
		{
			if (comp->popup()->isHidden())
			{
				QTextBlock b = textCursor().block();
				QRegExp tab("(\\t)+\\w");
				bool tabfound = (b.text().indexOf(tab) == 0);
				textCursor().insertText("\n");
				if (tabfound)
				{
					QString cap = tab.cap();
					int tabcount = cap.lastIndexOf(QRegExp("\\t")) + 1;
					QString tabst;
					for(int ii = 0;ii < tabcount;++ii)
						tabst += '\t';
					textCursor().insertText(tabst);
				}
			}
			else
			{
				insertSuggestedWord(comp->currentCompletion());
				comp->popup()->hide();
			}
			return;
		}
		case (Qt::Key_Tab):
		{
			if (!comp->popup()->isHidden())
			{
				insertSuggestedWord(comp->currentCompletion());
				comp->popup()->hide();
				return;
			}
			break;
		}
	}
	QPlainTextEdit::keyPressEvent(e);
	//!(e->text().isEmpty) is meaningful: you need it when (only) a modifier (SHIFT/CTRL) has been pressed in order to avoid the autocompleter to be visualized
	if (!(e->text().isEmpty()) && (e->text().indexOf(synt->worddelimiter) == -1))
		showAutoComplete(e);
}