From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- parts/filecreate/Makefile.am | 23 + parts/filecreate/README | 3 + parts/filecreate/README.dox | 76 +++ parts/filecreate/addglobaldlg.cpp | 106 ++++ parts/filecreate/addglobaldlg.h | 44 ++ parts/filecreate/fcconfigwidget.cpp | 709 +++++++++++++++++++++++++ parts/filecreate/fcconfigwidget.h | 72 +++ parts/filecreate/fcconfigwidgetbase.ui | 540 +++++++++++++++++++ parts/filecreate/fctemplateedit.cpp | 36 ++ parts/filecreate/fctemplateedit.h | 30 ++ parts/filecreate/fctemplateeditbase.ui | 193 +++++++ parts/filecreate/fctemplateeditbase.ui.h | 26 + parts/filecreate/fctypeedit.cpp | 40 ++ parts/filecreate/fctypeedit.h | 30 ++ parts/filecreate/fctypeeditbase.ui | 282 ++++++++++ parts/filecreate/fctypeeditbase.ui.h | 26 + parts/filecreate/file-templates/Makefile.am | 2 + parts/filecreate/file-templates/dox | 22 + parts/filecreate/file-templates/qrc | 5 + parts/filecreate/file-templates/ts | 2 + parts/filecreate/file-templates/ui | 20 + parts/filecreate/file-templates/ui-confdialog | 165 ++++++ parts/filecreate/file-templates/ui-dialog | 20 + parts/filecreate/file-templates/ui-dialog-qt4 | 22 + parts/filecreate/file-templates/ui-dialogb | 123 +++++ parts/filecreate/file-templates/ui-dialogb-qt4 | 100 ++++ parts/filecreate/file-templates/ui-dialogr | 123 +++++ parts/filecreate/file-templates/ui-dialogr-qt4 | 100 ++++ parts/filecreate/file-templates/ui-mainwin | 436 +++++++++++++++ parts/filecreate/file-templates/ui-mainwin-qt4 | 34 ++ parts/filecreate/file-templates/ui-tabdialog | 147 +++++ parts/filecreate/file-templates/ui-widget | 20 + parts/filecreate/file-templates/ui-widget-qt4 | 22 + parts/filecreate/file-templates/ui-wizard | 28 + parts/filecreate/filecreate_filedialog.cpp | 65 +++ parts/filecreate/filecreate_filedialog.h | 46 ++ parts/filecreate/filecreate_filetype.cpp | 21 + parts/filecreate/filecreate_filetype.h | 63 +++ parts/filecreate/filecreate_listitem.cpp | 101 ++++ parts/filecreate/filecreate_listitem.h | 49 ++ parts/filecreate/filecreate_newfile.cpp | 162 ++++++ parts/filecreate/filecreate_newfile.h | 59 ++ parts/filecreate/filecreate_part.cpp | 562 ++++++++++++++++++++ parts/filecreate/filecreate_part.h | 144 +++++ parts/filecreate/filecreate_typechooser.h | 47 ++ parts/filecreate/filecreate_typechoosersig.h | 28 + parts/filecreate/filecreate_widget2.cpp | 228 ++++++++ parts/filecreate/filecreate_widget2.h | 113 ++++ parts/filecreate/filecreate_widget3.cpp | 119 +++++ parts/filecreate/filecreate_widget3.h | 50 ++ parts/filecreate/kdevfilecreate.desktop | 77 +++ parts/filecreate/kdevpart_filecreate.rc | 11 + parts/filecreate/template-info.xml | 181 +++++++ 53 files changed, 5753 insertions(+) create mode 100644 parts/filecreate/Makefile.am create mode 100644 parts/filecreate/README create mode 100644 parts/filecreate/README.dox create mode 100644 parts/filecreate/addglobaldlg.cpp create mode 100644 parts/filecreate/addglobaldlg.h create mode 100644 parts/filecreate/fcconfigwidget.cpp create mode 100644 parts/filecreate/fcconfigwidget.h create mode 100644 parts/filecreate/fcconfigwidgetbase.ui create mode 100644 parts/filecreate/fctemplateedit.cpp create mode 100644 parts/filecreate/fctemplateedit.h create mode 100644 parts/filecreate/fctemplateeditbase.ui create mode 100644 parts/filecreate/fctemplateeditbase.ui.h create mode 100644 parts/filecreate/fctypeedit.cpp create mode 100644 parts/filecreate/fctypeedit.h create mode 100644 parts/filecreate/fctypeeditbase.ui create mode 100644 parts/filecreate/fctypeeditbase.ui.h create mode 100644 parts/filecreate/file-templates/Makefile.am create mode 100644 parts/filecreate/file-templates/dox create mode 100644 parts/filecreate/file-templates/qrc create mode 100644 parts/filecreate/file-templates/ts create mode 100644 parts/filecreate/file-templates/ui create mode 100644 parts/filecreate/file-templates/ui-confdialog create mode 100644 parts/filecreate/file-templates/ui-dialog create mode 100644 parts/filecreate/file-templates/ui-dialog-qt4 create mode 100644 parts/filecreate/file-templates/ui-dialogb create mode 100644 parts/filecreate/file-templates/ui-dialogb-qt4 create mode 100644 parts/filecreate/file-templates/ui-dialogr create mode 100644 parts/filecreate/file-templates/ui-dialogr-qt4 create mode 100644 parts/filecreate/file-templates/ui-mainwin create mode 100644 parts/filecreate/file-templates/ui-mainwin-qt4 create mode 100644 parts/filecreate/file-templates/ui-tabdialog create mode 100644 parts/filecreate/file-templates/ui-widget create mode 100644 parts/filecreate/file-templates/ui-widget-qt4 create mode 100644 parts/filecreate/file-templates/ui-wizard create mode 100644 parts/filecreate/filecreate_filedialog.cpp create mode 100644 parts/filecreate/filecreate_filedialog.h create mode 100644 parts/filecreate/filecreate_filetype.cpp create mode 100644 parts/filecreate/filecreate_filetype.h create mode 100644 parts/filecreate/filecreate_listitem.cpp create mode 100644 parts/filecreate/filecreate_listitem.h create mode 100644 parts/filecreate/filecreate_newfile.cpp create mode 100644 parts/filecreate/filecreate_newfile.h create mode 100644 parts/filecreate/filecreate_part.cpp create mode 100644 parts/filecreate/filecreate_part.h create mode 100644 parts/filecreate/filecreate_typechooser.h create mode 100644 parts/filecreate/filecreate_typechoosersig.h create mode 100644 parts/filecreate/filecreate_widget2.cpp create mode 100644 parts/filecreate/filecreate_widget2.h create mode 100644 parts/filecreate/filecreate_widget3.cpp create mode 100644 parts/filecreate/filecreate_widget3.h create mode 100644 parts/filecreate/kdevfilecreate.desktop create mode 100644 parts/filecreate/kdevpart_filecreate.rc create mode 100644 parts/filecreate/template-info.xml (limited to 'parts/filecreate') diff --git a/parts/filecreate/Makefile.am b/parts/filecreate/Makefile.am new file mode 100644 index 00000000..462a8543 --- /dev/null +++ b/parts/filecreate/Makefile.am @@ -0,0 +1,23 @@ +# + +SUBDIRS = file-templates + +INCLUDES = -I$(top_srcdir)/lib/interfaces \ + -I$(top_srcdir)/lib/interfaces/extensions -I$(top_srcdir)/lib/util $(all_includes) + +kde_module_LTLIBRARIES = libkdevfilecreate.la +libkdevfilecreate_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) +libkdevfilecreate_la_LIBADD = $(top_builddir)/lib/libkdevelop.la + +libkdevfilecreate_la_SOURCES = filecreate_part.cpp filecreate_listitem.cpp \ + filecreate_filetype.cpp filecreate_filedialog.cpp fcconfigwidgetbase.ui fcconfigwidget.cpp \ + fctypeeditbase.ui fctypeedit.cpp fctemplateeditbase.ui fctemplateedit.cpp \ + filecreate_newfile.cpp + +METASOURCES = AUTO + +servicedir = $(kde_servicesdir) +service_DATA = kdevfilecreate.desktop + +rcdir = $(kde_datadir)/kdevfilecreate +rc_DATA = kdevpart_filecreate.rc template-info.xml diff --git a/parts/filecreate/README b/parts/filecreate/README new file mode 100644 index 00000000..731741e1 --- /dev/null +++ b/parts/filecreate/README @@ -0,0 +1,3 @@ +Please read the on-line, automaticaly updated KDevelop API documentation at: +http://www.kdevelop.org +or read the README.dox file. diff --git a/parts/filecreate/README.dox b/parts/filecreate/README.dox new file mode 100644 index 00000000..50e267e8 --- /dev/null +++ b/parts/filecreate/README.dox @@ -0,0 +1,76 @@ +/** \class FileCreatePart +FileCreatePart is a template manager and wizard system to assist with creation of new files. + +Assists with creation of new files. + +For those who want to look beyond the GUI, the following illustrates the XML to configure the FileCreate part for a project. It simply consists of a list of filetypes that the user may wish to create for a particular project. At present, the "create" attribute is ignored. + +The file create part looks for a file template called \@ext (i.e. the value of the ext attribute) in the *project's* templates directory (see the PyQT appwizard template for an example). + +For subtypes, it looks for a template called \@ext-\@ref, so in the example below the following files would need to be present in the project's templates directory: + + +py +ui +ui-dialog +ui-mainwin + + +Example XML: + + +\verbatim + + + + + + + + + +\endverbatim + + +You can also use global template definitions supplied with the FileCreate part: + + +\verbatim + + + + + + + + +\endverbatim + + +If a type has subtypes, and no subtypes are specified, then all subtypes are assumed to be required (as in the example above). Otherwise, specific subtypes should be specified: + + +\verbatim + + + + + +\endverbatim + + +Usually, this XML forms part of the base .kdevelop file created by the appwizard. + +\authors Julian Rockey +\authors Alexander Dymo + +\maintainer Julian Rockey + +\feature friendly sidebar listing the types of new file that can be created for your project +\feature configurable per-project file types and global file types + +\bug bugs in file create component at Bugzilla database +\bug Arrangement of text in sidebar is not always perfect + + +*/ diff --git a/parts/filecreate/addglobaldlg.cpp b/parts/filecreate/addglobaldlg.cpp new file mode 100644 index 00000000..0757d220 --- /dev/null +++ b/parts/filecreate/addglobaldlg.cpp @@ -0,0 +1,106 @@ +#include +/**************************************************************************** +** Form implementation generated from reading ui file './addglobaldlg.ui' +** +** Created: Сбт Лют 8 20:51:03 2003 +** by: The User Interface Compiler ($Id$) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "addglobaldlg.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * Constructs a AddGlobalDlg as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +AddGlobalDlg::AddGlobalDlg( QWidget* parent, const char* name, bool modal, WFlags fl ) + : QDialog( parent, name, modal, fl ) + +{ + if ( !name ) + setName( "AddGlobalDlg" ); + setSizeGripEnabled( TRUE ); + AddGlobalDlgLayout = new QGridLayout( this, 1, 1, 11, 6, "AddGlobalDlgLayout"); + + Layout1 = new QHBoxLayout( 0, 0, 6, "Layout1"); + + buttonHelp = new KPushButton( this, "buttonHelp" ); + buttonHelp->setAutoDefault( TRUE ); + Layout1->addWidget( buttonHelp ); + QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + Layout1->addItem( spacer ); + + buttonOk = new KPushButton( this, "buttonOk" ); + buttonOk->setAutoDefault( TRUE ); + buttonOk->setDefault( TRUE ); + Layout1->addWidget( buttonOk ); + + buttonCancel = new KPushButton( this, "buttonCancel" ); + buttonCancel->setAutoDefault( TRUE ); + Layout1->addWidget( buttonCancel ); + + AddGlobalDlgLayout->addLayout( Layout1, 1, 0 ); + + fcglobal_view = new QListView( this, "fcglobal_view" ); + fcglobal_view->addColumn( i18n( "Type Extension" ) ); + fcglobal_view->addColumn( i18n( "Type Name" ) ); + fcglobal_view->addColumn( i18n( "Template Location" ) ); + fcglobal_view->addColumn( i18n( "Icon" ) ); + fcglobal_view->addColumn( i18n( "Description" ) ); + fcglobal_view->setResizePolicy( QListView::AutoOne ); + fcglobal_view->setAllColumnsShowFocus( TRUE ); + fcglobal_view->setRootIsDecorated( TRUE ); + fcglobal_view->setResizeMode( QListView::AllColumns ); + + AddGlobalDlgLayout->addWidget( fcglobal_view, 0, 0 ); + languageChange(); + resize( QSize(511, 282).expandedTo(minimumSizeHint()) ); + + // signals and slots connections + connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + +/* + * Destroys the object and frees any allocated resources + */ +AddGlobalDlg::~AddGlobalDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void AddGlobalDlg::languageChange() +{ + setCaption( i18n( "Select Global File Types" ) ); + buttonHelp->setGuiItem( KStdGuiItem::help() ); + buttonHelp->setAccel( QKeySequence( tr2i18n( "F1" ) ) ); + buttonOk->setGuiItem( KStdGuiItem::ok() ); + buttonOk->setAccel( QKeySequence( QString::null ) ); + buttonCancel->setGuiItem( KStdGuiItem::cancel() ); + buttonCancel->setAccel( QKeySequence( QString::null ) ); + fcglobal_view->header()->setLabel( 0, i18n( "Type extension:" ) ); + fcglobal_view->header()->setLabel( 1, i18n( "Type name:" ) ); + fcglobal_view->header()->setLabel( 2, i18n( "Template location:" ) ); + fcglobal_view->header()->setLabel( 3, i18n( "Icon:" ) ); + fcglobal_view->header()->setLabel( 4, i18n( "Description:" ) ); +} + +#include "addglobaldlg.moc" diff --git a/parts/filecreate/addglobaldlg.h b/parts/filecreate/addglobaldlg.h new file mode 100644 index 00000000..0ec8e588 --- /dev/null +++ b/parts/filecreate/addglobaldlg.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** Form interface generated from reading ui file './addglobaldlg.ui' +** +** Created: Сбт Лют 8 20:48:22 2003 +** by: The User Interface Compiler ($Id$) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#ifndef ADDGLOBALDLG_H +#define ADDGLOBALDLG_H + +#include +#include + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QListView; +class QListViewItem; +class QPushButton; + +class AddGlobalDlg : public QDialog +{ + Q_OBJECT + +public: + AddGlobalDlg( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~AddGlobalDlg(); + + QPushButton* buttonHelp; + QPushButton* buttonOk; + QPushButton* buttonCancel; + QListView* fcglobal_view; + +protected: + QGridLayout* AddGlobalDlgLayout; + QHBoxLayout* Layout1; + +protected slots: + virtual void languageChange(); +}; + +#endif // ADDGLOBALDLG_H diff --git a/parts/filecreate/fcconfigwidget.cpp b/parts/filecreate/fcconfigwidget.cpp new file mode 100644 index 00000000..480d38e0 --- /dev/null +++ b/parts/filecreate/fcconfigwidget.cpp @@ -0,0 +1,709 @@ +/*************************************************************************** + * Copyright (C) 2003 by Alexander Dymo * + * cloudtemple@mksat.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fctypeedit.h" +#include "fctemplateedit.h" +#include "domutil.h" +#include "fcconfigwidget.h" +#include "filecreate_part.h" +#include "filecreate_filetype.h" +#include "kdevproject.h" +#include "kdevpartcontroller.h" + + +FCConfigWidget::FCConfigWidget(FileCreatePart * part, bool global, QWidget *parent, const char *name): + FCConfigWidgetBase(parent, name), m_part(part), m_global(global) +{ + fc_view->setSorting(-1, FALSE); + fcglobal_view->setSorting(-1, FALSE); + + if (m_global) + { + loadGlobalConfig(fc_view); + fc_tabs->setTabLabel(tab1, i18n("Global Types") ); + fc_tabs->setTabEnabled(tab2, false); + fc_tabs->setTabEnabled(tab3, false); + delete tab2; + delete tab3; + } + else + { + loadGlobalConfig(fcglobal_view, true); + loadProjectConfig(fc_view); + loadProjectTemplates(fctemplates_view); + templatesDir_label->setText(i18n("Project templates in ") + m_part->project()->projectDirectory() + "/templates"); + } + + m_globalfiletypes.setAutoDelete(true); + m_projectfiletypes.setAutoDelete(true); + m_projectfiletemplates.setAutoDelete(true); +} + +FCConfigWidget::~FCConfigWidget() +{ +} + +void FCConfigWidget::accept() +{ + if (m_global) { + saveGlobalConfig(); + } + else + saveProjectConfig(); + + m_part->m_filetypes.clear(); + m_part->slotProjectOpened(); + + for (QValueList::iterator it = urlsToEdit.begin(); it != urlsToEdit.end(); ++it ) + { + m_part->partController()->editDocument(*it); + } +} + +void FCConfigWidget::loadGlobalConfig(QListView *view, bool checkmarks) +{ + QString globalXMLFile = ::locate("data", "kdevfilecreate/template-info.xml"); + QDomDocument globalDom; + if (!globalXMLFile.isNull() && + DomUtil::openDOMFile(globalDom,globalXMLFile)) { + m_part->readTypes(globalDom, m_globalfiletypes, false); + } + + + loadFileTypes(m_globalfiletypes, view, checkmarks); + + if (checkmarks) + { + QDomElement useGlobalTypes = + DomUtil::elementByPath(*(m_part->projectDom()),"/kdevfilecreate/useglobaltypes"); + for(QDomNode node = useGlobalTypes.firstChild(); !node.isNull();node=node.nextSibling()) + { + if (node.isElement() && node.nodeName()=="type") + { + QDomElement element = node.toElement(); + QString ext = element.attribute("ext"); + QString subtyperef = element.attribute("subtyperef"); + if (subtyperef.isNull()) + { + QListViewItem *it = view->findItem(ext, 0); + if (it) + { + ((QCheckListItem*)it)->setOn(true); + + QListViewItem *lastChild = it->firstChild(); + while ( lastChild ) + { + ((QCheckListItem*)lastChild)->setOn(true); + lastChild = lastChild->nextSibling(); + } + } + } + else + { + QListViewItem *it = view->findItem(subtyperef, 0); + if (it) + ((QCheckListItem*)it)->setOn(true); + } + } + } + } +} + +void FCConfigWidget::loadProjectConfig(QListView *view) +{ + m_part->readTypes( *(m_part->projectDom()), m_projectfiletypes, false ); + loadFileTypes(m_projectfiletypes, view, false); +} + +void FCConfigWidget::loadProjectTemplates(QListView *view) +{ + QDir templDir( m_part->project()->projectDirectory() + "/templates/" ); + templDir.setFilter( QDir::Files ); + const QFileInfoList * list = templDir.entryInfoList(); + if( list ){ + QFileInfoListIterator it( *list ); + QFileInfo *fi; + while ( (fi = it.current()) != 0 ) { + FileType * filetype; + filetype = new FileType; + //name shall be "" for proper configuration + filetype->setName( "" ); + filetype->setExt( fi->fileName() ); + m_projectfiletemplates.append(filetype); + filetype->setEnabled(false); + ++it; + } + } + loadFileTypes(m_projectfiletemplates, view, false); +} + + +void FCConfigWidget::saveGlobalConfig() +{ + QDomDocument globalDom; + QDomElement element = globalDom.createElement("kdevelop" ); + globalDom.appendChild(element); + QDomElement apPart = globalDom.createElement("kdevfilecreate"); + element.appendChild(apPart); + QDomElement fileTypes = globalDom.createElement( "filetypes" ); + apPart.appendChild( fileTypes ); + + saveConfiguration(globalDom, fileTypes, true); + + QFile config( KGlobal::dirs()->saveLocation("data", "kdevfilecreate/", true) + "template-info.xml" ); + config.open(IO_WriteOnly | IO_Truncate); + QTextStream stream(&config); + stream << ""; + stream << globalDom.toString(); + config.close(); +} + +void FCConfigWidget::saveProjectConfig() +{ + QDomDocument dom = *m_part->projectDom( ); + QDomElement element = dom.documentElement( ); + QDomElement apPart = element.namedItem( "kdevfilecreate" ).toElement( ); + if( apPart.isNull( ) ) + { + apPart = dom.createElement( "kdevfilecreate" ); + element.appendChild( apPart ); + } + + + // project template configuration + + QDomElement projectTypes = apPart.namedItem( "filetypes" ).toElement( ); + apPart.removeChild(projectTypes); + projectTypes = dom.createElement( "filetypes" ); + apPart.appendChild( projectTypes ); + + saveConfiguration(dom, projectTypes, false); + + + // global template usage + + QDomElement globalTypes = apPart.namedItem( "useglobaltypes" ).toElement( ); + apPart.removeChild(globalTypes); + globalTypes = dom.createElement( "useglobaltypes" ); + apPart.appendChild( globalTypes ); + + QListViewItemIterator it( fcglobal_view ); + for( ; it.current( ); ++it ){ + if (!it.current()->parent()) + { + QCheckListItem *chit = dynamic_cast(it.current()); + if ( !chit ) continue; + if (chit->isOn()) + { + QDomElement type = dom.createElement( "type" ); + type.setAttribute( "ext", chit->text(0) ); + globalTypes.appendChild( type ); + } + else + { + QListViewItem *lastChild = chit->firstChild(); + while ( lastChild ) + { + QCheckListItem *chsit = dynamic_cast(lastChild); + if ( (chsit) && (chsit->isOn())) + { + QDomElement type = dom.createElement( "type" ); + type.setAttribute( "ext", chit->text(0) ); + type.setAttribute( "subtyperef", chsit->text(0) ); + globalTypes.appendChild( type ); + } + + lastChild = lastChild->nextSibling(); + } + } + } + } + + + // project template files + + //check for new templates and those with location changed + QListViewItemIterator it2(fctemplates_view); + while (it2.current()) + { + if (!it2.current()->text(1).isEmpty()) + { + QString dest; + dest = m_part->project()->projectDirectory() + "/templates/"; + if (it2.current()->text(1) == "create") + copyTemplate(QString::null, dest, it2.current()->text(0)); + else + copyTemplate(it2.current()->text(1), dest, it2.current()->text(0)); + } + ++it2; + } +} + +void FCConfigWidget::saveConfiguration(QDomDocument &dom, QDomElement &element, bool global) +{ + QListViewItemIterator it( fc_view ); + for( ; it.current( ); ++it ){ + if (!it.current()->parent()) + { + QDomElement type = dom.createElement( "type" ); + type.setAttribute( "ext", it.current()->text(0) ); + type.setAttribute( "name", it.current()->text(1) ); + if (it.current()->childCount() > 0) + type.setAttribute( "create", "no"); + else + type.setAttribute( "create", "template"); + type.setAttribute( "icon", it.current()->text(2) ); + + QDomElement edescr = dom.createElement("descr"); + type.appendChild(edescr); + QDomText descr = dom.createTextNode( it.current()->text(3) ); + edescr.appendChild(descr); + + if (!it.current()->text(4).isEmpty()) + { + QString dest; + if (global) + dest = KGlobal::dirs()->saveLocation("data", "/kdevfilecreate/file-templates/", true); + else + dest = m_part->project()->projectDirectory() + "/templates/"; + if (it.current()->text(4) == "create") + copyTemplate(QString::null, dest, it.current()->text(0)); + else + copyTemplate(it.current()->text(4), dest, it.current()->text(0)); + } + + + QListViewItem *lastChild = it.current()->firstChild(); + while ( lastChild ) + { + QDomElement subtype = dom.createElement( "subtype" ); + subtype.setAttribute( "ref", lastChild->text(0) ); + subtype.setAttribute( "name", lastChild->text(1) ); + subtype.setAttribute( "icon", lastChild->text(2) ); + + QDomElement edescr = dom.createElement("descr"); + subtype.appendChild(edescr); + QDomText descr = dom.createTextNode( lastChild->text(3) ); + edescr.appendChild(descr); + + if (!lastChild->text(4).isEmpty()) + { + QString dest; + if (global) + dest = KGlobal::dirs()->saveLocation("data", "/kdevfilecreate/file-templates/", true); + else + dest = m_part->project()->projectDirectory() + "/templates/"; + if (lastChild->text(4) == "create") + copyTemplate(QString::null, dest, it.current()->text(0) + "-" + lastChild->text(0)); + else + copyTemplate(lastChild->text(4), dest, it.current()->text(0) + "-" + lastChild->text(0)); + } + + type.appendChild( subtype ); + lastChild = lastChild->nextSibling(); + } + + element.appendChild( type ); + } + } +} + +void FCConfigWidget::copyTemplate(QString templateUrl, QString dest, QString destName) +{ + if (templateUrl.isEmpty()) + { + QDir d(dest); + if (!d.exists()) + d.mkdir(dest); + + QFile f(dest + destName); + f.open(IO_WriteOnly); + f.close(); + } + else + { + KURL destDir; + destDir.setPath(dest); + if (!KIO::NetAccess::exists(destDir, false, 0 )) + KIO::NetAccess::mkdir(destDir); + + KURL destination; + destination.setPath(dest + destName); + + KIO::NetAccess::upload(templateUrl, destination); + } +} + +void FCConfigWidget::loadFileTypes(QPtrList list, QListView *view, bool checkmarks) +{ + FileType *ft; + + for( ft = list.last(); ft; ft = list.prev()) + for( int i = list.count() - 1; i >= 0; --i) + { + if ( (ft = list.at(i)) ) + { + QListViewItem *it; + if (!checkmarks) + it = new QListViewItem(view); + else + it = new QCheckListItem(view, "", QCheckListItem::CheckBox); + + it->setText(0, ft->ext()); + it->setText(1, ft->name()); + it->setText(2, ft->icon()); + it->setText(3, ft->descr()); + it->setText(4, ""); + + FileType *sft; + for( int j = ft->subtypes().count() - 1; j >= 0; --j) + { + if ( (sft = ft->subtypes().at(j)) ) + { + QListViewItem *sit; + if (!checkmarks) + sit = new QListViewItem(it); + else + sit = new QCheckListItem(it, "", QCheckListItem::CheckBox); + + sit->setText(0, sft->subtypeRef()); + sit->setText(1, sft->name()); + sit->setText(2, sft->icon()); + sit->setText(3, sft->descr()); + sit->setText(4, ""); + } + } + } + } +} + +void FCConfigWidget::removetemplate_button_clicked( ) +{ + if (fctemplates_view->currentItem()) + { + KURL removedTemplate; + removedTemplate.setPath(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0)); + KIO::NetAccess::del(removedTemplate); + QListViewItem *it = fctemplates_view->currentItem(); + if (it->itemBelow()) + { + fc_view->setSelected(it->itemBelow(), true); + fc_view->setCurrentItem(it->itemBelow()); + } + else if (it->itemAbove()) + { + fc_view->setSelected(it->itemAbove(), true); + fc_view->setCurrentItem(it->itemAbove()); + } + delete it; + } +} + +void FCConfigWidget::copyToProject_button_clicked() +{ + QListViewItem *it = fcglobal_view->currentItem(); + if (it) + { + QListViewItem *it_copy_parent = 0; + QString destParent; + if (it->parent()) + { + it_copy_parent = new QListViewItem(fc_view, it->parent()->text(0), + it->parent()->text(1), + it->parent()->text(2), + it->parent()->text(3), + locate("data", "kdevfilecreate/file-templates/"+ it->parent()->text(0))); + destParent += it->parent()->text(0) + "-"; + QCheckListItem *chk = dynamic_cast(it->parent()); + if (chk) + chk->setOn(false); + } + QListViewItem *it_copy = 0; + if (it_copy_parent) + it_copy = new QListViewItem(it_copy_parent, it->text(0), + it->text(1), + it->text(2), + it->text(3), + locate("data", "kdevfilecreate/file-templates/"+destParent + it->text(0))); + else + it_copy = new QListViewItem(fc_view, it->text(0), + it->text(1), + it->text(2), + it->text(3), + locate("data", "kdevfilecreate/file-templates/" +destParent+ it->text(0))); + QCheckListItem *chk = dynamic_cast(it); + if (chk) + chk->setOn(false); + fc_view->setSelected(it_copy, true); + fc_view->setCurrentItem(it_copy); + QListViewItem * it_child = it->firstChild(); + while( it_child ) { + new QListViewItem(it_copy, it_child->text(0), + it_child->text(1), + it_child->text(2), + it_child->text(3), + locate("data", "kdevfilecreate/file-templates/"+ it_copy->text(0) + "-" + it_child->text(0))); + QCheckListItem *chk_child = dynamic_cast(it_child); + if (chk_child) + chk_child->setOn(false); + it_child = it_child->nextSibling(); + } + } +} + +void FCConfigWidget::newtype_button_clicked() +{ + FCTypeEdit *te = new FCTypeEdit(); + if (te->exec() == QDialog::Accepted ) + { + QListViewItem *it = new QListViewItem(fc_view, te->typeext_edit->text(), + te->typename_edit->text(), + te->icon_url->icon(), + te->typedescr_edit->text(), + te->template_url->url().isEmpty() ? QString("create") : te->template_url->url()); + fc_view->setSelected(it, true); + fc_view->setCurrentItem(it); + } + delete te; +} + +void FCConfigWidget::newsubtype_button_clicked() +{ + if (fc_view->currentItem() && (!fc_view->currentItem()->parent())) + { + FCTypeEdit *te = new FCTypeEdit(this); + if (te->exec() == QDialog::Accepted ) + { + /*QListViewItem *it =*/(void) new QListViewItem(fc_view->currentItem(), + te->typeext_edit->text(), + te->typename_edit->text(), + te->icon_url->icon(), + te->typedescr_edit->text(), + te->template_url->url().isEmpty() ? QString("create") : te->template_url->url()); + fc_view->currentItem()->setOpen(true); + } + delete te; + } +} + +void FCConfigWidget::remove_button_clicked() +{ + if (fc_view->currentItem()) + { + QListViewItem *it = fc_view->currentItem(); + if (it->itemBelow()) + { + fc_view->setSelected(it->itemBelow(), true); + fc_view->setCurrentItem(it->itemBelow()); + } + else if (it->itemAbove()) + { + fc_view->setSelected(it->itemAbove(), true); + fc_view->setCurrentItem(it->itemAbove()); + } + delete it; + } +} + + +void FCConfigWidget::moveup_button_clicked() +{ + QListViewItem *i = fc_view->currentItem(); + if ( !i ) + return; + + QListViewItemIterator it( i ); + QListViewItem *parent = i->parent(); + --it; + while ( it.current() ) { + if ( it.current()->parent() == parent ) + break; + --it; + } + + if ( !it.current() ) + return; + QListViewItem *other = it.current(); + + other->moveItem( i ); +} + + +void FCConfigWidget::movedown_button_clicked() +{ + QListViewItem *i = fc_view->currentItem(); + if ( !i ) + return; + + QListViewItemIterator it( i ); + QListViewItem *parent = i->parent(); + it++; + while ( it.current() ) { + if ( it.current()->parent() == parent ) + break; + it++; + } + + if ( !it.current() ) + return; + QListViewItem *other = it.current(); + + i->moveItem( other ); +} + + +void FCConfigWidget::edittype_button_clicked() +{ + QListViewItem *it = fc_view->currentItem(); + if ( it ) + { + FCTypeEdit *te = new FCTypeEdit(this); + + te->typeext_edit->setText(it->text(0)); + te->typename_edit->setText(it->text(1)); + te->icon_url->setIcon(it->text(2)); + te->typedescr_edit->setText(it->text(3)); + if (it->text(4) != "create") + te->template_url->setURL(it->text(4)); + + if (te->exec() == QDialog::Accepted ) + { + it->setText(0, te->typeext_edit->text()); + it->setText(1, te->typename_edit->text()); + it->setText(2, te->icon_url->icon()); + it->setText(3, te->typedescr_edit->text()); + if ((te->template_url->url() == "") && ((it->text(4) == "create"))) + it->setText(4, "create"); + else + it->setText(4, te->template_url->url()); + } + } +} + + +void FCConfigWidget::newtemplate_button_clicked() +{ + FCTemplateEdit *te = new FCTemplateEdit; + if (te->exec() == QDialog::Accepted) + { + /*QListViewItem *it =*/(void) new QListViewItem(fctemplates_view, te->templatename_edit->text(), + te->template_url->url().isEmpty() ? QString("create") : te->template_url->url()); + } +} + + +void FCConfigWidget::edittemplate_button_clicked() +{ + QListViewItem *it; + if ( (it = fctemplates_view->currentItem()) ) + { + FCTemplateEdit *te = new FCTemplateEdit; + te->templatename_edit->setText(it->text(0)); + te->templatename_edit->setEnabled(false); + if (te->exec() == QDialog::Accepted) + { + if ((te->template_url->url() == "") && ((it->text(1) == "create"))) + it->setText(1, "create"); + else + it->setText(1, te->template_url->url()); + } + } +} + +void FCConfigWidget::edit_template_content_button_clicked( ) +{ + if (fctemplates_view->currentItem()) + { + QFileInfo fi(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0)); + KURL content; + content.setPath(m_part->project()->projectDirectory() + "/templates/" + fctemplates_view->currentItem()->text(0)); + if (fi.exists()) + m_part->partController()->editDocument(content); + else + { + 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"); + fctemplates_view->currentItem()->setPixmap(0, SmallIcon("edit")); + urlsToEdit.append(content); + } + } +} + +void FCConfigWidget::edit_type_content_button_clicked( ) +{ + if (!fc_view->currentItem()) + return; + QListViewItem *it = fc_view->currentItem(); + QString type_name = it->text(0); + if (it->parent()) + type_name.prepend(it->parent()->text(0) + "-"); + if (!m_global) + { + QString typePath = m_part->project()->projectDirectory() + "/templates/" + type_name; + KURL content; + content.setPath(typePath); + if (it->text(4).isEmpty()) + m_part->partController()->editDocument(content); + else + { + if (it->text(4) == "create") + 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"); + else + 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"); + fc_view->currentItem()->setPixmap(0, SmallIcon("edit")); + urlsToEdit.append(content); + } + } + else + { + QString dest = KGlobal::dirs()->saveLocation("data", "/kdevfilecreate/file-templates/", true); + QString typePath = dest + type_name; + KURL content; + content.setPath(typePath); + if (it->text(4).isEmpty()) + { + QFileInfo fi(dest+type_name); + if (!fi.exists()) + copyTemplate(locate("data", "kdevfilecreate/file-templates/" + type_name), dest, type_name); + m_part->partController()->editDocument(content); + } + else + { + if (it->text(4) == "create") + 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"); + else + 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"); + fc_view->currentItem()->setPixmap(0, SmallIcon("edit")); + urlsToEdit.append(content); + } + } +} + +#include "fcconfigwidget.moc" diff --git a/parts/filecreate/fcconfigwidget.h b/parts/filecreate/fcconfigwidget.h new file mode 100644 index 00000000..52acd29c --- /dev/null +++ b/parts/filecreate/fcconfigwidget.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (C) 2003 by Alexander Dymo * + * cloudtemple@mksat.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef FCCONFIGWIDGET_H +#define FCCONFIGWIDGET_H + +#include +#include +#include + +#include "fcconfigwidgetbase.h" + +class FileCreatePart; +class QListView; +class QDomDocument; +class QDomElement; + +namespace FileCreate{ +class FileType; +} + +class FCConfigWidget : public FCConfigWidgetBase +{ +Q_OBJECT +public: + FCConfigWidget(FileCreatePart * part, bool global, QWidget *parent, const char *name); + + ~FCConfigWidget(); + +public slots: + void accept(); + void removetemplate_button_clicked(); + void copyToProject_button_clicked(); + void newtype_button_clicked(); + void newsubtype_button_clicked(); + void remove_button_clicked(); + void moveup_button_clicked(); + void movedown_button_clicked(); + void edittype_button_clicked(); + void newtemplate_button_clicked(); + void edittemplate_button_clicked(); + void edit_template_content_button_clicked(); + void edit_type_content_button_clicked(); + +protected: + void loadGlobalConfig(QListView *view, bool checkmarks = false); + void loadProjectConfig(QListView *view); + void loadProjectTemplates(QListView *view); + void saveGlobalConfig(); + void saveProjectConfig(); + void loadFileTypes(QPtrList list, QListView *view, bool checkmarks = false); + void copyTemplate(QString templateUrl, QString dest, QString destName); + void saveConfiguration(QDomDocument &dom, QDomElement &element, bool global); + +private: + FileCreatePart * m_part; + QPtrList m_globalfiletypes; + QPtrList m_projectfiletypes; + QPtrList m_projectfiletemplates; + bool m_global; + + QValueList urlsToEdit; +}; + +#endif diff --git a/parts/filecreate/fcconfigwidgetbase.ui b/parts/filecreate/fcconfigwidgetbase.ui new file mode 100644 index 00000000..72f62260 --- /dev/null +++ b/parts/filecreate/fcconfigwidgetbase.ui @@ -0,0 +1,540 @@ + +FCConfigWidgetBase + + + FCConfigWidgetBase + + + + 0 + 0 + 505 + 388 + + + + New File Wizard Options + + + + unnamed + + + 0 + + + + fc_tabs + + + + tab1 + + + Pro&ject Types + + + + unnamed + + + + remove_button + + + Re&move Type + + + + + edittype_button + + + Edit T&ype... + + + + + newsubtype_button + + + New &Subtype... + + + + + newtype_button + + + &New Type... + + + + + + Type Extension + + + true + + + true + + + + + Type Name + + + true + + + true + + + + + Icon + + + true + + + true + + + + + Description + + + true + + + true + + + + fc_view + + + Manual + + + true + + + true + + + AllColumns + + + + + spacer2 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + moveup_button + + + Move &Up + + + + + movedown_button + + + Move &Down + + + + + spacer1 + + + Vertical + + + Fixed + + + + 20 + 20 + + + + + + spacer1_2 + + + Vertical + + + Fixed + + + + 20 + 20 + + + + + + edit_type_content_button + + + Ed&it Template + + + + + + + tab2 + + + Used &Global Types + + + + unnamed + + + + + Type Extension + + + true + + + true + + + + + Type Name + + + true + + + true + + + + + Icon + + + true + + + true + + + + + Description + + + true + + + true + + + + fcglobal_view + + + true + + + true + + + AllColumns + + + + + spacer4_2 + + + Horizontal + + + Expanding + + + + 330 + 20 + + + + + + copyToProject_button + + + Copy to Pro&ject Types + + + + + + + tab3 + + + Proje&ct Templates + + + + unnamed + + + + + Template Name + + + true + + + true + + + + fctemplates_view + + + true + + + true + + + AllColumns + + + + + edittemplate_button + + + C&hange Content... + + + + + newtemplate_button + + + &New Template... + + + + + templatesDir_label + + + + + + + + removetemplate_button + + + Re&move Template + + + + + spacer4 + + + Vertical + + + Expanding + + + + 20 + 150 + + + + + + edit_template_content_button + + + &Edit Template + + + + + spacer6 + + + Vertical + + + Fixed + + + + 20 + 20 + + + + + + + + + + + newtype_button + clicked() + FCConfigWidgetBase + newtype_button_clicked() + + + newsubtype_button + clicked() + FCConfigWidgetBase + newsubtype_button_clicked() + + + remove_button + clicked() + FCConfigWidgetBase + remove_button_clicked() + + + moveup_button + clicked() + FCConfigWidgetBase + moveup_button_clicked() + + + movedown_button + clicked() + FCConfigWidgetBase + movedown_button_clicked() + + + edittype_button + clicked() + FCConfigWidgetBase + edittype_button_clicked() + + + newtemplate_button + clicked() + FCConfigWidgetBase + newtemplate_button_clicked() + + + edittemplate_button + clicked() + FCConfigWidgetBase + edittemplate_button_clicked() + + + removetemplate_button + clicked() + FCConfigWidgetBase + removetemplate_button_clicked() + + + copyToProject_button + clicked() + FCConfigWidgetBase + copyToProject_button_clicked() + + + edit_template_content_button + clicked() + FCConfigWidgetBase + edit_template_content_button_clicked() + + + edit_type_content_button + clicked() + FCConfigWidgetBase + edit_type_content_button_clicked() + + + + fc_view + newtype_button + newsubtype_button + edittype_button + remove_button + edit_type_content_button + moveup_button + movedown_button + fc_tabs + fcglobal_view + copyToProject_button + fctemplates_view + newtemplate_button + edittemplate_button + removetemplate_button + edit_template_content_button + + + addglobaldlg.h + kdialog.h + + + class AddGlobalDlg; + + + AddGlobalDlg *global_dlg; + + + removetemplate_button_clicked() + copyToProject_button_clicked() + newtype_button_clicked() + newsubtype_button_clicked() + remove_button_clicked() + moveup_button_clicked() + movedown_button_clicked() + edittype_button_clicked() + newtemplate_button_clicked() + edittemplate_button_clicked() + edit_template_contents_button_clicked() + edit_template_content_button_clicked() + edit_type_content_button_clicked() + + + + diff --git a/parts/filecreate/fctemplateedit.cpp b/parts/filecreate/fctemplateedit.cpp new file mode 100644 index 00000000..fc495fd5 --- /dev/null +++ b/parts/filecreate/fctemplateedit.cpp @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (C) 2003 by Alexander Dymo * + * cloudtemple@mksat.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include +#include "fctemplateedit.h" +#include + +FCTemplateEdit::FCTemplateEdit(QWidget *parent, const char *name): + FCTemplateEditBase(parent, name) +{ + connect( templatename_edit, SIGNAL(textChanged ( const QString & )), + this, SLOT( slotTemplateNameChanged( ))); + slotTemplateNameChanged(); +} + +FCTemplateEdit::~FCTemplateEdit() +{ +} + +void FCTemplateEdit::slotTemplateNameChanged( ) +{ + ok_button->setEnabled( !templatename_edit->text().isEmpty() ); +} + +void FCTemplateEdit::accept() +{ + if ( !templatename_edit->text().isEmpty() ) + FCTemplateEditBase::accept(); +} +#include "fctemplateedit.moc" diff --git a/parts/filecreate/fctemplateedit.h b/parts/filecreate/fctemplateedit.h new file mode 100644 index 00000000..0209c3b0 --- /dev/null +++ b/parts/filecreate/fctemplateedit.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2003 by Alexander Dymo * + * cloudtemple@mksat.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef FCTEMPLATEEDIT_H +#define FCTEMPLATEEDIT_H + +#include +#include "fctemplateeditbase.h" + +class FCTemplateEdit : public FCTemplateEditBase +{ +Q_OBJECT +public: + FCTemplateEdit(QWidget *parent=0, const char *name=0); + + ~FCTemplateEdit(); + +protected slots: + virtual void accept(); + void slotTemplateNameChanged( ); +}; + +#endif diff --git a/parts/filecreate/fctemplateeditbase.ui b/parts/filecreate/fctemplateeditbase.ui new file mode 100644 index 00000000..976bff33 --- /dev/null +++ b/parts/filecreate/fctemplateeditbase.ui @@ -0,0 +1,193 @@ + +FCTemplateEditBase + + + FCTemplateEditBase + + + + 0 + 0 + 467 + 149 + + + + File Template + + + + unnamed + + + + layout5 + + + + unnamed + + + 0 + + + + textLabel1 + + + Plain + + + Template &name: + + + AlignBottom + + + templatename_edit + + + + + templatename_edit + + + + + + + layout4 + + + + unnamed + + + + textLabel1_2 + + + + 0 + 5 + 0 + 0 + + + + Set template content from &file: + + + AlignBottom + + + template_url + + + + + template_url + + + + 7 + 0 + 0 + 0 + + + + + 0 + 26 + + + + StrongFocus + + + + + + + layout1 + + + + unnamed + + + + spacer1 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + ok_button + + + &OK + + + true + + + + + cancel_button + + + &Cancel + + + + + + + + + ok_button + clicked() + FCTemplateEditBase + accept() + + + cancel_button + clicked() + FCTemplateEditBase + reject() + + + + templatename_edit + template_url + ok_button + cancel_button + + + kdialog.h + fctemplateeditbase.ui.h + + + init() + + + + + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/parts/filecreate/fctemplateeditbase.ui.h b/parts/filecreate/fctemplateeditbase.ui.h new file mode 100644 index 00000000..6f2b9223 --- /dev/null +++ b/parts/filecreate/fctemplateeditbase.ui.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * Copyright (C) 2003 by Alexander Dymo * + * cloudtemple@mksat.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename functions or slots use +** Qt Designer which will update this file, preserving your code. Create an +** init() function in place of a constructor, and a destroy() function in +** place of a destructor. +*****************************************************************************/ + +#include +#include + +void FCTemplateEditBase::init() +{ + templatename_edit->setValidator(new QRegExpValidator(QRegExp("^\\S*$"), this)); +} diff --git a/parts/filecreate/fctypeedit.cpp b/parts/filecreate/fctypeedit.cpp new file mode 100644 index 00000000..310453ea --- /dev/null +++ b/parts/filecreate/fctypeedit.cpp @@ -0,0 +1,40 @@ +/*************************************************************************** + * Copyright (C) 2003 by Alexander Dymo * + * cloudtemple@mksat.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include +#include "fctypeedit.h" + + +FCTypeEdit::FCTypeEdit(QWidget *parent, char *name) + : FCTypeEditBase(parent, name) +{ + connect( typeext_edit, SIGNAL( textChanged ( const QString & )),this, SLOT( slotTypeEditTextChanged())); + connect( typename_edit, SIGNAL( textChanged ( const QString & )),this, SLOT( slotTypeEditTextChanged( ))); + slotTypeEditTextChanged( ); +} + +FCTypeEdit::~FCTypeEdit() +{ +} + +void FCTypeEdit::slotTypeEditTextChanged( ) +{ + ok_button->setEnabled( !typeext_edit->text().isEmpty() && + !typename_edit->text().isEmpty()); +} + +void FCTypeEdit::accept() +{ + if ( !typeext_edit->text().isEmpty() && + !typename_edit->text().isEmpty() ) + FCTypeEditBase::accept(); +} +#include "fctypeedit.moc" diff --git a/parts/filecreate/fctypeedit.h b/parts/filecreate/fctypeedit.h new file mode 100644 index 00000000..92c34e3f --- /dev/null +++ b/parts/filecreate/fctypeedit.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2003 by Alexander Dymo * + * cloudtemple@mksat.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef FCTYPEEDIT_H +#define FCTYPEEDIT_H + + +#include "fctypeeditbase.h" + +class FCTypeEdit : public FCTypeEditBase +{ +Q_OBJECT +public: + FCTypeEdit(QWidget *parent = 0, char *name = 0); + + ~FCTypeEdit(); + +protected slots: + virtual void accept(); + void slotTypeEditTextChanged( ); +}; + +#endif diff --git a/parts/filecreate/fctypeeditbase.ui b/parts/filecreate/fctypeeditbase.ui new file mode 100644 index 00000000..8bc06f87 --- /dev/null +++ b/parts/filecreate/fctypeeditbase.ui @@ -0,0 +1,282 @@ + +FCTypeEditBase + + + FCTypeEditBase + + + + 0 + 0 + 476 + 194 + + + + File Type + + + + unnamed + + + + layout5 + + + + unnamed + + + 0 + + + + textLabel1 + + + NoFrame + + + Plain + + + Type &extension: + + + AlignBottom + + + typename_edit + + + + + typeext_edit + + + + + + + layout3 + + + + unnamed + + + 0 + + + + textLabel3 + + + Type &name: + + + AlignBottom + + + typedescr_edit + + + + + typename_edit + + + + + + + layout3_2 + + + + unnamed + + + 0 + + + + textLabel3_2 + + + Type &description: + + + AlignBottom + + + typedescr_edit + + + + + typedescr_edit + + + + + + + icon_url + + + + 80 + 80 + + + + StrongFocus + + + + + + + + layout4 + + + + unnamed + + + + textLabel1_2 + + + + 0 + 5 + 0 + 0 + + + + Set template content from &file: + + + AlignBottom + + + template_url + + + + + template_url + + + + 7 + 0 + 0 + 0 + + + + + 0 + 26 + + + + StrongFocus + + + + + + + layout1 + + + + unnamed + + + + spacer1 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + ok_button + + + &OK + + + true + + + + + cancel_button + + + &Cancel + + + + + + + + + ok_button + clicked() + FCTypeEditBase + accept() + + + cancel_button + clicked() + FCTypeEditBase + reject() + + + + typeext_edit + typename_edit + typedescr_edit + icon_url + template_url + ok_button + cancel_button + + + kicondialog.h + kdialog.h + fctypeeditbase.ui.h + + + init() + + + + + kicondialog.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/parts/filecreate/fctypeeditbase.ui.h b/parts/filecreate/fctypeeditbase.ui.h new file mode 100644 index 00000000..e65a2ba7 --- /dev/null +++ b/parts/filecreate/fctypeeditbase.ui.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * Copyright (C) 2003 by Alexander Dymo * + * cloudtemple@mksat.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename functions or slots use +** Qt Designer which will update this file, preserving your code. Create an +** init() function in place of a constructor, and a destroy() function in +** place of a destructor. +*****************************************************************************/ + +#include +#include + +void FCTypeEditBase::init() +{ + typeext_edit->setValidator(new QRegExpValidator(QRegExp("^\\S*$"), this)); +} diff --git a/parts/filecreate/file-templates/Makefile.am b/parts/filecreate/file-templates/Makefile.am new file mode 100644 index 00000000..672a1cfa --- /dev/null +++ b/parts/filecreate/file-templates/Makefile.am @@ -0,0 +1,2 @@ +rcdir = $(kde_datadir)/kdevfilecreate/file-templates +rc_DATA = ui ui-dialog ui-mainwin ui-confdialog ui-dialogb ui-widget ui-dialogr ui-tabdialog ui-wizard dox ts ui-mainwin-qt4 ui-widget-qt4 ui-dialogb-qt4 ui-dialogr-qt4 ui-dialog-qt4 qrc diff --git a/parts/filecreate/file-templates/dox b/parts/filecreate/file-templates/dox new file mode 100644 index 00000000..fda0e141 --- /dev/null +++ b/parts/filecreate/file-templates/dox @@ -0,0 +1,22 @@ +/** \file $MODULE$.dox + * \brief put an explanation here + */ + +/** \page $MODULE$ put the page title here + +\section put_sectionLabelName_here put section name here + +Here comes the text this is code, the text is continued. + + - This is a item list + - This is the second item! + . + +Here comes the text this is code, the text is continued. + +\subsection put_subSectionLabelName_here put subsection name here + +Subsection text. + +*/ + diff --git a/parts/filecreate/file-templates/qrc b/parts/filecreate/file-templates/qrc new file mode 100644 index 00000000..4a4d7e46 --- /dev/null +++ b/parts/filecreate/file-templates/qrc @@ -0,0 +1,5 @@ + + + + + diff --git a/parts/filecreate/file-templates/ts b/parts/filecreate/file-templates/ts new file mode 100644 index 00000000..4eb9e187 --- /dev/null +++ b/parts/filecreate/file-templates/ts @@ -0,0 +1,2 @@ + + diff --git a/parts/filecreate/file-templates/ui b/parts/filecreate/file-templates/ui new file mode 100644 index 00000000..858b4678 --- /dev/null +++ b/parts/filecreate/file-templates/ui @@ -0,0 +1,20 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 600 + 480 + + + + Form1 + + + + diff --git a/parts/filecreate/file-templates/ui-confdialog b/parts/filecreate/file-templates/ui-confdialog new file mode 100644 index 00000000..975ba4d4 --- /dev/null +++ b/parts/filecreate/file-templates/ui-confdialog @@ -0,0 +1,165 @@ + +MyDialog1 + + + MyDialog1 + + + + 0 + 0 + 597 + 364 + + + + MyDialog1 + + + true + + + + unnamed + + + 11 + + + 6 + + + + + New Item + + + + listBox + + + + 0 + 7 + 0 + 0 + + + + + + tabWidget + + + + Widget2 + + + Tab + + + + + Widget3 + + + Tab + + + + + + Layout1 + + + + unnamed + + + 0 + + + 6 + + + + buttonHelp + + + &Help + + + F1 + + + true + + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + buttonOk + + + &OK + + + + + + true + + + true + + + + + buttonCancel + + + &Cancel + + + + + + true + + + + + + + + + buttonOk + clicked() + MyDialog1 + accept() + + + buttonCancel + clicked() + MyDialog1 + reject() + + + + diff --git a/parts/filecreate/file-templates/ui-dialog b/parts/filecreate/file-templates/ui-dialog new file mode 100644 index 00000000..fc2aefce --- /dev/null +++ b/parts/filecreate/file-templates/ui-dialog @@ -0,0 +1,20 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 600 + 480 + + + + Form1 + + + + diff --git a/parts/filecreate/file-templates/ui-dialog-qt4 b/parts/filecreate/file-templates/ui-dialog-qt4 new file mode 100644 index 00000000..d35cb285 --- /dev/null +++ b/parts/filecreate/file-templates/ui-dialog-qt4 @@ -0,0 +1,22 @@ + + + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + diff --git a/parts/filecreate/file-templates/ui-dialogb b/parts/filecreate/file-templates/ui-dialogb new file mode 100644 index 00000000..7ccbfb94 --- /dev/null +++ b/parts/filecreate/file-templates/ui-dialogb @@ -0,0 +1,123 @@ + +MyDialog1 + + + MyDialog1 + + + + 0 + 0 + 511 + 282 + + + + MyDialog1 + + + true + + + + Layout1 + + + + 20 + 240 + 476 + 33 + + + + + unnamed + + + 0 + + + 6 + + + + buttonHelp + + + &Help + + + F1 + + + true + + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + buttonOk + + + &OK + + + + + + true + + + true + + + + + buttonCancel + + + &Cancel + + + + + + true + + + + + + + + buttonOk + clicked() + MyDialog1 + accept() + + + buttonCancel + clicked() + MyDialog1 + reject() + + + + diff --git a/parts/filecreate/file-templates/ui-dialogb-qt4 b/parts/filecreate/file-templates/ui-dialogb-qt4 new file mode 100644 index 00000000..2413393e --- /dev/null +++ b/parts/filecreate/file-templates/ui-dialogb-qt4 @@ -0,0 +1,100 @@ + + + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 20 + 250 + 351 + 33 + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + OK + + + + + + + Cancel + + + + + + + + + + + okButton + clicked() + Dialog + accept() + + + 278 + 253 + + + 96 + 254 + + + + + cancelButton + clicked() + Dialog + reject() + + + 369 + 253 + + + 179 + 282 + + + + + diff --git a/parts/filecreate/file-templates/ui-dialogr b/parts/filecreate/file-templates/ui-dialogr new file mode 100644 index 00000000..8cf208ec --- /dev/null +++ b/parts/filecreate/file-templates/ui-dialogr @@ -0,0 +1,123 @@ + +MyDialog1 + + + MyDialog1 + + + + 0 + 0 + 592 + 470 + + + + MyDialog1 + + + true + + + + Layout5 + + + + 500 + 30 + 82 + 410 + + + + + unnamed + + + 0 + + + 6 + + + + buttonOk + + + &OK + + + + + + true + + + true + + + + + buttonCancel + + + &Cancel + + + + + + true + + + + + buttonHelp + + + &Help + + + F1 + + + true + + + + + Spacer1 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + + buttonOk + clicked() + MyDialog1 + accept() + + + buttonCancel + clicked() + MyDialog1 + reject() + + + + diff --git a/parts/filecreate/file-templates/ui-dialogr-qt4 b/parts/filecreate/file-templates/ui-dialogr-qt4 new file mode 100644 index 00000000..57d81913 --- /dev/null +++ b/parts/filecreate/file-templates/ui-dialogr-qt4 @@ -0,0 +1,100 @@ + + + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 300 + 20 + 77 + 106 + + + + + 0 + + + 6 + + + + + OK + + + + + + + Cancel + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + okButton + clicked() + Dialog + accept() + + + 351 + 38 + + + 233 + 29 + + + + + cancelButton + clicked() + Dialog + reject() + + + 330 + 66 + + + 197 + 125 + + + + + diff --git a/parts/filecreate/file-templates/ui-mainwin b/parts/filecreate/file-templates/ui-mainwin new file mode 100644 index 00000000..854da009 --- /dev/null +++ b/parts/filecreate/file-templates/ui-mainwin @@ -0,0 +1,436 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 600 + 480 + + + + Form1 + + + + + menubar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fileNewAction + + + image0 + + + New + + + &New + + + Ctrl+N + + + + + fileOpenAction + + + image1 + + + Open + + + &Open... + + + Ctrl+O + + + + + fileSaveAction + + + image2 + + + Save + + + &Save + + + Ctrl+S + + + + + fileSaveAsAction + + + Save As + + + Save &As... + + + + + + + + filePrintAction + + + image3 + + + Print + + + &Print... + + + Ctrl+P + + + + + fileExitAction + + + Exit + + + E&xit + + + + + + + + editUndoAction + + + image4 + + + Undo + + + &Undo + + + Ctrl+Z + + + + + editRedoAction + + + image5 + + + Redo + + + &Redo + + + Ctrl+Y + + + + + editCutAction + + + image6 + + + Cut + + + &Cut + + + Ctrl+X + + + + + editCopyAction + + + image7 + + + Copy + + + C&opy + + + Ctrl+C + + + + + editPasteAction + + + image8 + + + Paste + + + &Paste + + + Ctrl+V + + + + + editFindAction + + + image9 + + + Find + + + &Find... + + + Ctrl+F + + + + + helpContentsAction + + + Contents + + + &Contents... + + + + + + + + helpIndexAction + + + Index + + + &Index... + + + + + + + + helpAboutAction + + + About + + + &About + + + + + + + + + 789cedd2b10ac2301405d03d5ff148b62056035241fc04c5511087f425a2432b681d44fc777ba329d6b47fe07d19dee50cc9904cd376b3229d896b6deb13131fed85b4bb95e57db75f3e8434869a93d3548e841c13d3fa5c79ecaad9d52404b540351e83caa833c6a03ad4798e41f5a86c30a816f510126ee94d14d52611fb8e2ad49070a4445ca4447ca4446ca444da07fecac7ffd2956ebe64f81ff4c873215e0583a9b0 + + + 789cad914d0ac2301085f739c5d0d915b11a140ae211149782b898448b2e5a41eb42c4bb9b9fa6a67644045f0299978f37134896c27ab5803413979aeaa3067da033a4bb6b59de36dbf95d245282d953182703910c41c3f254ed6d8da6c69193b5dada7c924b6fc9dac2c85b156c51b83eacfe41d0c89defc4dfa2dd7c37fc44b025a179043c4152a4b055f4365414ad0e8901fd94c1ae5e19441da9211c68e7f44098d3074d86019e70a0210c089958df7ffb31134fa13797a8 + + + 789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523232520022530543251d2e253d856405bffcbc54105b19c856360003103711c4b530b13082709340dc644310047193c1dcc424d314883958015846190b80ca24262a2721012087349964a030ba69c9c9303d403e9132087b68279388ecff4414193440948c32aa71d86470bb80863258a21b9a0eb0a7905a6b2e006d59a436 + + + 789c7d944973db461085effa152cf54d956a932089a55239c896572d96bcc4b253390033186ea2488aa416a7f2dfd3db0cbd44e6d340f8f8def43406209e1c742ecf4f3b074ff6d69b7a33711d37ae6f3a077e3b9f3ffcf5f71fffeced675987fecab293edffb6b77fb1e9b8ced9e2ba65c08c00baf2117e2f5c86d02d99e196b9d7ed963df53f2ab3c47789258fa7c26564688d4bf30f23673de113e6ac1719ae9459e27f4d5c893f17ae126f8d2be3ebc87d9dff4e3904f317ccfd5ef23f28b3c45f26963c7e510ec1fc9570157dd81857967f883c90cd8635f3208b8c0b6596f863e17a500fd597fe8744c35afc1be33aef8bff5ad9b5e637cc7993f7f346fca571637c1fb9d0f99f9543b07ab2df453ff9723d0551a1f3d791cb8170573904f3a5bf725034e66f133be96fa44c1246799e4a573495e461a29cfcbbc8e64f8d9df96564f5519e876a1019668975fda05c593d5c25d67a6f945d6ef3bdb08b3ed491eba1e467c6561fcf229bff4ad9b5c6c7ccf530fa8089bdf8136596703fb1f800c23ee5ff548e3e7a636f3c8ddc68bd8ab91926066596b05c5fe359c285b2cf8de5f7ed7296f050b825d6f74763dc1a0f227bcdbf60f679e29789353f5666093f4facfe857208e63f156e93df8bdc16c223e358ff28b2f939735b240eca2ce1678983f0a57208e6bf150ec96f8d83f127e650b084cf85e5a32fdf9d10b0c6c6e44835c9631dfd9ff235b618925ad1e89779278af5750df7681ea40316d8111eef876a79ad977ae773d8257ec8efead629fdeb3ca4ba9ae6e11fcdbbef6aa72b7934ef695702eddf4e631a13d2f4c73cd599e115f533a639bbc173e6788d0b5cf23a314fe915dee01a37df698bb77887f7f8805ff190e64c342fb59fe2333ca2e373d30b7c89aff035bec1634a9e904ef1417faf78866ff1fc275de03b7c4fa3a1553e50fd8f78a2ef0bfcf43fe973bcc4cff805bb74d6a3de0e31b37c9f561fe090c6583a19612e9d1dd179417db1575237191eeafb172b9cd22a7d409a7bcc8f0c4e68f01900ef44090db8547f4ee9a966456732445083078f779a8756dfdf52f19b1cd59c699254e31c46d0703f30b6fa5239a5d27faabc22b78409de838316bdd51fd1377730a531a12bd363c949aa3d936f1a6821e8fda566aef8fe011d612eba860569495a9196721ebe7d7ed0c30dac491b58d2bd21c116b634bf25ddd2fd9dd9f3f6efef7bff0111915e41 + + + 789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523232520022630543251d2e253d856405bffcbc54105b19c8563600020b13103711c4b530b1308270f5b082019251068344848c32b23808206494a1e23015890819653db8b81e44255c0659025d460fa70c6e3d78ec814b21b90d052422fb070540f50ebaf84196a9b5e6020011bc73cc + + + 789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523232520022630543251d2e253d856405bffcbc54103b11c8563600020b13105719c4b530b1308270f5b0027acb28278201a64c221c4084136132ca7011885c225c06c91890542256193d98a198327a386570ea49449581bb4d2f114d0624a08c230c50fd4f5cb80da04cad351700f7fd8672 + + + 789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523232520022630543251d2e253d856405bffcbc54105b19c856360003103711c6b53002abc40a90649491482ac92863955146d6822ca387474619c9301419a03842825819245bd064129513b1cb242602512216994430d44bc4904984c8c1a5e032897a3019a8144c26518f800c92715864d0ec81ab4dc4701b924fb0850e8a4cad351700fbd07ccb + + + 789c9d92cb0ac2301045f7f98aa1d915b1da8214c44f505c0ae26226b1e8a20a5a1722febb9924a5af58c19b40e77238a1842431ecb66b881371afb03a2b5027bc41ac1f65f9dc1f562f11a52998bd80793411d114146cae9723cfd2cc7266c395ea9aa75c15d74c65aad05c35d79c727215b91636f6d860c689f40910b4e92147d840b3be39d8416d877c860eb9af478d23919c4b8a7a0ed68eb628e4a04521c7fd46c07138e47448dbf1f32fc767e8d43735741af287d3ced83b782fc5075b18a5a5 + + + 789c7d92d10a82301486eff714c3dd49649984103d42d165105dcce3465d58507611d1bbb773d674aed93f85fd7efb183ab394ef771b9e66ecdecaf60c1c4ef2c6d3fad134cfc371fd62499e7373957c9e4c5832e5c0b7d78bc2b9307331a36055ae960556c05a16656e69e5aaa5355658c202965825566d62176b57b5a64da3f188c084841e0a29a5e831910ef8885e4854501922e8a6b923586a176a8e40051ec1e63b7d0267387c6738424775091d653f98565a858e26c110447107d1886350d4a1c41c3dea7864e87c37f3ce47fc3aee7cd5207ffe90f78a7d0007c6c175 + + + 789cb5d5594f1b491007f0773e8545bda1d53ff81a7bb4da07830103b603b92059edc34cf78c0ff0812f3051befb5677554f56c24428d2aa78e0a7aeaeea6be0dd41e9f6aa573a78b7b75c25ab91299961b2281dd8f564b2fdfb9fbfbeefed572a25fe291f46a5cafe1f7bfbd7ab9229f567d3cc81fa0caa945d785f78c72ebc2f9dabb10bef9e73ade2c21913e77ae2c28f2fc48d6a947ab7c4b169d6bc8f9ca3aa0b3fbfaf4e35ff4c5cccdf8813db34de1def34e4c3881b3cc38fb7d5a918f78525ff46dcaca9576a23a627715cd3f53e8a131b7b63edecba69fd8d3af41b1496fa6d7153f78f86b8a86f0bcbfe9ec5493d16cfc5695dfad34c6d651ca9f7cffdbd173743fd441cd64f0f85a5fe489c6a3fd4d5613c0d4eeade43b189747c1b2ce3683abbeebadf5a702ae343716c743d53313f1febc7bfa843bf1371581f9d06ebf8581df257e2b01eba57675a5fea19177e7c109cfa712271aceba58938b13a6ec4a13fba62ee27f53fa9b51fe5c1ba7f7f1f71cd85f7545cdcf73ad8f8ef137762de9fd4ef898b7e51b0d63f52877e65b10de3c785657eacced4fe7b77b763236fab36fa3e1ec5a9d5f341b0e4d3526c42bd4ab0eee7505cf4fb28ce1aea6fc146fa7f76e6d3e115fafa5d7112cebf254eeb328e6a70967b9f8b437fba13db4ceb2fc5453f7f5ffcfac2795f046bbd0fe2a2df486c42bd2bb18dd46375e89f89b99fccf7ef2dadbbf0eea8add6bf16db4cbd1067b9de8fafc7b7a1ef13cf6213e50defadd846b9acff569c3574fe833ad7fa5fc57943cfdb9f9f894cd8cf93982748fdb9386f64dee4df97c978ff52ef4c9d69ff9938cff53cfdf7ec5627f5ae576f8fdfcf0721410ac391c222fb753e720c30c408638e3bdcf31c7a3d9fb3279862c631c70316586285f5ae1e727fd8e091f3e678c216cf68e108c768e3e4957ccb2b39e5fc337470ce71814b74d143ffe59ae4ff01ae7825d7f8c0753fe213d7ff8c2ffcfb0deccefc016ef115df380e51460555d4504784069aafe48f798f87885126a04a4409a564c8be92bfc115655cb94c395a34409d8634a231afe7c58ee5ef35d7bae3dc2eddd384a634a339c7032d90efcce7bba225ad38525aa3461b7ae478da75037a5f2758d196525ec93359aedde23882a563ae95edc8cf90529b4ee894c6bcf2844f66e2ce1239cf9afc7755c5fbc9b8479fdabcc71b3aa38ee4d039d7b9a04b1ecb5ebe677ea1964712ead2f9cf8aac1ecfd10a6f79ffdc7b4d7dee92bcfd7be1bd5ff29ccedbbf2f90dbfbfffefdfef873ef5fce01d04a + + + + + fileNewAction + activated() + Form1 + fileNew() + + + fileOpenAction + activated() + Form1 + fileOpen() + + + fileSaveAction + activated() + Form1 + fileSave() + + + fileSaveAsAction + activated() + Form1 + fileSaveAs() + + + filePrintAction + activated() + Form1 + filePrint() + + + fileExitAction + activated() + Form1 + fileExit() + + + editUndoAction + activated() + Form1 + editUndo() + + + editRedoAction + activated() + Form1 + editRedo() + + + editCutAction + activated() + Form1 + editCut() + + + editCopyAction + activated() + Form1 + editCopy() + + + editPasteAction + activated() + Form1 + editPaste() + + + editFindAction + activated() + Form1 + editFind() + + + helpIndexAction + activated() + Form1 + helpIndex() + + + helpContentsAction + activated() + Form1 + helpContents() + + + helpAboutAction + activated() + Form1 + helpAbout() + + + + fileNew() + fileOpen() + fileSave() + fileSaveAs() + filePrint() + fileExit() + editUndo() + editRedo() + editCut() + editCopy() + editPaste() + editFind() + helpIndex() + helpContents() + helpAbout() + + + diff --git a/parts/filecreate/file-templates/ui-mainwin-qt4 b/parts/filecreate/file-templates/ui-mainwin-qt4 new file mode 100644 index 00000000..814096cc --- /dev/null +++ b/parts/filecreate/file-templates/ui-mainwin-qt4 @@ -0,0 +1,34 @@ + + + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 0 + 0 + 800 + 33 + + + + + + + + + diff --git a/parts/filecreate/file-templates/ui-tabdialog b/parts/filecreate/file-templates/ui-tabdialog new file mode 100644 index 00000000..a28ae7c7 --- /dev/null +++ b/parts/filecreate/file-templates/ui-tabdialog @@ -0,0 +1,147 @@ + +MyDialog1 + + + MyDialog1 + + + + 0 + 0 + 528 + 368 + + + + MyDialog1 + + + true + + + + unnamed + + + 11 + + + 6 + + + + tabWidget + + + + Widget8 + + + Tab + + + + + Widget9 + + + Tab + + + + + + Layout1 + + + + unnamed + + + 0 + + + 6 + + + + buttonHelp + + + &Help + + + F1 + + + true + + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + buttonOk + + + &OK + + + + + + true + + + true + + + + + buttonCancel + + + &Cancel + + + + + + true + + + + + + + + + buttonOk + clicked() + MyDialog1 + accept() + + + buttonCancel + clicked() + MyDialog1 + reject() + + + + diff --git a/parts/filecreate/file-templates/ui-widget b/parts/filecreate/file-templates/ui-widget new file mode 100644 index 00000000..858b4678 --- /dev/null +++ b/parts/filecreate/file-templates/ui-widget @@ -0,0 +1,20 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 600 + 480 + + + + Form1 + + + + diff --git a/parts/filecreate/file-templates/ui-widget-qt4 b/parts/filecreate/file-templates/ui-widget-qt4 new file mode 100644 index 00000000..2aecd3c9 --- /dev/null +++ b/parts/filecreate/file-templates/ui-widget-qt4 @@ -0,0 +1,22 @@ + + + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + diff --git a/parts/filecreate/file-templates/ui-wizard b/parts/filecreate/file-templates/ui-wizard new file mode 100644 index 00000000..7c68689b --- /dev/null +++ b/parts/filecreate/file-templates/ui-wizard @@ -0,0 +1,28 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 600 + 480 + + + + Form1 + + + + page + + + Page + + + + + diff --git a/parts/filecreate/filecreate_filedialog.cpp b/parts/filecreate/filecreate_filedialog.cpp new file mode 100644 index 00000000..81d711cf --- /dev/null +++ b/parts/filecreate/filecreate_filedialog.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "filecreate_filedialog.h" + +#include +#include +#include +#include + +#include "filecreate_part.h" +#include "filecreate_filetype.h" + +namespace FileCreate { + + FileDialog::FileDialog(const QString& startDir, const QString& filter, + QWidget *parent, const char *name, + bool modal, QWidget * extraWidget) : + KFileDialog(startDir, filter, parent, name, modal, extraWidget) { + + setOperationMode(Saving); + + m_extraWidget = extraWidget; + m_typeChooser = dynamic_cast(extraWidget); + + connect(this, SIGNAL(filterChanged(const QString &)), this, SLOT(slotActionFilterChanged(const QString &)) ); + connect(locationEdit, SIGNAL(textChanged(const QString &)), this, SLOT(slotActionTextChanged(const QString &)) ); + + } + + FileDialog::~FileDialog() { } + + + void FileDialog::initGUI() + { + KFileDialog::initGUI(); + } + + void FileDialog::slotActionFilterChanged(const QString & /*filter*/) { + } + + void FileDialog::slotActionTextChanged(const QString & text) { + kdDebug(9034) << "slotActionTextChanged - " << text << endl; + if (!m_typeChooser) return; + QString ext = QFileInfo(text).extension(); + kdDebug(9034) << "Extension is: " << ext << endl; + FileType * filetype = m_typeChooser->part()->getType(ext); + if (!filetype) return; + kdDebug(9034) << "found matching extension: " << ext << endl; + kdDebug(9034) << "Description: " << filetype->descr() << endl; + m_typeChooser->setCurrent(filetype); + } + + + +} + +#include "filecreate_filedialog.moc" diff --git a/parts/filecreate/filecreate_filedialog.h b/parts/filecreate/filecreate_filedialog.h new file mode 100644 index 00000000..04e40111 --- /dev/null +++ b/parts/filecreate/filecreate_filedialog.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + + + +#ifndef __KDEVPART_FILECREATE_FILEDIALOG_H__ +#define __KDEVPART_FILECREATE_FILEDIALOG_H__ + +#include + +#include "filecreate_typechooser.h" + +namespace FileCreate { + + class FileDialog : public KFileDialog { + Q_OBJECT + + public: + FileDialog(const QString& startDir, const QString& filter, + QWidget *parent, const char *name, + bool modal, QWidget * extraWidget); + virtual ~FileDialog(); + + virtual void initGUI(); + + protected: + QWidget * m_extraWidget; + TypeChooser * m_typeChooser; + + protected slots: + void slotActionFilterChanged(const QString & filter); + void slotActionTextChanged(const QString & text); + + + }; + +} + +#endif diff --git a/parts/filecreate/filecreate_filetype.cpp b/parts/filecreate/filecreate_filetype.cpp new file mode 100644 index 00000000..ca786565 --- /dev/null +++ b/parts/filecreate/filecreate_filetype.cpp @@ -0,0 +1,21 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "filecreate_filetype.h" + +namespace FileCreate { + +void FileType::setSubtypesEnabled(bool enabled) { + for(FileType * subtype = m_subtypes.first(); + subtype;subtype=m_subtypes.next()) + subtype->setEnabled(enabled); +} + +} diff --git a/parts/filecreate/filecreate_filetype.h b/parts/filecreate/filecreate_filetype.h new file mode 100644 index 00000000..9b8e039c --- /dev/null +++ b/parts/filecreate/filecreate_filetype.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef __FILECREATE_FILETYPE_H__ +#define __FILECREATE_FILETYPE_H__ + +#include +#include + +namespace FileCreate { + +class FileType { + +public: + + FileType() : m_enabled(false) { + m_subtypes.setAutoDelete(true); + } + + void setName(const QString & name) { m_name = name; } + QString name() const { return m_name; } + void setExt(const QString & ext) { m_ext = ext; } + QString ext() const { return m_ext; } + void setCreateMethod(const QString & createMethod) { m_createMethod = createMethod; } + QString createMethod() const { return m_createMethod; } + void setSubtypeRef(const QString & subtypeRef) { m_subtypeRef = subtypeRef; } + QString subtypeRef() const { return m_subtypeRef; } + void setIcon(const QString & iconName) { m_iconName = iconName; } + QString icon() const { return m_iconName; } + void setDescr(const QString & descr) { m_descr = descr; } + QString descr() const { return m_descr; } + void setEnabled(bool on) { m_enabled = on; } + bool enabled() const { return m_enabled; } + + void setSubtypesEnabled(bool enabled = true); + + void addSubtype(const FileType * subtype) { m_subtypes.append(subtype); } + QPtrList subtypes() const { return m_subtypes; } + +private: + QString m_name; + QString m_ext; + QString m_createMethod; + QString m_subtypeRef; + QString m_iconName; + QString m_descr; + + bool m_enabled; + + QPtrList m_subtypes; + +}; + +} + +#endif diff --git a/parts/filecreate/filecreate_listitem.cpp b/parts/filecreate/filecreate_listitem.cpp new file mode 100644 index 00000000..4b33514f --- /dev/null +++ b/parts/filecreate/filecreate_listitem.cpp @@ -0,0 +1,101 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * thanks: Roberto Raggi for QSimpleRichText stuff * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + + +#include "filecreate_listitem.h" + +#include +#include + +#include +#include + +namespace FileCreate { + + ListItem::ListItem(QListView * listview, const FileType * filetype) : + KListViewItem(listview), m_filetype(filetype), + m_filetypeRenderer(NULL) + { + init(); + } + + + ListItem::ListItem(ListItem * listitem, const FileType * filetype) : + KListViewItem(listitem), m_filetype(filetype), + m_filetypeRenderer(NULL) + { + init(); + } + + ListItem::~ListItem() + { + if (m_filetypeRenderer) delete m_filetypeRenderer; + } + + void ListItem::setup() + { + if (m_filetypeRenderer) delete m_filetypeRenderer; + m_filetypeRenderer = new QSimpleRichText( text(1), listView()->font() ); + m_filetypeRenderer->setWidth(listView()->columnWidth(1)); + setHeight(m_filetypeRenderer->height()); + KListViewItem::setup(); + } + + void ListItem::setHeight( int height ) + { + KListViewItem::setHeight( QMAX(QMAX(height,m_iconHeight), m_filetypeRenderer->height() ) ); + } + + void ListItem::prepareResize() { + if (m_filetypeRenderer) { + m_filetypeRenderer->setWidth(listView()->columnWidth(1)); + setHeight(m_filetypeRenderer->height()); + } + } + + void ListItem::paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int align ) + { + + QBrush brush( isSelected() ? cg.highlight() : backgroundColor() ); + + if( column == 1 ){ +// m_filetypeRenderer->setWidth(width); +// setHeight(m_filetypeRenderer->height()); + m_filetypeRenderer->draw( p, 0, 0, QRect(0, 0, width, height()), cg, &brush ); + return; + } + + KListViewItem::paintCell( p, cg, column, width, align ); + } + + void ListItem::init() + { + m_iconHeight = 0; + setText(0, m_filetype->ext()!="" ? QString("." + m_filetype->ext()) : QString("") ); + setText(1, ""+m_filetype->name()+". " + m_filetype->descr() ); + + KIconLoader * loader = KGlobal::iconLoader(); + QPixmap iconPix = loader->loadIcon(m_filetype->icon(), KIcon::Desktop, + KIcon::SizeMedium, + KIcon::DefaultState, NULL, + true); + if (!iconPix.isNull()) { + setPixmap(0, iconPix); + m_iconHeight = iconPix.height(); + } + + } + + + +} + + diff --git a/parts/filecreate/filecreate_listitem.h b/parts/filecreate/filecreate_listitem.h new file mode 100644 index 00000000..3b2702d3 --- /dev/null +++ b/parts/filecreate/filecreate_listitem.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * thanks: Roberto Raggi for QSimpleRichText stuff * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef __FILECREATE_LISTITEM_H__ +#define __FILECREATE_LISTITEM_H__ + +#include +#include + +#include "filecreate_filetype.h" + +class QSimpleRichText; + +namespace FileCreate { + +class ListItem : public KListViewItem { + +public: + ListItem(QListView *listview, const FileType *filetype); + ListItem(ListItem *listitem, const FileType *filetype); + virtual ~ListItem(); + + const FileType *filetype() const { return m_filetype; } + + virtual void setup(); + virtual void setHeight( int height ); + virtual void paintCell( QPainter* p, const QColorGroup& gc, int column, int width, int align ); + virtual void prepareResize(); + +private: + const FileType *m_filetype; + int m_iconHeight; + void init(); + QSimpleRichText *m_filetypeRenderer; + +}; + +} + +#endif + diff --git a/parts/filecreate/filecreate_newfile.cpp b/parts/filecreate/filecreate_newfile.cpp new file mode 100644 index 00000000..2077556c --- /dev/null +++ b/parts/filecreate/filecreate_newfile.cpp @@ -0,0 +1,162 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "filecreate_newfile.h" + +#include "filecreate_newfile.moc" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace FileCreate { + + NewFileChooser::NewFileChooser(QWidget * parent) : + KDialogBase(KDialogBase::Plain, i18n("New file dialog (title)", "New File"), KDialogBase::Ok|KDialogBase::Cancel, + KDialogBase::Ok, parent, "New file", true) + { + QVBoxLayout* lay = new QVBoxLayout( plainPage(), 5, 5 ); + + lay->addWidget( new QLabel( i18n("New File Creation"), plainPage() ) ); + + QGridLayout* grid = new QGridLayout(lay, 2, 2, 5 ); + QLabel * l = new QLabel(i18n("&Directory:"), plainPage() ); + grid->addWidget(l, 0, 0); + m_urlreq = new KURLRequester( plainPage(), "url request" ); + grid->addWidget(m_urlreq, 0, 1); + l->setBuddy(m_urlreq); + l = new QLabel(i18n("&File name:"), plainPage() ); + grid->addWidget(l, 1, 0); + m_filename = new KLineEdit( plainPage() ); + grid->addWidget(m_filename, 1, 1); + l->setBuddy(m_filename); +// lay->addWidget( grid ); + + QHBoxLayout* hbox = new QHBoxLayout( lay, 5 ); + m_filetypes = new KComboBox( plainPage(), "combo" ); + hbox->addWidget(m_filetypes); + m_addToProject = new QCheckBox( i18n("Add to project (on checkbox)", "&Add to project"), plainPage(), "addproject" ); + hbox->addWidget(m_addToProject); + + lay->addStretch(20); + + m_filename->setFocus(); + m_addToProject->setChecked( true ); + + m_urlreq->setMode((int) KFile::Directory); + connect( m_filename, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotFileNameChanged(const QString & ) ) ); + slotFileNameChanged( m_filename->text() ); + } + + NewFileChooser::~NewFileChooser() { + } + + void NewFileChooser::slotFileNameChanged(const QString & _text) + { + enableButtonOK( !_text.isEmpty() ); + } + + void NewFileChooser::setFileTypes(QPtrList filetypes) { + for(FileType * filetype = filetypes.first(); + filetype; + filetype=filetypes.next()) { + + if (filetype->enabled()) { + + if (filetype->subtypes().count()==0) + addType(filetype); + + QPtrList subtypes = filetype->subtypes(); + for(FileType * subtype = subtypes.first(); + subtype; + subtype=subtypes.next()) { + if (subtype->enabled()) + addType(subtype); + + } + + } + + } + + } + + KURL NewFileChooser::url() const { + + KURL result ( m_urlreq->url() ); + result.cd( m_filename->text() ); + return result; + } + + bool NewFileChooser::addToProject() const { + return m_addToProject->isChecked(); + } + + const FileType *NewFileChooser::selectedType() const { + if (!m_filetypes->count()) return NULL; + return m_typeInCombo[m_filetypes->currentItem()]; + } + + void NewFileChooser::addType(const FileType * filetype) { + m_typeInCombo[m_filetypes->count()]=filetype; + m_filetypes->insertItem( filetype->name() + + (filetype->ext()!="" ? QString(" (." + filetype->ext() + ")") : QString("") ) ); + } + + void NewFileChooser::setCurrent(const FileType *filetype) { + int changeToRow = -1; + QMap::Iterator it; + for ( it = m_typeInCombo.begin(); it != m_typeInCombo.end() && changeToRow==-1; ++it ) { + if (it.data()==filetype) + changeToRow=it.key(); + } + if (changeToRow>-1) m_filetypes->setCurrentItem(changeToRow); + } + + void NewFileChooser::setDirectory(const QString & url) { + m_urlreq->setURL(url); + } + + void NewFileChooser::setName(const QString & name) { + m_filename->setText(name); + } + + void NewFileChooser::setInProjectMode( bool m ) + { + m_addToProject->setEnabled(m); + m_addToProject->setChecked(m); + } + + void NewFileChooser::accept() + { + QString fullPath = url().path(); + if ( !selectedType()->ext().isEmpty() && !fullPath.endsWith("." + selectedType()->ext())) fullPath+="." + selectedType()->ext(); + QFileInfo file( fullPath ); + if ( file.exists() ) + { + KMessageBox::sorry( this, i18n("A file with this name already exists"), i18n("File Exists") ); + return; + } + KDialogBase::accept(); + } + +} + diff --git a/parts/filecreate/filecreate_newfile.h b/parts/filecreate/filecreate_newfile.h new file mode 100644 index 00000000..5123c7d9 --- /dev/null +++ b/parts/filecreate/filecreate_newfile.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef FILECREATE_NEWFILE_H +#define FILECREATE_NEWFILE_H + +#include +#include +#include +#include + +#include "filecreate_filetype.h" + +class KURLRequester; +class QGridLayout; +class KComboBox; +class QCheckBox; +class KLineEdit; + +namespace FileCreate { + class NewFileChooser : public KDialogBase { + Q_OBJECT + public: + NewFileChooser(QWidget *parent=0); + virtual ~NewFileChooser(); + void setFileTypes(QPtrList typelist); + KURL url() const; + bool addToProject() const; + const FileType *selectedType() const; + void setCurrent(const FileType *filetype); + void setDirectory(const QString & url); + void setName(const QString & name); + + void setInProjectMode(bool m); + private slots: + void slotFileNameChanged(const QString &); + protected: + void addType(const FileType * filetype); + void accept(); + + QGridLayout *m_grid; + KURLRequester *m_urlreq; + KComboBox *m_filetypes; + QCheckBox *m_addToProject; + KLineEdit *m_filename; + + QMap m_typeInCombo; + + }; + +} + +#endif diff --git a/parts/filecreate/filecreate_part.cpp b/parts/filecreate/filecreate_part.cpp new file mode 100644 index 00000000..3733753a --- /dev/null +++ b/parts/filecreate/filecreate_part.cpp @@ -0,0 +1,562 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "filecreate_part.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kdevcore.h" +#include "kdevmainwindow.h" +#include "kdevproject.h" +#include "kdevpartcontroller.h" +#include "configwidgetproxy.h" + +#include "filetemplate.h" +#include "domutil.h" +#include "urlutil.h" + +#include "filecreate_widget2.h" +#include "filecreate_widget3.h" +#include "filecreate_filetype.h" +#include "filecreate_filedialog.h" +#include "filecreate_newfile.h" +#include "fcconfigwidget.h" + +#define PROJECTSETTINGSPAGE 1 +#define GLOBALSETTINGSPAGE 2 + +#include "kdevplugininfo.h" + +#include "config.h" + +static const KDevPluginInfo data("kdevfilecreate"); + +typedef KDevGenericFactory FileCreateFactory; +K_EXPORT_COMPONENT_FACTORY( libkdevfilecreate, FileCreateFactory( data ) ) + +using namespace FileCreate; + +FileCreatePart::FileCreatePart(QObject *parent, const char *name, const QStringList & ) +// : KDevCreateFile(&data, parent, name ? name : "FileCreatePart"), m_selectedWidget(-1), m_useSideTab(true), m_subPopups(0) + : KDevCreateFile(&data, parent, name ? name : "FileCreatePart"), m_subPopups(0) +{ + setInstance(FileCreateFactory::instance()); + setXMLFile("kdevpart_filecreate.rc"); + + connect( core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) ); + connect( core(), SIGNAL(projectClosed()), this, SLOT(slotProjectClosed()) ); + + _configProxy = new ConfigWidgetProxy( core() ); + _configProxy->createProjectConfigPage( i18n("File Templates"), PROJECTSETTINGSPAGE, info()->icon() ); + _configProxy->createGlobalConfigPage( i18n("File Templates"), GLOBALSETTINGSPAGE, info()->icon() ); + connect( _configProxy, SIGNAL(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int )), + this, SLOT(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int )) ); + + + KToolBarPopupAction * newAction = new KToolBarPopupAction( i18n("&New"), "filenew", CTRL+Qt::Key_N, this, SLOT(slotNewFile()), actionCollection(), "file_new"); + newAction->setWhatsThis( i18n("New file

