KDevelop API Documentation

FileCreatePart Class Reference

FileCreatePart is a template manager and wizard system to assist with creation of new files. More...

#include <filecreate_part.h>

Inheritance diagram for FileCreatePart:

Inheritance graph
[legend]
Collaboration diagram for FileCreatePart:

Collaboration graph
[legend]
List of all members.

Public Slots

void slotProjectOpened ()
void slotProjectClosed ()
void slotInitialize ()
void slotGlobalInitialize ()
void slotFiletypeSelected (const FileType *)
 Called when a file type is selected from the docked widget.
void slotNewFile ()
 Called when a new file is required - for example, from the "New.." menu action.
void slotNewFilePopup (int pFileType)
 Called from KToolBarPopupMenu to request a new file action.

Public Member Functions

 FileCreatePart (QObject *parent, const char *name, const QStringList &)
virtual ~FileCreatePart ()
QPtrList< FileTypegetFileTypes () const
 Returns the list of available file types.
virtual KDevCreateFile::CreatedFile createNewFile (QString ext=QString::null, QString dir=QString::null, QString name=QString::null, QString subtype=QString::null)
 Call this method to create a new file, within or without the project.
void setShowSideTab (bool on)
 Show file creation friendly side tab, yes or no.
void selectWidget (int widgetNumber)
 Selects a docked widget.
TypeChoosertypeChooserWidget () const
 Returns the current type chooser as a TypeChooser* type.
QWidgettypeChooserWidgetAsQWidget () const
 Returns the current type chooser as a QWidget* type.
FileTypegetType (const QString &ext, const QString subtype=QString::null)
 Finds the file type object for a given extension and optionally subtype.
FileTypegetEnabledType (const QString &ext, const QString subtype=QString::null)
 Finds the file type object for a given extension and optionally subtype.

Protected Slots

void slotNoteFiletype (const FileType *filetype)
void slotAboutToShowNewPopupMenu ()
void insertConfigWidget (const KDialogBase *dlg, QWidget *page, unsigned int)

Private Member Functions

void openCreatedFile (const KDevCreateFile::CreatedFile &createdFile)
 If a file has been successfully created, open it.
int readTypes (const QDomDocument &dom, QPtrList< FileType > &m_filetypes, bool enable)
 Reads in file type definitions from a config DOM and adds them to the file type list.
void addFileType (const QString &filename)
 Add a file type.
bool setWidget (TypeChooser *widget)
 Set the current widget.
void refresh ()
 Refreshes the widget in use - i.e.

Private Attributes

int m_selectedWidget
 The number (index to m_availableWidgets) of the widget currently in use, or -1 if none.
QPtrList< FileTypem_filetypes
 List of file types from which the user can choose.
TypeChooserm_availableWidgets [2]
 List of available chooser widgets.
int m_numWidgets
 Number of chooser widgets.
const FileTypem_filedialogFiletype
 The file type selected by the new file dialog, if appropriate.
bool m_useSideTab
ConfigWidgetProxy_configProxy
KPopupMenum_newPopupMenu
QPtrList< KPopupMenu > * m_subPopups

Friends

class FCConfigWidget

Detailed Description

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:

  <kdevfilecreate>
    <filetypes>
      <type ext="py" name="Python" create="template"/>
      <type ext="ui" name="QT Designer" create="template">
        <subtype ref="dialog" name="Dialog"/>
         <subtype ref="mainwin" name="Main window"/>
      </type>
    </filetypes>
  </kdevfilecreate>

You can also use global template definitions supplied with the FileCreate part:

  <kdevfilecreate>
    <useglobaltypes>
      <type ext="ui" />
    </useglobaltypes>
    <filetypes>
      <type ext="py" name="Python" create="template"/>
    </filetypes>
  </kdevfilecreate>

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:

<useglobaltypes>
  <type ext="ui">
    <subtype ref="dialog"/>
  </type>
</useglobaltypes>

Usually, this XML forms part of the base .kdevelop file created by the appwizard.

Author(s):
Julian Rockey

Alexander Dymo

Maintainer(s):
Julian Rockey

Feature(s):
friendly sidebar listing the types of new file that can be created for your project

