diff options
Diffstat (limited to 'parts/filecreate/filecreate_part.cpp')
-rw-r--r-- | parts/filecreate/filecreate_part.cpp | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/parts/filecreate/filecreate_part.cpp b/parts/filecreate/filecreate_part.cpp index 371e3733..40c8e2c0 100644 --- a/parts/filecreate/filecreate_part.cpp +++ b/parts/filecreate/filecreate_part.cpp @@ -137,7 +137,7 @@ void FileCreatePart::slotAboutToShowNewPopupMenu() TDEIcon::DefaultState, NULL, true); m_newPopupMenu->insertItem(iconPix, filetype->name(), this, TQT_SLOT(slotNewFilePopup(int)), 0, ++id ); - m_newPopupMenu->setItemParameter( id, (long)filetype ); + m_newPopupMenu->setItemParameter( id, filetype->id() ); } else { TDEPopupMenu* subMenu = NULL; @@ -152,7 +152,7 @@ void FileCreatePart::slotAboutToShowNewPopupMenu() TDEIcon::DefaultState, NULL, true); subMenu->insertItem(iconPix, subtype->name(), this, TQT_SLOT(slotNewFilePopup(int)), 0, ++id ); - subMenu->setItemParameter( id, (long)subtype ); + subMenu->setItemParameter( id, subtype->id() ); } } if( subMenu ) @@ -172,9 +172,9 @@ void FileCreatePart::slotAboutToShowNewPopupMenu() } } -void FileCreatePart::slotNewFilePopup( int pFileType ) +void FileCreatePart::slotNewFilePopup( int fileTypeId ) { - const FileType* filetype = (const FileType*) pFileType; + const FileType* filetype = getType(fileTypeId); slotFiletypeSelected( filetype ); } @@ -193,10 +193,13 @@ void FileCreatePart::slotProjectOpened() { void FileCreatePart::addFileType(const TQString & filename) { FileType * filetype = getType(filename); if (!filetype) { + FileType* lastFiletype = m_filetypes.last(); + int lastTypeId = (lastFiletype && lastFiletype->id() < 0 ? lastFiletype->id() : 0); filetype = new FileType; filetype->setName( filename + " files" ); filetype->setExt( filename ); filetype->setCreateMethod("template"); + filetype->setId(--lastTypeId); m_filetypes.append(filetype); } filetype->setEnabled(true); @@ -212,7 +215,9 @@ void FileCreatePart::slotFiletypeSelected(const FileType * filetype) { KDevCreateFile::CreatedFile createdFile = createNewFile(filetype->ext(), TQString(), TQString(), - filetype->subtypeRef()); + filetype + ? filetype->subtypeRef() + : TQString()); openCreatedFile(createdFile); } @@ -228,6 +233,7 @@ void FileCreatePart::openCreatedFile(const KDevCreateFile::CreatedFile & created int FileCreatePart::readTypes(const TQDomDocument & dom, TQPtrList<FileType> &m_filetypes, bool enable) { int numRead = 0; + int typeId = 0; TQDomElement fileTypes = DomUtil::elementByPath(dom,"/kdevfilecreate/filetypes"); if (!fileTypes.isNull()) { for(TQDomNode node = fileTypes.firstChild();!node.isNull();node=node.nextSibling()) { @@ -242,6 +248,7 @@ int FileCreatePart::readTypes(const TQDomDocument & dom, TQPtrList<FileType> &m_ filetype->setIcon( element.attribute("icon") ); filetype->setDescr( (DomUtil::namedChildElement(element, "descr")).text() ); filetype->setEnabled(enable || (filetype->ext()=="")); + filetype->setId(++typeId); m_filetypes.append(filetype); numRead++; @@ -260,6 +267,7 @@ int FileCreatePart::readTypes(const TQDomDocument & dom, TQPtrList<FileType> &m_ subtype->setName( subelement.attribute("name") ); subtype->setDescr( (DomUtil::namedChildElement(subelement, "descr")).text() ); subtype->setEnabled(enable); + subtype->setId(++typeId); filetype->addSubtype(subtype); } } @@ -297,6 +305,25 @@ FileType * FileCreatePart::getType(const TQString & ex, const TQString subtRef) return NULL; } +FileType * FileCreatePart::getType(int id) { + + TQPtrList<FileType> filetypes = getFileTypes(); + for(FileType* filetype = filetypes.first(); + filetype; + filetype = filetypes.next()) + { + if (filetype->id() == id) return filetype; + TQPtrList<FileType> subtypes = filetype->subtypes(); + for(FileType* subtype = subtypes.first(); + subtype; + subtype = subtypes.next()) + { + if (subtype->id() == id) return subtype; + } + } + return NULL; +} + FileType * FileCreatePart::getEnabledType(const TQString & ex, const TQString subtRef) { TQString subtypeRef = subtRef; |