Creates a new file. Also adds it the project if the Add to project checkbox is turned on.") ); + newAction->setToolTip( i18n("Create a new file") ); + m_newPopupMenu = newAction->popupMenu(); + connect(m_newPopupMenu, SIGNAL(aboutToShow()), this, SLOT(slotAboutToShowNewPopupMenu())); + + QTimer::singleShot( 0, this, SLOT(slotGlobalInitialize()) ); +} + + +FileCreatePart::~FileCreatePart() +{ + delete _configProxy; + + m_newPopupMenu->clear(); + delete m_subPopups; +} + +void FileCreatePart::insertConfigWidget( const KDialogBase * dlg, QWidget * page, unsigned int pagenumber ) +{ + kdDebug() << k_funcinfo << endl; + + switch( pagenumber ) + { + case PROJECTSETTINGSPAGE: + { + FCConfigWidget* w = new FCConfigWidget( this, false, page, "filecreate config widget" ); + connect( dlg, SIGNAL( okClicked( ) ), w, SLOT( accept( ) ) ); + } + break; + + case GLOBALSETTINGSPAGE: + { + FCConfigWidget *w = new FCConfigWidget( this, true, page, "filecreate config widget" ); + connect(dlg, SIGNAL(okClicked()), w, SLOT(accept())); + } + break; + } +} + +void FileCreatePart::slotAboutToShowNewPopupMenu() +{ + KIconLoader * m_iconLoader = KGlobal::iconLoader(); + m_newPopupMenu->clear(); + delete m_subPopups; + m_subPopups = NULL; + int id = 0; + FileType * filetype = m_filetypes.first(); + for(; filetype; filetype=m_filetypes.next()) + { + if (filetype->enabled()) + { + if (filetype->subtypes().count()==0) + { + QPixmap iconPix = m_iconLoader->loadIcon( + filetype->icon(), KIcon::Desktop, KIcon::SizeSmall, + KIcon::DefaultState, NULL, true); + m_newPopupMenu->insertItem(iconPix, filetype->name(), this, + SLOT(slotNewFilePopup(int)), 0, ++id ); + m_newPopupMenu->setItemParameter( id, (long)filetype ); + } else + { + KPopupMenu* subMenu = NULL; + QPtrList subtypes = filetype->subtypes(); + for(FileType * subtype = subtypes.first(); subtype; subtype=subtypes.next()) + { + if (subtype->enabled()){ + if( !subMenu ) + subMenu = new KPopupMenu(0,0); + QPixmap iconPix = m_iconLoader->loadIcon( + subtype->icon(), KIcon::Desktop, KIcon::SizeSmall, + KIcon::DefaultState, NULL, true); + subMenu->insertItem(iconPix, subtype->name(), this, + SLOT(slotNewFilePopup(int)), 0, ++id ); + subMenu->setItemParameter( id, (long)subtype ); + } + } + if( subMenu ) + { + if( !m_subPopups ) + { + m_subPopups = new QPtrList; + m_subPopups->setAutoDelete(true); + } + m_subPopups->append( subMenu ); + m_newPopupMenu->insertItem( filetype->name(), subMenu ); + } + } + + } + + } +} + +void FileCreatePart::slotNewFilePopup( int pFileType ) +{ + const FileType* filetype = (const FileType*) pFileType; + slotFiletypeSelected( filetype ); +} + +void FileCreatePart::slotNewFile() { + KDevCreateFile::CreatedFile createdFile = createNewFile(); + if (createdFile.status == KDevCreateFile::CreatedFile::STATUS_NOTCREATED) + KMessageBox::error(0, i18n("Cannot create file. Check whether the directory and filename are valid.")); + else if (createdFile.status != KDevCreateFile::CreatedFile::STATUS_CANCELED) + openCreatedFile(createdFile); +} + +void FileCreatePart::slotProjectOpened() { + QTimer::singleShot( 0, this, SLOT(slotInitialize()) ); +} + +void FileCreatePart::addFileType(const QString & filename) { + FileType * filetype = getType(filename); + if (!filetype) { + filetype = new FileType; + filetype->setName( filename + " files" ); + filetype->setExt( filename ); + filetype->setCreateMethod("template"); + m_filetypes.append(filetype); + } + filetype->setEnabled(true); +} + +void FileCreatePart::slotProjectClosed() { + m_filetypes.clear(); + QTimer::singleShot( 0, this, SLOT(slotGlobalInitialize()) ); +} + +void FileCreatePart::slotFiletypeSelected(const FileType * filetype) { + + KDevCreateFile::CreatedFile createdFile = createNewFile(filetype->ext(), + QString::null, + QString::null, + filetype->subtypeRef()); + + openCreatedFile(createdFile); +} + +void FileCreatePart::openCreatedFile(const KDevCreateFile::CreatedFile & createdFile) +{ + if ( createdFile.status == KDevCreateFile::CreatedFile::STATUS_OK ) + { + KURL uu( createdFile.dir + "/" + createdFile.filename ); + partController()->editDocument ( uu ); + } +} + +int FileCreatePart::readTypes(const QDomDocument & dom, QPtrList &m_filetypes, bool enable) { + int numRead = 0; + QDomElement fileTypes = DomUtil::elementByPath(dom,"/kdevfilecreate/filetypes"); + if (!fileTypes.isNull()) { + for(QDomNode node = fileTypes.firstChild();!node.isNull();node=node.nextSibling()) { + + if (node.isElement() && node.nodeName()=="type") { + QDomElement element = node.toElement(); + FileType * filetype = new FileType; + filetype->setName( element.attribute("name") ); + filetype->setExt( element.attribute("ext") ); + filetype->setCreateMethod( element.attribute("create") ); + + filetype->setIcon( element.attribute("icon") ); + filetype->setDescr( (DomUtil::namedChildElement(element, "descr")).text() ); + filetype->setEnabled(enable || (filetype->ext()=="")); + m_filetypes.append(filetype); + numRead++; + + kdDebug(9034) << "node: " << filetype->name().latin1() << endl; + + if (node.hasChildNodes()) { + for(QDomNode subnode = node.firstChild();!subnode.isNull();subnode=subnode.nextSibling()) { + kdDebug(9034) << "subnode: " << subnode.nodeName().latin1() << endl; + if (subnode.isElement() && subnode.nodeName()=="subtype") { + QDomElement subelement = subnode.toElement(); + FileType * subtype = new FileType; + subtype->setExt( filetype->ext() ); + subtype->setCreateMethod( filetype->createMethod() ); + subtype->setSubtypeRef( subelement.attribute("ref") ); + subtype->setIcon( subelement.attribute("icon") ); + subtype->setName( subelement.attribute("name") ); + subtype->setDescr( (DomUtil::namedChildElement(subelement, "descr")).text() ); + subtype->setEnabled(enable); + filetype->addSubtype(subtype); + } + } + } + } + } + } + return numRead; +} + +FileType * FileCreatePart::getType(const QString & ex, const QString subtRef) { + + QString subtypeRef = subtRef; + QString ext = ex; + int dashPos = ext.find('-'); + if (dashPos>-1 && subtRef.isNull()) { + ext = ex.left(dashPos); + subtypeRef = ex.mid(dashPos+1); + } + + QPtrList filetypes = getFileTypes(); + for(FileType * filetype = filetypes.first(); + filetype; + filetype=filetypes.next()) { + if (filetype->ext()==ext) { + if (subtypeRef.isNull()) return filetype; + QPtrList subtypes = filetype->subtypes(); + for(FileType * subtype = subtypes.first(); + subtype; + subtype=subtypes.next()) { + if (subtypeRef==subtype->subtypeRef()) return subtype; + } + } + } + return NULL; +} + +FileType * FileCreatePart::getEnabledType(const QString & ex, const QString subtRef) { + + QString subtypeRef = subtRef; + QString ext = ex; + int dashPos = ext.find('-'); + if (dashPos>-1 && subtRef.isNull()) { + ext = ex.left(dashPos); + subtypeRef = ex.mid(dashPos+1); + } + + QPtrList filetypes = getFileTypes(); + for(FileType * filetype = filetypes.first(); + filetype; + filetype=filetypes.next()) { + if (filetype->ext()==ext) { + if ( (subtypeRef.isNull()) && (filetype->enabled()) ) return filetype; + QPtrList subtypes = filetype->subtypes(); + for(FileType * subtype = subtypes.first(); + subtype; + subtype=subtypes.next()) { + if ( (subtypeRef==subtype->subtypeRef()) && (filetype->enabled()) ) return subtype; + } + } + } + return NULL; +} + +// KDevFileCreate interface + +KDevCreateFile::CreatedFile FileCreatePart::createNewFile(QString ext, QString dir, QString name, QString subtype) +{ + KDevCreateFile::CreatedFile result; + + KURL projectURL; + if ( !project() ) + { + //result.status = KDevCreateFile::CreatedFile::STATUS_NOTCREATED; + //return result; + } + else + { + projectURL = project()->projectDirectory(); + } + + KURL selectedURL; + + NewFileChooser dialog; + dialog.setFileTypes(m_filetypes); + const FileType *filetype = getEnabledType(ext,subtype); + kdDebug(9034) << "Looking for filetype pointer for " << ext << "/" << subtype << endl; + if (filetype) { + kdDebug(9034) << "found filetype" << endl; + } else { + kdDebug(9034) << "could not find filetype" << endl; + } + if (!project()) + dialog.setInProjectMode(false); + + if (!dir.isNull()) + dialog.setDirectory(dir); + else if (!project()) + dialog.setDirectory(QDir::currentDirPath()); + else + { + QString activeDir = project()->activeDirectory(); + dialog.setDirectory( project()->projectDirectory() + + ( activeDir[0] == '/' ? "" : "/" ) + + activeDir ); + } + if (!name.isNull()) dialog.setName(name); + if (filetype) dialog.setCurrent(filetype); + + dialog.setInitialSize(QSize(500, 200)); + int dialogResult = dialog.exec(); + + if (dialogResult == KDialogBase::Rejected) { + result.status = KDevCreateFile::CreatedFile::STATUS_CANCELED; + return result; + } + + // OK was pressed + + result.addToProject = dialog.addToProject(); + selectedURL = dialog.url(); + const FileType *selectedFileType = dialog.selectedType(); + + if (dialog.addToProject() && !projectURL.isParentOf(selectedURL) && !(project()->options() & KDevProject::UsesQMakeBuildSystem) ) { + result.status = KDevCreateFile::CreatedFile::STATUS_NOTWITHINPROJECT; + return result; + } + + if (selectedFileType) { + ext = selectedFileType->ext(); + subtype = selectedFileType->subtypeRef(); + } + + QString fullPath = selectedURL.path(); + // add appropriate extension, if not already there + if ( !ext.isEmpty() && !fullPath.endsWith("." + ext)) fullPath+="." + ext; + + QString filename = URLUtil::filename(fullPath); + kdDebug(9034) << "full path = " << fullPath << endl; + + // add in subtype, if specified + if (!subtype.isEmpty()) + ext += "-" + subtype; + + // create file from template + bool created = false; + if (FileTemplate::exists(this, ext)) + created = FileTemplate::copy(this, ext, fullPath); + else { + // no template, create a blank file instead + QFile f(fullPath); + created = f.open( IO_WriteOnly ); + f.close(); + } + if (!created) + { + result.status = KDevCreateFile::CreatedFile::STATUS_NOTCREATED; + return result; + } + + if (dialog.addToProject()) + { + // work out the path relative to the project directory +// QString relToProj = URLUtil::relativePath(projectURL, selectedURL, URLUtil::SLASH_PREFIX ); + QString relToProj; + if( project()->options() & KDevProject::UsesQMakeBuildSystem ) + { + relToProj = URLUtil::relativePathToFile( project()->projectDirectory(), fullPath ); + project()->addFile(relToProj); + }else + { + relToProj = URLUtil::relativePath(projectURL.path(), fullPath, URLUtil::SLASH_PREFIX ); + project()->addFile(relToProj.mid(1)); + } + } + + KURL url; + url.setPath(fullPath); + partController()->editDocument(url); + + QString fileName = URLUtil::filename(fullPath); + kdDebug(9034) << "file name = " << filename << endl; + + result.filename = fileName; + result.dir = URLUtil::directory(fullPath); + result.status = KDevCreateFile::CreatedFile::STATUS_OK; + + return result; +} + +void FileCreatePart::slotNoteFiletype(const FileType * filetype) { + kdDebug(9034) << "Noting file type: " << (filetype ? filetype->ext() : QString::fromLatin1("Null") ) << endl; + m_filedialogFiletype = filetype; +} + +void FileCreatePart::slotInitialize( ) +{ + m_filetypes.clear(); + + //read global configuration + slotGlobalInitialize(); + + // read in which global templates are to be used for this project + QDomElement useGlobalTypes = + DomUtil::elementByPath(*projectDom(),"/kdevfilecreate/useglobaltypes"); + for(QDomNode node = useGlobalTypes.firstChild(); + !node.isNull();node=node.nextSibling()) { + + if (node.isElement() && node.nodeName()=="type") { + QDomElement element = node.toElement(); + QString ext = element.attribute("ext"); + QString subtyperef = element.attribute("subtyperef"); + // if an extension has been specified as enabled, ensure it + // and all its subtypes are enabled + if (subtyperef.isNull()) { + FileType * filetype = getType(ext); + if (filetype) { + filetype->setEnabled(true); + if (filetype->subtypes().count()) + filetype->setSubtypesEnabled(true); + } + } else { + // if an extension + subtype have been specified, enable + // the subtype and the extension (the 'parent') + FileType * filetype = getType(ext); + FileType * subtype = getType(ext,subtyperef); + if (filetype && subtype) { + filetype->setEnabled(true); + subtype->setEnabled(true); + } + } + } + } + + // read in the list of file types for this project + if ( project() && readTypes( *projectDom(), m_filetypes, true )==0 ) { + // default by scanning the templates directory if no template info + // found in project file + QDir templDir( project()->projectDirectory() + "/templates/" ); + if (templDir.exists()) { + templDir.setFilter( QDir::Files ); + const QFileInfoList * list = templDir.entryInfoList(); + if( list ){ + QFileInfoListIterator it( *list ); + QFileInfo *fi; + while ( (fi = it.current()) != 0 ) { + addFileType(fi->fileName()); + ++it; + } + } + } +/* else { // it was probably an imported project + // KLUDGE: we need a better way to determine file types + // the current method looks a bit too restrictive + addFileType( "cpp" ); + addFileType( "h" ); + }*/ + } +} + +QString FileCreatePart::findGlobalXMLFile() const +{ + int version = 0; + QString filename; + QStringList filenames = KGlobal::instance()->dirs()->findAllResources("data", "kdevfilecreate/template-info.xml"); + for( QStringList::const_iterator it = filenames.begin(); it != filenames.end(); ++it ) + { + QDomDocument globalDom; + DomUtil::openDOMFile(globalDom,*it); + QDomElement e = globalDom.documentElement(); + if( !e.hasAttribute( "version" ) && e.attribute( "version" ).toInt() < version ) + { + continue; + }else + { + version = e.attribute( "version" ).toInt(); + filename = *it; + } + } + return filename; +} + +void FileCreatePart::slotGlobalInitialize( ) +{ + // read in global template information + QString globalXMLFile = findGlobalXMLFile(); + kdDebug(9034) << "Found global template info info " << globalXMLFile << endl; + QDomDocument globalDom; + if (!globalXMLFile.isNull() && DomUtil::openDOMFile(globalDom,globalXMLFile)) + { + kdDebug(9034) << "Reading global template info..." << endl; + + readTypes(globalDom, m_filetypes, false); + + } +} + +#include "filecreate_part.moc" + +// kate: indent-width 2; replace-tabs on; tab-width 4; space-indent on; diff --git a/parts/filecreate/filecreate_part.h b/parts/filecreate/filecreate_part.h new file mode 100644 index 00000000..3cbc9909 --- /dev/null +++ b/parts/filecreate/filecreate_part.h @@ -0,0 +1,144 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + + + +#ifndef __KDEVPART_FILECREATE_H__ +#define __KDEVPART_FILECREATE_H__ + + +#include +#include + +#include +#include +#include + +#include "filecreate_typechooser.h" + +class KPopupMenu; + +namespace FileCreate { + class Widget; + class FileType; +} + +class KDialogBase; +class FCConfigWidget; +class ConfigWidgetProxy; + +using namespace FileCreate; + +class FileCreatePart : public KDevCreateFile +{ + Q_OBJECT + + friend class FCConfigWidget; +public: + FileCreatePart(QObject *parent, const char *name, const QStringList &); + virtual ~FileCreatePart(); + + /** + * Returns the list of available file types. + */ + QPtrList getFileTypes() const { return m_filetypes; } + + /** + * Call this method to create a new file, within or without the project. Supply as + * much information as you know. Leave what you don't know as QString::null. + * The user will be prompted as necessary for the missing information, and the + * file created, and added to the project as necessary. + */ + virtual KDevCreateFile::CreatedFile createNewFile(QString ext = QString::null, + QString dir = QString::null, + QString name = QString::null, + QString subtype = QString::null); + + /** + * Finds the file type object for a given extension and optionally subtype. + * You can omit the subtype and specify the extension as ext-subtype if you wish. + */ + FileType * getType(const QString & ext, const QString subtype = QString::null); + /** + * Finds the file type object for a given extension and optionally subtype. + * You can omit the subtype and specify the extension as ext-subtype if you wish. + * Returns only enabled type (i.e. used in the project). + */ + FileType * getEnabledType(const QString & ext, const QString subtype = QString::null); + +public slots: + + void slotProjectOpened(); + void slotProjectClosed(); + void slotInitialize(); + void slotGlobalInitialize(); + + /** + * Called when a file type is selected from the docked widget. + */ + void slotFiletypeSelected(const FileType *); + + /** + * Called when a new file is required - for example, from the "New.." menu action. + */ + void slotNewFile(); + + /** + * Called from KToolBarPopupMenu to request a new file action + * @param pFileType is acutally a pointer to FileType + */ + void slotNewFilePopup(int pFileType); + +protected slots: + void slotNoteFiletype(const FileType * filetype); + void slotAboutToShowNewPopupMenu(); + void insertConfigWidget( const KDialogBase * dlg, QWidget * page, unsigned int ); + +private: + /** + * If a file has been successfully created, open it + */ + void openCreatedFile(const KDevCreateFile::CreatedFile & createdFile); + + /** + * Reads in file type definitions from a config DOM and adds them + * to the file type list. If enable is true, sets them all to + * enabled=true by default. + */ + int readTypes(const QDomDocument & dom, QPtrList &m_filetypes, bool enable); + + /** + * Add a file type + */ + void addFileType(const QString & filename); + + /** + * Finds the global XML file that has the same version as KDevelop + */ + QString findGlobalXMLFile() const; + + /** + * List of file types from which the user can choose + */ + QPtrList m_filetypes; + + /** + * The file type selected by the new file dialog, if appropriate. + */ + const FileType * m_filedialogFiletype; + + ConfigWidgetProxy * _configProxy; + + KPopupMenu* m_newPopupMenu; + QPtrList* m_subPopups; +}; + + +#endif diff --git a/parts/filecreate/filecreate_typechooser.h b/parts/filecreate/filecreate_typechooser.h new file mode 100644 index 00000000..8e1e37e8 --- /dev/null +++ b/parts/filecreate/filecreate_typechooser.h @@ -0,0 +1,47 @@ +#ifndef __FILECREATE_TYPECHOOSER_H__ +#define __FILECREATE_TYPECHOOSER_H__ + +#include "filecreate_typechoosersig.h" + +#include + +class FileCreatePart; + +namespace FileCreate { + +class FileType; + +class TypeChooser { + +public: + + TypeChooser(FileCreatePart * part) : m_part(part), m_current(NULL) { + m_signaller = new Signaller; + } + virtual ~TypeChooser() { delete m_signaller; } + + virtual void setPart(FileCreatePart * part) { m_part = part; } + virtual FileCreatePart * part() const { return m_part; } + virtual void refresh() = 0; + virtual void setCurrent(const FileType * current) = 0; + virtual const FileType * current() const { return m_current; } + + virtual void filetypeSelected(const FileType * filetype) { + m_current = filetype; + kdDebug(9034) << "type selected: about to signal" << endl; + if (filetype) m_signaller->signal(filetype); + kdDebug(9034) << "type selected: done signal" << endl; + } + + const Signaller * signaller() const { return m_signaller; } + +protected: + FileCreatePart * m_part; + Signaller * m_signaller; + const FileType * m_current; + +}; + +} + +#endif diff --git a/parts/filecreate/filecreate_typechoosersig.h b/parts/filecreate/filecreate_typechoosersig.h new file mode 100644 index 00000000..7f16208a --- /dev/null +++ b/parts/filecreate/filecreate_typechoosersig.h @@ -0,0 +1,28 @@ +#ifndef __FILECREATE_TYPECHOOSERSIG_H__ +#define __FILECREATE_TYPECHOOSERSIG_H__ + +#include + +namespace FileCreate { + +class FileType; + +class Signaller : public QObject { + Q_OBJECT + +public: + Signaller() : QObject() { } + virtual ~Signaller() { } + + virtual void signal(const FileType * filetype ) { + emit filetypeSelected(filetype); + } + + +signals: + void filetypeSelected(const FileType * filetype); +}; + +} + +#endif diff --git a/parts/filecreate/filecreate_widget2.cpp b/parts/filecreate/filecreate_widget2.cpp new file mode 100644 index 00000000..c8e6d051 --- /dev/null +++ b/parts/filecreate/filecreate_widget2.cpp @@ -0,0 +1,228 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "kdevproject.h" +#include "filecreate_part.h" +#include "filecreate_widget2.h" +#include "filecreate_filetype.h" +#include "filecreate_listitem.h" + +namespace FileCreate { + + FriendlyWidget::FriendlyWidget(FileCreatePart *part) + : QTable(0,4,0), TypeChooser(part), m_selected(NULL) + { + + setReadOnly(true); + setShowGrid(false); + horizontalHeader()->hide(); + setTopMargin(0); + verticalHeader()->hide(); + setLeftMargin(0); + setSelectionMode(SingleRow); + setFocusStyle(FollowStyle); + setColumnStretchable(3, true); + + m_iconLoader = KGlobal::iconLoader(); + + QWhatsThis::add(this, i18n("Use this to create new files within your project.")); + + setDefaultColumnWidths(); + + } + + + FriendlyWidget::~FriendlyWidget() + { + } + + void FriendlyWidget::setCurrent(const FileType * current) { + int changeToRow = -1; + QMap::Iterator it; + kdDebug(9034) << "Checking " << current->descr() << " for matches in row..." << endl; + for ( it = typeForRow.begin(); it != typeForRow.end() && changeToRow==-1; ++it ) { + kdDebug(9034) << "Checking: " << it.data()->descr() << endl; + if (it.data()==current) + changeToRow=it.key(); + else kdDebug(9034) << "No match!" << endl; + } + + // If an exact match is not found (e.g. current points to a 'parent' type) then + // look instead for an extension match + if (changeToRow==-1) { + for(it = typeForRow.begin(); it!= typeForRow.end() && changeToRow==-1; ++it) { + if (it.data()->ext() == current->ext() ) + changeToRow = it.key(); + } + } + + if (changeToRow!=-1) { + m_current = current; + kdDebug(9034) << "Found row, setting current to row " << changeToRow << endl; + slotCellSelected(changeToRow,0); + clearSelection(); + selectRow(changeToRow); + } + + } + + void FriendlyWidget::refresh() { + + disconnect( this, SIGNAL(currentChanged(int,int)), this, SLOT(slotCellSelected(int,int)) ); + + empty(); + + int row = 0; + QPtrList filetypes = m_part->getFileTypes(); + for(FileType * filetype = filetypes.first(); + filetype; + filetype=filetypes.next()) { + + if (filetype->enabled()) { + + if (filetype->subtypes().count()==0) + setRow(row++, filetype); + + QPtrList subtypes = filetype->subtypes(); + for(FileType * subtype = subtypes.first(); + subtype; + subtype=subtypes.next()) { + if (subtype->enabled()) + setRow(row++, subtype); + } + + } + + } + resizeCells(); + if (currentSelection()>-1) removeSelection(currentSelection()); + + connect( this, SIGNAL(currentChanged(int,int)), this, SLOT(slotCellSelected(int,int)) ); + + + } + + void FriendlyWidget::setRow(int row, FileType * filetype) { + if (row+1>numRows()) setNumRows(row+1); + setText(row, 1, filetype->name() ); + setText(row, 2, filetype->ext() ); + setText(row, 3, filetype->descr() ); + item(row,1)->setWordWrap(true); + item(row,3)->setWordWrap(true); + //setRowStretchable(row,true); + QPixmap iconPix = m_iconLoader->loadIcon(filetype->icon(), KIcon::Desktop, KIcon::SizeMedium, + KIcon::DefaultState, NULL, + true); + if (!iconPix.isNull()) { + setPixmap(row, 0, iconPix); + setRowHeight(row, iconPix.height()+4 ); + if (iconPix.width()+4>columnWidth(0)) + setColumnWidth(0, iconPix.width()+4 ); + } + + typeForRow[row]=filetype; + + } + + void FriendlyWidget::empty() { + typeForRow.clear(); + while(numRows()) removeRow(0); + } + + void FriendlyWidget::setDefaultColumnWidths() { + // set some defaults - resizeCells will later ensure that column widths + // and row heights are set big enough for the cell contents + setColumnWidth(0,1); + setColumnWidth(1,60); + setColumnWidth(2,30); + setColumnWidth(3,150); + } + + void FriendlyWidget::slotCellSelected(int row, int col) { + if (col!=0) { + setCurrentCell(row, 0); + return; + } + + m_selected = typeForRow.contains(row) ? typeForRow[row] : NULL; + QTimer::singleShot(0, this, SLOT(slotDoSelection()) ); + + } + + void FriendlyWidget::slotDoSelection() { + kdDebug(9034) << "widget2: slotDoSelection" << endl; + if (m_selected) filetypeSelected(m_selected); + kdDebug(9034) << "widget2: slotDoSelection middle" << endl; + if (currentSelection()>-1) removeSelection(currentSelection()); + kdDebug(9034) << "widget2: slotDoSelection ending" << endl; + } + + void FriendlyWidget::resizeCells() { + for(int r=0;r=numRows() || row<0) return; + int maxHeight = 0; + + for(int c=0;csizeHint(); + maxHeight = size.height()>maxHeight ? size.height() : maxHeight; + } + setRowHeight(row,maxHeight+2); // bit of extra room + } + + void FriendlyWidget::resizeColumn(int col) { + if (col>=numCols() || col<0) return; + int maxWidth = 0; + for(int r=0;rsizeHint(); + maxWidth = size.width()>maxWidth ? size.width() : maxWidth; + } + setColumnWidth(col,maxWidth+2); // bit of extra room + } + +#if QT_VERSION < 0x030100 + void FriendlyWidget::selectRow(int row) { + if (numCols()>0 && row +#include +#include +#include + +//#include + +#include "filecreate_typechooser.h" + +class KIconLoader; +class KDevProject; +class FileCreatePart; + +namespace FileCreate { + + class FileType; + + class FriendlyWidget : public QTable, public TypeChooser + { + Q_OBJECT + + public: + + FriendlyWidget(FileCreatePart *part); + virtual ~FriendlyWidget(); + + /** + * Refreshes the widget with the part's file type list. + */ + virtual void refresh(); + /** + * Sets the currently highlighted file type. + */ + virtual void setCurrent(const FileType * current); + +#if QT_VERSION < 0x030100 + void selectRow(int row); +#endif + + protected: + /** + * Sets row row to filetype filetype. + */ + virtual void setRow(int row, FileType * filetype); + /** + * Clears the table. + */ + virtual void empty(); + /** + * Sets some default column widths. + */ + virtual void setDefaultColumnWidths(); + /** + * Scans the cells in the table and adjusts their size based + * on their contents. + */ + virtual void resizeCells(); + /** + * Sets the height of a row to the highest + * cell in the row. + */ + virtual void resizeRow(int row); + /** + * Sets the width of a column to the widest + * cell in the column. + */ + virtual void resizeColumn(int col); + + /** + * The default icon loader, here for convenience. + */ + KIconLoader * m_iconLoader; + /** + * A mapping of each row number to a file type. + */ + QMap typeForRow; + /** + * The currently selected file type, or null if none. + */ + FileType * m_selected; + + protected slots: + /** + * When a cell is selected by the user. + */ + virtual void slotCellSelected(int row, int col); + /** + * Invoked as a single shot after slotCellSelected, with m_selected + * set to the selected file type, so that + * the GUI will be updated before the selection event + * takes place. + */ + virtual void slotDoSelection(); + + + }; + +} + +#endif diff --git a/parts/filecreate/filecreate_widget3.cpp b/parts/filecreate/filecreate_widget3.cpp new file mode 100644 index 00000000..f766cbcf --- /dev/null +++ b/parts/filecreate/filecreate_widget3.cpp @@ -0,0 +1,119 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * thanks: Roberto Raggi for QSimpleRichText stuff * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "filecreate_widget3.h" + +#include "kdevproject.h" +#include "filecreate_part.h" +#include "filecreate_filetype.h" +#include "filecreate_listitem.h" + +namespace FileCreate { + + ListWidget::ListWidget(FileCreatePart *part) + : KListView(0, "KDevFileCreate"), TypeChooser(part) + { + setIcon( SmallIcon("filenew2") ); + setCaption(i18n("File Create")); + setResizeMode( AllColumns ); + setAllColumnsShowFocus(true); + setRootIsDecorated(true); + + addColumn(""); + addColumn(""); + + QWhatsThis::add(this, i18n("New file

