Hi all,

I prepare patch that may be helpful in development process.

With this patch you can go to Header file, write function prototype (or method 
prototype in class
definition), press Shift-F2 (or press Right mouse button on prototype and 
select item "Switch
between Method Declaration/Definition"), in case when definition does not 
present, you can see
message box: Implementation does not found. Will I try to create it? [Yes/No]
If you answer Yes, template of method will created and you moved to it.

Path is attached to this letter.

For russian-speak guys avail my description in blog:
http://hatred.homelinux.net/wiki/zhurnal:2010-02-11_20.47_qt_creator_i_avtomaticheskoe_sozdanie_realizacii_metoda_prototipa
also, here you can see screens that demonstrate work of patch.

-- 
WBR
Alexander Drozdov
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 <utils/uncommentselection.h>
 #include <extensionsystem/pluginmanager.h>
 #include <projectexplorer/projectexplorerconstants.h>
+#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/session.h>
 #include <texteditor/basetextdocument.h>
+#include <texteditor/basetexteditor.h>
+#include <texteditor/itexteditable.h>
 #include <texteditor/fontsettings.h>
 #include <texteditor/texteditorconstants.h>
 #include <texteditor/textblockiterator.h>
@@ -81,6 +85,7 @@
 #include <QtCore/QStack>
 #include <QtCore/QSettings>
 #include <QtCore/QSignalMapper>
+#include <QtCore/QFileInfo>
 #include <QtGui/QAction>
 #include <QtGui/QApplication>
 #include <QtGui/QHeaderView>
@@ -92,8 +97,10 @@
 #include <QtGui/QToolBar>
 #include <QtGui/QTreeView>
 #include <QtGui/QSortFilterProxyModel>
+#include <QtGui/QMessageBox>
 
 #include <sstream>
+#include <iostream>
 
 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<LookupItem> 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<TextEditor::ITextEditable *>( 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;
+                        }
+                    }
+                }
+            }
+        }
     }
 }
 
_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-creator

Reply via email to