KDevelop API Documentation

parts/filecreate/filecreate_newfile.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 by Julian Rockey * 00003 * linux@jrockey.com * 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 #include "filecreate_newfile.h" 00012 00013 #include "filecreate_newfile.moc" 00014 00015 #include <qvbox.h> 00016 #include <qgrid.h> 00017 00018 #include <qhbox.h> 00019 #include <qlayout.h> 00020 #include <qcheckbox.h> 00021 #include <qlabel.h> 00022 #include <qlineedit.h> 00023 #include <kurlrequester.h> 00024 #include <kcombobox.h> 00025 #include <klocale.h> 00026 #include <kdebug.h> 00027 00028 namespace FileCreate { 00029 00030 NewFileChooser::NewFileChooser(QWidget * parent) : 00031 KDialogBase(KDialogBase::Plain, i18n("New file dialog (title)", "New File"), KDialogBase::Ok|KDialogBase::Cancel, 00032 KDialogBase::Ok, parent, "New file", true) 00033 { 00034 QVBoxLayout* lay = new QVBoxLayout( plainPage(), 5, 5 ); 00035 00036 lay->addWidget( new QLabel( i18n("<b>New file creation</b>"), plainPage() ) ); 00037 00038 QGridLayout* grid = new QGridLayout(lay, 2, 2, 5 ); 00039 QLabel * l = new QLabel(i18n("&Directory:"), plainPage() ); 00040 grid->addWidget(l, 0, 0); 00041 m_urlreq = new KURLRequester( plainPage(), "url request" ); 00042 grid->addWidget(m_urlreq, 0, 1); 00043 l->setBuddy(m_urlreq); 00044 l = new QLabel(i18n("&File name:"), plainPage() ); 00045 grid->addWidget(l, 1, 0); 00046 m_filename = new QLineEdit( plainPage() ); 00047 grid->addWidget(m_filename, 1, 1); 00048 l->setBuddy(m_filename); 00049 // lay->addWidget( grid ); 00050 00051 QHBoxLayout* hbox = new QHBoxLayout( lay, 5 ); 00052 m_filetypes = new KComboBox( plainPage(), "combo" ); 00053 hbox->addWidget(m_filetypes); 00054 m_addToProject = new QCheckBox( i18n("Add to project (on checkbox)", "&Add to project"), plainPage(), "addproject" ); 00055 hbox->addWidget(m_addToProject); 00056 00057 lay->addStretch(20); 00058 00059 m_filename->setFocus(); 00060 m_addToProject->setChecked( true ); 00061 00062 m_urlreq->setMode((int) KFile::Directory); 00063 connect( m_filename, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotFileNameChanged(const QString & ) ) ); 00064 slotFileNameChanged( m_filename->text() ); 00065 } 00066 00067 NewFileChooser::~NewFileChooser() { 00068 } 00069 00070 void NewFileChooser::slotFileNameChanged(const QString & _text) 00071 { 00072 enableButtonOK( !_text.isEmpty() ); 00073 } 00074 00075 void NewFileChooser::setFileTypes(QPtrList<FileType> filetypes) { 00076 for(FileType * filetype = filetypes.first(); 00077 filetype; 00078 filetype=filetypes.next()) { 00079 00080 if (filetype->enabled()) { 00081 00082 if (filetype->subtypes().count()==0) 00083 addType(filetype); 00084 00085 QPtrList<FileType> subtypes = filetype->subtypes(); 00086 for(FileType * subtype = subtypes.first(); 00087 subtype; 00088 subtype=subtypes.next()) { 00089 if (subtype->enabled()) 00090 addType(subtype); 00091 00092 } 00093 00094 } 00095 00096 } 00097 00098 } 00099 00100 KURL NewFileChooser::url() const { 00101 00102 KURL result = m_urlreq->url(); 00103 result.cd( m_filename->text() ); 00104 return result; 00105 } 00106 00107 bool NewFileChooser::addToProject() const { 00108 return m_addToProject->isChecked(); 00109 } 00110 00111 const FileType *NewFileChooser::selectedType() const { 00112 if (!m_filetypes->count()) return NULL; 00113 return m_typeInCombo[m_filetypes->currentItem()]; 00114 } 00115 00116 void NewFileChooser::addType(const FileType * filetype) { 00117 m_typeInCombo[m_filetypes->count()]=filetype; 00118 m_filetypes->insertItem( filetype->name() + 00119 (filetype->ext()!="" ? QString(" (." + filetype->ext() + ")") : QString("") ) ); 00120 } 00121 00122 void NewFileChooser::setCurrent(const FileType *filetype) { 00123 int changeToRow = -1; 00124 QMap<int,const FileType*>::Iterator it; 00125 for ( it = m_typeInCombo.begin(); it != m_typeInCombo.end() && changeToRow==-1; ++it ) { 00126 if (it.data()==filetype) 00127 changeToRow=it.key(); 00128 } 00129 if (changeToRow>-1) m_filetypes->setCurrentItem(changeToRow); 00130 } 00131 00132 void NewFileChooser::setDirectory(const QString & url) { 00133 m_urlreq->setURL(url); 00134 } 00135 00136 void NewFileChooser::setName(const QString & name) { 00137 m_filename->setText(name); 00138 } 00139 00140 00141 }
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:39:11 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003