This part makes the creation of new files easier. Select a type in the list to create a file. " + "The list of project file types can be configured in project settings dialog, New File Wizard tab. " + "Globally available file types are listed and can be configured in KDevelop settings dialog, New File Wizard tab.")); + + + connect( this, SIGNAL(clicked(QListViewItem*)), this, SLOT(slotTypeSelected(QListViewItem*)) ); + } + + + ListWidget::~ListWidget() + { + } + + void ListWidget::setCurrent(const FileType * current) { + + bool found = false; + QListViewItem * lvi = firstChild(); + while(lvi && !found) { + ListItem * li = dynamic_cast(lvi); + if (li) { + if (li->filetype()==current) { + found=true; + setSelected(li,true); + } + } + if (lvi->nextSibling()) + lvi = lvi->nextSibling(); + else { + while (lvi && !lvi->nextSibling()) + lvi = lvi->parent(); + } + } + + } + + void ListWidget::resizeEvent(QResizeEvent *event) { + ListItem *li = dynamic_cast(firstChild()); + while(li) { + li->prepareResize(); + li = dynamic_cast(li->nextSibling()); + } + KListView::resizeEvent(event); + } + + void ListWidget::refresh() { + clear(); + QPtrList filetypes = m_part->getFileTypes(); + for(FileType * filetype = filetypes.first(); + filetype!=NULL; + filetype=filetypes.next()) { + if (filetype->enabled()) { + QPtrList subtypes = filetype->subtypes(); + if (subtypes.count()==0) + new ListItem( this, filetype ); + for(FileType * subtype = subtypes.first(); + subtype!=NULL; + subtype=subtypes.next()) { + if (subtype->enabled()) + new ListItem( this, subtype ); + } + } + } + } + + void ListWidget::slotTypeSelected(QListViewItem * item) { + ListItem * fileitem = dynamic_cast(item); + if (!fileitem) return; + + const FileType * filetype = fileitem->filetype(); + + TypeChooser::filetypeSelected(filetype); + } + + +} +#include "filecreate_widget3.moc" diff --git a/parts/filecreate/filecreate_widget3.h b/parts/filecreate/filecreate_widget3.h new file mode 100644 index 00000000..58fc5129 --- /dev/null +++ b/parts/filecreate/filecreate_widget3.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2003 by Julian Rockey * + * linux@jrockey.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef __FILECREATE_WIDGET3_H__ +#define __FILECREATE_WIDGET3_H__ + + +#include +#include + +#include + +#include "filecreate_typechooser.h" + +class KDevProject; +class FileCreatePart; +class QResizeEvent; + +namespace FileCreate { + + class FileType; + + class ListWidget : public KListView, public TypeChooser + { + Q_OBJECT + + public: + + ListWidget(FileCreatePart *part); + virtual ~ListWidget(); + + virtual void refresh(); + virtual void setCurrent(const FileType * current); + virtual void resizeEvent(QResizeEvent *event); + + public slots: + void slotTypeSelected(QListViewItem * item); + + }; + +} + +#endif diff --git a/parts/filecreate/kdevfilecreate.desktop b/parts/filecreate/kdevfilecreate.desktop new file mode 100644 index 00000000..82adbb30 --- /dev/null +++ b/parts/filecreate/kdevfilecreate.desktop @@ -0,0 +1,77 @@ +[Desktop Entry] +Type=Service +Exec=blubb +Comment=FileCreate +Comment[ca]=Creació de fitxers +Comment[da]=Filoprettelse +Comment[de]=Eine Komponente, die Unterstützung bei der Erstellung von Dateien bietet +Comment[el]=ΔημιουργίαΑρχείου +Comment[es]=Creación de archivos +Comment[eu]=Fitxategi sorkuntza +Comment[fa]=ایجاد پرونده +Comment[fr]=Création de fichiers +Comment[hi]=फ़ाइल-क्रिएट +Comment[hu]=Fájl létrehozása +Comment[it]=Crea file +Comment[ja]=ファイル作成 +Comment[ms]=CiptaFail +Comment[nds]=Dateiopstellen +Comment[ne]=फाइल सिर्जना +Comment[nl]=Bestand aanmaken +Comment[pl]=Tworzenie pliku +Comment[pt]=Criação de Ficheiros +Comment[ru]=Мастер создания файлов +Comment[sk]=Vytvoriť súbor +Comment[sl]=Ustvarjanje datotek +Comment[sr]=Направи фајл +Comment[sr@Latn]=Napravi fajl +Comment[sv]=Skapa filer +Comment[ta]= கோப்பு உருவாக்கப்பட்டது +Comment[tg]=Устои бунёд кардани файлҳо +Comment[zh_CN]=文件创建 +Comment[zh_TW]=檔案建立 +Name=KDevFileCreate +Name[da]=KDevelop filoprettelse +Name[de]=Dateierstellungs-Komponente (KDevelop) +Name[hi]=के-डेव-फ़ाइल-क्रिएट +Name[nds]=KDevelop-Dateiopstellen +Name[pl]=KDevTworzeniePliku +Name[sk]=KDev vytvoriť súbor +Name[sv]=KDevelop skapa filer +Name[ta]=KDev உருவாக்கப்பட்ட கோப்பு +Name[tg]=Сохткунандаи KDev +Name[zh_TW]=KDevelop 檔案建立 +GenericName=FileCreate +GenericName[ca]=Creació de fitxers +GenericName[da]=Filoprettelse +GenericName[de]=Dateierstellungs-Komponente +GenericName[el]=ΔημιουργίαΑρχείου +GenericName[es]=Creación de archivos +GenericName[eu]=Fitxategi sorkuntza +GenericName[fa]=ایجاد پرونده +GenericName[hi]=फ़ाइल-क्रिएट +GenericName[hu]=Fájl létrehozása +GenericName[it]=Crea file +GenericName[ja]=ファイル作成 +GenericName[ms]=CiptaFail +GenericName[nds]=Dateiopstellen +GenericName[ne]=फाइल सिर्जना +GenericName[nl]=Bestand aanmaken +GenericName[pl]=Tworzenie pliku +GenericName[pt]=Criação de Ficheiros +GenericName[ru]=Мастер создания файлов +GenericName[sk]=Vytvoriť súbor +GenericName[sl]=Ustvarjanje datotek +GenericName[sr]=Направи фајл +GenericName[sr@Latn]=Napravi fajl +GenericName[sv]=Skapa filer +GenericName[ta]=கோப்பு உருவாக்கம் +GenericName[tg]=Устои бунёд кардани файлҳо +GenericName[zh_CN]=文件创建 +GenericName[zh_TW]=檔案建立 +Icon=wizard +ServiceTypes=KDevelop/CreateFile +X-KDE-Library=libkdevfilecreate +X-KDevelop-Version=5 +X-KDevelop-Properties=FileCreation +X-KDevelop-Scope=Core diff --git a/parts/filecreate/kdevpart_filecreate.rc b/parts/filecreate/kdevpart_filecreate.rc new file mode 100644 index 00000000..401a1378 --- /dev/null +++ b/parts/filecreate/kdevpart_filecreate.rc @@ -0,0 +1,11 @@ + + + +

