void QuickOpenFunctionDialog::gotoFile( QString name ) { FunctionModel *fmodel; FunctionList funcList; FunctionDom fdom; for( FunctionList::ConstIterator it = m_functionDefList.begin() ; it!=m_functionDefList.end() ; ++it ){ fdom = *it; fmodel = fdom.data(); if( fmodel->name() == name ){ funcList.append( fdom ); } } if( funcList.count() == 1 ){ fdom = funcList.first(); fmodel = fdom.data(); QString fileNameStr = fmodel->fileName(); int startline, startcol; fmodel->getStartPosition( &startline, &startcol ); m_part->partController()->editDocument( KURL( fileNameStr), startline, startcol ); selectClassViewItem( ItemDom(&(*fmodel)) ); }else if( funcList.count() > 1 ){ QString fileStr; QuickOpenFunctionChooseForm fdlg( this, name.ascii() ); for( FunctionList::Iterator it = funcList.begin() ; it!=funcList.end() ; ++it ){ fmodel = (*it).data(); fdlg.argBox->insertItem( m_part->languageSupport()->formatModelItem(fmodel) + (fmodel->scope().isEmpty() ? "" : " (in " + fmodel->scope().join("::") + ")")); fileStr = KURL( fmodel->fileName() ).fileName(); KURL full_url( fmodel->fileName() ); KURL base_url( part()->project()->projectDirectory()+"/" ); fdlg.setRelativePath(fdlg.fileBox->count(), KURL::relativeURL( base_url, full_url )); fdlg.fileBox->insertItem(fileStr); } if( fdlg.exec() ){ int id = fdlg.argBox->currentItem(); if( id>-1 && id < (int) funcList.count() ){ FunctionModel *model = funcList[id].data(); int line, col; model->getStartPosition( &line, &col ); selectClassViewItem( ItemDom(&(*model)) ); QString fileNameStr = model->fileName(); m_part->partController()->editDocument( KURL(fileNameStr), line ); } } } else{ KMessageBox::error( this, i18n("Error: cannot find matching name function.") ); } accept(); }
void QuickOpenFunctionDialog::slotTextChangedDelayed() { QString text = nameEdit->text(); QString txt = text; QStringList parts = QStringList::split("::", text); if(text.endsWith("::") || parts.isEmpty()) { txt = ""; }else{ txt = parts.back(); parts.pop_back(); } QValueList<QRegExp> regExpParts; for( QStringList::const_iterator it = parts.begin(); it != parts.end(); ++it ) { regExpParts << QRegExp( *it, false, true ); } QString scope = parts.join("::"); if( m_scope != scope ) { if( !scope.startsWith(m_scope) ) { ///Not a specialization, so reload all function-definitions fillItemList(); } if(!parts.isEmpty()) { FunctionList accepted; QStringList acceptedItems; FunctionList::iterator it = m_functionDefList.begin(); while(it != m_functionDefList.end()) { QStringList scope = (*it)->scope(); QValueList<QRegExp>::iterator mit = regExpParts.begin(); QStringList::iterator sit = scope.begin(); bool fail = false; while(mit != regExpParts.end()) { while(sit != scope.end() && !(*mit).exactMatch( *sit ) ) ++sit; if(sit == scope.end()) { fail = true; break; } ++mit; } if(!fail) { accepted.append(*it); acceptedItems << (*it)->name(); } ++it; } m_functionDefList = accepted; m_items = acceptedItems; QStringList_unique( m_items ); } m_scope = scope; } itemList->clear(); itemList->insertStringList( wildCardCompletion( txt ) ); itemList->setCurrentItem(0); }