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/fileview/filetreeviewwidgetimpl.cpp | 169 ++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 parts/fileview/filetreeviewwidgetimpl.cpp (limited to 'parts/fileview/filetreeviewwidgetimpl.cpp') diff --git a/parts/fileview/filetreeviewwidgetimpl.cpp b/parts/fileview/filetreeviewwidgetimpl.cpp new file mode 100644 index 00000000..9e40a3bb --- /dev/null +++ b/parts/fileview/filetreeviewwidgetimpl.cpp @@ -0,0 +1,169 @@ +/*************************************************************************** + * Copyright (C) 2003 by Mario Scalas * + * mario.scalas@libero.it * + * * + * 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 "fileviewpart.h" +#include "filetreewidget.h" +#include "fileitemfactory.h" + +#include "filetreeviewwidgetimpl.h" + +using namespace filetreeview; + +/////////////////////////////////////////////////////////////////////////////// +// class FileTreeViewWidgetImpl +/////////////////////////////////////////////////////////////////////////////// + +FileTreeViewWidgetImpl::FileTreeViewWidgetImpl( FileTreeWidget *parent, const char *name ) + : QObject( parent, name ), m_branchItemFactory( 0 ), + m_part( parent->part() ), m_isReloadingTree( false ) +{ + kdDebug(9017) << "FileTreeViewWidgetImpl::FileTreeViewWidgetImpl()" << endl; + + // Actions + m_actionToggleShowNonProjectFiles = new KToggleAction( i18n("Show Non Project Files"), KShortcut(), + this, SLOT(slotToggleShowNonProjectFiles()), this, "actiontoggleshowshownonprojectfiles" ); + m_actionToggleShowNonProjectFiles->setCheckedState(i18n("Hide Non Project Files")); + m_actionToggleShowNonProjectFiles->setWhatsThis(i18n("Show non project files

Shows files that do not belong to a project in a file tree.")); + + // Reload good ol' settings + QDomDocument &dom = *m_part->projectDom(); + m_actionToggleShowNonProjectFiles->setChecked( !DomUtil::readBoolEntry(dom, "/kdevfileview/tree/hidenonprojectfiles") ); +} + +/////////////////////////////////////////////////////////////////////////////// + +FileTreeViewWidgetImpl::~FileTreeViewWidgetImpl() +{ + kdDebug(9017) << "FileTreeViewWidgetImpl::~FileTreeViewWidgetImpl()" << endl; + + delete m_branchItemFactory; + + QDomDocument &dom = *m_part->projectDom(); + DomUtil::writeBoolEntry( dom, "/kdevfileview/tree/hidenonprojectfiles", !showNonProjectFiles() ); +} + +/////////////////////////////////////////////////////////////////////////////// + +FileTreeWidget *FileTreeViewWidgetImpl::fileTree() const +{ + return static_cast( parent() ); +} + +/////////////////////////////////////////////////////////////////////////////// + +QDomDocument &FileTreeViewWidgetImpl::projectDom() const +{ + return *part()->projectDom(); +} + +/////////////////////////////////////////////////////////////////////////////// + +QString FileTreeViewWidgetImpl::projectDirectory() const +{ + return part()->project()->projectDirectory(); +} + +/////////////////////////////////////////////////////////////////////////////// + +bool FileTreeViewWidgetImpl::showNonProjectFiles() const +{ + return m_actionToggleShowNonProjectFiles->isChecked(); +} + +/////////////////////////////////////////////////////////////////////////////// + +void FileTreeViewWidgetImpl::fillPopupMenu( QPopupMenu *popupMenu, QListViewItem *item ) const +{ + // Show the "reload tree" menu-item only if it is requested for the root object + // and we don't have a sync-with-repository operation pending (which otherwise will + // kill the call-back's from working) + if (item == fileTree()->firstChild() && canReloadTree()) + { + int id = popupMenu->insertItem( i18n( "Reload Tree"), this, SLOT( slotReloadTree() ) ); + popupMenu->setWhatsThis( id, i18n("Reload tree

Reloads the project files tree.") ); + } + + m_actionToggleShowNonProjectFiles->plug( popupMenu ); +} + +/////////////////////////////////////////////////////////////////////////////// + +KURL::List FileTreeViewWidgetImpl::selectedPathUrls() +{ + kdDebug(9017) << "FileTreeViewWidgetImpl::selectedPathUrls()" << endl; + + KURL::List urlList; + + QValueList list = allSelectedItems( fileTree()->firstChild() ); + QValueList::Iterator it = list.begin(); + while( it != list.end() ) + { + FileTreeViewItem * item = static_cast( *it ); + if ( fileTree()->shouldBeShown( item ) ) + { + KURL url; + url.setPath( item->path() ); + urlList << url; + } + ++it; + } + + return urlList; +} + +/////////////////////////////////////////////////////////////////////////////// + +QValueList FileTreeViewWidgetImpl::allSelectedItems( QListViewItem * item ) const +{ + QValueList list; + + if ( item ) + { + if ( item->isSelected() ) + { + list << item; + } + + QListViewItem * it = item->firstChild(); + while( it ) + { + list += allSelectedItems( it ); + it = it->nextSibling(); + } + } + + return list; +} + +/////////////////////////////////////////////////////////////////////////////// + +void FileTreeViewWidgetImpl::slotReloadTree() +{ + fileTree()->openDirectory( projectDirectory() ); +} + +/////////////////////////////////////////////////////////////////////////////// + +void FileTreeViewWidgetImpl::slotToggleShowNonProjectFiles() +{ + fileTree()->hideOrShow(); +} + +#include "filetreeviewwidgetimpl.moc" -- cgit v1.2.3