configurable per-project file types and global file types

Bug:
bugs in file create component at Bugzilla database

Arrangement of text in sidebar is not always perfect

Definition at line 39 of file filecreate_part.h.


Constructor & Destructor Documentation

FileCreatePart::FileCreatePart QObject parent,
const char *  name,
const QStringList
 

Todo:
provide a way of choosing your preferred widget without having to change the source, as this is not considered 'user-friendly' these days, I'm led to believe.

Definition at line 60 of file filecreate_part.cpp.

References GLOBALSETTINGSPAGE, KToolBarPopupAction::popupMenu(), PROJECTSETTINGSPAGE, KAction::setToolTip(), and KAction::setWhatsThis().

FileCreatePart::~FileCreatePart  )  [virtual]
 

Definition at line 97 of file filecreate_part.cpp.

References m_newPopupMenu.


Member Function Documentation

void FileCreatePart::addFileType const QString filename  )  [private]
 

Add a file type.

Definition at line 244 of file filecreate_part.cpp.

References getType(), m_filetypes, FileCreate::FileType::setCreateMethod(), FileCreate::FileType::setEnabled(), FileCreate::FileType::setExt(), and FileCreate::FileType::setName().

Referenced by slotInitialize().

KDevCreateFile::CreatedFile FileCreatePart::createNewFile QString  ext = QString::null,
QString  dir = QString::null,
QString  name = QString::null,
QString  subtype = QString::null
[virtual]
 

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.

Implements KDevCreateFile.

Definition at line 384 of file filecreate_part.cpp.

References KDevProject::activeDirectory(), KDevProject::addFile(), FileCreate::NewFileChooser::addToProject(), KDevCreateFile::CreatedFile::addToProject, FileTemplate::copy(), KDevCreateFile::CreatedFile::dir, URLUtil::directory(), KDevPartController::editDocument(), FileTemplate::exists(), FileCreate::FileType::ext(), KDevCreateFile::CreatedFile::filename, URLUtil::filename(), getEnabledType(), KURL::isParentOf(), kdDebug(), m_filetypes, KDevPlugin::partController(), KURL::path(), KDevPlugin::project(), KDevProject::projectDirectory(), URLUtil::relativePath(), FileCreate::NewFileChooser::selectedType(), FileCreate::NewFileChooser::setCurrent(), FileCreate::NewFileChooser::setDirectory(), FileCreate::NewFileChooser::setFileTypes(), FileCreate::NewFileChooser::setInProjectMode(), FileCreate::NewFileChooser::setName(), KURL::setPath(), KDevCreateFile::CreatedFile::status, FileCreate::FileType::subtypeRef(), and FileCreate::NewFileChooser::url().

Referenced by slotFiletypeSelected(), and slotNewFile().

FileType * FileCreatePart::getEnabledType 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).

Definition at line 355 of file filecreate_part.cpp.

References FileCreate::FileType::enabled(), FileCreate::FileType::ext(), getFileTypes(), FileCreate::FileType::subtypeRef(), and FileCreate::FileType::subtypes().

Referenced by createNewFile().

QPtrList<FileType> FileCreatePart::getFileTypes  )  const [inline]
 

Returns the list of available file types.

Definition at line 51 of file filecreate_part.h.

Referenced by getEnabledType(), getType(), FileCreate::ListWidget::refresh(), and FileCreate::FriendlyWidget::refresh().

FileType * FileCreatePart::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.

Definition at line 328 of file filecreate_part.cpp.

References FileCreate::FileType::ext(), getFileTypes(), FileCreate::FileType::subtypeRef(), and FileCreate::FileType::subtypes().

Referenced by addFileType(), FileCreate::FileDialog::slotActionTextChanged(), and slotInitialize().

void FileCreatePart::insertConfigWidget const KDialogBase dlg,
QWidget page,
unsigned  int
[protected, slot]
 

Definition at line 116 of file filecreate_part.cpp.

References FCConfigWidget, GLOBALSETTINGSPAGE, k_funcinfo, kdDebug(), and PROJECTSETTINGSPAGE.

void FileCreatePart::openCreatedFile const KDevCreateFile::CreatedFile createdFile  )  [private]
 

