KDevelop API Documentation

fcconfigwidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Alexander Dymo                                  *
00003  *   cloudtemple@mksat.net                                                 *
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 <qlistview.h>
00012 #include <qpushbutton.h>
00013 #include <qdir.h>
00014 #include <qfileinfo.h>
00015 #include <qtabwidget.h>
00016 #include <qdom.h>
00017 #include <qfile.h>
00018 #include <qtextstream.h>
00019 #include <qcheckbox.h>
00020 #include <qlineedit.h>
00021 #include <qlabel.h>
00022 
00023 #include <kstandarddirs.h>
00024 #include <kio/netaccess.h>
00025 #include <kurlrequester.h>
00026 #include <kicondialog.h>
00027 #include <klocale.h>
00028 #include <kmessagebox.h>
00029 #include <kiconloader.h>
00030 #include <kdeversion.h>
00031 
00032 #include "fctypeedit.h"
00033 #include "fctemplateedit.h"
00034 #include "domutil.h"
00035 #include "fcconfigwidget.h"
00036 #include "filecreate_part.h"
00037 #include "filecreate_filetype.h"
00038 #include "kdevproject.h"
00039 #include "kdevpartcontroller.h"
00040 
00041 
00042 FCConfigWidget::FCConfigWidget(FileCreatePart * part, bool global, QWidget *parent, const char *name):
00043     FCConfigWidgetBase(parent, name), m_part(part), m_global(global)
00044 {
00045     fc_view->setSorting(-1, FALSE);
00046     fcglobal_view->setSorting(-1, FALSE);
00047 
00048     if (m_global)
00049     {
00050         loadGlobalConfig(fc_view);
00051         fc_tabs->setTabLabel(tab1, i18n("Global Types") );
00052         fc_tabs->setTabEnabled(tab2, false);
00053         fc_tabs->setTabEnabled(tab3, false);
00054         delete tab2;
00055         delete tab3;
00056         sidetab_checkbox->setChecked(m_part->m_useSideTab);
00057     }
00058     else
00059     {
00060         loadGlobalConfig(fcglobal_view, true);
00061         loadProjectConfig(fc_view);
00062         loadProjectTemplates(fctemplates_view);
00063         sidetab_checkbox->setEnabled(false);
00064         templatesDir_label->setText(i18n("Project templates in ") + m_part->project()->projectDirectory() + "/templates");
00065     }
00066 
00067     m_globalfiletypes.setAutoDelete(true);
00068     m_projectfiletypes.setAutoDelete(true);
00069     m_projectfiletemplates.setAutoDelete(true);
00070 //    connect( fctemplates_view, SIGNAL( doubleClicked ( QListViewItem *, const QPoint &, int ) ), this, SLOT( edittemplate_button_clicked() ) );
00071 }
00072 
00073 FCConfigWidget::~FCConfigWidget()
00074 {
00075 }
00076 
00077 void FCConfigWidget::accept()
00078 {
00079     if (m_global) {
00080         m_part->m_useSideTab = sidetab_checkbox->isChecked();
00081         m_part->setShowSideTab(m_part->m_useSideTab);
00082         saveGlobalConfig();
00083     }
00084     else
00085         saveProjectConfig();
00086 
00087     m_part->m_filetypes.clear();
00088     m_part->slotProjectOpened();
00089 
00090     for (QValueList<KURL>::iterator it = urlsToEdit.begin(); it != urlsToEdit.end(); ++it )
00091     {
00092         m_part->partController()->editDocument(*it);
00093     }
00094 }
00095 
00096 void FCConfigWidget::loadGlobalConfig(QListView *view, bool checkmarks)
00097 {
00098     QString globalXMLFile = ::locate("data", "kdevfilecreate/template-info.xml");
00099     QDomDocument globalDom;
00100     if (!globalXMLFile.isNull() &&
00101         DomUtil::openDOMFile(globalDom,globalXMLFile)) {
00102         m_part->readTypes(globalDom, m_globalfiletypes, false);
00103     }
00104 
00105 
00106     loadFileTypes(m_globalfiletypes, view, checkmarks);
00107 
00108     if (checkmarks)
00109     {
00110         QDomElement useGlobalTypes =
00111             DomUtil::elementByPath(*(m_part->projectDom()),"/kdevfilecreate/useglobaltypes");
00112         for(QDomNode node = useGlobalTypes.firstChild(); !node.isNull();node=node.nextSibling())
00113         {
00114             if (node.isElement() && node.nodeName()=="type")
00115             {
00116                 QDomElement element = node.toElement();
00117                 QString ext = element.attribute("ext");
00118                 QString subtyperef = element.attribute("subtyperef");
00119                 if (subtyperef.isNull())
00120                 {
00121                     QListViewItem *it = view->findItem(ext, 0);
00122                     if (it)
00123                     {
00124                         ((QCheckListItem*)it)->setOn(true);
00125 
00126                         QListViewItem *lastChild = it->firstChild();
00127                         while ( lastChild )
00128                         {
00129                             ((QCheckListItem*)lastChild)->setOn(true);
00130                             lastChild = lastChild->nextSibling();
00131                         }
00132                     }
00133                 }
00134                 else
00135                 {
00136                     QListViewItem *it = view->findItem(subtyperef, 0);
00137                     if (it)
00138                         ((QCheckListItem*)it)->setOn(true);
00139                 }
00140             }
00141         }
00142     }
00143 }
00144 
00145 void FCConfigWidget::loadProjectConfig(QListView *view)
00146 {
00147     m_part->readTypes( *(m_part->projectDom()), m_projectfiletypes, false );
00148     loadFileTypes(m_projectfiletypes, view, false);
00149 }
00150 
00151 void FCConfigWidget::loadProjectTemplates(QListView *view)
00152 {
00153     QDir templDir( m_part->project()->projectDirectory() + "/templates/" );
00154     templDir.setFilter( QDir::Files );
00155     const QFileInfoList * list = templDir.entryInfoList();
00156     if( list ){
00157       QFileInfoListIterator it( *list );
00158       QFileInfo *fi;
00159       while ( (fi = it.current()) != 0 ) {
00160         FileType * filetype;
00161         filetype = new FileType;
00162         //name shall be "" for proper configuration
00163         filetype->setName( "" );
00164         filetype->setExt( fi->fileName() );
00165         m_projectfiletemplates.append(filetype);
00166         filetype->setEnabled(false);
00167         ++it;
00168       }
00169     }
00170     loadFileTypes(m_projectfiletemplates, view, false);
00171 }
00172 
00173 
00174 void FCConfigWidget::saveGlobalConfig()
00175 {
00176     QDomDocument globalDom;
00177     QDomElement  element = globalDom.createElement("kdevelop" );
00178     globalDom.appendChild(element);
00179     QDomElement  apPart  = globalDom.createElement("kdevfilecreate");
00180     element.appendChild(apPart);
00181     QDomElement useST = globalDom.createElement("sidetab");
00182     useST.setAttribute("active", m_part->m_useSideTab ? "yes" : "no" );
00183     apPart.appendChild(useST);
00184     QDomElement fileTypes = globalDom.createElement( "filetypes" );
00185     apPart.appendChild( fileTypes );
00186 
00187     saveConfiguration(globalDom, fileTypes, true);
00188 
00189     QFile config( KGlobal::dirs()->saveLocation("data", "kdevfilecreate/", true) + "template-info.xml" );
00190     config.open(IO_WriteOnly | IO_Truncate);
00191     QTextStream stream(&config);
00192     stream << "<?xml version = '1.0'?>";
00193     stream << globalDom.toString();
00194     config.close();
00195 }
00196 
00197 void FCConfigWidget::saveProjectConfig()
00198 {
00199     QDomDocument dom     = *m_part->projectDom( );
00200     QDomElement  element = dom.documentElement( );
00201     QDomElement  apPart  = element.namedItem( "kdevfilecreate" ).toElement( );
00202     if( apPart.isNull( ) )
00203     {
00204         apPart = dom.createElement( "kdevfilecreate" );
00205         element.appendChild( apPart );
00206     }
00207 
00208 
00209     // project template configuration
00210 
00211     QDomElement projectTypes = apPart.namedItem( "filetypes" ).toElement( );
00212     apPart.removeChild(projectTypes);
00213     projectTypes = dom.createElement( "filetypes" );
00214     apPart.appendChild( projectTypes );
00215 
00216     saveConfiguration(dom, projectTypes, false);
00217 
00218 
00219     // global template usage
00220 
00221     QDomElement globalTypes = apPart.namedItem( "useglobaltypes" ).toElement( );
00222     apPart.removeChild(globalTypes);
00223     globalTypes = dom.createElement( "useglobaltypes" );
00224     apPart.appendChild( globalTypes );
00225 
00226     QListViewItemIterator it( fcglobal_view );
00227     for( ; it.current( ); ++it ){
00228         if (!it.current()->parent())
00229         {
00230             QCheckListItem *chit = dynamic_cast<QCheckListItem*>(it.current());
00231             if ( !chit ) continue;
00232             if (chit->isOn())
00233             {
00234                 QDomElement type = dom.createElement( "type" );
00235                 type.setAttribute( "ext", chit->text(0) );
00236                 globalTypes.appendChild( type );
00237             }
00238             else
00239             {
00240                 QListViewItem *lastChild = chit->firstChild();
00241                 while ( lastChild )
00242                 {
00243                     QCheckListItem *chsit = dynamic_cast<QCheckListItem*>(lastChild);
00244                     if ( (chsit) && (chsit->isOn()))
00245                     {
00246                         QDomElement type = dom.createElement( "type" );
00247                         type.setAttribute( "ext", chit->text(0) );
00248                         type.setAttribute( "subtyperef", chsit->text(0) );
00249                         globalTypes.appendChild( type );
00250                     }
00251 
00252                     lastChild = lastChild->nextSibling();
00253                 }
00254             }
00255         }
00256     }
00257 
00258 
00259     // project template files
00260 
00261     //check for removed templates
00262 /*    QDir templDir( m_part->project()->projectDirectory() + "/templates/" );
00263     templDir.setFilter( QDir::Files );
00264     const QFileInfoList * list = templDir.entryInfoList();
00265     if( list )
00266     {
00267         QFileInfoListIterator it( *list );
00268         QFileInfo *fi;
00269         while ( (fi = it.current()) != 0 )
00270         {
00271             if ( ( !(fctemplates_view->findItem(fi->fileName(), 0)) ) &&
00272                 ( !(fc_view->findItem(fi->fileName(), 0)) ) )
00273             {
00274                 KURL removedTemplate;
00275                 removedTemplate.setPath(m_part->project()->projectDirectory() + "/templates/" + fi->fileName());
00276                 KIO::NetAccess::del(removedTemplate);
00277             }
00278             ++it;
00279         }
00280     }*/
00281     //check for new templates and those with location changed
00282     QListViewItemIterator it2(fctemplates_view);
00283     while (it2.current())
00284     {
00285         if (!it2.current()->text(1).isEmpty())
00286         {
00287             QString dest;
00288             dest = m_part->project()->projectDirectory() + "/templates/";
00289             if (it2.current()->text(1) == "create")
00290                 copyTemplate(QString::null, dest, it2.current()->text(0));
00291             else
00292                 copyTemplate(it2.current()->text(1), dest, it2.current()->text(0));
00293         }
00294         ++it2;
00295     }
00296 }
00297 
00298 void FCConfigWidget::saveConfiguration(QDomDocument &dom, QDomElement &element, bool global)
00299 {
00300     QListViewItemIterator it( fc_view );
00301     for( ; it.current( ); ++it ){
00302         if (!it.current()->parent())
00303         {
00304             QDomElement type = dom.createElement( "type" );
00305             type.setAttribute( "ext", it.current()->text(0) );
00306             type.setAttribute( "name", it.current()->text(1) );
00307             if (it.current()->childCount() > 0)
00308                 type.setAttribute( "create", "no");
00309             else
00310                 type.setAttribute( "create", "template");
00311             type.setAttribute( "icon", it.current()->text(2) );
00312 
00313             QDomElement edescr = dom.createElement("descr");
00314             type.appendChild(edescr);
00315             QDomText descr = dom.createTextNode( it.current()->text(3) );
00316             edescr.appendChild(descr);
00317 
00318             if (!it.current()->text(4).isEmpty())
00319             {
00320                 QString dest;
00321                 if (global)
00322                     dest = KGlobal::dirs()->saveLocation("data", "/kdevfilecreate/file-templates/", true);
00323                 else
00324                     dest = m_part->project()->projectDirectory() + "/templates/";
00325                 if (it.current()->text(4) == "create")
00326                     copyTemplate(QString::null, dest, it.current()->text(0));
00327                 else
00328                     copyTemplate(it.current()->text(4), dest, it.current()->text(0));
00329             }
00330 
00331 
00332             QListViewItem *lastChild = it.current()->firstChild();
00333             while ( lastChild )
00334             {
00335                 QDomElement subtype = dom.createElement( "subtype" );
00336                 subtype.setAttribute( "ref", lastChild->text(0) );
00337                 subtype.setAttribute( "name", lastChild->text(1) );
00338                 subtype.setAttribute( "icon", lastChild->text(2) );
00339 
00340                 QDomElement edescr = dom.createElement("descr");
00341                 subtype.appendChild(edescr);
00342                 QDomText descr = dom.createTextNode( lastChild->text(3) );
00343                 edescr.appendChild(descr);
00344 
00345                 if (!lastChild->text(4).isEmpty())
00346                 {
00347                     QString dest;
00348                     if (global)
00349                         dest = KGlobal::dirs()->saveLocation("data", "/kdevfilecreate/file-templates/", true);
00350                     else
00351                         dest = m_part->project()->projectDirectory() + "/templates/";
00352                     if (lastChild->text(4) == "create")
00353                         copyTemplate(QString::null, dest, it.current()->text(0) + "-" + lastChild->text(0));
00354                     else
00355                         copyTemplate(lastChild->text(4), dest, it.current()->text(0) + "-" + lastChild->text(0));
00356                 }
00357 
00358                 type.appendChild( subtype );
00359                 lastChild = lastChild->nextSibling();
00360             }
00361 
00362             element.appendChild( type );
00363         }
00364     }
00365 }
00366 
00367 void FCConfigWidget::copyTemplate(QString templateUrl, QString dest, QString destName)
00368 {
00369     if (templateUrl.isEmpty())
00370     {
00371         QDir d(dest);
00372         if (!d.exists())
00373             d.mkdir(dest);
00374 
00375         QFile f(dest + destName);
00376         f.open(IO_WriteOnly);
00377         f.close();
00378     }
00379     else
00380     {
00381         KURL destDir;
00382         destDir.setPath(dest);
00383         if (!KIO::NetAccess::exists(destDir, false, 0 ))
00384             KIO::NetAccess::mkdir(destDir);
00385 
00386         KURL destination;
00387         destination.setPath(dest + destName);
00388 
00389         KIO::NetAccess::upload(templateUrl, destination);
00390     }
00391 }
00392 
00393 void FCConfigWidget::loadFileTypes(QPtrList<FileCreate::FileType> list, QListView *view, bool checkmarks)
00394 {
00395     FileType *ft;
00396 
00397     for( ft = list.last(); ft; ft = list.prev())
00398     for( int i = list.count() - 1; i >= 0; --i)
00399     {
00400         if ( (ft = list.at(i)) )
00401         {
00402             QListViewItem *it;
00403             if (!checkmarks)
00404                 it = new QListViewItem(view);
00405             else
00406                 it = new QCheckListItem(view, "", QCheckListItem::CheckBox);
00407 
00408             it->setText(0, ft->ext());
00409             it->setText(1, ft->name());
00410             it->setText(2, ft->icon());
00411             it->setText(3, ft->descr());
00412             it->setText(4, "");
00413 
00414             FileType *sft;
00415             for( int j = ft->subtypes().count() - 1; j >= 0; --j)
00416             {
00417                 if ( (sft = ft->subtypes().at(j)) )
00418                 {
00419                     QListViewItem *sit;
00420                     if (!checkmarks)
00421                         sit = new QListViewItem(it);
00422                     else
00423                         sit = new QCheckListItem(it, "", QCheckListItem::CheckBox);
00424 
00425                     sit->setText(0, sft->subtypeRef());
00426                     sit->setText(1, sft->name());
00427                     sit->setText(2, sft->icon());
00428                     sit->setText(3, sft->descr());
00429                     sit->setText(4, "");
00430                 }
00431             }
00432         }
00433     }
00434 }
00435 
00436 void FCConfigWidget::removetemplate_button_clicked( )
00437 {
00438     if (fctemplates_view->currentItem())
00439     {
00440         KURL removedTemplate;
00441         removedTemplate.setPath(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0));
00442         KIO::NetAccess::del(removedTemplate);
00443         QListViewItem *it = fctemplates_view->currentItem();
00444         if (it->itemBelow())
00445         {
00446             fc_view->setSelected(it->itemBelow(), true);
00447             fc_view->setCurrentItem(it->itemBelow());
00448         }
00449         else if (it->itemAbove())
00450         {
00451             fc_view->setSelected(it->itemAbove(), true);
00452             fc_view->setCurrentItem(it->itemAbove());
00453         }
00454         delete it;
00455     }
00456 }
00457 
00458 void FCConfigWidget::copyToProject_button_clicked()
00459 {
00460     QListViewItem *it = fcglobal_view->currentItem();
00461     if (it)
00462     {
00463         QListViewItem *it_copy_parent = 0;
00464         QString destParent;
00465         if (it->parent())
00466         {
00467             it_copy_parent = new QListViewItem(fc_view, it->parent()->text(0),
00468                 it->parent()->text(1),
00469                 it->parent()->text(2),
00470                 it->parent()->text(3),
00471                 locate("data", "kdevfilecreate/file-templates/"+ it->parent()->text(0)));
00472             destParent += it->parent()->text(0) + "-";
00473             QCheckListItem *chk = dynamic_cast<QCheckListItem*>(it->parent());
00474             if (chk)
00475                 chk->setOn(false);
00476         }
00477         QListViewItem *it_copy = 0;
00478         if (it_copy_parent)
00479             it_copy = new QListViewItem(it_copy_parent, it->text(0),
00480                 it->text(1),
00481                 it->text(2),
00482                 it->text(3),
00483                 locate("data", "kdevfilecreate/file-templates/"+destParent + it->text(0)));
00484         else
00485             it_copy = new QListViewItem(fc_view, it->text(0),
00486                 it->text(1),
00487                 it->text(2),
00488                 it->text(3),
00489                 locate("data", "kdevfilecreate/file-templates/" +destParent+ it->text(0)));
00490         QCheckListItem *chk = dynamic_cast<QCheckListItem*>(it);
00491         if (chk)
00492             chk->setOn(false);
00493         fc_view->setSelected(it_copy, true);
00494         fc_view->setCurrentItem(it_copy);
00495         QListViewItem * it_child = it->firstChild();
00496         while( it_child ) {
00497             new QListViewItem(it_copy, it_child->text(0),
00498                 it_child->text(1),
00499                 it_child->text(2),
00500                 it_child->text(3),
00501                 locate("data", "kdevfilecreate/file-templates/"+ it_copy->text(0) + "-" + it_child->text(0)));
00502             QCheckListItem *chk_child = dynamic_cast<QCheckListItem*>(it_child);
00503             if (chk_child)
00504                 chk_child->setOn(false);
00505             it_child = it_child->nextSibling();
00506         }
00507     }
00508 }
00509 
00510 void FCConfigWidget::newtype_button_clicked()
00511 {
00512     FCTypeEdit *te = new FCTypeEdit();
00513     if (te->exec() == QDialog::Accepted )
00514     {
00515         QListViewItem *it = new QListViewItem(fc_view, te->typeext_edit->text(),
00516             te->typename_edit->text(),
00517             te->icon_url->icon(),
00518             te->typedescr_edit->text(),
00519             te->template_url->url().isEmpty() ? QString("create") : te->template_url->url());
00520         fc_view->setSelected(it, true);
00521         fc_view->setCurrentItem(it);
00522     }
00523     delete te;
00524 }
00525 
00526 void FCConfigWidget::newsubtype_button_clicked()
00527 {
00528     if (fc_view->currentItem() && (!fc_view->currentItem()->parent()))
00529     {
00530         FCTypeEdit *te = new FCTypeEdit(this);
00531         if (te->exec() == QDialog::Accepted )
00532         {
00533             /*QListViewItem *it =*/(void) new QListViewItem(fc_view->currentItem(),
00534                 te->typeext_edit->text(),
00535                 te->typename_edit->text(),
00536                 te->icon_url->icon(),
00537                 te->typedescr_edit->text(),
00538                 te->template_url->url().isEmpty() ? QString("create") : te->template_url->url());
00539             fc_view->currentItem()->setOpen(true);
00540         }
00541         delete te;
00542     }
00543 }
00544 
00545 void FCConfigWidget::remove_button_clicked()
00546 {
00547     if (fc_view->currentItem())
00548     {
00549         QListViewItem *it = fc_view->currentItem();
00550         if (it->itemBelow())
00551         {
00552             fc_view->setSelected(it->itemBelow(), true);
00553             fc_view->setCurrentItem(it->itemBelow());
00554         }
00555         else if (it->itemAbove())
00556         {
00557             fc_view->setSelected(it->itemAbove(), true);
00558             fc_view->setCurrentItem(it->itemAbove());
00559         }
00560         delete it;
00561     }
00562 }
00563 
00564 
00565 void FCConfigWidget::moveup_button_clicked()
00566 {
00567     QListViewItem *i = fc_view->currentItem();
00568     if ( !i )
00569         return;
00570 
00571     QListViewItemIterator it( i );
00572     QListViewItem *parent = i->parent();
00573     --it;
00574     while ( it.current() ) {
00575         if ( it.current()->parent() == parent )
00576             break;
00577         --it;
00578     }
00579 
00580     if ( !it.current() )
00581         return;
00582     QListViewItem *other = it.current();
00583 
00584     other->moveItem( i );
00585 }
00586 
00587 
00588 void FCConfigWidget::movedown_button_clicked()
00589 {
00590     QListViewItem *i = fc_view->currentItem();
00591     if ( !i )
00592         return;
00593 
00594     QListViewItemIterator it( i );
00595     QListViewItem *parent = i->parent();
00596     it++;
00597     while ( it.current() ) {
00598         if ( it.current()->parent() == parent )
00599             break;
00600         it++;
00601     }
00602 
00603     if ( !it.current() )
00604         return;
00605     QListViewItem *other = it.current();
00606 
00607     i->moveItem( other );
00608 }
00609 
00610 
00611 void FCConfigWidget::edittype_button_clicked()
00612 {
00613     QListViewItem *it = fc_view->currentItem();
00614     if ( it )
00615     {
00616         FCTypeEdit *te = new FCTypeEdit(this);
00617 
00618         te->typeext_edit->setText(it->text(0));
00619         te->typename_edit->setText(it->text(1));
00620         te->icon_url->setIcon(it->text(2));
00621         te->typedescr_edit->setText(it->text(3));
00622         if (it->text(4) != "create")
00623             te->template_url->setURL(it->text(4));
00624 
00625         if (te->exec() == QDialog::Accepted )
00626         {
00627             it->setText(0, te->typeext_edit->text());
00628             it->setText(1, te->typename_edit->text());
00629             it->setText(2, te->icon_url->icon());
00630             it->setText(3, te->typedescr_edit->text());
00631             if ((te->template_url->url() == "") && ((it->text(4) == "create")))
00632                 it->setText(4, "create");
00633             else
00634                 it->setText(4, te->template_url->url());
00635         }
00636     }
00637 }
00638 
00639 
00640 void FCConfigWidget::newtemplate_button_clicked()
00641 {
00642     FCTemplateEdit *te = new FCTemplateEdit;
00643     if (te->exec() == QDialog::Accepted)
00644     {
00645         /*QListViewItem *it =*/(void) new QListViewItem(fctemplates_view, te->templatename_edit->text(),
00646             te->template_url->url().isEmpty() ? QString("create") : te->template_url->url());
00647     }
00648 }
00649 
00650 
00651 void FCConfigWidget::edittemplate_button_clicked()
00652 {
00653     QListViewItem *it;
00654     if ( (it = fctemplates_view->currentItem()) )
00655     {
00656         FCTemplateEdit *te = new FCTemplateEdit;
00657         te->templatename_edit->setText(it->text(0));
00658         te->templatename_edit->setEnabled(false);
00659         if (te->exec() == QDialog::Accepted)
00660         {
00661             if ((te->template_url->url() == "") && ((it->text(1) == "create")))
00662                 it->setText(1, "create");
00663             else
00664                 it->setText(1, te->template_url->url());
00665         }
00666     }
00667 }
00668 
00669 void FCConfigWidget::edit_template_content_button_clicked( )
00670 {
00671     if (fctemplates_view->currentItem())
00672     {
00673         QFileInfo fi(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0));
00674         KURL content;
00675         content.setPath(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0));
00676         if (fi.exists())
00677             m_part->partController()->editDocument(content);
00678         else
00679         {
00680             KMessageBox::information(this, i18n("Requested template does not exist yet.\nIt will be opened immediately after accepting the configuration dialog."), QString::null, "Edit template content warning");
00681             fctemplates_view->currentItem()->setPixmap(0, SmallIcon("edit"));
00682             urlsToEdit.append(content);
00683         }
00684     }
00685 }
00686 
00687 void FCConfigWidget::edit_type_content_button_clicked( )
00688 {
00689     if (!fc_view->currentItem())
00690         return;
00691     QListViewItem *it = fc_view->currentItem();
00692     QString type_name = it->text(0);
00693     if (it->parent())
00694         type_name.prepend(it->parent()->text(0) + "-");
00695     if (!m_global)
00696     {
00697         QString typePath = m_part->project()->projectDirectory() + "/templates/" + type_name;
00698         KURL content;
00699         content.setPath(typePath);
00700         if (it->text(4).isEmpty())
00701             m_part->partController()->editDocument(content);
00702         else
00703         {
00704             if (it->text(4) == "create")
00705                 KMessageBox::information(this, i18n("Template for the selected file type does not exist yet.\nIt will be opened immediately after accepting the configuration dialog."), QString::null, "Edit type template content warning");
00706             else
00707                 KMessageBox::information(this, i18n("Template for the selected file type has been changed.\nIt will be opened immediately after accepting the configuration dialog."), QString::null, "Edit type template content warning");
00708             fc_view->currentItem()->setPixmap(0, SmallIcon("edit"));
00709             urlsToEdit.append(content);
00710         }
00711     }
00712     else
00713     {
00714         QString dest = KGlobal::dirs()->saveLocation("data", "/kdevfilecreate/file-templates/", true);
00715         QString typePath = dest + type_name;
00716         KURL content;
00717         content.setPath(typePath);
00718         if (it->text(4).isEmpty())
00719         {
00720             QFileInfo fi(dest+type_name);
00721             if (!fi.exists())
00722                 copyTemplate(locate("data", "kdevfilecreate/file-templates/" + type_name), dest, type_name);
00723             m_part->partController()->editDocument(content);
00724         }
00725         else
00726         {
00727             if (it->text(4) == "create")
00728                 KMessageBox::information(this, i18n("Template for the selected file type does not exist yet.\nIt will be opened immediately after accepting the configuration dialog."), QString::null, "Edit global type template content warning");
00729             else
00730                 KMessageBox::information(this, i18n("Template for the selected file type has been changed.\nIt will be opened immediately after accepting the configuration dialog."), QString::null, "Edit global type template content warning");
00731             fc_view->currentItem()->setPixmap(0, SmallIcon("edit"));
00732             urlsToEdit.append(content);
00733         }
00734     }
00735 }
00736 
00737 #include "fcconfigwidget.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:56 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003