+ + + + + + + diff --git a/parts/filecreate/template-info.xml b/parts/filecreate/template-info.xml new file mode 100644 index 00000000..bddd5d65 --- /dev/null +++ b/parts/filecreate/template-info.xml @@ -0,0 +1,181 @@ + + + + + + + + A new blank file. + + + A new empty Python source file. + + + A new empty Ruby source file. + + + A new empty rhtml source file. + + + A new empty html.erb source file. + + + A new empty rxml builder template source file. + + + A new empty rxml builder template source file. + + + A new empty Ruby JavaScript template source file. + + + A new empty Ruby JavaScript template source file. + + + A new empty cascading style sheet source file. + + + A new empty JavaScript source file. + + + + + + A new widget. + + + A new empty Dialog box. + + + A new empty Tab Dialog box. + + + A new Dialog box with buttons on the right. + + + A new Dialog box with buttons on the bottom. + + + A new Configuration Dialog box. + + + A new empty Wizard dialog. + + + A new empty main window. + + + A new Qt4 widget. + + + A new empty Qt4 Dialog box. + + + A new empty Qt4 main window. + + + A new Qt4 Dialog box with buttons on the right. + + + A new Qt4 Dialog box with buttons on the bottom. + + + + A new Qt4 Resource file. + + + A new empty C++ file. + + + A new empty C file. + + + A new empty header file for C or C++. + + + A new empty PHP source file. + + + A new empty Java source file. + + + A new empty Ada spec file. + + + A new empty Ada body file. + + + A new empty Fortran source file. + + + A new empty preprocessed Fortran file. + + + A new empty Fortran77 source file. + + + A new empty Fortran90 source file. + + + A new empty Fortran95 source file. + + + A new empty preprocessed Fortran file. + + + A new empty Fortran77 source file. + + + A new empty Fortran source file. + + + A new Perl script. + + + A new perl module. + + + + + A new pascal program. + + + A new pascal unit. + + + + + + A new pascal program. + + + A new pascal unit. + + + + A new Delphi project. + + + A new empty flex C source source file. + + + A new empty flex C++ source source file. + + + A new empty bison C source source file. + + + A new empty bison C++ source source file. + + + A new empty Doxygen documentation page. + + + A new empty Haskell source file. + + + A new empty Qt Linguist translation source file. + + + + -- cgit v1.2.3