diff -Nur ./src/plugins/cppeditor.orig/cppeditor.cpp ./src/plugins/cppeditor/cppeditor.cpp --- ./src/plugins/cppeditor.orig/cppeditor.cpp 2010-02-11 03:07:28.122106992 +1000 +++ ./src/plugins/cppeditor/cppeditor.cpp 2010-02-11 20:47:29.062472254 +1000 @@ -69,7 +69,11 @@ #include #include #include +#include +#include #include +#include +#include #include #include #include @@ -81,6 +85,7 @@ #include #include #include +#include #include #include #include @@ -92,8 +97,10 @@ #include #include #include +#include #include +#include enum { UPDATE_METHOD_BOX_INTERVAL = 150, @@ -1248,6 +1255,7 @@ } if (f) { + // We move here when our direct is DECLARATION TypeOfExpression typeOfExpression; typeOfExpression.setSnapshot(m_modelManager->snapshot()); QList resolvedSymbols = typeOfExpression(QString(), doc, lastSymbol); @@ -1268,8 +1276,126 @@ if (declaration) openCppEditorAt(linkToSymbol(declaration)); } else if (lastSymbol->type()->isFunctionType()) { - if (Symbol *def = findDefinition(lastSymbol)) + // We move here when out direction is IMPLEMENTATION + Symbol *def = findDefinition(lastSymbol); + if (def) + { openCppEditorAt(linkToSymbol(def)); + } + else + { + // Ask for create method implementation + if ( QMessageBox::question(this, + "Implementation not found", + "Implementation does not found. Will I try to create it?", + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes) == QMessageBox::Yes ) + { + Overview o; + QString definition; + QString className; + QString functionName; + QString functionSignature; + QString functionReturnType; + + functionName = o.prettyName( lastSymbol->name() ); + + if (lastSymbol->scope()->isClassScope()) + { + className = o.prettyName( lastSymbol->scope()->owner()->name() ); + className += QLatin1String("::"); + } + + if (lastSymbol->isDeclaration()) + { + o.setShowArgumentNames(true); + o.setShowFunctionSignatures(true); + o.setShowReturnTypes(false); + functionSignature = o.prettyType( lastSymbol->asDeclaration()->type() ); + + o.setShowArgumentNames(false); + o.setShowFunctionSignatures(false); + o.setShowReturnTypes(true); + functionReturnType = o.prettyType( lastSymbol->asDeclaration()->type() ); + } + else + { + return; + } + + definition += QLatin1String("\n"); + definition += QLatin1String("/**\n"); + definition += QLatin1String(" * \n"); + definition += QLatin1String(" */\n"); + definition += functionReturnType; + definition += QLatin1String(" "); + definition += className; + definition += functionName; + definition += functionSignature; + definition += QLatin1String("\n{\n"); + definition += QLatin1String(" /// @TODO"); + definition += QLatin1String("\n}\n"); + + const ProjectExplorer::Project *current_project = + ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projectForFile(file()->fileName()); + if (!current_project) + { + std::cout << "Can't locate current project\n"; + return; + } + + Snapshot::iterator it; + QFileInfo headerFI(file()->fileName()); + const QString headerBaseName = headerFI.completeBaseName(); + const QString headerPath = headerFI.absolutePath(); + const QString headerExt = headerFI.suffix(); + + for (it = snapshot.begin(); it != snapshot.end(); ++it) + { + const ProjectExplorer::Project *project = + ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projectForFile(it.key()); + + if (project == current_project) + { + const QString sourceFileName(it.value()->fileName()); + const QFileInfo sourceFI(sourceFileName); + Document::Ptr doc(it.value()); + if (headerBaseName == sourceFI.completeBaseName() && + headerPath == sourceFI.absolutePath() && + // Skip myself + headerExt != sourceFI.suffix()) + { + TextEditor::ITextEditable *editable = 0; + bool isHeaderIncluded = false; + const QStringList includes = doc->includedFiles(); + foreach (const QString &include, includes) + { + const QFileInfo fi(include); + if(fi.fileName() == headerFI.fileName()) + { + isHeaderIncluded = true; + break; + } + } + + if(isHeaderIncluded) + editable = qobject_cast( openEditorAt(sourceFileName, 0, 0) ); + + if(editable) + { + const QString contents = editable->contents(); + editable->convertPosition(contents.length(), &line, &column); + editable->gotoLine(line, column); + editable->insert(definition); + editable->gotoLine(line + 3, 4); + } + + break; + } + } + } + } + } } }