void AddMethodDialog::accept() { m_cppSupport->partController() ->editDocument( KURL( m_klass->fileName() ) ); KTextEditor::EditInterface* editIface = dynamic_cast<KTextEditor::EditInterface*>( m_cppSupport->partController() ->activePart() ); if ( !editIface ) { /// @todo show messagebox QDialog::accept(); return ; } int line, column; m_klass->getEndPosition( &line, &column ); // compute the insertion point map QMap<QString, QPair<int, int> > points; QStringList accessList; const FunctionList functionList = m_klass->functionList(); for ( FunctionList::ConstIterator it = functionList.begin(); it != functionList.end(); ++it ) { int funEndLine, funEndColumn; ( *it ) ->getEndPosition( &funEndLine, &funEndColumn ); QString access = accessID( *it ); QPair<int, int> funEndPoint = qMakePair( funEndLine, funEndColumn ); if ( !points.contains( access ) || points[ access ] < funEndPoint ) { accessList.remove( access ); accessList.push_back( access ); // move 'access' at the end of the list points[ access ] = funEndPoint; } } int insertedLine = 0; accessList += newAccessList( accessList ); for ( QStringList::iterator it = accessList.begin(); it != accessList.end(); ++it ) { QListViewItem* item = methods->firstChild(); while ( item ) { QListViewItem * currentItem = item; item = item->nextSibling(); if ( currentItem->text( 1 ) != *it ) continue; QString access = ( *it ).lower(); bool isInline = currentItem->text( 0 ) == "True"; QString str = isInline ? functionDefinition( currentItem ) : functionDeclaration( currentItem ); QPair<int, int> pt; if ( points.contains( *it ) ) { pt = points[ *it ]; } else { str.prepend( access + ":\n" ); points[ *it ] = qMakePair( line - 1, 0 ); pt = points[ *it ]; // end of class declaration } editIface->insertText( pt.first + insertedLine + 1, 0 /*pt.second*/, str ); insertedLine += str.contains( QChar( '\n' ) ); } } m_cppSupport->backgroundParser() ->addFile( m_klass->fileName() ); QString str; QListViewItem* item = methods->firstChild(); while ( item ) { QListViewItem * currentItem = item; item = item->nextSibling(); QString str = functionDefinition( currentItem ); if ( str.isEmpty() ) continue; QString implementationFile = currentItem->text( 5 ); if ( currentItem->text( 0 ) == "True" ) implementationFile = m_klass->fileName(); QFileInfo fileInfo( implementationFile ); if ( !QFile::exists( fileInfo.absFilePath() ) ) { if ( KDevCreateFile * createFileSupp = m_cppSupport->extension<KDevCreateFile>( "KDevelop/CreateFile" ) ) createFileSupp->createNewFile( fileInfo.extension(), fileInfo.dirPath( true ), fileInfo.baseName() ); } m_cppSupport->partController() ->editDocument( KURL( implementationFile ) ); editIface = dynamic_cast<KTextEditor::EditInterface*>( m_cppSupport->partController() ->activePart() ); if ( !editIface ) continue; bool isInline = currentItem->text( 0 ) == "True"; if ( !isInline ) { editIface->insertLine( editIface->numLines(), QString::fromLatin1( "" ) ); editIface->insertText( editIface->numLines() - 1, 0, str ); m_cppSupport->backgroundParser() ->addFile( implementationFile ); } } QDialog::accept(); }