If a file has been successfully created, open it.

Definition at line 275 of file filecreate_part.cpp.

References KDevCreateFile::CreatedFile::dir, KDevPartController::editDocument(), KDevCreateFile::CreatedFile::filename, KDevPlugin::partController(), KDevPlugin::project(), and KDevCreateFile::CreatedFile::status.

Referenced by slotFiletypeSelected(), and slotNewFile().

int FileCreatePart::readTypes const QDomDocument dom,
QPtrList< FileType > &  m_filetypes,
bool  enable
[private]
 

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.

Definition at line 282 of file filecreate_part.cpp.

References FileCreate::FileType::addSubtype(), FileCreate::FileType::createMethod(), DomUtil::elementByPath(), FileCreate::FileType::ext(), kdDebug(), FileCreate::FileType::name(), FileCreate::FileType::setCreateMethod(), FileCreate::FileType::setDescr(), FileCreate::FileType::setEnabled(), FileCreate::FileType::setExt(), FileCreate::FileType::setIcon(), FileCreate::FileType::setName(), FileCreate::FileType::setSubtypeRef(), and text().

Referenced by FCConfigWidget::loadGlobalConfig(), FCConfigWidget::loadProjectConfig(), slotGlobalInitialize(), and slotInitialize().

void FileCreatePart::refresh  )  [private]
 

Refreshes the widget in use - i.e.

updates list of filetypes in the widget.

Definition at line 171 of file filecreate_part.cpp.

References FileCreate::TypeChooser::refresh(), and typeChooserWidget().

Referenced by slotGlobalInitialize(), slotInitialize(), and slotProjectClosed().

void FileCreatePart::selectWidget int  widgetNumber  ) 
 

Selects a docked widget.

Definition at line 138 of file filecreate_part.cpp.

References m_availableWidgets, m_selectedWidget, and setWidget().

Referenced by setShowSideTab().

void FileCreatePart::setShowSideTab bool  on  ) 
 

Show file creation friendly side tab, yes or no.

Definition at line 493 of file filecreate_part.cpp.

References selectWidget().

Referenced by FCConfigWidget::accept(), slotGlobalInitialize(), and slotInitialize().

bool FileCreatePart::setWidget TypeChooser widget  )  [private]
 

Set the current widget.

Argument of null sets no widget.

Definition at line 146 of file filecreate_part.cpp.

References KDevMainWindow::embedSelectView(), kdDebug(), kdWarning(), KDevPlugin::mainWindow(), KDevMainWindow::removeView(), FileCreate::TypeChooser::signaller(), slotFiletypeSelected(), and typeChooserWidget().

Referenced by selectWidget().

void FileCreatePart::slotAboutToShowNewPopupMenu  )  [protected, slot]
 

Definition at line 175 of file filecreate_part.cpp.

References FileCreate::FileType::enabled(), FileCreate::FileType::icon(), KGlobal::iconLoader(), KIconLoader::loadIcon(), m_filetypes, m_newPopupMenu, m_subPopups, FileCreate::FileType::name(), slotNewFilePopup(), and FileCreate::FileType::subtypes().

void FileCreatePart::slotFiletypeSelected const FileType  )  [slot]
 

Called when a file type is selected from the docked widget.

Definition at line 262 of file filecreate_part.cpp.

References createNewFile(), FileCreate::FileType::ext(), openCreatedFile(), KDevPlugin::project(), and FileCreate::FileType::subtypeRef().

Referenced by setWidget(), and slotNewFilePopup().

void FileCreatePart::slotGlobalInitialize  )  [slot]
 

Definition at line 575 of file filecreate_part.cpp.

References DomUtil::elementByPath(), kdDebug(), m_filetypes, m_useSideTab, DomUtil::openDOMFile(), readTypes(), refresh(), and setShowSideTab().

Referenced by slotInitialize(), and slotProjectClosed().

void FileCreatePart::slotInitialize  )  [slot]
 

Definition at line 502 of file filecreate_part.cpp.

References addFileType(), DomUtil::elementByPath(), getType(), m_filetypes, m_useSideTab, KDevPlugin::project(), KDevPlugin::projectDom(), readTypes(), refresh(), FileCreate::FileType::setEnabled(), setShowSideTab(), FileCreate::FileType::setSubtypesEnabled(), slotGlobalInitialize(), and FileCreate::FileType::subtypes().

