From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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 --- buildtools/script/Makefile.am | 26 ++ buildtools/script/README.dox | 48 +++ buildtools/script/kdevscriptproject.desktop | 87 ++++++ buildtools/script/kdevscriptproject.rc | 12 + buildtools/script/scriptnewfiledlg.cpp | 119 +++++++ buildtools/script/scriptnewfiledlg.h | 39 +++ buildtools/script/scriptoptionswidget.cpp | 69 +++++ buildtools/script/scriptoptionswidget.h | 35 +++ buildtools/script/scriptoptionswidgetbase.ui | 155 ++++++++++ buildtools/script/scriptprojectpart.cpp | 446 +++++++++++++++++++++++++++ buildtools/script/scriptprojectpart.h | 69 +++++ 11 files changed, 1105 insertions(+) create mode 100644 buildtools/script/Makefile.am create mode 100644 buildtools/script/README.dox create mode 100644 buildtools/script/kdevscriptproject.desktop create mode 100644 buildtools/script/kdevscriptproject.rc create mode 100644 buildtools/script/scriptnewfiledlg.cpp create mode 100644 buildtools/script/scriptnewfiledlg.h create mode 100644 buildtools/script/scriptoptionswidget.cpp create mode 100644 buildtools/script/scriptoptionswidget.h create mode 100644 buildtools/script/scriptoptionswidgetbase.ui create mode 100644 buildtools/script/scriptprojectpart.cpp create mode 100644 buildtools/script/scriptprojectpart.h (limited to 'buildtools/script') diff --git a/buildtools/script/Makefile.am b/buildtools/script/Makefile.am new file mode 100644 index 00000000..73cee869 --- /dev/null +++ b/buildtools/script/Makefile.am @@ -0,0 +1,26 @@ +# Here resides the script project part. +# This is a generic part for various scripting languages that simply +# includes all files from the project directory without managing +# them. If a language needs more specific features, it deserves +# its own part (or the respective features should be added to the +# language support part) + +INCLUDES = -I$(top_srcdir)/buildtools/lib/base \ + -I$(top_srcdir)/buildtools/lib/widgets -I$(top_srcdir)/lib/interfaces \ + -I$(top_srcdir)/lib/interfaces/extensions -I$(top_srcdir)/lib/interfaces/external -I$(top_srcdir)/lib/util \ + -I$(top_srcdir)/lib/external_interfaces $(all_includes) + +kde_module_LTLIBRARIES = libkdevscriptproject.la +libkdevscriptproject_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) +libkdevscriptproject_la_LIBADD = $(top_builddir)/lib/libkdevelop.la \ + $(top_builddir)/buildtools/lib/widgets/libkdevbuildtoolswidgets.la $(top_builddir)/buildtools/lib/base/libkdevbuildbase.la + +libkdevscriptproject_la_SOURCES = scriptprojectpart.cpp scriptoptionswidget.cpp scriptoptionswidgetbase.ui scriptnewfiledlg.cpp + +METASOURCES = AUTO + +servicedir = $(kde_servicesdir) +service_DATA = kdevscriptproject.desktop + +rcdir = $(kde_datadir)/kdevscriptproject +rc_DATA = kdevscriptproject.rc diff --git a/buildtools/script/README.dox b/buildtools/script/README.dox new file mode 100644 index 00000000..a7a19983 --- /dev/null +++ b/buildtools/script/README.dox @@ -0,0 +1,48 @@ +/** \class ScriptProjectPart +This is the script build tool part +Put a more detailed description of your part in these lines. It can span +over several lines. You can even use some html commands in these lines like: +This is code, html links link text, +and images. + +\authors Bernd Gehrmann + +\unmaintained This part is currently un-maintained + +\deprecated This class is deprecated, use GenericProjectPart (buildtools/generic) instead. + +\feature Describe the first feature +\feature Describe the second feature +... +\feature Describe the last feature + +\bug Describe a the 1st bug that you know of, but probably hasn't been reported yet. +.. +\bug Describe a the nth bug that you know of, but probably hasn't been reported yet. + +\requirement Describe a the 1st requirement of your part. +\requirement Describe a the 2nd requirement of your part. +... +\requirement Describe a the nth requirement of your part. + +\todo Describe a the 1st TODO of your part. +\todo Describe a the 2nd TODO of your part. +... +\todo Describe a the nth TODO of your part. + +\faq First frequenly asked question about your part ? Answer. +\faq Second frequenly asked question about your part ? Answer. +... +\faq Last frequenly asked question about your part ? Answer. + +\note First note text. +\note Second note text. +... +\note Last note text. + +\warning First warning text. +\warning Second warning text. +... +\warning Last warning text. + +*/ diff --git a/buildtools/script/kdevscriptproject.desktop b/buildtools/script/kdevscriptproject.desktop new file mode 100644 index 00000000..1200f9ba --- /dev/null +++ b/buildtools/script/kdevscriptproject.desktop @@ -0,0 +1,87 @@ +[Desktop Entry] +Type=Service +Exec=blubb +Comment=Scripting Language Project +Comment[ca]=Projecte de llenguatge escrivint scripts +Comment[da]=Scriptsprog-projekt +Comment[de]=Skriptsprachen-Projekt für KDevelop +Comment[el]=Έργο γλώσσας γραφής σεναρίων +Comment[es]=Proyecto de lenguaje de guiones +Comment[et]=Skriptikeele projekt +Comment[eu]=Script lengoai proiektua +Comment[fa]=پروژۀ زبان دست‌نوشته‌ای +Comment[fr]=Projet avec les langages de scripts +Comment[ga]=Tionscadal i dTeanga Scriptithe +Comment[gl]=Proxecto de linguaxe de scripting +Comment[hi]=स्क्रिप्टिंग भाषा परियोजना +Comment[hu]=Szkript-projekt +Comment[is]=Skriftumálsverkefni +Comment[it]=Progetto con linguaggio di scripting +Comment[ja]=スクリプト言語プロジェクト +Comment[ms]=Projek Bahasa Penskrip +Comment[nds]=Skriptspraak-Projekt +Comment[ne]=स्क्रिप्टिङ भाषा परियोजना +Comment[nl]=Scripttaal-project +Comment[pl]=Projekt w języku skryptowym +Comment[pt]=Projecto de uma Linguagem de 'Scripting' +Comment[pt_BR]=Projeto de Linguagem de Script +Comment[ru]=Проект скриптового языка +Comment[sk]=Skriptovací jazyk projekt +Comment[sl]=Projekt skriptnega jezika +Comment[sr]=Пројекат скриптног језика +Comment[sr@Latn]=Projekat skriptnog jezika +Comment[sv]=Projekt för skriptspråk +Comment[ta]=ஸ்கிரிப்டிங் மொழி பிராஜக்ட் +Comment[tg]=Лоиҳа бо забони ғарчкунӣ +Comment[tr]=Betik Dili Projesi +Comment[zh_CN]=脚本语言工程 +Comment[zh_TW]=文稿語言專案 +Name=KDevScriptProject +Name[da]=KDevelop script-projekt +Name[de]=Skriptsprachen-Projekt (KDevelop) +Name[hi]=के-डेव-स्क्रिप्ट-परियोजना +Name[nds]=Skriptspraak-Projekt (KDevelop) +Name[ne]=केडीई विकास स्क्रिप्ट परियोजना +Name[pl]=KDevProjektSkrypt +Name[sk]=KDevSkriptProjekt +Name[sv]=KDevelop skriptprojekt +Name[ta]=கெடெவ் ஸ்கிரிப்ட் பிராஜக்ட் +Name[tg]=KDevЛоиҳаи скрипт +Name[zh_TW]=KDevelop 文稿專案 +GenericName=Scripting Language Project +GenericName[ca]=Projecte de llenguatge escrivint scripts +GenericName[da]=Scriptsprog-projekt +GenericName[de]=Skriptsprachen-Projekt +GenericName[el]=Έργο γλώσσας γραφής σεναρίων +GenericName[es]=Proyecto de lenguaje de guiones +GenericName[et]=Skriptikeele projekt +GenericName[eu]=Script lengoaia proiektua +GenericName[fa]=پروژۀ زبان دست‌نوشته‌ای +GenericName[fr]=Projet avec les langages de scripts +GenericName[ga]=Tionscadal i dTeanga Scriptithe +GenericName[gl]=Proxecto de linguaxe de scripting +GenericName[hi]=स्क्रिप्टिंग भाषा परियोजना +GenericName[hu]=Szkript-projekt +GenericName[it]=Progetto con linguaggio di scripting +GenericName[ja]=スクリプト言語プロジェクト +GenericName[nds]=Skriptspraak-Projekt +GenericName[ne]=स्क्रिप्टिङ भाषा परियोजना +GenericName[nl]=Scripttaal-project +GenericName[pl]=Projekt w języku skryptowym +GenericName[pt]=Projecto de uma Linguagem de 'Scripting' +GenericName[pt_BR]=Projeto de Linguagem de Script +GenericName[ru]=Проект скриптового языка +GenericName[sk]=Skriptovací jazyk projekt +GenericName[sl]=Projekt skriptnega jezika +GenericName[sr]=Пројекат скриптног језика +GenericName[sr@Latn]=Projekat skriptnog jezika +GenericName[sv]=Projekt för skriptspråk +GenericName[ta]=ஸ்கிரிப்டிங் மொழி பிராஜக்ட் +GenericName[tg]=Лоиҳа бо забони ғарчкунӣ +GenericName[tr]=Betik Dili Projesi +GenericName[zh_CN]=脚本语言工程 +GenericName[zh_TW]=文稿語言專案 +ServiceTypes=KDevelop/Project +Icon=kdevelop +X-KDE-Library=libkdevscriptproject +X-KDevelop-Version=5 diff --git a/buildtools/script/kdevscriptproject.rc b/buildtools/script/kdevscriptproject.rc new file mode 100644 index 00000000..651b10b4 --- /dev/null +++ b/buildtools/script/kdevscriptproject.rc @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/buildtools/script/scriptnewfiledlg.cpp b/buildtools/script/scriptnewfiledlg.cpp new file mode 100644 index 00000000..336187d3 --- /dev/null +++ b/buildtools/script/scriptnewfiledlg.cpp @@ -0,0 +1,119 @@ +/*************************************************************************** + * Copyright (C) 2001-2002 by Bernd Gehrmann * + * bernd@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 "scriptnewfiledlg.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "scriptprojectpart.h" +#include "filetemplate.h" + + +ScriptNewFileDialog::ScriptNewFileDialog(ScriptProjectPart *part, + QWidget *parent, const char *name) + : QDialog(parent, name, true) +{ + setCaption(i18n("New File")); + + QLabel *filename_label = new QLabel(i18n("&File name:"), this); + + filename_edit = new KLineEdit(this); + filename_edit->setFocus(); + filename_label->setBuddy(this); + QFontMetrics fm(filename_edit->fontMetrics()); + filename_edit->setMinimumWidth(fm.width('X')*35); + + usetemplate_box = new QCheckBox(i18n("&Use file template"), this); + usetemplate_box->setChecked(true); + + QFrame *frame = new QFrame(this); + frame->setFrameStyle(QFrame::HLine | QFrame::Sunken); + + KButtonBox *buttonbox = new KButtonBox(this); + buttonbox->addStretch(); + QPushButton *ok_button = buttonbox->addButton(KStdGuiItem::ok()); + QPushButton *cancel_button = buttonbox->addButton(KStdGuiItem::cancel()); + ok_button->setDefault(true); + connect( ok_button, SIGNAL(clicked()), this, SLOT(accept()) ); + connect( cancel_button, SIGNAL(clicked()), this, SLOT(reject()) ); + buttonbox->layout(); + + QVBoxLayout *layout = new QVBoxLayout(this, 10, 4); + layout->addWidget(filename_label); + layout->addWidget(filename_edit); + layout->addWidget(usetemplate_box); + layout->addWidget(frame, 0); + layout->addWidget(buttonbox, 0); + + m_part = part; +} + + +ScriptNewFileDialog::~ScriptNewFileDialog() +{} + + +void ScriptNewFileDialog::accept() +{ + QString fileName = filename_edit->text(); + if (fileName.find('/') != -1) { + KMessageBox::sorry(this, i18n("Please enter the file name without '/' and so on.")); + return; + } + + KDevProject *project = m_part->project(); + if (!project->activeDirectory().isEmpty()) + fileName.prepend(project->activeDirectory() + "/"); + QString destpath = project->projectDirectory() + "/" + fileName; + + if (QFileInfo(destpath).exists()) { + KMessageBox::sorry(this, i18n("A file with this name already exists.")); + return; + } + + bool success = false; + + if (usetemplate_box->isChecked()) { + QString extension = QFileInfo(destpath).extension(); + if (!FileTemplate::exists(m_part, extension)) { + KMessageBox::sorry(this, i18n("A file template for this extension does not exist.")); + return; + } + success = FileTemplate::copy(m_part, extension, destpath); + } else { + QFile f(destpath); + success = f.open(IO_WriteOnly); + if (success) + f.close(); + } + + if (!success) + KMessageBox::sorry(this, i18n("Could not create the new file.")); + + kdDebug(9015) << "AddFile1: " << fileName << endl; + m_part->addFile(fileName); + + QDialog::accept(); +} + +#include "scriptnewfiledlg.moc" diff --git a/buildtools/script/scriptnewfiledlg.h b/buildtools/script/scriptnewfiledlg.h new file mode 100644 index 00000000..b3c73713 --- /dev/null +++ b/buildtools/script/scriptnewfiledlg.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2001-2002 by Bernd Gehrmann * + * bernd@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. * + * * + ***************************************************************************/ + +#ifndef _SCRIPTNEWFILEDLG_H_ +#define _SCRIPTNEWFILEDLG_H_ + +#include + +class QCheckBox; +class KLineEdit; +class ScriptProjectPart; + + +class ScriptNewFileDialog : public QDialog +{ + Q_OBJECT + +public: + ScriptNewFileDialog( ScriptProjectPart *part, QWidget *parent=0, const char *name=0 ); + ~ScriptNewFileDialog(); + +protected: + virtual void accept(); + +private: + QCheckBox *usetemplate_box; + KLineEdit *filename_edit; + ScriptProjectPart *m_part; +}; + +#endif diff --git a/buildtools/script/scriptoptionswidget.cpp b/buildtools/script/scriptoptionswidget.cpp new file mode 100644 index 00000000..c1660b00 --- /dev/null +++ b/buildtools/script/scriptoptionswidget.cpp @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (C) 2002 by Bernd Gehrmann * + * bernd@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 "scriptoptionswidget.h" + +#include +#include +#include +#include +#include "domutil.h" +#include "kdevlanguagesupport.h" + + +ScriptOptionsWidget::ScriptOptionsWidget(KDevPlugin *part, + QWidget *parent, const char *name) + : ScriptOptionsWidgetBase(parent, name) +{ + m_part = part; + + QDomDocument &dom = *m_part->projectDom(); + + QString includepatterns + = DomUtil::readEntry(dom, "/kdevscriptproject/general/includepatterns"); + + if (includepatterns.isNull() && part->languageSupport()){ + QStringList includepatternList; + KMimeType::List list = part->languageSupport()->mimeTypes(); + KMimeType::List::Iterator it = list.begin(); + while( it != list.end() ){ + includepatternList += (*it)->patterns(); + ++it; + } + includepatterns = includepatternList.join( "," ); + } + + QString excludepatterns + = DomUtil::readEntry(dom, "/kdevscriptproject/general/excludepatterns"); + if (excludepatterns.isNull()) + excludepatterns = "*~"; + + includepatterns_edit->setText(includepatterns); + excludepatterns_edit->setText(excludepatterns); +} + + +ScriptOptionsWidget::~ScriptOptionsWidget() +{} + + +void ScriptOptionsWidget::accept() +{ + QDomDocument &dom = *m_part->projectDom(); + + QString includepatterns = includepatterns_edit->text(); + QString excludepatterns = excludepatterns_edit->text(); + + DomUtil::writeEntry(dom, "/kdevscriptproject/general/includepatterns", includepatterns); + DomUtil::writeEntry(dom, "/kdevscriptproject/general/excludepatterns", excludepatterns); +} + +#include "scriptoptionswidget.moc" diff --git a/buildtools/script/scriptoptionswidget.h b/buildtools/script/scriptoptionswidget.h new file mode 100644 index 00000000..c33d099d --- /dev/null +++ b/buildtools/script/scriptoptionswidget.h @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright (C) 2002 by Bernd Gehrmann * + * bernd@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. * + * * + ***************************************************************************/ + +#ifndef _SCRIPTPROJECTOPTIONSWIDGET_H_ +#define _SCRIPTPROJECTOPTIONSWIDGET_H_ + +#include "scriptoptionswidgetbase.h" + +class KDevPlugin; + + +class ScriptOptionsWidget : public ScriptOptionsWidgetBase +{ + Q_OBJECT + +public: + ScriptOptionsWidget( KDevPlugin *part, QWidget *parent=0, const char *name=0 ); + ~ScriptOptionsWidget(); + +public slots: + void accept(); + +private: + KDevPlugin *m_part; +}; + +#endif diff --git a/buildtools/script/scriptoptionswidgetbase.ui b/buildtools/script/scriptoptionswidgetbase.ui new file mode 100644 index 00000000..3a8f7b99 --- /dev/null +++ b/buildtools/script/scriptoptionswidgetbase.ui @@ -0,0 +1,155 @@ + +ScriptOptionsWidgetBase + + + script_project_options + + + + 0 + 0 + 600 + 482 + + + + Script Project Options + + + + unnamed + + + + includepatterns_label + + + &Include files into the project with the following patterns: + + + includepatterns_edit + + + + + Layout2 + + + + unnamed + + + 0 + + + + Spacer4 + + + Horizontal + + + Minimum + + + + 20 + 20 + + + + + + includepatterns_edit + + + + + + + Spacer7 + + + Vertical + + + Minimum + + + + 20 + 20 + + + + + + excludepatterns_label + + + &Exclude the following patterns: + + + excludepatterns_edit + + + + + Layout2_2 + + + + unnamed + + + 0 + + + + Spacer4_2 + + + Horizontal + + + Minimum + + + + 20 + 20 + + + + + + excludepatterns_edit + + + + + + + Spacer6 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + kdialog.h + + + + diff --git a/buildtools/script/scriptprojectpart.cpp b/buildtools/script/scriptprojectpart.cpp new file mode 100644 index 00000000..ff560f23 --- /dev/null +++ b/buildtools/script/scriptprojectpart.cpp @@ -0,0 +1,446 @@ +/*************************************************************************** + * Copyright (C) 2001-2002 by Bernd Gehrmann * + * bernd@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 "scriptprojectpart.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "domutil.h" +#include "kdevcore.h" +#include "kdevmainwindow.h" +#include "kdevpartcontroller.h" +#include "kdevlanguagesupport.h" +#include "scriptoptionswidget.h" +#include "scriptnewfiledlg.h" +#include "kdevplugininfo.h" + +typedef KDevGenericFactory ScriptProjectFactory; +static const KDevPluginInfo data("kdevscriptproject"); +K_EXPORT_COMPONENT_FACTORY( libkdevscriptproject, ScriptProjectFactory( data ) ) + +ScriptProjectPart::ScriptProjectPart(QObject *parent, const char *name, const QStringList &) + : KDevBuildTool(&data, parent, name ? name : "ScriptProjectPart") +{ + setInstance(ScriptProjectFactory::instance()); + + setXMLFile("kdevscriptproject.rc"); + + // only create new file action if file creation part not available + if (!extension("KDevelop/CreateFile")) { + KAction *action; + action = new KAction( i18n("New File..."), 0, + this, SLOT(slotNewFile()), + actionCollection(), "file_newfile" ); + action->setWhatsThis( i18n("New file

