summaryrefslogtreecommitdiffstats
path: root/languages/php/phpnewclassdlg.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /languages/php/phpnewclassdlg.cpp
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'languages/php/phpnewclassdlg.cpp')
-rw-r--r--languages/php/phpnewclassdlg.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/languages/php/phpnewclassdlg.cpp b/languages/php/phpnewclassdlg.cpp
new file mode 100644
index 00000000..f17034db
--- /dev/null
+++ b/languages/php/phpnewclassdlg.cpp
@@ -0,0 +1,123 @@
+/***************************************************************************
+ phpnewclassdlg.cpp - description
+ -------------------
+ begin : Sat Aug 11 2001
+ copyright : (C) 2001 by Sandy Meier
+ email : smeier@kdevelop.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "phpnewclassdlg.h"
+#include <klineedit.h>
+#include <kcompletion.h>
+#include <kfiledialog.h>
+#include <qtoolbutton.h>
+#include <iostream>
+#include <qregexp.h>
+#include <qtextedit.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+#include <kinstance.h>
+#include <kdebug.h>
+
+using namespace std;
+
+PHPNewClassDlg::PHPNewClassDlg(const QStringList& baseClassNames,const QString& directory,QWidget *parent, const char *name) : PHPNewClassDlgBase(parent,name,true) {
+ m_filenameModified = false;
+ KCompletion *comp = new KCompletion();
+ comp->setItems(baseClassNames);
+ m_dirEdit->setText(directory);
+
+ // load the class template if available
+ QString templateFile = KGlobal::instance()->dirs()->findResource("data","kdevphpsupport/newclasstemplate.txt");
+ if(!templateFile.isNull()){
+ QFile file(templateFile);
+ QTextStream stream(&file);
+ if(file.open(IO_ReadOnly)){
+ m_classTemplate->setText(stream.read());
+ file.close();
+ }
+ }
+
+
+ m_baseClassEdit->setCompletionObject( comp ); /// @todo change it to KLineEdit
+ connect(m_baseClassEdit,SIGNAL(returnPressed(const QString&)),comp,SLOT(addItem(const QString&)));
+ connect(m_classNameEdit,SIGNAL(textChanged(const QString&)),
+ this,SLOT(classNameTextChanged(const QString&)));
+ connect(m_fileNameEdit,SIGNAL(textChanged(const QString&)),
+ this,SLOT(fileNameTextChanged(const QString&)));
+ connect(m_dirButton,SIGNAL(clicked()),
+ this,SLOT(slotDirButtonClicked()));
+}
+PHPNewClassDlg::~PHPNewClassDlg(){
+}
+
+void PHPNewClassDlg::slotDirButtonClicked(){
+ QString dir = KFileDialog::getExistingDirectory(m_dirEdit->text(),this);
+ if(!dir.isEmpty()){
+ m_dirEdit->setText(dir);
+ }
+}
+void PHPNewClassDlg::classNameTextChanged(const QString& str){
+ if(!m_filenameModified){
+ m_fileNameEdit->setText(str.lower() + ".inc");
+ }
+}
+
+void PHPNewClassDlg::fileNameTextChanged(const QString&){
+ if(m_fileNameEdit->hasFocus()){
+ m_filenameModified = true;
+ }
+}
+void PHPNewClassDlg::accept(){
+ PHPNewClassDlgBase::accept(); // hide the dialog
+
+ QString text = m_classTemplate->text();
+ QString classDir = m_dirEdit->text();
+ if(!classDir.endsWith("/")) classDir += "/"; // append /
+ QString absFileName = classDir + m_fileNameEdit->text();
+
+ // save the template for the next time
+ QString templateDir = KGlobal::instance()->dirs()->saveLocation("data") + "/kdevphpsupport/";
+ QString templateFile = templateDir + "newclasstemplate.txt";
+ QDir dir(templateDir);
+ if(!dir.exists()){
+ if(!dir.mkdir(templateDir)){
+ kdWarning() << "Error on creating directory for the classtemplate" << templateDir << endl;
+ }
+ }
+ QFile file(templateFile);
+ QTextStream stream(&file);
+
+ if(file.open(IO_WriteOnly)){
+ stream << text; // write
+ file.close();
+ }
+
+ // generate the sourcecode for the class
+ if(m_baseClassEdit->text().isEmpty()){
+ text = text.replace(QRegExp("extends BASECLASS"),"");
+ text = text.replace(QRegExp("BASECLASS\\:\\:BASECLASS\\(\\);"),"");
+ }else{
+ text = text.replace(QRegExp("BASECLASS"),m_baseClassEdit->text());
+ }
+ text = text.replace(QRegExp("CLASSNAME"),m_classNameEdit->text());
+ text = text.replace(QRegExp("FILENAME"),m_fileNameEdit->text().upper());
+ text = text.replace(QRegExp("AUTHOR"),"not implemented");
+
+ file.setName(absFileName);
+ if(file.open(IO_WriteOnly)){
+ stream << text; // write
+ file.close();
+ }
+}
+
+#include "phpnewclassdlg.moc"