KDevelop API Documentation

parts/filecreate/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 #ifdef KDE_MAKE_VERSION 00384 # if KDE_VERSION < KDE_MAKE_VERSION(3,1,90) 00385 # define OLD__KDE 00386 # endif 00387 #else 00388 # define OLD__KDE 00389 #endif 00390 #ifdef OLD__KDE 00391 if (!KIO::NetAccess::exists(destDir)) 00392 #else 00393 if (!KIO::NetAccess::exists(destDir, false, 0 )) 00394 #endif 00395 KIO::NetAccess::mkdir(destDir); 00396 00397 KURL destination; 00398 destination.setPath(dest + destName); 00399 00400 KIO::NetAccess::upload(templateUrl, destination); 00401 } 00402 } 00403 00404 void FCConfigWidget::loadFileTypes(QPtrList<FileCreate::FileType> list, QListView *view, bool checkmarks) 00405 { 00406 FileType *ft; 00407 00408 for( ft = list.last(); ft; ft = list.prev()) 00409 for( int i = list.count() - 1; i >= 0; --i) 00410 { 00411 if ( (ft = list.at(i)) ) 00412 { 00413 QListViewItem *it; 00414 if (!checkmarks) 00415 it = new QListViewItem(view); 00416 else 00417 it = new QCheckListItem(view, "", QCheckListItem::CheckBox); 00418 00419 it->setText(0, ft->ext()); 00420 it->setText(1, ft->name()); 00421 it->setText(2, ft->icon()); 00422 it->setText(3, ft->descr()); 00423 it->setText(4, ""); 00424 00425 FileType *sft; 00426 for( int j = ft->subtypes().count() - 1; j >= 0; --j) 00427 { 00428 if ( (sft = ft->subtypes().at(j)) ) 00429 { 00430 QListViewItem *sit; 00431 if (!checkmarks) 00432 sit = new QListViewItem(it); 00433 else 00434 sit = new QCheckListItem(it, "", QCheckListItem::CheckBox); 00435 00436 sit->setText(0, sft->subtypeRef()); 00437 sit->setText(1, sft->name()); 00438 sit->setText(2, sft->icon()); 00439 sit->setText(3, sft->descr()); 00440 sit->setText(4, ""); 00441 } 00442 } 00443 } 00444 } 00445 } 00446 00447 void FCConfigWidget::removetemplate_button_clicked( ) 00448 { 00449 if (fctemplates_view->currentItem()) 00450 { 00451 KURL removedTemplate; 00452 removedTemplate.setPath(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0)); 00453 KIO::NetAccess::del(removedTemplate); 00454 QListViewItem *it = fctemplates_view->currentItem(); 00455 if (it->itemBelow()) 00456 { 00457 fc_view->setSelected(it->itemBelow(), true); 00458 fc_view->setCurrentItem(it->itemBelow()); 00459 } 00460 else if (it->itemAbove()) 00461 { 00462 fc_view->setSelected(it->itemAbove(), true); 00463 fc_view->setCurrentItem(it->itemAbove()); 00464 } 00465 delete it; 00466 } 00467 } 00468 00469 void FCConfigWidget::copyToProject_button_clicked() 00470 { 00471 QListViewItem *it = fcglobal_view->currentItem(); 00472 if (it) 00473 { 00474 QListViewItem *it_copy_parent = 0; 00475 QString destParent; 00476 if (it->parent()) 00477 { 00478 it_copy_parent = new QListViewItem(fc_view, it->parent()->text(0), 00479 it->parent()->text(1), 00480 it->parent()->text(2), 00481 it->parent()->text(3), 00482 locate("data", "kdevfilecreate/file-templates/"+ it->parent()->text(0))); 00483 destParent += it->parent()->text(0) + "-"; 00484 QCheckListItem *chk = dynamic_cast<QCheckListItem*>(it->parent()); 00485 if (chk) 00486 chk->setOn(false); 00487 } 00488 QListViewItem *it_copy = 0; 00489 if (it_copy_parent) 00490 it_copy = new QListViewItem(it_copy_parent, it->text(0), 00491 it->text(1), 00492 it->text(2), 00493 it->text(3), 00494 locate("data", "kdevfilecreate/file-templates/"+destParent + it->text(0))); 00495 else 00496 it_copy = new QListViewItem(fc_view, it->text(0), 00497 it->text(1), 00498 it->text(2), 00499 it->text(3), 00500 locate("data", "kdevfilecreate/file-templates/" +destParent+ it->text(0))); 00501 QCheckListItem *chk = dynamic_cast<QCheckListItem*>(it); 00502 if (chk) 00503 chk->setOn(false); 00504 fc_view->setSelected(it_copy, true); 00505 fc_view->setCurrentItem(it_copy); 00506 QListViewItem * it_child = it->firstChild(); 00507 while( it_child ) { 00508 new QListViewItem(it_copy, it_child->text(0), 00509 it_child->text(1), 00510 it_child->text(2), 00511 it_child->text(3), 00512 locate("data", "kdevfilecreate/file-templates/"+ it_copy->text(0) + "-" + it_child->text(0))); 00513 QCheckListItem *chk_child = dynamic_cast<QCheckListItem*>(it_child); 00514 if (chk_child) 00515 chk_child->setOn(false); 00516 it_child = it_child->nextSibling(); 00517 } 00518 } 00519 } 00520 00521 void FCConfigWidget::newtype_button_clicked() 00522 { 00523 FCTypeEdit *te = new FCTypeEdit(); 00524 if (te->exec() == QDialog::Accepted ) 00525 { 00526 QListViewItem *it = new QListViewItem(fc_view, te->typeext_edit->text(), 00527 te->typename_edit->text(), 00528 te->icon_url->icon(), 00529 te->typedescr_edit->text(), 00530 te->template_url->url().isEmpty() ? QString("create") : te->template_url->url()); 00531 fc_view->setSelected(it, true); 00532 fc_view->setCurrentItem(it); 00533 } 00534 delete te; 00535 } 00536 00537 void FCConfigWidget::newsubtype_button_clicked() 00538 { 00539 if (fc_view->currentItem() && (!fc_view->currentItem()->parent())) 00540 { 00541 FCTypeEdit *te = new FCTypeEdit(this); 00542 if (te->exec() == QDialog::Accepted ) 00543 { 00544 /*QListViewItem *it =*/(void) new QListViewItem(fc_view->currentItem(), 00545 te->typeext_edit->text(), 00546 te->typename_edit->text(), 00547 te->icon_url->icon(), 00548 te->typedescr_edit->text(), 00549 te->template_url->url().isEmpty() ? QString("create") : te->template_url->url()); 00550 fc_view->currentItem()->setOpen(true); 00551 } 00552 delete te; 00553 } 00554 } 00555 00556 void FCConfigWidget::remove_button_clicked() 00557 { 00558 if (fc_view->currentItem()) 00559 { 00560 QListViewItem *it = fc_view->currentItem(); 00561 if (it->itemBelow()) 00562 { 00563 fc_view->setSelected(it->itemBelow(), true); 00564 fc_view->setCurrentItem(it->itemBelow()); 00565 } 00566 else if (it->itemAbove()) 00567 { 00568 fc_view->setSelected(it->itemAbove(), true); 00569 fc_view->setCurrentItem(it->itemAbove()); 00570 } 00571 delete it; 00572 } 00573 } 00574 00575 00576 void FCConfigWidget::moveup_button_clicked() 00577 { 00578 QListViewItem *i = fc_view->currentItem(); 00579 if ( !i ) 00580 return; 00581 00582 QListViewItemIterator it( i ); 00583 QListViewItem *parent = i->parent(); 00584 --it; 00585 while ( it.current() ) { 00586 if ( it.current()->parent() == parent ) 00587 break; 00588 --it; 00589 } 00590 00591 if ( !it.current() ) 00592 return; 00593 QListViewItem *other = it.current(); 00594 00595 other->moveItem( i ); 00596 } 00597 00598 00599 void FCConfigWidget::movedown_button_clicked() 00600 { 00601 QListViewItem *i = fc_view->currentItem(); 00602 if ( !i ) 00603 return; 00604 00605 QListViewItemIterator it( i ); 00606 QListViewItem *parent = i->parent(); 00607 it++; 00608 while ( it.current() ) { 00609 if ( it.current()->parent() == parent ) 00610 break; 00611 it++; 00612 } 00613 00614 if ( !it.current() ) 00615 return; 00616 QListViewItem *other = it.current(); 00617 00618 i->moveItem( other ); 00619 } 00620 00621 00622 void FCConfigWidget::edittype_button_clicked() 00623 { 00624 QListViewItem *it = fc_view->currentItem(); 00625 if ( it ) 00626 { 00627 FCTypeEdit *te = new FCTypeEdit(this); 00628 00629 te->typeext_edit->setText(it->text(0)); 00630 te->typename_edit->setText(it->text(1)); 00631 te->icon_url->setIcon(it->text(2)); 00632 te->typedescr_edit->setText(it->text(3)); 00633 if (it->text(4) != "create") 00634 te->template_url->setURL(it->text(4)); 00635 00636 if (te->exec() == QDialog::Accepted ) 00637 { 00638 it->setText(0, te->typeext_edit->text()); 00639 it->setText(1, te->typename_edit->text()); 00640 it->setText(2, te->icon_url->icon()); 00641 it->setText(3, te->typedescr_edit->text()); 00642 if ((te->template_url->url() == "") && ((it->text(4) == "create"))) 00643 it->setText(4, "create"); 00644 else 00645 it->setText(4, te->template_url->url()); 00646 } 00647 } 00648 } 00649 00650 00651 void FCConfigWidget::newtemplate_button_clicked() 00652 { 00653 FCTemplateEdit *te = new FCTemplateEdit; 00654 if (te->exec() == QDialog::Accepted) 00655 { 00656 /*QListViewItem *it =*/(void) new QListViewItem(fctemplates_view, te->templatename_edit->text(), 00657 te->template_url->url().isEmpty() ? QString("create") : te->template_url->url()); 00658 } 00659 } 00660 00661 00662 void FCConfigWidget::edittemplate_button_clicked() 00663 { 00664 QListViewItem *it; 00665 if ( (it = fctemplates_view->currentItem()) ) 00666 { 00667 FCTemplateEdit *te = new FCTemplateEdit; 00668 te->templatename_edit->setText(it->text(0)); 00669 te->templatename_edit->setEnabled(false); 00670 if (te->exec() == QDialog::Accepted) 00671 { 00672 if ((te->template_url->url() == "") && ((it->text(1) == "create"))) 00673 it->setText(1, "create"); 00674 else 00675 it->setText(1, te->template_url->url()); 00676 } 00677 } 00678 } 00679 00680 void FCConfigWidget::edit_template_content_button_clicked( ) 00681 { 00682 if (fctemplates_view->currentItem()) 00683 { 00684 QFileInfo fi(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0)); 00685 KURL content; 00686 content.setPath(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0)); 00687 if (fi.exists()) 00688 m_part->partController()->editDocument(content); 00689 else 00690 { 00691 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"); 00692 fctemplates_view->currentItem()->setPixmap(0, SmallIcon("edit")); 00693 urlsToEdit.append(content); 00694 } 00695 } 00696 } 00697 00698 void FCConfigWidget::edit_type_content_button_clicked( ) 00699 { 00700 if (!fc_view->currentItem()) 00701 return; 00702 QListViewItem *it = fc_view->currentItem(); 00703 QString type_name = it->text(0); 00704 if (it->parent()) 00705 type_name.prepend(it->parent()->text(0) + "-"); 00706 if (!m_global) 00707 { 00708 QString typePath = m_part->project()->projectDirectory() + "/templates/" + type_name; 00709 KURL content; 00710 content.setPath(typePath); 00711 if (it->text(4).isEmpty()) 00712 m_part->partController()->editDocument(content); 00713 else 00714 { 00715 if (it->text(4) == "create") 00716 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"); 00717 else 00718 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"); 00719 fc_view->currentItem()->setPixmap(0, SmallIcon("edit")); 00720 urlsToEdit.append(content); 00721 } 00722 } 00723 else 00724 { 00725 QString dest = KGlobal::dirs()->saveLocation("data", "/kdevfilecreate/file-templates/", true); 00726 QString typePath = dest + type_name; 00727 KURL content; 00728 content.setPath(typePath); 00729 if (it->text(4).isEmpty()) 00730 { 00731 QFileInfo fi(dest+type_name); 00732 if (!fi.exists()) 00733 copyTemplate(locate("data", "kdevfilecreate/file-templates/" + type_name), dest, type_name); 00734 m_part->partController()->editDocument(content); 00735 } 00736 else 00737 { 00738 if (it->text(4) == "create") 00739 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"); 00740 else 00741 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"); 00742 fc_view->currentItem()->setPixmap(0, SmallIcon("edit")); 00743 urlsToEdit.append(content); 00744 } 00745 } 00746 } 00747 00748 #include "fcconfigwidget.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 Tue Oct 19 08:01:51 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003