Referenced by slotProjectOpened().

void FileCreatePart::slotNewFile  )  [slot]
 

Called when a new file is required - for example, from the "New.." menu action.

Definition at line 235 of file filecreate_part.cpp.

References createNewFile(), and openCreatedFile().

void FileCreatePart::slotNewFilePopup int  pFileType  )  [slot]
 

Called from KToolBarPopupMenu to request a new file action.

Parameters:
pFileType is acutally a pointer to FileType

Definition at line 229 of file filecreate_part.cpp.

References slotFiletypeSelected().

Referenced by slotAboutToShowNewPopupMenu().

void FileCreatePart::slotNoteFiletype const FileType filetype  )  [protected, slot]
 

Definition at line 497 of file filecreate_part.cpp.

References FileCreate::FileType::ext(), kdDebug(), and m_filedialogFiletype.

void FileCreatePart::slotProjectClosed  )  [slot]
 

Definition at line 256 of file filecreate_part.cpp.

References m_filetypes, refresh(), and slotGlobalInitialize().

void FileCreatePart::slotProjectOpened  )  [slot]
 

Definition at line 240 of file filecreate_part.cpp.

References slotInitialize().

Referenced by FCConfigWidget::accept().

TypeChooser* FileCreatePart::typeChooserWidget  )  const [inline]
 

Returns the current type chooser as a TypeChooser* type.

Definition at line 77 of file filecreate_part.h.

References m_availableWidgets, and m_selectedWidget.

Referenced by refresh(), setWidget(), and typeChooserWidgetAsQWidget().

QWidget* FileCreatePart::typeChooserWidgetAsQWidget  )  const [inline]
 

Returns the current type chooser as a QWidget* type.

Definition at line 85 of file filecreate_part.h.

References typeChooserWidget().


Friends And Related Function Documentation

friend class FCConfigWidget [friend]
 

Definition at line 43 of file filecreate_part.h.

Referenced by insertConfigWidget().


Member Data Documentation

ConfigWidgetProxy* FileCreatePart::_configProxy [private]
 

Definition at line 185 of file filecreate_part.h.

TypeChooser* FileCreatePart::m_availableWidgets[2] [private]
 

List of available chooser widgets.

Definition at line 162 of file filecreate_part.h.

Referenced by selectWidget(), and typeChooserWidget().

const FileType* FileCreatePart::m_filedialogFiletype [private]
 

The file type selected by the new file dialog, if appropriate.

Definition at line 182 of file filecreate_part.h.

Referenced by slotNoteFiletype().

QPtrList<FileType> FileCreatePart::m_filetypes [private]
 

List of file types from which the user can choose.

Definition at line 157 of file filecreate_part.h.

Referenced by FCConfigWidget::accept(), addFileType(), createNewFile(), slotAboutToShowNewPopupMenu(), slotGlobalInitialize(), slotInitialize(), and slotProjectClosed().

KPopupMenu* FileCreatePart::m_newPopupMenu [private]
 

Definition at line 187 of file filecreate_part.h.

Referenced by slotAboutToShowNewPopupMenu(), and ~FileCreatePart().

int FileCreatePart::m_numWidgets [private]
 

Number of chooser widgets.

Definition at line 167 of file filecreate_part.h.

int FileCreatePart::m_selectedWidget [private]
 

The number (index to m_availableWidgets) of the widget currently in use, or -1 if none.

Definition at line 152 of file filecreate_part.h.

Referenced by selectWidget(), and typeChooserWidget().

QPtrList<KPopupMenu>* FileCreatePart::m_subPopups [private]
 

Definition at line 188 of file filecreate_part.h.

Referenced by slotAboutToShowNewPopupMenu().

bool FileCreatePart::m_useSideTab [private]
 

Definition at line 184 of file filecreate_part.h.

Referenced by FCConfigWidget::accept(), FCConfigWidget::FCConfigWidget(), FCConfigWidget::saveGlobalConfig(), slotGlobalInitialize(), and slotInitialize().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:42:03 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003