Creates a new file.") ); + action->setToolTip( i18n("Create a new file") ); + } + new KAction( i18n("Rescan Project"), 0, CTRL+ALT+Key_R, + this, SLOT(rescan()), + actionCollection(), "rescan" ); + + connect( core(), SIGNAL(projectConfigWidget(KDialogBase*)), + this, SLOT(projectConfigWidget(KDialogBase*)) ); +} + + +ScriptProjectPart::~ScriptProjectPart() +{} + + +void ScriptProjectPart::projectConfigWidget(KDialogBase *dlg) +{ + QVBox *vbox; + vbox = dlg->addVBoxPage(i18n("Script Project Options"), i18n("Script Project Options"), BarIcon("kdevelop", KIcon::SizeMedium)); + ScriptOptionsWidget *w = new ScriptOptionsWidget(this, vbox); + connect( dlg, SIGNAL(okClicked()), w, SLOT(accept()) ); +} + + +/** + * @todo This should really be merged with FileTreeWidget::matchesHidePattern() + * and put in its own class. Currently this is repeated in scriptprojectpart.cpp, pascalproject_part.cpp, adaproject_part.cpp + */ +static bool matchesPattern(const QString &fileName, const QStringList &patternList) +{ + QStringList::ConstIterator it; + for (it = patternList.begin(); it != patternList.end(); ++it) { + QRegExp re(*it, true, true); + if (re.search(fileName) == 0 && re.matchedLength() == (int)fileName.length()) + return true; + } + + return false; +} + + +void ScriptProjectPart::openProject(const QString &dirName, const QString &projectName) +{ + if (!languageSupport()) + kdDebug(9015) << "ScriptProjectPart::openProject: no language support found!" << endl; + + m_projectDirectory = dirName; + m_projectName = projectName; + + QDomDocument &dom = *projectDom(); + + // Set the default directory radio to "executable" + if (DomUtil::readEntry(dom, "/kdevscriptproject/run/directoryradio") == "" ) { + DomUtil::writeEntry(dom, "/kdevscriptproject/run/directoryradio", "executable"); + } + + // Put all files from all subdirectories into file list + QValueStack s; + int prefixlen = m_projectDirectory.length()+1; + s.push(m_projectDirectory); + + QDir dir; + do { + dir.setPath(s.pop()); + kdDebug(9015) << "Examining: " << dir.path() << endl; + const QFileInfoList *dirEntries = dir.entryInfoList(); + if ( dirEntries ) + { + QPtrListIterator it(*dirEntries); + for (; it.current(); ++it) { + QString fileName = it.current()->fileName(); + if (fileName == "." || fileName == "..") + continue; + QString path = it.current()->absFilePath(); + if (it.current()->isDir()) { + //do not follow symlinks which point to the themselves + if (it.current()->isSymLink()) + { + QString symLink = it.current()->readLink(); + if ((symLink == path) || (symLink == "./")) + continue; + } else if (canAddDirectoryToProject(path)) { + kdDebug(9015) << "Pushing: " << path << endl; + s.push(path); + } + } + else { + if (canAddToProject(path)) + m_sourceFiles.append(path.mid(prefixlen)); + } + } + } + } while (!s.isEmpty()); + + KDevProject::openProject( dirName, projectName ); +} + + +void ScriptProjectPart::closeProject() +{ +} + + +QString ScriptProjectPart::projectDirectory() const +{ + return m_projectDirectory; +} + + +QString ScriptProjectPart::buildDirectory() const +{ + return m_projectDirectory; +} + +QString ScriptProjectPart::projectName() const +{ + return m_projectName; +} + + +/** Retuns a PairList with the run environment variables */ +DomUtil::PairList ScriptProjectPart::runEnvironmentVars() const +{ + return DomUtil::readPairListEntry(*projectDom(), "/kdevscriptproject/run/envvars", "envvar", "name", "value"); +} + + +/** Retuns the currently selected run directory + * The returned string can be: + * if run/directoryradio == executable + * The directory where the executable is + * if run/directoryradio == build + * The directory where the executable is relative to build directory + * if run/directoryradio == custom + * The custom directory absolute path + */ +QString ScriptProjectPart::runDirectory() const +{ + QString cwd = defaultRunDirectory("kdevscriptproject"); + if (cwd.isEmpty()) + cwd = buildDirectory(); + return cwd; +} + + +/** Retuns the currently selected main program + * The returned string can be: + * if run/directoryradio == executable + * The executable name + * if run/directoryradio == build + * The path to executable relative to build directory + * if run/directoryradio == custom or relative == false + * The absolute path to executable + */ +QString ScriptProjectPart::mainProgram() const +{ + QDomDocument * dom = projectDom(); + + if ( !dom ) return QString(); + + QString DomMainProgram = DomUtil::readEntry( *dom, "/kdevscriptproject/run/mainprogram"); + + if ( DomMainProgram.isEmpty() ) return QString(); + + if ( DomMainProgram.startsWith("/") ) // assume absolute path + { + return DomMainProgram; + } + else // assume project relative path + { + return projectDirectory() + "/" + DomMainProgram; + } + + return QString(); +} + +/** Retuns a QString with the debug command line arguments */ +QString ScriptProjectPart::debugArguments() const +{ + return DomUtil::readEntry(*projectDom(), "/kdevscriptproject/run/globaldebugarguments"); +} + + +/** Retuns a QString with the run command line arguments */ +QString ScriptProjectPart::runArguments() const +{ + return DomUtil::readEntry(*projectDom(), "/kdevscriptproject/run/programargs"); +} + + +QString ScriptProjectPart::activeDirectory() const +{ + QDomDocument &dom = *projectDom(); + + return DomUtil::readEntry(dom, "/kdevscriptproject/general/activedir"); +} + + +QStringList ScriptProjectPart::allFiles() const +{ +/* QStringList res; + + QStringList::ConstIterator it; + for (it = m_sourceFiles.begin(); it != m_sourceFiles.end(); ++it) + res += (m_projectDirectory + "/" + (*it)); + + return res;*/ + + // return all files relative to the project directory! + return m_sourceFiles; +} + +void ScriptProjectPart::addFile(const QString &fileName) +{ + kdDebug(9015) << "AddFile2" << fileName << endl; + + QStringList fileList; + fileList.append ( fileName ); + + this->addFiles ( fileList ); +} + +void ScriptProjectPart::addFiles ( const QStringList& fileList ) +{ + QStringList::ConstIterator it; + + for ( it = fileList.begin(); it != fileList.end(); ++it ) + { + m_sourceFiles.append ( ( *it ) ); + } + + emit addedFilesToProject ( fileList ); +} + +void ScriptProjectPart::removeFile(const QString &fileName) +{ + QStringList fileList; + fileList.append ( fileName ); + + this->addFiles ( fileList ); +} + +void ScriptProjectPart::removeFiles ( const QStringList& fileList ) +{ + emit removedFilesFromProject ( fileList ); + + QStringList::ConstIterator it; + + for ( it = fileList.begin(); it != fileList.end(); ++it ) + { + m_sourceFiles.remove ( ( *it ) ); + } +} + +void ScriptProjectPart::slotNewFile() +{ + ScriptNewFileDialog dlg(this); + dlg.exec(); +} + +/*! + \fn ScriptProjectPart::distFiles() const + */ +QStringList ScriptProjectPart::distFiles() const +{ + QStringList sourceList = allFiles(); + // Scan current source directory for any .pro files. + QString projectDir = projectDirectory(); + QDir dir(projectDir); + QStringList files = dir.entryList( "*README*"); + return sourceList + files; +} + +void ScriptProjectPart::rescan() +{ +// kdDebug() << "Directory " << path << " changed, scanning for new files in the project" << endl; + + // Put all files from all subdirectories into file list + QValueStack s; + int prefixlen = m_projectDirectory.length()+1; + s.push(m_projectDirectory); + + QDir dir; + do { + dir.setPath(s.pop()); + kdDebug(9015) << "Examining: " << dir.path() << endl; + const QFileInfoList *dirEntries = dir.entryInfoList(); + if ( dirEntries ) + { + QPtrListIterator it(*dirEntries); + for (; it.current(); ++it) { + QString fileName = it.current()->fileName(); + if (fileName == "." || fileName == "..") + continue; + QString path = it.current()->absFilePath(); + if (it.current()->isDir()) { + //do not follow symlinks which point to the themselves + if (it.current()->isSymLink()) + { + QString symLink = it.current()->readLink(); + if ((symLink == path) || (symLink == "./")) + continue; + } else if (canAddDirectoryToProject(path)) { + kdDebug(9015) << "Pushing: " << path << endl; + s.push(path); + } + } + else { + if (!isProjectFile(path) && canAddToProject(path)) + addFile(path.mid(prefixlen)); +// m_sourceFiles.append(path.mid(prefixlen)); + } + } + } + } while (!s.isEmpty()); + +/* const QFileInfoList *dirEntries = QDir(path).entryInfoList(); + if ( dirEntries ) + { + kdDebug() << "1" << endl; + QPtrListIterator it(*dirEntries); + for (; it.current(); ++it) { + kdDebug() << "2" << endl; + QString fileName = it.current()->fileName(); + if (fileName == "." || fileName == "..") + continue; + kdDebug() << "3" << endl; + QString filePath = it.current()->absFilePath(); + if (!it.current()->isDir() && canAddToProject(filePath) && !isProjectFile(filePath)) { + kdDebug() << "=== adding " << filePath << endl; + addFile(filePath); + } + } + }*/ +} + +bool ScriptProjectPart::canAddToProject(const QString & path) +{ + QDomDocument &dom = *projectDom(); + QString includepatterns + = DomUtil::readEntry(dom, "/kdevscriptproject/general/includepatterns"); + QStringList includepatternList; + if ( includepatterns.isNull() ) { + if ( languageSupport() ){ + KMimeType::List list = languageSupport()->mimeTypes(); + KMimeType::List::Iterator it = list.begin(); + while( it != list.end() ){ + includepatternList += (*it)->patterns(); + ++it; + } + } + } else { + includepatternList = QStringList::split(",", includepatterns); + } + + QString excludepatterns + = DomUtil::readEntry(dom, "/kdevscriptproject/general/excludepatterns"); + if (excludepatterns.isNull()) + excludepatterns = "*~"; + QStringList excludepatternList = QStringList::split(",", excludepatterns); + + if (matchesPattern(path, includepatternList) + && !matchesPattern(path, excludepatternList)) { + kdDebug(9015) << "Adding: " << path << endl; + return true; + } else { + kdDebug(9015) << "Ignoring: " << path << endl; + return false; + } +} + +bool ScriptProjectPart::canAddDirectoryToProject(const QString & path) +{ + QDomDocument &dom = *projectDom(); + QString excludepatterns + = DomUtil::readEntry(dom, "/kdevscriptproject/general/excludepatterns"); + if (excludepatterns.isNull()) { + return true; + } + QStringList excludepatternList = QStringList::split(",", excludepatterns); + + if (!matchesPattern(path, excludepatternList)) { + return true; + } else { + kdDebug(9015) << "Ignoring Directory: " << path << endl; + return false; + } +} + +#include "scriptprojectpart.moc" diff --git a/buildtools/script/scriptprojectpart.h b/buildtools/script/scriptprojectpart.h new file mode 100644 index 00000000..b16c4ffb --- /dev/null +++ b/buildtools/script/scriptprojectpart.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (C) 2001-2002 by Bernd Gehrmann * + * bernd@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. * + * * + ***************************************************************************/ + +#ifndef _SCRIPTPROJECTPART_H_ +#define _SCRIPTPROJECTPART_H_ + +#include +#include + +#include "kdevbuildtool.h" + +class QListViewItem; +class QStringList; +class KDialogBase; +class ScriptProjectWidget; + +class ScriptProjectPart : public KDevBuildTool +{ + Q_OBJECT + +public: + ScriptProjectPart( QObject *parent, const char *name, const QStringList &args ); + ~ScriptProjectPart(); + QStringList distFiles() const; + +protected: + virtual void openProject(const QString &dirName, const QString &projectName); + virtual void closeProject(); + + virtual QString projectDirectory() const; + virtual QString projectName() const; + virtual QString mainProgram() const; + virtual QString activeDirectory() const; + virtual QStringList allFiles() const; + virtual void addFile(const QString &fileName); + virtual void addFiles ( const QStringList& fileList ); + virtual void removeFile(const QString &fileName); + virtual void removeFiles ( const QStringList& fileList ); + virtual QString buildDirectory() const; + virtual QString runDirectory() const; + virtual QString debugArguments() const; + virtual QString runArguments() const; + virtual DomUtil::PairList runEnvironmentVars() const; + + bool canAddToProject(const QString &path); + bool canAddDirectoryToProject(const QString &path); + +private slots: + void projectConfigWidget(KDialogBase *dlg); + void slotNewFile(); + void rescan(); + +private: + QString m_projectDirectory; + QString m_projectName; + QStringList m_sourceFiles; + + friend class ScriptNewFileDialog; +}; + +#endif -- cgit v1.2.3