[prev in list] [next in list] [prev in thread] [next in thread]
List: kdevelop-devel
Subject: FW: Small KDevelop File Group part patch
From: "GEHRMANN BERND" <BERND.GEHRMANN () gruppotc ! com>
Date: 2003-10-07 15:01:05
[Download RAW message or body]
-----Original Message-----
From: Mihnea Balta [mailto:mihnea.balta@digitalsummoners.ro]
Sent: martedi, 7. ottobre 2003 15:35
To: bernd@kdevelop.org
Subject: Small KDevelop File Group part patch
Hello,
I've written a small patch for the File Group part of KDevelop
to address two
issues:
a) the part was matching the file group pattern agains the file
NAME, which
prevented me from using patterns like "*ClientServer/*.h" for
"ClientServer
Headers". I just changed FileViewFolderItem::matches() to check with the
file
path instead of file name.
b) I changed the context menu for the Group item so that it now
contains CVS
options. I made it use a FileContext context and fill it with all the
files
that the goup contains.
All my code is enclosed in "/* Dark begins */" -> "/* Dark ends
*/". Please
consider incorporating these changes into KDevelop, so I can use further
versions of it with my project.
Thank you for your time.
["filegroupswidget.cpp" (text/x-c++src)]
/***************************************************************************
* Copyright (C) 2001-2002 by Bernd Gehrmann *
* bernd@kdevelop.org *
* *
* 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 "filegroupswidget.h"
#include <qfileinfo.h>
#include <qdir.h>
#include <qheader.h>
#include <qtimer.h>
#include <qvbox.h>
#include <qregexp.h>
#include <kdebug.h>
#include <kdialogbase.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kpopupmenu.h>
#include <kaction.h>
#include "kdevcore.h"
#include "kdevproject.h"
#include "kdevmainwindow.h"
#include "kdevpartcontroller.h"
#include "domutil.h"
#include "filegroupspart.h"
#include "filegroupsconfigwidget.h"
// Translations for strings in the project file
static const char *translations[] = {
I18N_NOOP("Sources"),
I18N_NOOP("Translations"),
I18N_NOOP("User Interface"),
I18N_NOOP("Others")
};
class FileViewFolderItem : public QListViewItem
{
public:
FileViewFolderItem(QListView *parent, const QString &name, const QString \
&pattern); bool matches(const QString &fileName);
private:
QStringList patterns;
};
FileViewFolderItem::FileViewFolderItem(QListView *parent, const QString &name, const \
QString &pattern) : QListViewItem(parent, name)
{
setPixmap(0, SmallIcon("folder"));
patterns = QStringList::split(';', pattern);
}
bool FileViewFolderItem::matches(const QString &fileName)
{
// QString fName = QFileInfo(fileName).fileName();
// Dark begins: test with the file path, so that "*ClientServer/*.h" patterns work
QString fName = QFileInfo(fileName).filePath();
/* Dark ends... */
QStringList::ConstIterator it;
for (it = patterns.begin(); it != patterns.end(); ++it) {
// The regexp objects could be created already
// in the constructor
QRegExp re(*it, true, true);
if (re.exactMatch(fName))
return true;
}
return false;
}
class FileGroupsFileItem : public QListViewItem
{
public:
FileGroupsFileItem(QListViewItem *parent, const QString &fileName);
QString fileName() const
{ return fullname; }
private:
QString fullname;
};
FileGroupsFileItem::FileGroupsFileItem(QListViewItem *parent, const QString \
&fileName) : QListViewItem(parent), fullname(fileName)
{
setPixmap(0, SmallIcon("document"));
QFileInfo fi(fileName);
setText(0, fi.fileName());
setText(1, fi.dirPath() + "/");
}
FileGroupsWidget::FileGroupsWidget(FileGroupsPart *part)
: KListView(0, "file view widget"),
m_actionToggleShowNonProjectFiles( 0 )
{
setFocusPolicy(ClickFocus);
setRootIsDecorated(true);
setResizeMode(QListView::LastColumn);
setSorting(-1);
addColumn(i18n("Name"));
addColumn(i18n("Location"));
connect( this, SIGNAL(executed(QListViewItem*)),
this, SLOT(slotItemExecuted(QListViewItem*)) );
connect( this, SIGNAL(returnPressed(QListViewItem*)),
this, SLOT(slotItemExecuted(QListViewItem*)) );
connect( this, SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint&)),
this, SLOT(slotContextMenu(KListView*, QListViewItem*, const QPoint&)) \
);
m_actionToggleShowNonProjectFiles = new KToggleAction( i18n("Show Non Project \
Files"), KShortcut(),
this, SLOT(slotToggleShowNonProjectFiles()), this, \
"actiontoggleshowshownonprojectfiles" ); \
m_actionToggleShowNonProjectFiles->setWhatsThis(i18n("<b>Show non project \
files</b><p>Shows files that do not belong to a project in a file tree."));
m_part = part;
(void) translations; // supress compiler warning
QDomDocument &dom = *m_part->projectDom();
m_actionToggleShowNonProjectFiles->setChecked( !DomUtil::readBoolEntry(dom, \
"/kdevfileview/groups/hidenonprojectfiles") ); }
FileGroupsWidget::~FileGroupsWidget()
{
QDomDocument &dom = *m_part->projectDom();
DomUtil::writeBoolEntry( dom, "/kdevfileview/groups/hidenonprojectfiles", \
!m_actionToggleShowNonProjectFiles->isChecked() ); }
void FileGroupsWidget::slotItemExecuted(QListViewItem *item)
{
if (!item)
return;
// toggle open state for parents
if (item->childCount() > 0)
setOpen(item, !isOpen(item));
// Is it a group item?
if (!item->parent())
return;
FileGroupsFileItem *fgfitem = static_cast<FileGroupsFileItem*>(item);
m_part->partController()->editDocument(QString("file://") + \
m_part->project()->projectDirectory() + "/" + fgfitem->fileName()); \
m_part->mainWindow()->lowerView(this); }
void FileGroupsWidget::slotContextMenu(KListView *, QListViewItem *item, const QPoint \
&p) {
if (!item)
return;
KPopupMenu popup(i18n("File Groups"), this);
/// @todo Add, remove groups
int customizeId = popup.insertItem(i18n("Customize..."));
popup.setWhatsThis(customizeId, i18n("<b>Customize</b><p>Opens <b>Cusomtize File \
Groups</b> dialog where the groups can be managed.")); if (item->parent()) {
// Not for group items
FileGroupsFileItem *fvfitem = static_cast<FileGroupsFileItem*>(item);
QString pathName = m_part->project()->projectDirectory() + QDir::separator() \
+ fvfitem->fileName(); FileContext context( pathName, false);
m_part->core()->fillContextMenu(&popup, &context);
}
else{
/* Dark begins... */
QStringList file_list;
QListViewItem* i = item->firstChild();
while(i){
FileGroupsFileItem *fvgitem = static_cast<FileGroupsFileItem*>(i);
file_list << fvgitem->fileName();
i = i->nextSibling();
}
FileContext context(file_list);
m_part->core()->fillContextMenu(&popup, &context);
/* Dark ends... */
}
m_actionToggleShowNonProjectFiles->plug( &popup );
int res = popup.exec(p);
if (res == customizeId) {
KDialogBase dlg(KDialogBase::TreeList, i18n("Customize File Groups"),
KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, this,
"customization dialog");
QVBox *vbox = dlg.addVBoxPage(i18n("File Groups"));
FileGroupsConfigWidget *w = new FileGroupsConfigWidget(m_part, vbox, "file \
groups config widget"); connect(&dlg, SIGNAL(okClicked()), w, SLOT(accept()));
dlg.exec();
}
}
void FileGroupsWidget::refresh()
{
while (firstChild())
delete firstChild();
QDomDocument &dom = *m_part->projectDom();
DomUtil::PairList list =
DomUtil::readPairListEntry(dom, "/kdevfileview/groups", "group", "name", \
"pattern");
FileViewFolderItem *lastGroup = 0;
DomUtil::PairList::ConstIterator git;
for (git = list.begin(); git != list.end(); ++git) {
FileViewFolderItem *newItem = new FileViewFolderItem(this, (*git).first, \
(*git).second); if (lastGroup)
newItem->moveItem(lastGroup);
lastGroup = newItem;
}
QStringList allFiles;
if (m_actionToggleShowNonProjectFiles->isChecked()) {
// get all files in the project directory
QDir projectDir = m_part->project()->projectDirectory();
allFiles = projectDir.entryList(QDir::Files);
// @todo get all files in all subdirectories
}
else {
// get all project files
allFiles = m_part->project()->allFiles();
}
QStringList::ConstIterator fit;
for (fit = allFiles.begin(); fit != allFiles.end(); ++fit) {
QListViewItem *item = firstChild();
while (item) {
FileViewFolderItem *fvgitem = static_cast<FileViewFolderItem*>(item);
if (fvgitem->matches(*fit)) {
(void) new FileGroupsFileItem(fvgitem, *fit);
break;
}
item = item->nextSibling();
}
}
QListViewItem *item = firstChild();
while (item) {
item->sortChildItems(0, true);
item = item->nextSibling();
}
}
void FileGroupsWidget::addFile(const QString &fileName)
{
kdDebug(9017) << "FileView add " << fileName << endl;
QListViewItem *item = firstChild();
while (item) {
FileViewFolderItem *fvgitem = static_cast<FileViewFolderItem*>(item);
if (fvgitem->matches(fileName))
{
(void) new FileGroupsFileItem(fvgitem, fileName);
fvgitem->sortChildItems(0, true);
break;
}
item = item->nextSibling();
}
}
void FileGroupsWidget::addFiles ( const QStringList& fileList )
{
QStringList::ConstIterator it;
for ( it = fileList.begin(); it != fileList.end(); ++it )
{
this->addFile ( *it );
}
}
void FileGroupsWidget::removeFile(const QString &fileName)
{
kdDebug(9017) << "FileView remove " << fileName << endl;
QListViewItem *item = firstChild();
while (item)
{
FileViewFolderItem *fvgitem = static_cast<FileViewFolderItem*>(item);
QListViewItem *childItem = fvgitem->firstChild();
while (childItem)
{
FileGroupsFileItem *fgfitem = \
static_cast<FileGroupsFileItem*>(childItem);
kdDebug ( 9017 ) << "fvfitem->fileName() is " << fgfitem->fileName() << \
endl; if (fgfitem->fileName() == fileName )
{
kdDebug ( 9017 ) << "Deleting: " << fgfitem->fileName() << endl;
delete fgfitem;
return;
}
childItem = childItem->nextSibling();
}
item = item->nextSibling();
}
}
void FileGroupsWidget::removeFiles ( const QStringList& fileList )
{
QStringList::ConstIterator it;
for ( it = fileList.begin(); it != fileList.end(); ++it )
{
removeFile ( *it );
}
}
void FileGroupsWidget::slotToggleShowNonProjectFiles()
{
refresh();
}
#include "filegroupswidget.moc"
_______________________________________________
Kdevelop-devel mailing list
Kdevelop-devel@barney.cs.uni-potsdam.de
http://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic