00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#include "fortransupportpart.h"
00017
#include "ftnchekconfigwidget.h"
00018
#include "fixedformparser.h"
00019
00020
#include <qdir.h>
00021
#include <qfileinfo.h>
00022
#include <qpopupmenu.h>
00023
#include <qstringlist.h>
00024
#include <qtextstream.h>
00025
#include <qtimer.h>
00026
#include <qvbox.h>
00027
#include <kapplication.h>
00028
#include <kdebug.h>
00029
#include <kdialogbase.h>
00030
#include <klocale.h>
00031
#include <kmessagebox.h>
00032
#include <kregexp.h>
00033
#include <kdevgenericfactory.h>
00034
#include <kaction.h>
00035
00036
#include <kdevcore.h>
00037
#include <kdevproject.h>
00038
#include <kdevmakefrontend.h>
00039
#include <kdevpartcontroller.h>
00040
#include <domutil.h>
00041
#include <codemodel.h>
00042
00043
00044
00045 typedef KDevGenericFactory<FortranSupportPart> FortranSupportFactory;
00046
static const KAboutData data(
"kdevfortransupport",
I18N_NOOP(
"Language"),
"1.0");
00047 K_EXPORT_COMPONENT_FACTORY( libkdevfortransupport,
FortranSupportFactory( &data ) )
00048
00049
FortranSupportPart::
FortranSupportPart(
QObject *parent, const
char *name, const
QStringList &)
00050 :
KDevLanguageSupport("FortranSupport", "fortran", parent, name ? name : "
FortranSupportPart")
00051 {
00052 setInstance(FortranSupportFactory::instance());
00053
00054 setXMLFile(
"kdevfortransupport.rc");
00055
00056 connect( core(), SIGNAL(projectConfigWidget(
KDialogBase*)),
00057
this, SLOT(projectConfigWidget(
KDialogBase*)) );
00058 connect( core(), SIGNAL(projectOpened()),
this, SLOT(projectOpened()) );
00059 connect( core(), SIGNAL(projectClosed()),
this, SLOT(projectClosed()) );
00060 connect( partController(), SIGNAL(savedFile(
const QString&)),
00061
this, SLOT(savedFile(
const QString&)) );
00062
00063
KAction *action;
00064
00065 action =
new KAction( i18n(
"&Ftnchek"), 0,
00066
this, SLOT(slotFtnchek()),
00067 actionCollection(),
"project_ftnchek" );
00068 action->setToolTip(i18n(
"Run ftnchek"));
00069 action->setWhatsThis(i18n(
"<b>Run ftnchek</b><p>Runs <b>ftnchek</b> to check fortran programs for semantic errors. Configure ftnchek options in project settings dialog, <b>Ftnchek</b> tab."));
00070
00071 parser = 0;
00072 }
00073
00074
00075 FortranSupportPart::~FortranSupportPart()
00076 {}
00077
00078
00079 void FortranSupportPart::slotFtnchek()
00080 {
00081
00082
if (
makeFrontend()->
isRunning()) {
00083 KMessageBox::sorry(0, i18n(
"There is currently a job running."));
00084
return;
00085 }
00086
00087
partController()->
saveAllFiles();
00088
00089
QDomDocument &dom = *
projectDom();
00090
00091
QString cmdline =
"cd ";
00092 cmdline +=
project()->
projectDirectory();
00093 cmdline +=
"&& ftnchek -nonovice ";
00094
00095
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/division"))
00096 cmdline +=
"-division ";
00097
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/extern"))
00098 cmdline +=
"-extern ";
00099
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/declare"))
00100 cmdline +=
"-declare ";
00101
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/pure"))
00102 cmdline +=
"-pure ";
00103
00104 cmdline +=
"-arguments=";
00105
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/argumentsall"))
00106 cmdline +=
"all ";
00107
else
00108 cmdline += DomUtil::readEntry(dom,
"/kdevfortransupport/ftnchek/argumentsonly") +
" ";
00109
00110 cmdline +=
"-common=";
00111
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/commonall"))
00112 cmdline +=
"all ";
00113
else
00114 cmdline += DomUtil::readEntry(dom,
"/kdevfortransupport/ftnchek/commononly") +
" ";
00115
00116 cmdline +=
"-truncation=";
00117
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/truncationall"))
00118 cmdline +=
"all ";
00119
else
00120 cmdline += DomUtil::readEntry(dom,
"/kdevfortransupport/ftnchek/truncationonly") +
" ";
00121
00122 cmdline +=
"-usage=";
00123
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/usageall"))
00124 cmdline +=
"all ";
00125
else
00126 cmdline += DomUtil::readEntry(dom,
"/kdevfortransupport/ftnchek/usageonly") +
" ";
00127
00128 cmdline +=
"-f77=";
00129
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/f77all"))
00130 cmdline +=
"all ";
00131
else
00132 cmdline += DomUtil::readEntry(dom,
"/kdevfortransupport/ftnchek/f77only") +
" ";
00133
00134 cmdline +=
"-portability=";
00135
if (DomUtil::readBoolEntry(dom,
"/kdevfortransupport/ftnchek/portabilityall"))
00136 cmdline +=
"all ";
00137
else
00138 cmdline += DomUtil::readEntry(dom,
"/kdevfortransupport/ftnchek/portabilityonly") +
" ";
00139
00140
QStringList list =
project()->
allFiles();
00141 QStringList::ConstIterator it;
00142
for (it = list.begin(); it != list.end(); ++it) {
00143
QFileInfo fi(*it);
00144
QString extension = fi.extension();
00145
if (extension ==
"f77" || extension ==
"f" || extension ==
"for"
00146 || extension ==
"ftn") {
00147 cmdline += *it +
" ";
00148 }
00149 }
00150
00151
makeFrontend()->
queueCommand(QString::null, cmdline);
00152 }
00153
00154
00155 void FortranSupportPart::projectConfigWidget(
KDialogBase *dlg)
00156 {
00157
QVBox *vbox = dlg->
addVBoxPage(i18n(
"Ftnchek"));
00158
FtnchekConfigWidget *w =
new FtnchekConfigWidget(*
projectDom(), vbox,
"ftnchek config widget");
00159 connect( dlg, SIGNAL(okClicked()), w, SLOT(accept()) );
00160 }
00161
00162
00163 void FortranSupportPart::projectOpened()
00164 {
00165
kdDebug(9019) <<
"projectOpened()" <<
endl;
00166
00167 connect(
project(), SIGNAL(
addedFilesToProject(
const QStringList &)),
00168
this, SLOT(
addedFilesToProject(
const QStringList &)) );
00169 connect(
project(), SIGNAL(
removedFilesFromProject(
const QStringList &)),
00170
this, SLOT(
removedFilesFromProject(
const QStringList &)) );
00171
00172
00173
00174
parser =
new FixedFormParser(
codeModel());
00175
00176 QTimer::singleShot(0,
this, SLOT(
initialParse()));
00177 }
00178
00179
00180 void FortranSupportPart::projectClosed()
00181 {
00182
delete parser;
00183
parser = 0;
00184 }
00185
00186
00187 void FortranSupportPart::maybeParse(
const QString fileName)
00188 {
00189
QFileInfo fi(fileName);
00190
QString extension = fi.extension();
00191
if (extension ==
"f77" || extension ==
"f" || extension ==
"for" || extension ==
"ftn") {
00192
00193
if(
codeModel()->
hasFile(fileName) ){
00194 emit aboutToRemoveSourceInfo( fileName );
00195
codeModel()->
removeFile(
codeModel()->fileByName(fileName) );
00196 }
00197
00198
parser->
parse(fileName);
00199 }
00200 }
00201
00202
00203 void FortranSupportPart::initialParse()
00204 {
00205
kdDebug(9019) <<
"initialParse()" <<
endl;
00206
00207
if (
project()) {
00208 kapp->setOverrideCursor(waitCursor);
00209
QStringList files =
project()->
allFiles();
00210
for (QStringList::Iterator it = files.begin(); it != files.end() ;++it) {
00211
QFileInfo fileInfo(
project()->projectDirectory(), *it );
00212
kdDebug(9019) <<
"maybe parse " << fileInfo.absFilePath() <<
endl;
00213
maybeParse( fileInfo.absFilePath() );
00214 }
00215
00216 emit
updatedSourceInfo();
00217 kapp->restoreOverrideCursor();
00218 }
else {
00219
kdDebug(9019) <<
"No project" <<
endl;
00220 }
00221 }
00222
00223
00224 void FortranSupportPart::addedFilesToProject(
const QStringList &fileList)
00225 {
00226
kdDebug(9019) <<
"addedFilesToProject()" <<
endl;
00227
00228 QStringList::ConstIterator it;
00229
00230
for ( it = fileList.begin(); it != fileList.end(); ++it )
00231 {
00232
QFileInfo fileInfo(
project()->projectDirectory(), *it );
00233
QString path = fileInfo.absFilePath();
00234
maybeParse( path );
00235 emit addedSourceInfo( path );
00236 }
00237
00238
00239 }
00240
00241
00242 void FortranSupportPart::removedFilesFromProject(
const QStringList &fileList)
00243 {
00244
kdDebug(9019) <<
"removedFilesFromProject()" <<
endl;
00245
00246 QStringList::ConstIterator it;
00247
00248
for ( it = fileList.begin(); it != fileList.end(); ++it )
00249 {
00250
QFileInfo fileInfo(
project()->projectDirectory(), *it );
00251
QString path = fileInfo.absFilePath();
00252
00253
if(
codeModel()->
hasFile(path) ){
00254 emit aboutToRemoveSourceInfo( path );
00255
codeModel()->
removeFile(
codeModel()->fileByName(path) );
00256 }
00257 }
00258
00259
00260 }
00261
00262
00263 void FortranSupportPart::savedFile(
const QString &fileName)
00264 {
00265
kdDebug(9019) <<
"savedFile()" <<
endl;
00266
00267
if (
project()->
allFiles().contains(fileName.mid ( project()->projectDirectory().
length() + 1 ))) {
00268
maybeParse(fileName);
00269 emit addedSourceInfo( fileName );
00270 }
00271 }
00272
00273
00274 KDevLanguageSupport::Features
FortranSupportPart::features()
00275 {
00276
return Features(Functions);
00277 }
00278
00279
#include "fortransupportpart.moc"