/* Autocompletion in NW/NWNI */ void autoCompletionInConsoleMode(wchar_t ** commandLine, unsigned int *cursorLocation) { char *multiByteString = NULL; wchar_t *wideString = NULL; int sizeToAlloc = 0; unsigned int nbrCharInString; multiByteString = wide_string_to_UTF8(*commandLine); nbrCharInString = wcslen(*commandLine); doCompletion(&multiByteString, cursorLocation, &nbrCharInString); wideString = to_wide_string(multiByteString); /* Copy the new string in a buffer wich size is a multiple of 1024 */ sizeToAlloc = 1024 * (wcslen(wideString) / 1024 + 1); FREE(*commandLine); *commandLine = MALLOC(sizeof(**commandLine) * sizeToAlloc); wcscpy(*commandLine, wideString); FREE(wideString); FREE(multiByteString); }
bool EditorCompletion::eventFilter( QObject *o, QEvent *e ) { if ( !enabled ) return false; if ( e->type() == QEvent::KeyPress && ::qobject_cast<Editor*>(o) ) { curEditor = (Editor*)o; QKeyEvent *ke = (QKeyEvent*)e; if ( ke->key() == Qt::Key_Tab ) { QString s = curEditor->textCursor()->paragraph()->string()->toString(). left( curEditor->textCursor()->index() ); if ( curEditor->document()->hasSelection( Q3TextDocument::Standard ) || s.simplified().isEmpty() ) { if ( curEditor->document()->indent() ) { curEditor->indent(); int i = 0; for ( ; i < curEditor->textCursor()->paragraph()->length() - 1; ++i ) { if ( curEditor->textCursor()->paragraph()->at( i )->c != ' ' && curEditor->textCursor()->paragraph()->at( i )->c != '\t' ) break; } curEditor->drawCursor( false ); curEditor->textCursor()->setIndex( i ); curEditor->drawCursor( true ); } else { curEditor->insert( QString::fromLatin1("\t") ); } return true; } } if ( functionLabel->isVisible() ) { if ( ke->key() == Qt::Key_Up && ( ke->modifiers() & Qt::ControlModifier ) == Qt::ControlModifier ) { functionLabel->gotoPrev(); return true; } else if ( ke->key() == Qt::Key_Down && ( ke->modifiers() & Qt::ControlModifier ) == Qt::ControlModifier ) { functionLabel->gotoNext(); return true; } } if ( ke->text().length() && !( ke->modifiers() & Qt::AltModifier ) && (ke->text().isEmpty() || (!ke->text().isEmpty() && ke->text()[0] >= 32)) || ( ke->text() == QString::fromLatin1("\t") && !( ke->modifiers() & Qt::ControlModifier ) ) ) { if ( ke->key() == Qt::Key_Tab ) { if ( curEditor->textCursor()->index() == 0 && curEditor->textCursor()->paragraph()->isListItem() ) return false; if ( doCompletion() ) return true; } else if ( ke->key() == Qt::Key_Period && ( curEditor->textCursor()->index() == 0 || curEditor->textCursor()->paragraph()->at( curEditor->textCursor()->index() - 1 )->c != '.' ) || ke->key() == Qt::Key_Greater && curEditor->textCursor()->index() > 0 && curEditor->textCursor()->paragraph()->at( curEditor->textCursor()->index() - 1 )->c == '-' ) { doObjectCompletion(); } else { if ( !doArgumentHint( ke->text() == QString::fromLatin1("(") ) ) functionLabel->hide(); } } } else if ( o == completionPopup || o == completionListBox || o == completionListBox->viewport() ) { if ( e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent*)e; if ( ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Tab ) { if ( ke->key() == Qt::Key_Tab && completionListBox->count() > 1 && completionListBox->currentItem() < (int)completionListBox->count() - 1 ) { completionListBox->setCurrentItem( completionListBox->currentItem() + 1 ); return true; } completeCompletion(); return true; } else if ( ke->key() == Qt::Key_Left || ke->key() == Qt::Key_Right || ke->key() == Qt::Key_Up || ke->key() == Qt::Key_Down || ke->key() == Qt::Key_Home || ke->key() == Qt::Key_End || ke->key() == Qt::Key_PageUp || ke->key() == Qt::Key_PageDown ) { if (o == completionPopup) return QApplication::sendEvent(completionListBox, ke); else return false; } else if ( ke->key() != Qt::Key_Shift && ke->key() != Qt::Key_Control && ke->key() != Qt::Key_Alt ) { int l = searchString.length(); if ( ke->key() == Qt::Key_Backspace ) { searchString.remove( searchString.length() - 1, 1 ); } else { searchString += ke->text(); l = 1; } if ( !l || !continueComplete() ) { completionPopup->close(); curEditor->setFocus(); } QApplication::sendEvent( curEditor, e ); return true; } } else if ( e->type() == QEvent::MouseButtonDblClick ) { completeCompletion(); return true; } } if ( (o == functionLabel || qobject_cast<Editor*>(o)) && functionLabel->isVisible() ) { if ( e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent*)e; if ( ke->key() == Qt::Key_Escape ) { functionLabel->hide(); } else { if ( !doArgumentHint( ke->text() == QString::fromLatin1("(") ) ) functionLabel->hide(); if ( o == functionLabel ) { QApplication::sendEvent( curEditor, e ); return true; } } } } return false; }
/*--------------------------------------------------------------------------*/ types::Function::ReturnValue sci_completion(types::typed_list &in, int _iRetCount, types::typed_list &out) { types::String* pStrSomechars = NULL; char* pcSomechars = NULL; if (in.size() < 1 || in.size() > 2) { Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected."), "completion", 1, 2); return types::Function::Error; } if (_iRetCount > 6) { Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected."), "completion", 1, 6); return types::Function::Error; } if (in[0]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "completion", 1); return types::Function::Error; } pStrSomechars = in[0]->getAs<types::String>(); if (pStrSomechars->isScalar() == false) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "completion", 1); return types::Function::Error; } pcSomechars = wide_string_to_UTF8(pStrSomechars->get(0)); if (in.size() == 1) { if (_iRetCount == 1) { out.push_back(doCompletion(pcSomechars, &completion)); } else { out.resize(_iRetCount); switch (_iRetCount) { case 6 : out[5] = doCompletion(pcSomechars, &completionOnFiles); case 5 : out[4] = doCompletion(pcSomechars, &completionOnHandleGraphicsProperties); case 4 : out[3] = doCompletion(pcSomechars, &completionOnMacros); case 3 : out[2] = doCompletion(pcSomechars, &completionOnVariables); case 2 : out[1] = doCompletion(pcSomechars, &completionOnCommandWords); default : out[0] = doCompletion(pcSomechars, &completionOnFunctions); } } } else // if(in.size() == 2) { if (_iRetCount != 1) { Scierror(78, _("%s: Wrong number of output argument(s): %d expected."), "completion", 1); return types::Function::Error; } if (in[1]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "completion", 2); return types::Function::Error; } types::String* pStrDictionary = in[1]->getAs<types::String>(); if (pStrDictionary->isScalar() == false) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "completion", 2); return types::Function::Error; } wchar_t* wcsDictionary = pStrDictionary->get(0); if ( wcscmp(wcsDictionary, L"functions") == 0 ) { out.push_back(doCompletion(pcSomechars, &completionOnFunctions)); } else if ( wcscmp(wcsDictionary, L"commands") == 0 ) { out.push_back(doCompletion(pcSomechars, &completionOnCommandWords)); } else if ( wcscmp(wcsDictionary, L"variables") == 0 ) { out.push_back(doCompletion(pcSomechars, &completionOnVariables)); } else if ( wcscmp(wcsDictionary, L"macros") == 0 ) { out.push_back(doCompletion(pcSomechars, &completionOnMacros)); } else if ( wcscmp(wcsDictionary, L"graphic_properties") == 0 ) { out.push_back(doCompletion(pcSomechars, &completionOnHandleGraphicsProperties)); } else if ( wcscmp(wcsDictionary, L"files") == 0 ) { out.push_back(doCompletion(pcSomechars, &completionOnFiles)); } else { Scierror(999, _("%s: Wrong value for input argument: '%s', '%s', '%s', '%s', '%s' or '%s' expected.\n"), "completion", "functions", "commands", "variables", "macros", "graphic_properties", "files"); return types::Function::Error; } } FREE(pcSomechars); return types::Function::OK; }