diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /parts/filelist | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
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
Diffstat (limited to 'parts/filelist')
-rw-r--r-- | parts/filelist/Makefile.am | 20 | ||||
-rw-r--r-- | parts/filelist/README.dox | 13 | ||||
-rw-r--r-- | parts/filelist/fileinfo.h | 37 | ||||
-rw-r--r-- | parts/filelist/filelist_item.cpp | 104 | ||||
-rw-r--r-- | parts/filelist/filelist_item.h | 53 | ||||
-rw-r--r-- | parts/filelist/filelist_widget.cpp | 300 | ||||
-rw-r--r-- | parts/filelist/filelist_widget.h | 72 | ||||
-rw-r--r-- | parts/filelist/kdevfilelist.desktop | 76 | ||||
-rw-r--r-- | parts/filelist/kdevfilelist.rc | 24 | ||||
-rw-r--r-- | parts/filelist/projectviewconfig.cpp | 47 | ||||
-rw-r--r-- | parts/filelist/projectviewconfig.h | 38 | ||||
-rw-r--r-- | parts/filelist/projectviewconfigbase.ui | 93 | ||||
-rw-r--r-- | parts/filelist/projectviewpart.cpp | 585 | ||||
-rw-r--r-- | parts/filelist/projectviewpart.h | 169 | ||||
-rw-r--r-- | parts/filelist/projectviewprojectconfig.cpp | 41 | ||||
-rw-r--r-- | parts/filelist/projectviewprojectconfig.h | 41 | ||||
-rw-r--r-- | parts/filelist/projectviewprojectconfigbase.ui | 94 | ||||
-rw-r--r-- | parts/filelist/toolbarguibuilder.cpp | 59 | ||||
-rw-r--r-- | parts/filelist/toolbarguibuilder.h | 58 |
19 files changed, 1924 insertions, 0 deletions
diff --git a/parts/filelist/Makefile.am b/parts/filelist/Makefile.am new file mode 100644 index 00000000..0d75e942 --- /dev/null +++ b/parts/filelist/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = -I$(top_srcdir)/lib/interfaces -I$(top_srcdir)/lib/util $(all_includes) + +kde_module_LTLIBRARIES = libkdevfilelist.la +libkdevfilelist_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) +libkdevfilelist_la_LIBADD = $(top_builddir)/lib/libkdevelop.la + +libkdevfilelist_la_SOURCES = filelist_widget.cpp filelist_item.cpp \ + projectviewprojectconfigbase.ui projectviewprojectconfig.cpp projectviewpart.cpp toolbarguibuilder.cpp \ + projectviewconfigbase.ui projectviewconfig.cpp + +METASOURCES = AUTO + +servicedir = $(kde_servicesdir) +service_DATA = kdevfilelist.desktop + +rcdir = $(kde_datadir)/kdevfilelist + +noinst_HEADERS = filelist_item.h filelist_widget.h projectviewprojectconfig.h \ + projectviewpart.h toolbarguibuilder.h projectviewconfig.h fileinfo.h +rc_DATA = kdevfilelist.rc diff --git a/parts/filelist/README.dox b/parts/filelist/README.dox new file mode 100644 index 00000000..cc2090a0 --- /dev/null +++ b/parts/filelist/README.dox @@ -0,0 +1,13 @@ +/** \class filelist +This plugin provides a filelist selectview of the currently open files. This is quite handy +when the tabbar isn't wide enough to show all open files. + +\feature Provides filestate feedback +\feature Provides context menu for file operations + +\authors <a href="mailto:jens.dagerbo AT swipnet.se">Jens Dagerbo</a> + +\maintainer <a href="mailto:jens.dagerbo AT swipnet.se">Jens Dagerbo</a> + + +*/ diff --git a/parts/filelist/fileinfo.h b/parts/filelist/fileinfo.h new file mode 100644 index 00000000..0d4cb89f --- /dev/null +++ b/parts/filelist/fileinfo.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <kurl.h> + +struct FileInfo +{ + FileInfo() {url = KURL(); line = -1; col = -1; encoding = "";}; + FileInfo(const KURL & _url, int _line = -1, int _col = -1, QString _encoding = "") + {url = _url; line = _line; col = _col; encoding = _encoding;}; + + bool operator==(const FileInfo & f) const {return (f.url == url) /*&& (f.line == line) && (f.col ==col)*/;}; + + KURL url; + int line; + int col; + QString encoding; +}; + +typedef QValueList<FileInfo> FileInfoList; diff --git a/parts/filelist/filelist_item.cpp b/parts/filelist/filelist_item.cpp new file mode 100644 index 00000000..d528cc2c --- /dev/null +++ b/parts/filelist/filelist_item.cpp @@ -0,0 +1,104 @@ +/*************************************************************************** + * Copyright (C) 2004 by Jens Dagerbo * + * [email protected] * + * * + * 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 <kiconloader.h> +#include <qfontmetrics.h> +#include <qfileinfo.h> + +#include "filelist_item.h" + +#include <kiconloader.h> +#include <kfileitem.h> + +FileListItem * FileListItem::s_activeItem = 0; + +FileListItem::FileListItem( QListView * parent, KURL const & url, DocumentState state ) + : QListViewItem( parent, url.fileName() ), + _url( url ) + +{ + KFileItem fileItem( KFileItem::Unknown, KFileItem::Unknown, _url ); + _icon = fileItem.pixmap(KIcon::SizeSmall); + setState( state ); +} + +KURL FileListItem::url() +{ + return _url; +} + +DocumentState FileListItem::state( ) +{ + return _state; +} + +void FileListItem::setState( DocumentState state ) +{ + _state = state; + + switch( state ) + { + case Clean: + setPixmap( 0, _icon); +// setPixmap( 0, 0L ); + break; + case Modified: + setPixmap( 0, SmallIcon("filesave") ); + break; + case Dirty: + setPixmap( 0, SmallIcon("revert") ); + break; + case DirtyAndModified: + setPixmap( 0, SmallIcon("stop") ); + break; + } +} + +void FileListItem::setHeight( int ) +{ + QListViewItem::setHeight( KIcon::SizeSmall > listView()->fontMetrics().height() ? KIcon::SizeSmall : listView()->fontMetrics().height() ); +} + +void FileListItem::paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align ) +{ + QColorGroup mcg = cg; + + if ( isActive() ) + { + mcg.setColor( QColorGroup::Base, Qt::yellow ); + } + + QListViewItem::paintCell( p, mcg, column, width, align ); +} + +bool FileListItem::isActive( ) +{ + return ( s_activeItem == this ); +} + +//static +void FileListItem::setActive( FileListItem * item ) +{ + s_activeItem = item; +} + +int FileListItem::compare( QListViewItem * i, int col, bool ascending ) const +{ + QFileInfo info1( key( col, ascending ) ); //this + QFileInfo info2( i->key( col, ascending ) ); //that + int fileComp = info1.fileName().compare( info2.fileName() ); + if ( fileComp != 0 ) + return fileComp; + else + return info1.extension().compare( info2.extension() ); +} + +// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off; diff --git a/parts/filelist/filelist_item.h b/parts/filelist/filelist_item.h new file mode 100644 index 00000000..2b4019b8 --- /dev/null +++ b/parts/filelist/filelist_item.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2004 by Jens Dagerbo * + * [email protected] * + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef __FILELIST_ITEM_H__ +#define __FILELIST_ITEM_H__ + + +#include <qlistview.h> +#include <qpixmap.h> + +#include <kurl.h> + +#include <kdevpartcontroller.h> + +class FileListItem : public QListViewItem +{ +public: + FileListItem( QListView * parent, KURL const & url, DocumentState = Clean ); + + KURL url(); + + DocumentState state(); + void setState( DocumentState ); + + bool isActive(); + static void setActive( FileListItem * item ); + + virtual int compare( QListViewItem * i, int col, bool ascending ) const; +private: + virtual void setHeight( int ); // override of QListViewItem::setHeight() + virtual void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align ); // override of QListViewItem::paintCell() + + KURL _url; + DocumentState _state; + QPixmap _icon; + + static FileListItem * s_activeItem; + +}; + + + +#endif + +// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off; diff --git a/parts/filelist/filelist_widget.cpp b/parts/filelist/filelist_widget.cpp new file mode 100644 index 00000000..2ef03968 --- /dev/null +++ b/parts/filelist/filelist_widget.cpp @@ -0,0 +1,300 @@ +/*************************************************************************** + * Copyright (C) 2004 by Jens Dagerbo * + * [email protected] * + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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 <qheader.h> +#include <qpixmap.h> + +#include <kparts/part.h> +#include <klibloader.h> +#include <kurl.h> +#include <kdebug.h> +#include <klocale.h> +#include <kpopupmenu.h> + +#include <kdevcore.h> +#include <kdevpartcontroller.h> + +#include "projectviewpart.h" +#include "filelist_widget.h" +#include "filelist_item.h" + + +/** + * + * @param part + * @return + */ +FileListWidget::FileListWidget(ProjectviewPart *part, QWidget *parent) + : KListView(parent), QToolTip( viewport() ), _part( part ) +{ + addColumn( "" ); + header()->hide(); + setRootIsDecorated( false ); + setResizeMode( QListView::LastColumn ); + setAllColumnsShowFocus( true ); + + setSelectionMode( QListView::Extended ); + +// connect( _part->partController(), SIGNAL( partAdded(KParts::Part*) ), this, SLOT(partAdded(KParts::Part*)) ); +// connect( _part->partController(), SIGNAL( partRemoved(KParts::Part*) ), this, SLOT(partRemoved()) ); + connect( _part->partController(), SIGNAL( partAdded(KParts::Part*) ), this, SLOT(startRefreshTimer()) ); + connect( _part->partController(), SIGNAL( partRemoved(KParts::Part*) ), this, SLOT(startRefreshTimer()) ); + connect( _part->partController(), SIGNAL( activePartChanged(KParts::Part*) ), this, SLOT( activePartChanged(KParts::Part* )) ); + + connect( this, SIGNAL( executed( QListViewItem * ) ), this, SLOT( itemClicked( QListViewItem * ) ) ); + connect( this, SIGNAL( returnPressed( QListViewItem * ) ), this, SLOT( itemClicked( QListViewItem * ) ) ); + + connect( this, SIGNAL( contextMenuRequested ( QListViewItem *, const QPoint & , int ) ), + this, SLOT( popupMenu(QListViewItem *, const QPoint & , int ) ) ); + + connect( _part->partController(), SIGNAL(documentChangedState(const KURL &, DocumentState)), + this, SLOT(documentChangedState(const KURL&, DocumentState )) ); + + connect( _part->partController(), SIGNAL(partURLChanged(KParts::ReadOnlyPart * )), this, SLOT(refreshFileList()) ); + + setItemMargin(10); + + connect( &m_refreshTimer, SIGNAL(timeout()), this, SLOT(refreshFileList()) ); + + startRefreshTimer(); +} + + +FileListWidget::~FileListWidget() +{} + +void FileListWidget::startRefreshTimer( ) +{ + m_refreshTimer.start( 100, true ); +} + +void FileListWidget::maybeTip( QPoint const & p ) +{ + FileListItem * item = static_cast<FileListItem*>( itemAt( p ) ); + QRect r = itemRect( item ); + + if ( item && r.isValid() ) + { + const QPixmap * pixmap = item->pixmap(0); + if ( pixmap && ( p.x() <= pixmap->width() ) ) + { + QString message; + switch( item->state() ) + { + case Modified: + message = i18n("This file has unsaved changes."); + break; + case Dirty: + message = i18n("This file has changed on disk since it was last saved."); + break; + case DirtyAndModified: + message = i18n("Conflict: this file has changed on disk and has unsaved changes."); + break; + default: + message = item->url().prettyURL(); + } + + tip( r, message ); + } + else + { + tip( r, item->url().prettyURL() ); + } + } +} + +FileListItem * FileListWidget::itemForURL( KURL const & url ) +{ + FileListItem * item = static_cast<FileListItem*>( firstChild() ); + while ( item ) + { + if ( item->url() == url ) + { + return item; + } + item = static_cast<FileListItem*>( item->nextSibling() ); + } + return 0L; +} + +void FileListWidget::refreshFileList( ) +{ + QStringList selections = storeSelections(); + int scrollbarPos = verticalScrollBar()->value(); + + KListView::clear(); + + KURL::List list = _part->partController()->openURLs(); + QValueListIterator<KURL> it = list.begin(); + while ( it != list.end() ) + { + FileListItem * item = new FileListItem( this, *it ); + item->setState( _part->partController()->documentState( *it ) ); + ++it; + } + + restoreSelections( selections ); + + if ( selections.isEmpty() && firstChild() ) + { + firstChild()->setSelected( true ); + } + + verticalScrollBar()->setValue( scrollbarPos ); + + activePartChanged( _part->partController()->activePart() ); +} + +/* +void FileListWidget::partAdded( KParts::Part * part ) +{ + KParts::ReadOnlyPart * ro_part = dynamic_cast<KParts::ReadOnlyPart*>( part ); + if ( ro_part ) + { + new FileListItem( this, ro_part->url() ); + } + + activePartChanged( _part->partController()->activePart() ); +} + +void FileListWidget::partRemoved() +{ + FileListItem * item = static_cast<FileListItem*>( firstChild() ); + while ( item ) + { + if ( ! _part->partController()->partForURL( item->url() ) ) + { + delete item; + break; + } + item = static_cast<FileListItem*>( item->nextSibling() ); + } + + activePartChanged( _part->partController()->activePart() ); +} +*/ + +void FileListWidget::itemClicked( QListViewItem * item ) +{ + if ( !item ) return; + + FileListItem * listItem = static_cast<FileListItem*>( item ); + _part->partController()->editDocument( listItem->url() ); +} + +void FileListWidget::activePartChanged( KParts::Part * part ) +{ + KParts::ReadOnlyPart * ro_part = dynamic_cast<KParts::ReadOnlyPart*>( part ); + if ( ro_part ) + { + FileListItem * item = static_cast<FileListItem*>( firstChild() ); + while ( item ) + { + if ( item->url() == ro_part->url() ) + { + FileListItem::setActive( item ); + break; + } + item = static_cast<FileListItem*>( item->nextSibling() ); + } + } + repaintContents(); +} + +void FileListWidget::documentChangedState( const KURL & url, DocumentState state ) +{ + FileListItem * item = itemForURL( url ); + if ( item ) + { + item->setState( state ); + } +} + +void FileListWidget::popupMenu( QListViewItem * item, const QPoint & p, int ) +{ + if ( item ) + { + KPopupMenu popup; + popup.insertTitle( i18n("File List") ); + popup.insertItem( i18n("Close Selected"), this, SLOT(closeSelectedFiles()) ); + popup.insertItem( i18n("Save Selected"), this, SLOT(saveSelectedFiles()) ); + popup.insertItem( i18n("Reload Selected"), this, SLOT(reloadSelectedFiles()) ); + + FileContext context( getSelectedURLs() ); + _part->core()->fillContextMenu( &popup, &context ); + + popup.exec(p); + } +} + +KURL::List FileListWidget::getSelectedURLs( ) +{ + KURL::List list; + FileListItem * item = static_cast<FileListItem*>( firstChild() ); + while ( item ) + { + if ( item->isSelected() ) + { + list << item->url(); + } + item = static_cast<FileListItem*>( item->nextSibling() ); + } + return list; +} + +void FileListWidget::closeSelectedFiles( ) +{ + _part->partController()->closeFiles( getSelectedURLs() ); +} + +void FileListWidget::saveSelectedFiles( ) +{ + _part->partController()->saveFiles( getSelectedURLs() ); +} + +void FileListWidget::reloadSelectedFiles( ) +{ + _part->partController()->revertFiles( getSelectedURLs() ); +} + +QStringList FileListWidget::storeSelections() +{ + QStringList list; + QListViewItem * item = firstChild(); + while ( item ) + { + if ( item->isSelected() ) + { + list << item->text(0); + } + item = item->nextSibling(); + } + return list; +} + +void FileListWidget::restoreSelections(const QStringList & list) +{ + QListViewItem * item = firstChild(); + while ( item ) + { + if ( list.contains( item->text(0) ) ) + { + item->setSelected( true ); + } + item = item->nextSibling(); + } +} + +#include "filelist_widget.moc" + +// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off; diff --git a/parts/filelist/filelist_widget.h b/parts/filelist/filelist_widget.h new file mode 100644 index 00000000..5895103b --- /dev/null +++ b/parts/filelist/filelist_widget.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (C) 2004 by Jens Dagerbo * + * [email protected] * + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef __FILELIST_WIDGET_H__ +#define __FILELIST_WIDGET_H__ + + +#include <klistview.h> +#include <kurl.h> +#include <kdevpartcontroller.h> // for DocumentState + +#include <qstring.h> +#include <qtooltip.h> +#include <qtimer.h> + +#include "projectviewpart.h" + +class KDevProject; +class FileListItem; + +namespace KParts { class Part; } + +class FileListWidget : public KListView, public QToolTip +{ + Q_OBJECT + +public: + + FileListWidget(ProjectviewPart *part, QWidget *parent=0); + ~FileListWidget(); + +protected: + void maybeTip( QPoint const & ); + +private slots: +// void partAdded(KParts::Part*); +// void partRemoved(); + void activePartChanged(KParts::Part*); + void itemClicked( QListViewItem * ); + void popupMenu( QListViewItem * , const QPoint & , int ); + void closeSelectedFiles(); + void saveSelectedFiles(); + void reloadSelectedFiles(); + void documentChangedState( const KURL &, DocumentState ); + void refreshFileList(); + void startRefreshTimer(); + QStringList storeSelections(); + void restoreSelections( const QStringList & list ); + +private: + KURL::List getSelectedURLs(); + FileListItem * itemForURL( KURL const & url ); + + QTimer m_refreshTimer; + ProjectviewPart * _part; + +}; + + +#endif + +// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off; diff --git a/parts/filelist/kdevfilelist.desktop b/parts/filelist/kdevfilelist.desktop new file mode 100644 index 00000000..c3d097e4 --- /dev/null +++ b/parts/filelist/kdevfilelist.desktop @@ -0,0 +1,76 @@ +[Desktop Entry] +Type=Service +Exec=blubb +Comment=Provides a list of all currently open files. (Handy when the tab bar is not quite wide enough.) +Comment[ca]=Proporciona una llista de tots els fitxers oberts actualment. (Útil quan la barra de pestanyes no és suficientment ample) +Comment[da]=Sørger for en liste over alle filer der er åbne. (Praktisk når tab-linjen ikke er helt bred nok.) +Comment[de]=Stellt eine Liste aller offenen Dateien bereit. +Comment[el]=Προσφέρει μια λίστα των τρέχων ανοιγμένων αρχείων. (Χρήσιμο όταν η γραμμή καρτελών δεν είναι αρκετά πλατιά.) +Comment[es]=Proporciona una lista de los archivos abiertos actualmente (útil cuando la barra de pestañas no es lo suficientemente ancha). +Comment[et]=Näitab kõiki parajasti avatud faile (mugav, kui kaardiriba ei ole piisavalt lai). +Comment[eu]=Uneko irekitako fitxategien zerrenda eskeintzen du. (Erabilgarria fitxa-barra behar den bezain zabala ez bada) +Comment[fa]=فهرستی از همۀ پروندههای باز جاری را فراهم میکند. )دستی هنگامی که میله ابزار پهنای کافی نداشته باشد.( +Comment[fr]=Fournit une liste de tous les fichiers actuellement ouverts. (Pratique lorsque la barre d'onglets n'est plus assez large.) +Comment[gl]=Proporciona unha lista de tódolos ficheiros abertos actualmente. (Útil cando a barra de pestañas non é suficientemente ancha.) +Comment[hu]=Kilistázza a nyitott fájlokat. (Jól jöhet, ha a lapozósáv nem elég széles.) +Comment[it]=Fornisce una lista di tutti i file aperti correntemente. (Utile quando la barra delle schede non è sufficientemente larga.) +Comment[ja]=現在開かれているファイルのリストを提供します。(タブバーが十分広くない場合に便利です) +Comment[ms]=Menyediakan senarai semua fail yang sedang dibuka. (Berguna apabila bar tab tidak cukup lebar.) +Comment[nds]=Stellt en List vun all apen Dateien praat. (Goot, wenn de Paneelbalken nich wiet noog is.) +Comment[ne]=हालै खुला फाइलको सूची प्रदान गर्दछ (ट्याब बार पर्याप्त चौडा नहुदा सजिलो हुन्छ) +Comment[nl]=Geeft een lijst van alle open bestanden. (Handig als de tabbalk niet breed genoeg is.) +Comment[pl]=Pokazuje listę obecnie otwartych plików (przydaje się, gdy pasek kart nie mieści wszystkich) +Comment[pt]=Fornece uma lista de todos os ficheiros actualmente aberto. (Útil quando a barra de página não é suficientemente larga.) +Comment[pt_BR]=Fornece uma lista de todos os arquivos atualmente abertos (acessível quando a barra de abas não for larga o suficiente). +Comment[ru]=Список открытых в данных момент файлов (полезно, когда они не помещаются на панели вкладок). +Comment[sk]=Poskytne zoznam všetkých aktuálne otvorených súborov. (Užitočné keď panel kariet nie je dostatočne široký.) +Comment[sr]=Даје листу свих отворених фајлова. (Згодно кад трака са језичцима није довољно дугачка.) +Comment[sr@Latn]=Daje listu svih otvorenih fajlova. (Zgodno kad traka sa jezičcima nije dovoljno dugačka.) +Comment[sv]=Tillhandahåller en lista av alla för närvarande öppna filer. (Praktiskt när flikraden inte är riktigt bred nog.) +Comment[ta]=தற்போது திறக்கப்பட்ட கோப்புகளின் பட்டியலை வழங்குகிறது. (தத்தல் போதுமான வசதியை வழங்க இயலாத பொழுது) +Comment[tg]=Рӯйхати кушодашудагиҳои ҳозир будаи файлҳо (вақте ки онҳо дар панелмонӣ омехта намешаванд, фоидаовар аст.) +Comment[tr]=Bütün açık dosyaların bir listesini sunar. (Sekme çubuğu yeteri kadar geniş olmadığında işe yarar) +Comment[zh_CN]=提供目前已打开全部文件的列表。(当标签栏不够宽时非常实用。) +Comment[zh_TW]=提供目前開啟檔案的列表。 +Name=KDevfilelist +Name[da]=KDevelop filliste +Name[nds]=KDevelop-Dateilist +Name[pt_BR]=Lista de arq. do KDev +Name[sk]=KDev zoznam súborov +Name[sv]=KDevelop fillista +Name[ta]=KDev கோப்புக்காட்சி +Name[tg]=Рӯйхати файли KDev +Name[zh_TW]=KDevelop 檔案列表 +GenericName=FileList +GenericName[br]=Roll restr +GenericName[da]=Filliste +GenericName[de]=Dateiliste +GenericName[el]=ΛίσταΑρχείων +GenericName[eu]=Fitxategi zerrenda +GenericName[fa]=فهرست پرونده +GenericName[hu]=Fájllista +GenericName[it]=ListaFile +GenericName[ja]=ファイルリスト +GenericName[ms]=SenaraiFail +GenericName[nds]=Dateilist +GenericName[ne]=फाइल सूची +GenericName[nl]=Bestandenlijst +GenericName[pl]=Lista plików +GenericName[pt]=Lista de Ficheiros +GenericName[pt_BR]=Lista de Arquivos +GenericName[ru]=Список файлов +GenericName[sk]=Zoznam súborov +GenericName[sl]=Seznam datotek +GenericName[sr]=Листа фајлова +GenericName[sr@Latn]=Lista fajlova +GenericName[sv]=Fillista +GenericName[ta]=கோப்புப் பட்டியல் +GenericName[tg]=Рӯйхати файлҳо +GenericName[zh_CN]=文件列表 +GenericName[zh_TW]=檔案列表 +Icon=kdevelop +ServiceTypes=KDevelop/Plugin +X-KDevelop-Scope=Global +X-KDE-Library=libkdevfilelist +X-KDevelop-Version=5 +X-KDevelop-Properties=OpenFileNavigation diff --git a/parts/filelist/kdevfilelist.rc b/parts/filelist/kdevfilelist.rc new file mode 100644 index 00000000..5ab5de7c --- /dev/null +++ b/parts/filelist/kdevfilelist.rc @@ -0,0 +1,24 @@ +<!DOCTYPE kpartgui> +<kpartplugin name="filelist" version="3"> +<MenuBar> + <Menu name="view" > + <text>View</text> + <Separator/> + <Menu name="viewsession" > + <text>View Sessions</text> + <Action name="viewsession_new" /> + <Action name="viewsession_open" /> + <Action name="viewsession_save" /> + <Action name="viewsession_delete" /> + </Menu> + <Separator/> + </Menu> +</MenuBar> +<ToolBar name="viewsession_toolbar" > + <text>View Sessions Toolbar</text> + <Action name="viewsession_new" /> + <Action name="viewsession_open" /> + <Action name="viewsession_save" /> + <Action name="viewsession_deletecurrent" /> +</ToolBar> +</kpartplugin> diff --git a/parts/filelist/projectviewconfig.cpp b/parts/filelist/projectviewconfig.cpp new file mode 100644 index 00000000..fba2c6ca --- /dev/null +++ b/parts/filelist/projectviewconfig.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "projectviewconfig.h" + +#include <qcheckbox.h> + +#include <kconfig.h> +#include <kapplication.h> + + +ProjectviewConfig::ProjectviewConfig(QWidget *parent, const char *name) + : ProjectviewConfigBase(parent, name) +{ + KConfig * config = kapp->config(); + config->setGroup("File List Plugin"); + inToolview->setChecked(config->readBoolEntry("ToolbarInToolview", true)); + onlyProject->setChecked(config->readBoolEntry("OnlyProjectFiles", false)); + closeOpenFiles->setChecked(config->readBoolEntry("CloseOpenFiles", true)); +} + +void ProjectviewConfig::accept() +{ + KConfig * config = kapp->config(); + config->setGroup("File List Plugin"); + config->writeEntry("ToolbarInToolview", inToolview->isChecked()); + config->writeEntry("OnlyProjectFiles", onlyProject->isChecked()); + config->writeEntry("CloseOpenFiles", closeOpenFiles->isChecked()); +} + +#include "projectviewconfig.moc" diff --git a/parts/filelist/projectviewconfig.h b/parts/filelist/projectviewconfig.h new file mode 100644 index 00000000..64cffd10 --- /dev/null +++ b/parts/filelist/projectviewconfig.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef PROJECTVIEW_CONFIG_H +#define PROJECTVIEW_CONFIG_H + +#include "projectviewconfigbase.h" + + +class ProjectviewConfig: public ProjectviewConfigBase +{ + Q_OBJECT +public: + ProjectviewConfig(QWidget *parent = 0, const char *name = 0); + +public slots: + void accept(); + +}; + +#endif diff --git a/parts/filelist/projectviewconfigbase.ui b/parts/filelist/projectviewconfigbase.ui new file mode 100644 index 00000000..7a0241db --- /dev/null +++ b/parts/filelist/projectviewconfigbase.ui @@ -0,0 +1,93 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ProjectviewConfigBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ProjectviewConfigBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>File List</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>inToolview</cstring> + </property> + <property name="text"> + <string>Display toolbar in toolview (note: change needs a restart)</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="toolTip" stdset="0"> + <string>Uncheck this if you want the toolbar together with all other toolbars. You can disable it then</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Uncheck this if you want the toolbar together with all other toolbars. You can disable it then</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>onlyProject</cstring> + </property> + <property name="text"> + <string>Only save project files in a session</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="toolTip" stdset="0"> + <string>Check this if you want to ignore files that are not part of the project</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Check this if you want to ignore files that are not part of the project</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>closeOpenFiles</cstring> + </property> + <property name="text"> + <string>Close all open files before opening a session</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="toolTip" stdset="0"> + <string>Check this if you want the currently open files closed before opening a session</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Check this if you want the currently open files closed before opening a session</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>61</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/parts/filelist/projectviewpart.cpp b/parts/filelist/projectviewpart.cpp new file mode 100644 index 00000000..56fc02c3 --- /dev/null +++ b/parts/filelist/projectviewpart.cpp @@ -0,0 +1,585 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "projectviewprojectconfig.h" +#include "projectviewconfig.h" +#include "projectviewpart.h" +#include "filelist_widget.h" +#include "toolbarguibuilder.h" + +#include <qtimer.h> +#include <qpopupmenu.h> +#include <qwhatsthis.h> +#include <qvaluelist.h> +#include <qmap.h> +#include <qdir.h> +#include <qdom.h> +#include <qvbox.h> +#include <qhbox.h> +#include <qpoint.h> +#include <qlayout.h> + +#include <kmainwindow.h> +#include <kinputdialog.h> +#include <klocale.h> +#include <kaction.h> +#include <kdialogbase.h> +#include <kiconloader.h> +#include <kmessagebox.h> +#include <ktexteditor/viewcursorinterface.h> +#include <ktexteditor/encodinginterface.h> +#include <kparts/part.h> +#include <kxmlguibuilder.h> +#include <kdebug.h> +#include <kconfig.h> +#include <kapplication.h> + +#include <kdevplugininfo.h> +#include <kdevgenericfactory.h> +#include <kdevpartcontroller.h> +#include <kdevproject.h> +#include <kdevcore.h> +#include <kdevmainwindow.h> +#include <configwidgetproxy.h> + + + +typedef KDevGenericFactory<ProjectviewPart> projectviewFactory; +KDevPluginInfo data("kdevfilelist"); +K_EXPORT_COMPONENT_FACTORY(libkdevfilelist, projectviewFactory(data)) + +#define GLOBALDOC_OPTIONS 1 +#define PROJECTDOC_OPTIONS 2 + +ProjectviewPart::ProjectviewPart(QObject *parent, const char *name, const QStringList &/*args*/) + : KDevPlugin(&data, parent, name ? name : "FileListPart") +{ + setInstance(projectviewFactory::instance()); + setXMLFile("kdevfilelist.rc"); + setupActions(); + + m_configProxy = new ConfigWidgetProxy(core()); + m_configProxy->createGlobalConfigPage(i18n("File List"), GLOBALDOC_OPTIONS, info()->icon()); + m_configProxy->createProjectConfigPage(i18n("File List"), PROJECTDOC_OPTIONS, info()->icon()); + + connect(m_configProxy, SIGNAL(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int)), + this, SLOT(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int))); + + connect(core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)), + this, SLOT(contextMenu(QPopupMenu *, const Context *))); + + connect(core(), SIGNAL(projectOpened()), this, SLOT(projectOpened())); + connect(core(), SIGNAL(projectClosed()), this, SLOT(projectClosed())); + + KConfig * config = kapp->config(); + config->setGroup("File List Plugin"); + if (config->readBoolEntry("ToolbarInToolview", true)) + { + m_toolbarWidget = new QVBox(0, "toolbarContainer"); + m_toolbarWidget->setHidden(true); + m_guibuilder = new ToolbarGUIBuilder(m_toolbarWidget, mainWindow()->main()); + setClientBuilder(m_guibuilder); + } + m_restored = false; + QTimer::singleShot(0, this, SLOT(init())); +} + +ProjectviewPart::~ProjectviewPart() +{ + delete m_configProxy; + delete m_guibuilder; + if ( m_widget ) { + mainWindow()->removeView( m_widget ); + delete m_widget; // deletes the children as well + } +} + +void ProjectviewPart::restorePartialProjectSession(const QDomElement * el) +{ + m_projectViews.clear(); // remove the global views + m_restored = true; + if (!el) + { + return; + } + // get the base of the project + QString urlStr = project()->projectDirectory(); + if (KURL::isRelativeURL(urlStr)) + { + m_projectBase.setProtocol("file"); + m_projectBase.setPath(urlStr); + } else + { + m_projectBase = KURL::fromPathOrURL(urlStr); + } + m_projectBase.adjustPath(+1); // just in case + + // read all the views + QDomNodeList domList = el->elementsByTagName("projectview"); + + uint len = domList.length(); + for (uint i = 0; i < len; ++i) + { + const QDomElement viewEl = domList.item(i).toElement(); + if (viewEl.isNull()) + { + continue; + } + FileInfoList urlList; + QDomNodeList fileList = viewEl.elementsByTagName("file"); + + uint len2 = fileList.length(); + for (uint i2 = 0; i2 < len2; ++i2) + { + const QDomElement fileEl = fileList.item(i2).toElement(); + if (!fileEl.isNull()) + { + bool ok; + int line = -1; + QString attr = fileEl.attribute("line"); + if (! attr.isNull()) + { + line = attr.toInt(&ok); + if (!ok) + line = -1; + } + int col = -1; + attr = fileEl.attribute("col"); + if (! attr.isNull()) + { + col = attr.toInt(&ok); + if (!ok) + col = -1; + } + QString encoding = ""; + attr = fileEl.attribute("encoding"); + if (! attr.isNull()) + { + encoding = attr; + } + QString urlStr = fileEl.attribute("url"); + if (KURL::isRelativeURL(urlStr)) + { + KURL url = m_projectBase; + url.addPath(urlStr); + urlList.append(FileInfo(url, line, col, encoding)); + } else + urlList.append(FileInfo(KURL::fromPathOrURL(urlStr), line, col, encoding)); + } + } + m_projectViews.insert(viewEl.attribute("name"), urlList); + } + // read default view + domList = el->elementsByTagName("defaultview"); + if (domList.length() > 0) + { + m_defaultProjectView = domList.item(0).toElement().attribute("name"); + if (!m_defaultProjectView.isEmpty()) + { + slotOpenProjectView(m_defaultProjectView); + } + } else + { + m_defaultProjectView = ""; + } +} + +void ProjectviewPart::savePartialProjectSession(QDomElement * el) +{ + if (!el || m_projectViews.empty()) + { + return; + } + QDomDocument domDoc = el->ownerDocument(); + if (domDoc.isNull()) + { + return; + } + // write all views + ViewMap::ConstIterator it; + for (it = m_projectViews.constBegin(); it != m_projectViews.constEnd(); ++it) + { + // we create the view even if there is no file inside, might be wanted by the user + QDomElement viewEl = domDoc.createElement("projectview"); + viewEl.setAttribute("name", it.key()); + el->appendChild(viewEl); + for (FileInfoList::ConstIterator it2 = it.data().constBegin(); it2 != it.data().constEnd(); ++it2) + { + QDomElement urlEl = domDoc.createElement("file"); + + if (m_projectBase.isParentOf((*it2).url)) + urlEl.setAttribute("url", KURL::relativeURL(m_projectBase, (*it2).url)); + else + urlEl.setAttribute("url", (*it2).url.url()); + urlEl.setAttribute("line", (*it2).line); + urlEl.setAttribute("col", (*it2).col); + urlEl.setAttribute("encoding", (*it2).encoding); + viewEl.appendChild(urlEl); + } + } + // write the default view + QDomElement defaultEl = domDoc.createElement("defaultview"); + defaultEl.setAttribute("name", m_defaultProjectView); + el->appendChild(defaultEl); +} + + +void ProjectviewPart::init() +{ + // delayed initialization stuff goes here + + // create the toolview + m_widget = new QWidget(0, "filelist widget"); + m_widget->setIcon( SmallIcon(info()->icon()) ); + m_widget->setCaption(i18n("File List")); + + QBoxLayout * l = new QVBoxLayout(m_widget); + + // create the toolbar if needed + if (m_guibuilder) + { + m_toolbarWidget->reparent(m_widget, QPoint(0, 0), true); + l->addWidget(m_toolbarWidget); + QWhatsThis::add(m_toolbarWidget, i18n("<b>View Session Toolbar</b><p>This allows to create and work with view sessions. A view session is a set of open documents.</p>")); + } + + // create the listview + QWidget * fileListWidget = new FileListWidget(this, m_widget); + fileListWidget->setCaption(i18n("File List")); + QWhatsThis::add(fileListWidget, i18n("<b>File List</b><p>This is the list of opened files.</p>")); + l->addWidget(fileListWidget); + m_widget->setFocusProxy(fileListWidget); + + mainWindow()->embedSelectView(m_widget, i18n("File List"), i18n("Open files")); + + if (!project()) + readConfig(); +} + +void ProjectviewPart::setupActions() +{ + m_openPrjViewAction = new KSelectAction(i18n("Open Session..."), 0, actionCollection(), "viewsession_open"); + + connect(m_openPrjViewAction, SIGNAL(activated(const QString &)), this, SLOT(slotOpenProjectView(const QString &))); + + m_openPrjViewAction->setToolTip(i18n("Open Session")); + + m_savePrjViewAction = new KAction(i18n("Save Session"), "filesave", 0, this, SLOT(slotSaveProjectView()), actionCollection(), "viewsession_save"); + + m_newPrjViewAction = new KAction(i18n("New Session..."), "filenew", 0, this, SLOT(slotSaveAsProjectView()), actionCollection(), "viewsession_new"); + + m_deletePrjViewAction = new KSelectAction(i18n("Delete Session"), "editdelete", 0, actionCollection(), "viewsession_delete"); + + connect(m_deletePrjViewAction, SIGNAL(activated(const QString &)), this, SLOT(slotDeleteProjectView(const QString &))); + + m_deletePrjViewAction->setToolTip(i18n("Delete Session")); + + m_deleteCurrentPrjViewAction = new KAction(i18n("Delete Session"), "editdelete", 0, this, SLOT(slotDeleteProjectViewCurent()), actionCollection(), "viewsession_deletecurrent"); + + m_deleteCurrentPrjViewAction->setToolTip(i18n("Delete Session")); + + adjustViewActions(); +} + +void ProjectviewPart::insertConfigWidget(const KDialogBase *dlg, QWidget *page, unsigned int pageNo) +{ +// create configuraton dialogs here + switch (pageNo) + { + case PROJECTDOC_OPTIONS: + { + ProjectviewProjectConfig *w = new ProjectviewProjectConfig(this, page, "project config"); + connect(dlg, SIGNAL(okClicked()), w, SLOT(accept())); + break; + } + case GLOBALDOC_OPTIONS: + { + ProjectviewConfig *w = new ProjectviewConfig(page, "global config"); + connect(dlg, SIGNAL(okClicked()), w, SLOT(accept())); + break; + } + } +} + +void ProjectviewPart::contextMenu(QPopupMenu */*popup*/, const Context */*context*/) +{ +// put actions into the context menu here +// if (context->hasType(Context::EditorContext)) +// { +// // editor context menu +// const EditorContext *econtext = static_cast<const EditorContext*>(context); +// +// // use context and plug actions here +// // action->plug(popup); +// +// // or create menu items on the fly +// // int id = -1; +// // id = popup->insertItem(i18n("Do Something Here"), +// // this, SLOT(doSomething())); +// // popup->setWhatsThis(id, i18n("<b>Do something here</b><p>Describe here what does this action do." +// } +// else if (context->hasType(Context::FileContext)) +// { +// // file context menu +// const FileContext *fcontext = static_cast<const FileContext*>(context); +// +// //use context and plug actions here +// } +// else if (context->hasType(Context::ProjectModelItemContext)) +// { +// // project tree context menu +// const ProjectModelItemContext *pcontext = static_cast<const ProjectModelItemContext*>(context); +// +// // use context and plug actions here +// } +// else if (context->hasType(Context::CodeModelItemContext)) +// { +// // class tree context menu +// const CodeModelItemContext *mcontext = static_cast<const CodeModelItemContext*>(context); +// +// // use context and plug actions here +// } +// else if (context->hasType(Context::DocumentationContext)) +// { +// // documentation viewer context menu +// const DocumentationContext *dcontext = static_cast<const DocumentationContext*>(context); +// +// // use context and plug actions here +// } +} + +void ProjectviewPart::projectOpened() +{ + if ( !m_restored ) + m_projectViews.clear(); // remove the global views + adjustViewActions(); + m_restored = false; +} + +void ProjectviewPart::projectClosed() +{ + m_projectBase = KURL(); + m_defaultProjectView = ""; + readConfig(); // read the global project views +} + +void ProjectviewPart::slotOpenProjectView(const QString &view) +{ + KConfig * config = kapp->config(); + config->setGroup("File List Plugin"); + bool onlyProject = config->readBoolEntry("OnlyProjectFiles", false); + bool closeOpenFiles = config->readBoolEntry("CloseOpenFiles", true); + + m_currentProjectView = view; + + if (m_projectViews.contains(view) > 0) + { + FileInfoList viewUrls = m_projectViews[view]; + + if (closeOpenFiles) + { + // we close everything that is not part of the project view + KURL::List urlsToClose = partController()->openURLs(); + for (KURL::List::Iterator it = urlsToClose.begin(); it != urlsToClose.end(); ++it) + { + // it is in the list of wanted files and do we want it at all + if ((viewUrls.contains(*it) > 0) && (!onlyProject || !project() || project()->isProjectFile((*it).path()) )) + { + viewUrls.remove(*it); // don't open if it is open already + it = urlsToClose.remove(it); + --it; // do not skip one + } + } + if (!urlsToClose.empty()) + { + partController()->closeFiles(urlsToClose); + } + } + // we open what still needs to get opened + FileInfoList::const_iterator viewIt; + for (viewIt = viewUrls.begin(); viewIt != viewUrls.end(); ++viewIt) + { + if (!onlyProject || !project() || project()->isProjectFile((*viewIt).url.path())) + { + partController()->setEncoding( (*viewIt).encoding ); + partController()->editDocument((*viewIt).url, (*viewIt).line, (*viewIt).col); + } + } + } + adjustViewActions(); +} + + +void ProjectviewPart::slotSaveProjectView() +{ + slotSaveAsProjectView(m_currentProjectView.isEmpty()); +} + + +void ProjectviewPart::adjustViewActions() +{ + QStringList viewList = getViewList(); + + m_openPrjViewAction->clear(); + m_openPrjViewAction->setItems(viewList); + int i = viewList.findIndex(m_currentProjectView); + if (i > -1) + { + m_openPrjViewAction->setCurrentItem(i); + } + m_deletePrjViewAction->clear(); + m_deletePrjViewAction->setItems(viewList); + m_currentProjectView = m_openPrjViewAction->currentText(); + if (m_currentProjectView.isEmpty() && !viewList.empty()) + { + m_currentProjectView = viewList.front(); + } + bool haveView = !m_currentProjectView.isEmpty(); + m_savePrjViewAction->setEnabled(haveView); + m_deleteCurrentPrjViewAction->setEnabled(haveView); +} + + +void ProjectviewPart::slotDeleteProjectViewCurent() +{ + slotDeleteProjectView(m_currentProjectView); +} + +void ProjectviewPart::slotDeleteProjectView(const QString& view) +{ + m_projectViews.remove(view); + + if (m_currentProjectView == view) + m_currentProjectView = ""; + + if (m_defaultProjectView == view) + m_defaultProjectView = ""; + + if (! project()) + writeConfig(); + + adjustViewActions(); +} + + +void ProjectviewPart::slotSaveAsProjectView(bool askForName) +{ + if (askForName) + { + bool ok; + QString newProjectView = KInputDialog::getText(i18n("Save View Session As"), i18n("Enter the name of the session:"), "", &ok, mainWindow()->main()); + if (!ok) + { + return; + } + newProjectView = newProjectView.remove("="); // we use this string in config files and = would confuse it + if (m_projectViews.contains(newProjectView) > 0 && + KMessageBox::warningContinueCancel(mainWindow()->main(), i18n("<qt>A view session named <b>%1</b> already exists.<br>Do you want to overwrite it?</qt>").arg(newProjectView), QString::null, i18n("Overwrite")) != KMessageBox::Continue) + { + return; + } + m_currentProjectView = newProjectView; + } + + FileInfoList viewUrls; + KURL::List openURLs = partController()->openURLs(); + + for (KURL::List::Iterator it = openURLs.begin(); it != openURLs.end(); ++it) + { + // test if we have an editor + // FIXME this can fail if there are two parts with the same URL + KParts::ReadOnlyPart *ro_part = partController()->partForURL(*it); + KTextEditor::ViewCursorInterface* cursorIf = dynamic_cast<KTextEditor::ViewCursorInterface*>(ro_part->widget()); + if (cursorIf) + { + QString encoding; + if ( KTextEditor::EncodingInterface * ei = dynamic_cast<KTextEditor::EncodingInterface*>( ro_part ) ) + { + QString temp = ei->encoding(); + if ( !temp.isNull() ) + { + encoding = temp; + } + } + + unsigned int line, col; + cursorIf->cursorPositionReal(&line, &col); + viewUrls.append(FileInfo(*it, line, col, encoding)); + } + } + // add or overwrite the values + m_projectViews.insert(m_currentProjectView, viewUrls, true); + if (! project()) + writeConfig(); + + adjustViewActions(); +} + + +void ProjectviewPart::writeConfig() +{ + KConfig * config = kapp->config(); + config->deleteGroup("ProjectViews", true); + config->setGroup("ProjectViews"); + + // write all views + ViewMap::ConstIterator it; + for (it = m_projectViews.constBegin(); it != m_projectViews.constEnd(); ++it) + { + // we create the view even if there is no file inside, might be wanted by the user + QStringList urls; + for (FileInfoList::ConstIterator it2 = it.data().constBegin(); it2 != it.data().constEnd(); ++it2) + { + if ((*it2).encoding.isEmpty()) + urls.append((*it2).url.url()); + else + urls.append((*it2).url.url() + ";" + (*it2).encoding); + } + config->writeEntry(it.key(), urls); + } +} + + +void ProjectviewPart::readConfig() +{ + KConfig * config = kapp->config(); + QMap<QString, QString> entries = config->entryMap("ProjectViews"); + + m_projectViews.clear(); + QMap<QString, QString>::ConstIterator it; + for (it = entries.constBegin(); it != entries.constEnd(); ++it) + { + FileInfoList urlList; + QStringList urls = QStringList::split(",", it.data()); + for (QStringList::Iterator it2 = urls.begin(); it2 != urls.end(); ++it2 ) + { + // search the encoding. The entry can be like: fileURL;encoding + QStringList file = QStringList::split(";", *it2); + if (file.count() == 1) + urlList.append(FileInfo(KURL::fromPathOrURL(*it2))); + else + urlList.append(FileInfo(KURL::fromPathOrURL(file.first()), -1, -1, file.last())); + } + m_projectViews.insert(it.key(), urlList); + } + adjustViewActions(); +} + +#include "projectviewpart.moc" diff --git a/parts/filelist/projectviewpart.h b/parts/filelist/projectviewpart.h new file mode 100644 index 00000000..50cd5391 --- /dev/null +++ b/parts/filelist/projectviewpart.h @@ -0,0 +1,169 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef KDEVPROJECTVIEW_H +#define KDEVPROJECTVIEW_H + +#include "fileinfo.h" + +#include <qvaluelist.h> +#include <qmap.h> +#include <qguardedptr.h> + +#include <kdevplugin.h> +#include <kurl.h> + + +class QPopupMenu; +class KAction; +class KSelectAction; +class KDialogBase; +class Context; +class ConfigWidgetProxy; +class FileListWidget; +class KToolBar; +class QVBox; +class ToolbarGUIBuilder; + + + +/** +Please read the README.dox file for more info about this part + +this is a reimplementation of the project views in Quanta + +@TODO find a way to control the toolbar again +@TODO save html parts too +FIXME at project open I get the default view and the open files at last close +*/ +class ProjectviewPart: public KDevPlugin +{ + Q_OBJECT +public: + + typedef QMap<QString, FileInfoList> ViewMap; +// typedef QMap<KURL, FileInfo> FileInfoMap; + + + ProjectviewPart(QObject *parent, const char *name, const QStringList &args); + ~ProjectviewPart(); + + // reimplemented from KDevPlugin + void restorePartialProjectSession(const QDomElement * el); + void savePartialProjectSession(QDomElement * el); + + /** + * + * @return the current defaut view + */ + inline QString getDefaultView() const {return m_defaultProjectView;}; + + /** + * + * @param view new default view + */ + inline void setDefaultView(const QString& view) {m_defaultProjectView = view;}; + + /** + * get all current views + * @return QStringList of defined views + */ + inline QStringList getViewList() const {return m_projectViews.keys();}; + +private slots: + void init(); + + void insertConfigWidget(const KDialogBase *dlg, QWidget *page, unsigned int pageNo); + void contextMenu(QPopupMenu *popup, const Context *context); + void projectOpened(); + void projectClosed(); + + /** Deletes a project view + * + * @param view name of the project view + */ + void slotDeleteProjectView(const QString &view); + + /** + * Deletes the current project view + */ + void slotDeleteProjectViewCurent(); + + /** + * Saves a project view + * + * @param askForName true = show a dialog for the name + */ + void slotSaveAsProjectView(bool askForName = true); + + /** Saves the current project view + */ + void slotSaveProjectView(); + + /** Opens a project view + * + * @param view name of the project view + */ + void slotOpenProjectView(const QString &view); + +private: + /** + * create and initialize the actions + */ + void setupActions(); + + /** + * Change the actions according to the current available views + */ + void adjustViewActions(); + + /** + * write the views to the plugin config file + */ + void writeConfig(); + + /** + * read the views from the plugin config file + */ + void readConfig(); + + ViewMap m_projectViews; //container for the views + + KAction *m_savePrjViewAction; + KAction *m_newPrjViewAction; + KAction *m_deleteCurrentPrjViewAction; + KSelectAction *m_openPrjViewAction; + KSelectAction *m_deletePrjViewAction; + + QString m_currentProjectView; + QString m_defaultProjectView; // load this after project loaded + + KURL m_projectBase; // project base folder + ConfigWidgetProxy *m_configProxy; + + QGuardedPtr<QWidget> m_widget; + QGuardedPtr<ToolbarGUIBuilder> m_guibuilder; + QWidget * m_toolbarWidget; + + bool m_restored; +}; + + +#endif diff --git a/parts/filelist/projectviewprojectconfig.cpp b/parts/filelist/projectviewprojectconfig.cpp new file mode 100644 index 00000000..eb2d1b49 --- /dev/null +++ b/parts/filelist/projectviewprojectconfig.cpp @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <kcombobox.h> + +#include "projectviewprojectconfig.h" + +#include "projectviewpart.h" + +ProjectviewProjectConfig::ProjectviewProjectConfig(ProjectviewPart *part, QWidget *parent, const char *name) + : ProjectviewProjectConfigBase(parent, name), m_part(part) +{ + kComboDefault->clear(); + kComboDefault->insertItem(""); + kComboDefault->insertStringList( m_part->getViewList() ); + kComboDefault->setCurrentItem( m_part->getDefaultView() ); +} + +void ProjectviewProjectConfig::accept() +{ + m_part->setDefaultView( kComboDefault->currentText() ); +} + +#include "projectviewprojectconfig.moc" diff --git a/parts/filelist/projectviewprojectconfig.h b/parts/filelist/projectviewprojectconfig.h new file mode 100644 index 00000000..03928642 --- /dev/null +++ b/parts/filelist/projectviewprojectconfig.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef PROJECTVIEW_PROJECT_CONFIG_H +#define PROJECTVIEW_PROJECT_CONFIG_H + +#include "projectviewprojectconfigbase.h" + +class ProjectviewPart; + +class ProjectviewProjectConfig: public ProjectviewProjectConfigBase +{ + Q_OBJECT +public: + ProjectviewProjectConfig(ProjectviewPart *part, QWidget *parent = 0, const char *name = 0); + +public slots: + void accept(); + +private: + ProjectviewPart *m_part; +}; + +#endif diff --git a/parts/filelist/projectviewprojectconfigbase.ui b/parts/filelist/projectviewprojectconfigbase.ui new file mode 100644 index 00000000..7ff9a0b0 --- /dev/null +++ b/parts/filelist/projectviewprojectconfigbase.ui @@ -0,0 +1,94 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ProjectviewProjectConfigBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ProjectviewProjectConfigBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>Projectviews</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Open this session after project load:</string> + </property> + </widget> + <widget class="KComboBox" row="0" column="1"> + <property name="name"> + <cstring>kComboDefault</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip" stdset="0"> + <string>select a session</string> + </property> + </widget> + <spacer row="0" column="2"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>265</width> + <height>20</height> + </size> + </property> + </spacer> + <spacer row="1" column="1"> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>71</height> + </size> + </property> + </spacer> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kcombobox.h</includehint> +</includehints> +</UI> diff --git a/parts/filelist/toolbarguibuilder.cpp b/parts/filelist/toolbarguibuilder.cpp new file mode 100644 index 00000000..2e82691b --- /dev/null +++ b/parts/filelist/toolbarguibuilder.cpp @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "toolbarguibuilder.h" + +#include <ktoolbar.h> + +ToolbarGUIBuilder::ToolbarGUIBuilder(QWidget *parent, QWidget *widget) + : KXMLGUIBuilder(widget), KToolBar(parent, "ToolbarGUIbuilder"), m_parent(parent) +{ +// setHidden(true); + setFrameStyle(0); +} + + +ToolbarGUIBuilder::~ToolbarGUIBuilder() +{ +} + +QWidget * ToolbarGUIBuilder::createContainer(QWidget *parent, int index, const QDomElement &element, int &id) +{ + if (element.tagName().lower() == "toolbar") + { + reparent(m_parent, QPoint(0, 0), true); + return this; + } else + { + return KXMLGUIBuilder::createContainer(parent, index, element, id); + } +} + +void ToolbarGUIBuilder::removeContainer(QWidget *container, QWidget *parent, QDomElement &element, int id) +{ + if (container == this) + { + // i need to reparent to prevent a crash + reparent(0, QPoint(0, 0)); + } + else + KXMLGUIBuilder::removeContainer(container, parent, element, id); +} + diff --git a/parts/filelist/toolbarguibuilder.h b/parts/filelist/toolbarguibuilder.h new file mode 100644 index 00000000..1f92b922 --- /dev/null +++ b/parts/filelist/toolbarguibuilder.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2005 by Jens Herden * + * [email protected] * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef TOOLBARGUIBUILDER_H +#define TOOLBARGUIBUILDER_H + +#include <kxmlguibuilder.h> +#include <kdebug.h> +#include <ktoolbar.h> + + +/** +* Reimplemented the KXMLGUIBuilder in order use our toolbar in the +* toolview +* @author Jens Herden +*/ +class ToolbarGUIBuilder : public KXMLGUIBuilder, public KToolBar +{ +public: + ToolbarGUIBuilder(QWidget *parent, QWidget *widget); + + virtual ~ToolbarGUIBuilder(); + + /** + * Called when a new XML gui client is added to the gui factory. + */ + virtual QWidget *createContainer(QWidget *parent, int index, const QDomElement &element, int &id); + + /** + * Called when a XML gui client is removed the gui factory. + * Reimplemented from KXMLGUIBuilder in order to remove our custom toolbar. + */ + virtual void removeContainer(QWidget *container, QWidget *parent, QDomElement &element, int id); + +private: + QWidget * m_parent; +}; + + + +#endif |