KDevelop API Documentation

parts/closer/closer_part.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 by Jens Dagerbo * 00003 * jens.dagerbo@swipnet.se * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 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 // reimplemented from PartController::partForURL to avoid linking 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"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:50 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003