SVN commit 1005410 by rzarazua: Added functionality to insert generated classes into already existing files M +24 -6 kdevelop/languages/cpp/codegen/cppnewclass.cpp M +25 -9 kdevplatform/language/codegen/createclass.cpp M +12 -0 kdevplatform/language/codegen/createclass.h M +1 -1 kdevplatform/language/codegen/ui/outputlocation.ui --- trunk/KDE/kdevelop/languages/cpp/codegen/cppnewclass.cpp #1005409:1005410 @@ -184,12 +184,29 @@ Identifier classId = Identifier(name()); // Header protector - QString headerGuard = headerUrl().fileName().toUpper().replace('.', '_').replace('-','_'); - if (m_namespaces.size()) - headerGuard.prepend(m_namespaces.join("_").toUpper() + '_'); + //If this is a new file add the header guard + QString headerGuard; + bool headerExists; + { + QFileInfo info(headerUrl().toLocalFile()); + headerExists = info.exists(); + } + if(!headerExists) + { + if(headerPosition() != SimpleCursor()) + { + kWarning() << "A header position was specified for a new file, ignoring."; + setHeaderPosition(SimpleCursor()); + } + + headerGuard = headerUrl().fileName().toUpper().replace('.', '_').replace('-','_'); + if (m_namespaces.size()) + headerGuard.prepend(m_namespaces.join("_").toUpper() + '_'); - output << "#ifndef " << headerGuard << '\n'; - output << "#define " << headerGuard << "\n\n"; + + output << "#ifndef " << headerGuard << '\n'; + output << "#define " << headerGuard << "\n\n"; + } //Add #includes @@ -263,7 +280,8 @@ for(int i = 0; i < m_namespaces.size(); ++i) output << "}\n\n"; - output << "#endif // " << headerGuard << '\n'; + if(!headerExists) + output << "#endif // " << headerGuard << '\n'; DocumentChangeSet changes; changes.addChange(DocumentChange(IndexedString(headerUrl().path()), --- trunk/KDE/kdevplatform/language/codegen/createclass.cpp #1005409:1005410 @@ -631,8 +631,17 @@ Ui::OutputLocationDialog* output; CreateClassWizard* parent; + + void updateRanges(KIntNumInput * line, KIntNumInput * column, bool enable); }; +void OutputPagePrivate::updateRanges(KIntNumInput * line, KIntNumInput * column, bool enable) +{ + kDebug() << "Updating Ranges, file exists: " << enable; + line->setEnabled(enable); + column->setEnabled(enable); +} + OutputPage::OutputPage(CreateClassWizard* parent) : QWizardPage(parent) , d(new OutputPagePrivate) @@ -647,16 +656,11 @@ d->output->headerUrl->fileDialog()->setOperationMode( KFileDialog::Saving ); d->output->implementationUrl->setMode( KFile::File | KFile::LocalOnly ); d->output->implementationUrl->fileDialog()->setOperationMode( KFileDialog::Saving ); - - registerField("headerUrl*", d->output->headerUrl); - registerField("implementationUrl*", d->output->implementationUrl); - registerField("headerLine", d->output->headerLineNumber); - registerField("headerColumn", d->output->headerColumnNumber); - registerField("implementationLine", d->output->implementationLineNumber); - registerField("implementationColumn", d->output->implementationColumnNumber); connect(d->output->lowerFilenameCheckBox, SIGNAL(stateChanged(int)), this, SLOT(updateFileNames())); + connect(d->output->headerUrl, SIGNAL(textChanged(const QString &)), this, SLOT(updateHeaderRanges(const QString &))); + connect(d->output->implementationUrl, SIGNAL(textChanged(const QString &)), this, SLOT(updateImplementationRanges(const QString &))); } void OutputPage::initializePage() @@ -670,6 +674,18 @@ d->output->implementationUrl->setUrl(d->parent->generator()->implementationUrlFromBase(d->parent->d->baseUrl, d->output->lowerFilenameCheckBox->isChecked())); } +void OutputPage::updateHeaderRanges(const QString & url) +{ + QFileInfo info(url); + d->updateRanges(d->output->headerLineNumber, d->output->headerColumnNumber, info.exists() && !info.isDir()); +} + +void OutputPage::updateImplementationRanges(const QString & url) +{ + QFileInfo info(url); + d->updateRanges(d->output->implementationLineNumber, d->output->implementationColumnNumber, info.exists() && !info.isDir()); +} + bool OutputPage::isComplete() const { return !d->output->headerUrl->url().url().isEmpty() && !d->output->implementationUrl->url().url().isEmpty(); @@ -679,8 +695,8 @@ { d->parent->generator()->setHeaderUrl(d->output->headerUrl->text()); d->parent->generator()->setImplementationUrl(d->output->implementationUrl->text()); - d->parent->generator()->setHeaderPosition(SimpleCursor(field("headerLine").toInt(), field("headerColumn").toInt())); - d->parent->generator()->setHeaderPosition(SimpleCursor(field("implementationLine").toInt(), field("implementationColumn").toInt())); + d->parent->generator()->setHeaderPosition(SimpleCursor(d->output->headerLineNumber->value(), d->output->headerColumnNumber->value())); + d->parent->generator()->setImplementationPosition(SimpleCursor(d->output->implementationLineNumber->value(), d->output->implementationColumnNumber->value())); return true; } --- trunk/KDE/kdevplatform/language/codegen/createclass.h #1005409:1005410 @@ -307,6 +307,18 @@ private slots: virtual void updateFileNames(); + + /** + * This implementation simply enables the position widgets on a file that exists. + * Derived classes should overload to set the ranges where class generation should be allowed + */ + virtual void updateHeaderRanges(const QString &); + + /** + * This implementation simply enables the position widgets on a file that exists. + * Derived classes should overload to set the ranges where class generation should be allowed + */ + virtual void updateImplementationRanges(const QString &); }; } --- trunk/KDE/kdevplatform/language/codegen/ui/outputlocation.ui #1005409:1005410 @@ -71,7 +71,7 @@ - false + true Location within existing file(s)