diff --git a/plugins/documentview/kdevdocumentmodel.cpp b/plugins/documentview/kdevdocumentmodel.cpp index b411a81568..c7c102d1a8 100644 --- a/plugins/documentview/kdevdocumentmodel.cpp +++ b/plugins/documentview/kdevdocumentmodel.cpp @@ -1,113 +1,118 @@ /* This file is part of KDevelop Copyright 2005 Adam Treat + Copyright 2013 Sebastian Kügler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kdevdocumentmodel.h" +#include #include KDevDocumentItem::KDevDocumentItem( const QString &name ) : QStandardItem( name ), m_documentState( KDevelop::IDocument::Clean ) -{} +{ + setIcon( icon() ); +} KDevDocumentItem::~KDevDocumentItem() {} -// KDevDocumentItem *KDevDocumentItem::itemAt( int index ) const -// { -// return static_cast( QStandardItem::itemFromIndex( index ) ); -// } - -KDevMimeTypeItem::KDevMimeTypeItem( const QString &name ) +KDevCategoryItem::KDevCategoryItem( const QString &name ) : KDevDocumentItem( name ) -{} +{ + setToolTip( name ); +} -KDevMimeTypeItem::~KDevMimeTypeItem() +KDevCategoryItem::~KDevCategoryItem() {} -QList KDevMimeTypeItem::fileList() const +QList KDevCategoryItem::fileList() const { QList lst; for ( int i = 0; i < rowCount(); ++i ) { if ( KDevFileItem * item = dynamic_cast( child( i ) ) ->fileItem() ) lst.append( item ); } return lst; } -KDevFileItem* KDevMimeTypeItem::file( const KUrl &url ) const +KDevFileItem* KDevCategoryItem::file( const KUrl &url ) const { foreach( KDevFileItem * item, fileList() ) { if ( item->url() == url ) return item; } return 0; } KDevFileItem::KDevFileItem( const KUrl &url ) - : KDevDocumentItem( url.fileName() ), - m_url( url ) -{} + : KDevDocumentItem( url.fileName() ) +{ + setUrl( url ); + KFileItem fi = KFileItem( url, QString(), 0 ); + m_fileIcon = fi.iconName(); + setIcon( KIcon( m_fileIcon ) ); +} KDevFileItem::~KDevFileItem() {} KDevDocumentModel::KDevDocumentModel( QObject *parent ) : QStandardItemModel( parent ) { setRowCount(0); setColumnCount(1); } KDevDocumentModel::~KDevDocumentModel() {} -QList KDevDocumentModel::mimeTypeList() const +QList KDevDocumentModel::categoryList() const { - QList lst; + QList lst; for ( int i = 0; i < rowCount() ; ++i ) { - if ( KDevMimeTypeItem * mimeitem = dynamic_cast( item( i ) ) ->mimeTypeItem() ) + if ( KDevCategoryItem * categoryitem = dynamic_cast( item( i ) ) ->categoryItem() ) { - lst.append( mimeitem ); + lst.append( categoryitem ); } } return lst; } -KDevMimeTypeItem* KDevDocumentModel::mimeType( const QString& mimeType ) const +KDevCategoryItem* KDevDocumentModel::category( const QString& category ) const { - foreach( KDevMimeTypeItem * item, mimeTypeList() ) + foreach( KDevCategoryItem * item, categoryList() ) { - if ( item->text() == mimeType ) + if ( item->toolTip() == category ) return item; } return 0; } #include "kdevdocumentmodel.moc" diff --git a/plugins/documentview/kdevdocumentmodel.h b/plugins/documentview/kdevdocumentmodel.h index 05cff452c4..1e920d3628 100644 --- a/plugins/documentview/kdevdocumentmodel.h +++ b/plugins/documentview/kdevdocumentmodel.h @@ -1,136 +1,137 @@ /* This file is part of KDevelop Copyright 2005 Adam Treat + Copyright 2013 Sebastian Kügler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVDOCUMENTMODEL_H #define KDEVDOCUMENTMODEL_H #include #include #include #include #include #include class KUrl; class KDevDocumentItem; -class KDevMimeTypeItem; +class KDevCategoryItem; class KDevFileItem; class KDevDocumentItem: public QStandardItem { public: explicit KDevDocumentItem( const QString &name ); virtual ~KDevDocumentItem(); -// virtual KDevDocumentItem *itemAt( int index ) const; - virtual KDevMimeTypeItem *mimeTypeItem() const + virtual KDevCategoryItem *categoryItem() const { return 0; } virtual KDevFileItem *fileItem() const { return 0; } QIcon icon() const { switch ( m_documentState ) { case KDevelop::IDocument::Clean: - return QIcon(); + return KIcon ( m_fileIcon ); case KDevelop::IDocument::Modified: return KIcon( "document-save" ); case KDevelop::IDocument::Dirty: return KIcon( "document-revert" ); case KDevelop::IDocument::DirtyAndModified: return KIcon( "edit-delete" ); default: return QIcon(); } } KDevelop::IDocument::DocumentState documentState() const { return m_documentState; } void setDocumentState( KDevelop::IDocument::DocumentState state ) { m_documentState = state; setIcon(icon()); } + const KUrl &url() const + { + return m_url; + } + + void setUrl( const KUrl &url ) + { + m_url = url; + } + +protected: + QString m_fileIcon; + private: + KUrl m_url; KDevelop::IDocument::DocumentState m_documentState; }; -class KDevMimeTypeItem: public KDevDocumentItem +class KDevCategoryItem: public KDevDocumentItem { public: - explicit KDevMimeTypeItem( const QString &name ); - virtual ~KDevMimeTypeItem(); + explicit KDevCategoryItem( const QString &name ); + virtual ~KDevCategoryItem(); - virtual KDevMimeTypeItem *mimeTypeItem() const + virtual KDevCategoryItem *categoryItem() const { - return const_cast( this ); + return const_cast( this ); } QList fileList() const; KDevFileItem* file( const KUrl &url ) const; }; class KDevFileItem: public KDevDocumentItem { public: explicit KDevFileItem( const KUrl &url ); virtual ~KDevFileItem(); virtual KDevFileItem *fileItem() const { return const_cast( this ); } - - const KUrl &url() const - { - return m_url; - } - - void setUrl( const KUrl &url ) - { - m_url = url; - } - -private: - KUrl m_url; }; class KDevDocumentModel: public QStandardItemModel { Q_OBJECT public: KDevDocumentModel( QObject *parent = 0 ); virtual ~KDevDocumentModel(); - QList mimeTypeList() const; - KDevMimeTypeItem* mimeType( const QString& mimeType ) const; + QList categoryList() const; + KDevCategoryItem* category( const QString& category ) const; }; #endif // KDEVDOCUMENTMODEL_H diff --git a/plugins/documentview/kdevdocumentview.cpp b/plugins/documentview/kdevdocumentview.cpp index b8c4a02ad3..b9fe223a68 100644 --- a/plugins/documentview/kdevdocumentview.cpp +++ b/plugins/documentview/kdevdocumentview.cpp @@ -1,317 +1,364 @@ /* This file is part of KDevelop Copyright 2005 Adam Treat +Copyright 2013 Sebastian Kügler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kdevdocumentview.h" #include "kdevdocumentviewplugin.h" #include "kdevdocumentmodel.h" +#include #include #include #include #include #include #include //#include #include #include #include "kdevdocumentselection.h" #include "kdevdocumentviewdelegate.h" #include #include #include #include +#include +#include #include #include KDevDocumentView::KDevDocumentView( KDevDocumentViewPlugin *plugin, QWidget *parent ) : QTreeView( parent ), m_plugin( plugin ) { + connect(KDevelop::ICore::self()->projectController(), SIGNAL(projectOpened(KDevelop::IProject*)), + SLOT(updateProjectPaths())); + connect(KDevelop::ICore::self()->projectController(), SIGNAL(projectClosed(KDevelop::IProject*)), + SLOT(updateProjectPaths())); + m_documentModel = new KDevDocumentModel(); m_delegate = new KDevDocumentViewDelegate( this, this ); m_proxy = new QSortFilterProxyModel( this ); m_proxy->setSourceModel( m_documentModel ); m_proxy->setDynamicSortFilter( true ); m_proxy->setSortCaseSensitivity( Qt::CaseInsensitive ); m_proxy->sort(0); m_selectionModel = new KDevDocumentSelection( m_proxy ); setModel( m_proxy ); setSelectionModel( m_selectionModel ); setItemDelegate( m_delegate ); setObjectName( i18n( "Documents" ) ); setWindowIcon( SmallIcon( "document-multiple" ) ); setWindowTitle( i18n( "Documents" ) ); setFocusPolicy( Qt::NoFocus ); setRootIsDecorated( false ); header()->hide(); setSelectionBehavior( QAbstractItemView::SelectRows ); setSelectionMode( QAbstractItemView::ExtendedSelection ); } KDevDocumentView::~KDevDocumentView() {} KDevDocumentViewPlugin *KDevDocumentView::plugin() const { return m_plugin; } void KDevDocumentView::mousePressEvent( QMouseEvent * event ) { QModelIndex proxyIndex = indexAt( event->pos() ); QModelIndex index = m_proxy->mapToSource( proxyIndex ); if ( event->button() == Qt::LeftButton && proxyIndex.parent().isValid() && event->modifiers() == Qt::NoModifier ) { KDevelop::IDocumentController* dc = m_plugin->core()->documentController(); KUrl documentUrl = static_cast( m_documentModel->itemFromIndex( index ) )->fileItem()->url(); if (dc->documentForUrl(documentUrl) != dc->activeDocument()) { dc->openDocument(documentUrl); return; } } if ( !proxyIndex.parent().isValid() ) { setExpanded( proxyIndex, !isExpanded( proxyIndex ) ); return; } QTreeView::mousePressEvent( event ); } template void KDevDocumentView::visitItems(F f, bool selectedItems) { KDevelop::IDocumentController* dc = m_plugin->core()->documentController(); QList docs = selectedItems ? m_selectedDocs : m_unselectedDocs; foreach(const KUrl& url, docs) { KDevelop::IDocument* doc = dc->documentForUrl(url); if (doc) f(doc); } } namespace { class DocSaver { public: void operator()(KDevelop::IDocument* doc) { doc->save(); } }; class DocCloser { public: void operator()(KDevelop::IDocument* doc) { doc->close(); } }; class DocReloader { public: void operator()(KDevelop::IDocument* doc) { doc->reload(); } }; } void KDevDocumentView::saveSelected() { visitItems(DocSaver(), true); } void KDevDocumentView::closeSelected() { visitItems(DocCloser(), true); } void KDevDocumentView::closeUnselected() { visitItems(DocCloser(), false); } void KDevDocumentView::reloadSelected() { visitItems(DocReloader(), true); } void KDevDocumentView::contextMenuEvent( QContextMenuEvent * event ) { updateSelectedDocs(); if (!m_selectedDocs.isEmpty()) { KMenu* ctxMenu = new KMenu(this); KDevelop::FileContext context(m_selectedDocs); QList extensions = m_plugin->core()->pluginController()->queryPluginsForContextMenuExtensions( &context ); QList vcsActions; QList fileActions; QList editActions; QList extensionActions; foreach( const KDevelop::ContextMenuExtension& ext, extensions ) { fileActions += ext.actions(KDevelop::ContextMenuExtension::FileGroup); vcsActions += ext.actions(KDevelop::ContextMenuExtension::VcsGroup); editActions += ext.actions(KDevelop::ContextMenuExtension::EditGroup); extensionActions += ext.actions(KDevelop::ContextMenuExtension::ExtensionGroup); } appendActions(ctxMenu, fileActions); KAction* save = KStandardAction::save(this, SLOT(saveSelected()), ctxMenu); save->setEnabled(selectedDocHasChanges()); ctxMenu->addAction(save); ctxMenu->addAction(KIcon("view-refresh"), i18n( "Reload" ), this, SLOT(reloadSelected())); appendActions(ctxMenu, editActions); ctxMenu->addAction(KStandardAction::close(this, SLOT(closeSelected()), ctxMenu)); QAction* closeUnselected = ctxMenu->addAction(KIcon("document-close"), i18n( "Close Other Files" ), this, SLOT(closeUnselected())); closeUnselected->setEnabled(!m_unselectedDocs.isEmpty()); appendActions(ctxMenu, vcsActions); appendActions(ctxMenu, extensionActions); connect(ctxMenu, SIGNAL(aboutToHide()), ctxMenu, SLOT(deleteLater())); ctxMenu->popup( event->globalPos() ); } } void KDevDocumentView::appendActions(QMenu* menu, const QList& actions) { foreach( QAction* act, actions ) { menu->addAction(act); } menu->addSeparator(); } bool KDevDocumentView::selectedDocHasChanges() { KDevelop::IDocumentController* dc = m_plugin->core()->documentController(); foreach(const KUrl& url, m_selectedDocs) { KDevelop::IDocument* doc = dc->documentForUrl(url); if (!doc) continue; if (doc->state() != KDevelop::IDocument::Clean) { return true; } } return false; } void KDevDocumentView::updateSelectedDocs() { m_selectedDocs.clear(); m_unselectedDocs.clear(); QList allItems = m_documentModel->findItems("*", Qt::MatchWildcard | Qt::MatchRecursive); foreach (QStandardItem* item, allItems) { if (KDevFileItem * fileItem = dynamic_cast(item)->fileItem()) { if (m_selectionModel->isSelected(m_proxy->mapFromSource(m_documentModel->indexFromItem(fileItem)))) m_selectedDocs << fileItem->url(); else m_unselectedDocs << fileItem->url(); } } } void KDevDocumentView::activated( KDevelop::IDocument* document ) { setCurrentIndex( m_proxy->mapFromSource( m_documentModel->indexFromItem( m_doc2index[ document ] ) ) ); } void KDevDocumentView::saved( KDevelop::IDocument* ) { } void KDevDocumentView::opened( KDevelop::IDocument* document ) { - QString mimeType = document->mimeType()->comment(); - KDevMimeTypeItem *mimeItem = m_documentModel->mimeType( mimeType ); - if ( !mimeItem ) + const QString path = QFileInfo( document->url().path() ).path(); + + KDevCategoryItem *categoryItem = m_documentModel->category( path ); + if ( !categoryItem ) { - mimeItem = new KDevMimeTypeItem( mimeType ); - m_documentModel->insertRow( m_documentModel->rowCount(), mimeItem ); - setExpanded( m_proxy->mapFromSource( m_documentModel->indexFromItem( mimeItem ) ), false); + categoryItem = new KDevCategoryItem( path ); + categoryItem->setUrl( document->url() ); + m_documentModel->insertRow( m_documentModel->rowCount(), categoryItem ); + setExpanded( m_proxy->mapFromSource( m_documentModel->indexFromItem( categoryItem ) ), false); + updateCategoryItem( categoryItem ); } - if ( !mimeItem->file( document->url() ) ) + if ( !categoryItem->file( document->url() ) ) { KDevFileItem * fileItem = new KDevFileItem( document->url() ); - mimeItem->setChild( mimeItem->rowCount(), fileItem ); + categoryItem->setChild( categoryItem->rowCount(), fileItem ); setCurrentIndex( m_proxy->mapFromSource( m_documentModel->indexFromItem( fileItem ) ) ); m_doc2index[ document ] = fileItem; } } void KDevDocumentView::closed( KDevelop::IDocument* document ) { KDevFileItem* file = m_doc2index[ document ]; if ( !file ) return; - QStandardItem* mimeItem = file->parent(); + QStandardItem* categoryItem = file->parent(); - qDeleteAll(mimeItem->takeRow(m_documentModel->indexFromItem(file).row())); + qDeleteAll(categoryItem->takeRow(m_documentModel->indexFromItem(file).row())); m_doc2index.remove(document); - if ( mimeItem->hasChildren() ) + if ( categoryItem->hasChildren() ) return; - qDeleteAll(m_documentModel->takeRow(m_documentModel->indexFromItem(mimeItem).row())); + qDeleteAll(m_documentModel->takeRow(m_documentModel->indexFromItem(categoryItem).row())); doItemsLayout(); } +void KDevDocumentView::updateCategoryItem( KDevCategoryItem *item ) +{ + QString label = item->url().pathOrUrl(); + + foreach ( const KDevelop::IProject* prj, m_projects ) { + const QString possibleLabel = prj->relativeUrl( KUrl(label) ).pathOrUrl(); + if ( !possibleLabel.startsWith( "../" ) ) + label = possibleLabel; + else + label.replace( QDir::homePath(), "~" ); + } + + item->setText( label ); +} + +bool projectPathlongerThan( const KDevelop::IProject* prj1, const KDevelop::IProject* prj2 ) +{ + // compare path depth of two project folders + const int c1 = prj1->folder().pathOrUrl().split( QDir::separator() ).count(); + const int c2 = prj2->folder().pathOrUrl().split( QDir::separator() ).count(); + return c1 > c2; +} + +void KDevDocumentView::updateProjectPaths() +{ + + m_projects = KDevelop::ICore::self()->projectController()->projects(); + + // sort folders, longest first, so replacing them one by one is save + qSort( m_projects.begin(), m_projects.end(), projectPathlongerThan ); + + foreach ( KDevCategoryItem *it, m_documentModel->categoryList() ) + updateCategoryItem( it ); +} + void KDevDocumentView::contentChanged( KDevelop::IDocument* ) { } void KDevDocumentView::stateChanged( KDevelop::IDocument* document ) { KDevDocumentItem * documentItem = m_doc2index[ document ]; if ( documentItem && documentItem->documentState() != document->state() ) documentItem->setDocumentState( document->state() ); doItemsLayout(); } void KDevDocumentView::documentUrlChanged( KDevelop::IDocument* document ) { closed(document); opened(document); } #include "kdevdocumentview.moc" diff --git a/plugins/documentview/kdevdocumentview.desktop.cmake b/plugins/documentview/kdevdocumentview.desktop.cmake index 2cb6f0154e..bf3a03b9b7 100644 --- a/plugins/documentview/kdevdocumentview.desktop.cmake +++ b/plugins/documentview/kdevdocumentview.desktop.cmake @@ -1,112 +1,17 @@ [Desktop Entry] Type=Service Icon=document-preview Exec=blubb Comment=This plugin displays a graphical view of all documents currently loaded and separates them by mimetype. -Comment[bs]=Ovaj dodatak prikazuje grafički prikaz svih dokumenata koji su trenutno učitani i razdvaja ih pomoču mimetype-a. -Comment[ca]= Aquest connector mostra una visualització gràfica de tots els documents carregats actualment, separats per tipus MIME. -Comment[ca@valencia]= Este connector mostra una visualització gràfica de tots els documents carregats actualment, separats per tipus MIME. -Comment[da]=Dette plugin viser en grafisk oversigt over alle indlæste dokumenter og adskilder dem efter MIME-type. -Comment[de]=Dieses Modul zeigt alle aktuell geladenen Dokumente getrennt nach ihren MIME-Typen an. -Comment[el]=Το πρόσθετο αυτό εμφανίζει μια γραφική προβολή όλων των εγγράφων που φορτώνονται και τα διαχωρίζει με βάση το αναγνωριστικό τύπου. -Comment[en_GB]=This plugin displays a graphical view of all documents currently loaded and separates them by mimetype. -Comment[es]=Este complemento muestra una vista gráfica de todos los documentos cargados actualmente y los separa por su tipo MIME. -Comment[et]=See plugin näitab graafiliselt kõiki laaditud dokumente ja eraldab need MIME tüübi alusel. -Comment[fi]=Tämä liitännäinen näyttää kaikkien parhaillaan ladattujen asiakirjojen graafisen näkymän ja erottelee ne mime-tyypin perusteella. -Comment[fr]=Ce module externe affiche une vue graphique de tous les documents actuellement chargés et les sépare par type MIME. -Comment[ga]=Taispeánann an breiseán seo amharc grafach ar gach cáipéis atá luchtaithe faoi láthair, agus dealaíonn sé iad de réir a gcineál MIME. -Comment[gl]=Este engadido mostra unha vista gráfica de todos os documentos agora cargados e sepáraos segundo o seu tipo mime. -Comment[it]=Questa estensione mostra una vista grafica di tutti i documenti attualmente caricati e li separa per il tipo MIME. -Comment[kk]=Бұл плагині бүкіл жүктелген құжаттарды MIME-түрі бойынша бөліп графикалық пішінде көрсетеді. -Comment[nb]=Dette programtillegget gir en grafisk visning av alle dokumenter som nå er lastet inn og skiller dem etter mimetype. -Comment[nds]=Dit Moduul wiest all opstunns laadt Dokmenten graafsch un sorteert se na MIME-Typ. -Comment[nl]=Deze plugin toont een grafische voorstelling van alle nu geladen documenten en scheidt deze door het mimetype. -Comment[pl]=Ta wtyczka udostępnia graficzny widok wszystkich obecnie wczytanych dokumentów i dzieli je według typu MIME. -Comment[pt]=Este 'plugin' mostra uma vista gráfica sobre todos os documentos carregados de momento e separa-os por tipo MIME. -Comment[pt_BR]=Este plugin mostra uma vista gráfica sobre todos os documentos carregados no momento e separa-os por tipo MIME. -Comment[sk]=Tento plugin zobrazí grafický pohľad všetkých dokumentov aktuálne načítaných a rozdelí ich podľa mimetype. -Comment[sl]=Ta vstavek prikazuje vse trenutno naložene dokumente in jih ločuje glede na vrsto MIME. -Comment[sv]=Insticksprogrammet visar en grafisk vy av alla dokument som för närvarande har laddats och delar upp dem enligt Mime-typ. -Comment[tr]=Bu eklenti, o anda yüklenmiş olan tüm belgeleri grafiksel bir görünümde gösterir ve o dosyaları mime tiplerine göre ayırır. -Comment[uk]=Цей додаток відображає у графічному вигляді всі відкриті документи і впорядковує їх за типом MIME. -Comment[x-test]=xxThis plugin displays a graphical view of all documents currently loaded and separates them by mimetype.xx -Comment[zh_CN]=此插件显示当前已装入文档的图形视图并按照 mime 类型分类。 -Comment[zh_TW]=這個外掛程式顯示目前載入並依 MIME 型態分類的文件的圖形檢視。 Name=Document View -Name[bg]=Изглед за документи -Name[bs]=Pregled Dokumenta -Name[ca]=Visor de document -Name[ca@valencia]=Visor de document -Name[da]=Dokumentvisning -Name[de]=Dokumentansicht -Name[el]=Προβολή εγγράφου -Name[en_GB]=Document View -Name[es]=Vista de documento -Name[et]=Dokumendivaade -Name[fi]=Asiakirjanäkymä -Name[fr]=Vue Document -Name[ga]=Amharc Cáipéise -Name[gl]=Vista do documento -Name[hu]=Dokumentumnézet -Name[it]=Vista documento -Name[ja]=文書ビュー -Name[kk]=Құжат көрінісі -Name[nb]=Dokumentvisning -Name[nds]=Dokmentenansicht -Name[nl]=Document-overzicht -Name[pl]=Widok dokumentu -Name[pt]=Área de Documentos -Name[pt_BR]=Área de Documentos -Name[sk]=Pohľad na dokumenty -Name[sl]=Prikaz dokumentov -Name[sv]=Dokumentvy -Name[tr]=Belge Görünümü -Name[ug]=پۈتۈك كۆرۈنۈش -Name[uk]=Перегляд документів -Name[x-test]=xxDocument Viewxx -Name[zh_CN]=文档视图 -Name[zh_TW]=文件檢視 GenericName=Document Tool -GenericName[bg]=Инструмент за документи -GenericName[bs]=Alat za dokument -GenericName[ca]=Eina de document -GenericName[ca@valencia]=Eina de document -GenericName[da]=Dokumentværktøj -GenericName[de]=Dokument-Werkzeug -GenericName[el]=Εργαλείο εγγράφου -GenericName[en_GB]=Document Tool -GenericName[es]=Herramienta de documento -GenericName[et]=Dokumendi tööriist -GenericName[fi]=Asiakirjatyökalu -GenericName[fr]=Outil Document -GenericName[ga]=Uirlis Cháipéise -GenericName[gl]=Utilidade de documento -GenericName[hu]=Dokumentum eszköz -GenericName[it]=Strumenti documento -GenericName[ja]=文書ツール -GenericName[kk]=Құжат құралы -GenericName[nb]=Dokumentverktøy -GenericName[nds]=Dokmentenwarktüüch -GenericName[nl]=Document-hulpmiddel -GenericName[pl]=Narzędzie dokumentu -GenericName[pt]=Ferramenta de Documentos -GenericName[pt_BR]=Ferramenta de Documentos -GenericName[sk]=Nástroj na dokumenty -GenericName[sl]=Orodje za dokumente -GenericName[sv]=Dokumentverktyg -GenericName[tr]=Belge Aracı -GenericName[ug]=پۈتۈك قورالى -GenericName[uk]=Інструмент роботи з документами -GenericName[x-test]=xxDocument Toolxx -GenericName[zh_CN]=文档工具 -GenericName[zh_TW]=文件工具 ServiceTypes=KDevelop/Plugin X-KDE-Library=kdevdocumentview X-KDE-PluginInfo-Name=kdevdocumentview X-KDE-PluginInfo-Author=Adam Treat X-KDE-PluginInfo-Version=0.1 X-KDE-PluginInfo-License=LGPL X-KDE-PluginInfo-Category=Utilities X-KDevelop-Version=@KDEV_PLUGIN_VERSION@ X-KDevelop-Category=Global X-KDevelop-Mode=GUI diff --git a/plugins/documentview/kdevdocumentview.h b/plugins/documentview/kdevdocumentview.h index e237f1050a..743b92cce3 100644 --- a/plugins/documentview/kdevdocumentview.h +++ b/plugins/documentview/kdevdocumentview.h @@ -1,92 +1,98 @@ /* This file is part of KDevelop Copyright 2005 Adam Treat + Copyright 2013 Sebastian Kügler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVDOCUMENTVIEW_H #define KDEVDOCUMENTVIEW_H #include class QSortFilterProxyModel; class KAction; class KUrl; class KDevDocumentViewPlugin; class KDevDocumentModel; class KDevDocumentViewDelegate; class KDevDocumentSelection; class KDevFileItem; class KMenu; namespace KDevelop { class IDocument; + class IProject; } +class KDevCategoryItem; class KDevDocumentModel; class KDevDocumentItem; class KDevDocumentView: public QTreeView { Q_OBJECT public: explicit KDevDocumentView( KDevDocumentViewPlugin *plugin, QWidget *parent ); virtual ~KDevDocumentView(); KDevDocumentViewPlugin *plugin() const; signals: void activateURL( const KUrl &url ); public slots: void opened( KDevelop::IDocument* document ); private slots: void activated( KDevelop::IDocument* document ); void saved( KDevelop::IDocument* document ); void closed( KDevelop::IDocument* document ); void contentChanged( KDevelop::IDocument* document ); void stateChanged( KDevelop::IDocument* document ); void documentUrlChanged( KDevelop::IDocument* document ); + void updateCategoryItem( KDevCategoryItem *item ); + void updateProjectPaths(); void saveSelected(); void reloadSelected(); void closeSelected(); void closeUnselected(); protected: virtual void mousePressEvent( QMouseEvent * event ); virtual void contextMenuEvent( QContextMenuEvent * event ); private: template void visitItems(F, bool selectedItems); bool selectedDocHasChanges(); void updateSelectedDocs(); void appendActions(QMenu* menu, const QList< QAction* >& actions); private: KDevDocumentViewPlugin *m_plugin; KDevDocumentModel *m_documentModel; KDevDocumentSelection* m_selectionModel; QSortFilterProxyModel* m_proxy; KDevDocumentViewDelegate* m_delegate; QHash< KDevelop::IDocument*, KDevFileItem* > m_doc2index; QList m_selectedDocs; // used for ctx menu QList m_unselectedDocs; // used for ctx menu + QList m_projects; }; #endif // KDEVDOCUMENTVIEW_H diff --git a/plugins/documentview/kdevdocumentviewdelegate.cpp b/plugins/documentview/kdevdocumentviewdelegate.cpp index b172ac0d5b..ce8a7e3cd0 100644 --- a/plugins/documentview/kdevdocumentviewdelegate.cpp +++ b/plugins/documentview/kdevdocumentviewdelegate.cpp @@ -1,90 +1,90 @@ /* This file is part of KDevelop Copyright 2005 Adam Treat +Copyright 2013 Sebastian Kügler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kdevdocumentviewdelegate.h" #include #include KDevDocumentViewDelegate::KDevDocumentViewDelegate( QTreeView *view, QObject *parent ) : QItemDelegate( parent ), m_view( view ) {} KDevDocumentViewDelegate::~KDevDocumentViewDelegate() {} void KDevDocumentViewDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const { const QAbstractItemModel * model = index.model(); Q_ASSERT( model ); if ( !model->parent( index ).isValid() ) { // this is a top-level item. QStyleOptionButton buttonOption; buttonOption.state = option.state; #ifdef Q_WS_MAC buttonOption.state |= QStyle::State_Raised; #endif buttonOption.state &= ~QStyle::State_HasFocus; buttonOption.rect = option.rect; buttonOption.palette = option.palette; buttonOption.features = QStyleOptionButton::None; - m_view->style() ->drawControl( QStyle::CE_PushButton, &buttonOption, painter, m_view ); QStyleOption branchOption; static const int i = 9; // ### hardcoded in qcommonstyle.cpp QRect r = option.rect; branchOption.rect = QRect( r.left() + i / 2, r.top() + ( r.height() - i ) / 2, i, i ); branchOption.palette = option.palette; branchOption.state = QStyle::State_Children; if ( m_view->isExpanded( index ) ) branchOption.state |= QStyle::State_Open; m_view->style() ->drawPrimitive( QStyle::PE_IndicatorBranch, &branchOption, painter, m_view ); // draw text QRect textrect = QRect( r.left() + i * 2, r.top(), r.width() - ( ( 5 * i ) / 2 ), r.height() ); - QString text = elidedText( option.fontMetrics, textrect.width(), Qt::ElideMiddle, + QString text = elidedText( option.fontMetrics, textrect.width(), Qt::ElideRight, model->data( index, Qt::DisplayRole ).toString() ); - m_view->style() ->drawItemText( painter, textrect, Qt::AlignCenter, + m_view->style() ->drawItemText( painter, textrect, Qt::AlignLeft | Qt::AlignVCenter, option.palette, m_view->isEnabled(), text ); } else { QItemDelegate::paint( painter, option, index ); } } QSize KDevDocumentViewDelegate::sizeHint( const QStyleOptionViewItem &opt, const QModelIndex &index ) const { QStyleOptionViewItem option = opt; - QSize sz = QItemDelegate::sizeHint( opt, index ) + QSize( 2, 2 ); + QSize sz = QItemDelegate::sizeHint( opt, index ) + QSize( 2, 4 ); return sz; } #include "kdevdocumentviewdelegate.moc"