KDevelop API Documentation

buildtools/script/scriptnewfiledlg.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2001-2002 by Bernd Gehrmann * 00003 * bernd@kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include "scriptnewfiledlg.h" 00013 00014 #include <qcheckbox.h> 00015 #include <qfile.h> 00016 #include <qfileinfo.h> 00017 #include <qlabel.h> 00018 #include <qlayout.h> 00019 #include <qlineedit.h> 00020 #include <qpushbutton.h> 00021 #include <kbuttonbox.h> 00022 #include <kdebug.h> 00023 #include <klocale.h> 00024 #include <kmessagebox.h> 00025 00026 #include "scriptprojectpart.h" 00027 #include "filetemplate.h" 00028 00029 00030 ScriptNewFileDialog::ScriptNewFileDialog(ScriptProjectPart *part, 00031 QWidget *parent, const char *name) 00032 : QDialog(parent, name, true) 00033 { 00034 setCaption(i18n("New File")); 00035 00036 QLabel *filename_label = new QLabel(i18n("&File name:"), this); 00037 00038 filename_edit = new QLineEdit(this); 00039 filename_edit->setFocus(); 00040 filename_label->setBuddy(this); 00041 QFontMetrics fm(filename_edit->fontMetrics()); 00042 filename_edit->setMinimumWidth(fm.width('X')*35); 00043 00044 usetemplate_box = new QCheckBox(i18n("&Use file template"), this); 00045 usetemplate_box->setChecked(true); 00046 00047 QFrame *frame = new QFrame(this); 00048 frame->setFrameStyle(QFrame::HLine | QFrame::Sunken); 00049 00050 KButtonBox *buttonbox = new KButtonBox(this); 00051 buttonbox->addStretch(); 00052 QPushButton *ok_button = buttonbox->addButton(i18n("&OK")); 00053 QPushButton *cancel_button = buttonbox->addButton(i18n("Cancel")); 00054 ok_button->setDefault(true); 00055 connect( ok_button, SIGNAL(clicked()), this, SLOT(accept()) ); 00056 connect( cancel_button, SIGNAL(clicked()), this, SLOT(reject()) ); 00057 buttonbox->layout(); 00058 00059 QVBoxLayout *layout = new QVBoxLayout(this, 10, 4); 00060 layout->addWidget(filename_label); 00061 layout->addWidget(filename_edit); 00062 layout->addWidget(usetemplate_box); 00063 layout->addWidget(frame, 0); 00064 layout->addWidget(buttonbox, 0); 00065 00066 m_part = part; 00067 } 00068 00069 00070 ScriptNewFileDialog::~ScriptNewFileDialog() 00071 {} 00072 00073 00074 void ScriptNewFileDialog::accept() 00075 { 00076 QString fileName = filename_edit->text(); 00077 if (fileName.find('/') != -1) { 00078 KMessageBox::sorry(this, i18n("Please enter the file name without '/' and so on.")); 00079 return; 00080 } 00081 00082 KDevProject *project = m_part->project(); 00083 if (!project->activeDirectory().isEmpty()) 00084 fileName.prepend(project->activeDirectory() + "/"); 00085 QString destpath = project->projectDirectory() + "/" + fileName; 00086 00087 if (QFileInfo(destpath).exists()) { 00088 KMessageBox::sorry(this, i18n("A file with this name already exists.")); 00089 return; 00090 } 00091 00092 bool success = false; 00093 00094 if (usetemplate_box->isChecked()) { 00095 QString extension = QFileInfo(destpath).extension(); 00096 if (!FileTemplate::exists(m_part, extension)) { 00097 KMessageBox::sorry(this, i18n("A file template for this extension does not exist.")); 00098 return; 00099 } 00100 success = FileTemplate::copy(m_part, extension, destpath); 00101 } else { 00102 QFile f(destpath); 00103 success = f.open(IO_WriteOnly); 00104 if (success) 00105 f.close(); 00106 } 00107 00108 if (!success) 00109 KMessageBox::sorry(this, i18n("Could not create the new file.")); 00110 00111 kdDebug(9015) << "AddFile1: " << fileName << endl; 00112 m_part->addFile(fileName); 00113 00114 QDialog::accept(); 00115 } 00116 00117 #include "scriptnewfiledlg.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:38:55 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003