00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include <qdialog.h>
00013
#include <qstringlist.h>
00014
#include <qstring.h>
00015
00016
#include <kiconloader.h>
00017
#include <klocale.h>
00018
#include <kdevgenericfactory.h>
00019
#include <kaction.h>
00020
#include <kdebug.h>
00021
#include <kdevpartcontroller.h>
00022
#include <kparts/part.h>
00023
#include <kdevproject.h>
00024
#include <kdevcore.h>
00025
#include <kdevmainwindow.h>
00026
00027
#include "closer_part.h"
00028
#include "closer_dialogimpl.h"
00029
00030
static const KAboutData data(
"kdevcloser",
I18N_NOOP(
"Close Selected Windows..."),
"1.0");
00031
00032 typedef KDevGenericFactory<CloserPart> CloserFactory;
00033 K_EXPORT_COMPONENT_FACTORY( libkdevcloser,
CloserFactory( &data ) )
00034
00035
CloserPart::
CloserPart(
QObject *parent, const
char *name, const
QStringList& )
00036 :
KDevPlugin("Selected Window Closer", "closer", parent, name ? name : "closerPart" )
00037 {
00038 setInstance(CloserFactory::instance());
00039 setXMLFile(
"kdevpart_closer.rc");
00040
00041
KAction * action =
new KAction( i18n(
"Close Selected Windows..."), CTRL+ALT+Key_W,
this,
00042 SLOT( openDialog() ), actionCollection(),
"closer" );
00043 action->setToolTip( i18n(
"Select windows to close") );
00044 action->setWhatsThis(i18n(
"<b>Close selected windows</b><p>Provides a dialog to select files which will be closed."));
00045
00046 core()->insertNewAction( action );
00047 }
00048
00049
00050 CloserPart::~CloserPart()
00051 {}
00052
00053 void CloserPart::openDialog()
00054 {
00055
CloserDialogImpl d(
openFiles() );
00056
if ( d.exec() == QDialog::Accepted )
00057 {
00058
closeFiles( d.
getCheckedFiles() );
00059 }
00060 }
00061
00062 KURL::List CloserPart::openFiles()
00063 {
00064
KURL::List openfiles;
00065
if(
const QPtrList<KParts::Part> * partlist =
partController()->
parts() )
00066 {
00067
QPtrListIterator<KParts::Part> it( *partlist );
00068
while (
KParts::Part* part = it.current() )
00069 {
00070
if (
KParts::ReadOnlyPart * ro_part = dynamic_cast<KParts::ReadOnlyPart*>( part ) )
00071 {
00072 openfiles.append( ro_part->
url() );
00073 }
00074 ++it;
00075 }
00076 }
00077
return openfiles;
00078 }
00079
00080 void CloserPart::closeFiles(
KURL::List const & fileList )
00081 {
00082 KURL::List::ConstIterator it = fileList.begin();
00083
while ( it != fileList.end() )
00084 {
00085
if (
KParts::ReadOnlyPart * ro_part =
partForURL( *it ) )
00086 {
00087
partController()->
closePartForWidget( ro_part->
widget() );
00088 }
00089 ++it;
00090 }
00091 }
00092
00093
00094 KParts::ReadOnlyPart *
CloserPart::partForURL(
KURL const & url )
00095 {
00096
QPtrListIterator<KParts::Part> it( *
partController()->parts() );
00097
while( it.current() )
00098 {
00099
KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*>(it.current());
00100
if (ro_part && url == ro_part->
url())
00101 {
00102
return ro_part;
00103 }
00104 ++it;
00105 }
00106
return 0;
00107 }
00108
#include "closer_part.moc"