diff --git a/plugins/filemanager/filemanager.cpp b/plugins/filemanager/filemanager.cpp index c46d38f1a0..5783c4ef3d 100644 --- a/plugins/filemanager/filemanager.cpp +++ b/plugins/filemanager/filemanager.cpp @@ -1,182 +1,180 @@ /*************************************************************************** * Copyright 2006-2007 Alexander Dymo * * Copyright 2006 Andreas Pakulat * * * * 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 Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "filemanager.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../openwith/iopenwith.h" #include "kdevfilemanagerplugin.h" FileManager::FileManager(KDevFileManagerPlugin *plugin, QWidget* parent) :QWidget(parent) { Q_UNUSED( plugin ); setObjectName("FileManager"); setWindowIcon(SmallIcon("system-file-manager")); setWindowTitle(i18n("Filesystem")); setWhatsThis(i18n("Filesystem Browser")); QVBoxLayout *l = new QVBoxLayout(this); l->setMargin(0); l->setSpacing(0); KFilePlacesModel* model = new KFilePlacesModel( this ); urlnav = new KUrlNavigator(model, KUrl( QDir::homePath() ), this ); connect(urlnav, SIGNAL(urlChanged(const KUrl& )), SLOT(gotoUrl(const KUrl&))); l->addWidget(urlnav); dirop = new KDirOperator(QDir::homePath(), this); dirop->setView( KFile::Tree ); dirop->setupMenu( KDirOperator::SortActions | KDirOperator::FileActions | KDirOperator::NavActions | KDirOperator::ViewActions ); connect(dirop, SIGNAL(urlEntered(const KUrl&)), SLOT(updateNav(const KUrl&))); connect(dirop, SIGNAL(contextMenuAboutToShow(KFileItem,QMenu*)), SLOT(fillContextMenu(KFileItem,QMenu*))); //KDirOperator emits fileSelected() twice because both activated() and doubleClicked() emit fileClicked(). //activated() should be enough, so disconnect doubleClicked() disconnect(dirop->view(), SIGNAL(doubleClicked(const QModelIndex&)), dirop, SLOT(_k_slotDoubleClicked(const QModelIndex&))); l->addWidget(dirop); connect( dirop, SIGNAL(fileSelected(const KFileItem&)), this, SLOT(openFile(const KFileItem&)) ); setupActions(); } void FileManager::fillContextMenu(KFileItem item, QMenu* menu) { foreach(QAction* a, contextActions){ if(menu->actions().contains(a)){ menu->removeAction(a); } } contextActions.clear(); contextActions.append(menu->addSeparator()); menu->addAction(newFileAction); contextActions.append(newFileAction); - if (item.isFile()) { - KDevelop::FileContext context(item.url()); - QList extensions = KDevelop::ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &context ); - KDevelop::ContextMenuExtension::populateMenu(menu, extensions); - QMenu* tmpMenu = new QMenu(); - KDevelop::ContextMenuExtension::populateMenu(tmpMenu, extensions); - contextActions.append(tmpMenu->actions()); - delete tmpMenu; - } + KDevelop::FileContext context(item.url()); + QList extensions = KDevelop::ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &context ); + KDevelop::ContextMenuExtension::populateMenu(menu, extensions); + QMenu* tmpMenu = new QMenu(); + KDevelop::ContextMenuExtension::populateMenu(tmpMenu, extensions); + contextActions.append(tmpMenu->actions()); + delete tmpMenu; } void FileManager::openFile(const KFileItem& file) { KDevelop::IOpenWith::openFiles(KUrl::List() << file.url()); } -void FileManager::gotoUrl( const KUrl& url ) +void FileManager::gotoUrl( const KUrl& url ) { dirop->setUrl( url, true ); } void FileManager::updateNav( const KUrl& url ) { urlnav->setLocationUrl( url ); } void FileManager::setupActions() { KAction* action = new KAction(this); action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setText(i18n("Current Document Directory")); action->setIcon(KIcon("dirsync")); connect(action, SIGNAL(triggered(bool)), this, SLOT(syncCurrentDocumentDirectory())); tbActions << (dirop->actionCollection()->action("back")); tbActions << (dirop->actionCollection()->action("up")); tbActions << (dirop->actionCollection()->action("home")); tbActions << (dirop->actionCollection()->action("forward")); tbActions << (dirop->actionCollection()->action("reload")); tbActions << action; tbActions << (dirop->actionCollection()->action("sorting menu")); tbActions << (dirop->actionCollection()->action("show hidden")); newFileAction = new KAction(this); newFileAction->setText(i18n("New File...")); newFileAction->setIcon(KIcon("document-new")); connect(newFileAction, SIGNAL(triggered()), this, SLOT(createNewFile())); } void FileManager::createNewFile() { KParts::MainWindow *activeMainWindow = KDevelop::ICore::self()->uiController()->activeMainWindow(); //TODO: adymo: use KNameAndUrlInputDialog here once we depend on KDE 4.5 bool ok = false; QString fileName = KInputDialog::getText(i18n("Create New File"), i18n("Filename:"), "", &ok, activeMainWindow); if (!ok) return; KTemporaryFile tmpFile; if (!tmpFile.open()) { kError() << "Couldn't create temp file!"; return; } KUrl destUrl = dirop->url(); destUrl.addPath(fileName); if (KIO::NetAccess::file_copy(KUrl(tmpFile.fileName()), destUrl)) KDevelop::ICore::self()->documentController()->openDocument( destUrl ); else KMessageBox::error(activeMainWindow, i18n("Unable to create file '%1'").arg(fileName)); } void FileManager::syncCurrentDocumentDirectory() { - if( KDevelop::IDocument* activeDoc = + if( KDevelop::IDocument* activeDoc = KDevelop::ICore::self()->documentController()->activeDocument() ) updateNav( activeDoc->url().upUrl() ); } QList FileManager::toolBarActions() const { return tbActions; } #include "filemanager.moc" diff --git a/plugins/grepview/grepviewplugin.cpp b/plugins/grepview/grepviewplugin.cpp index 9d83d25bf4..dc4c707518 100644 --- a/plugins/grepview/grepviewplugin.cpp +++ b/plugins/grepview/grepviewplugin.cpp @@ -1,203 +1,214 @@ /*************************************************************************** * Copyright 1999-2001 by Bernd Gehrmann * * bernd@kdevelop.org * * Copyright 2007 Dukju Ahn * * Copyright 2010 Benjamin Port * * Copyright 2010 Julien Desgats * * 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 "grepviewplugin.h" #include "grepdialog.h" #include "grepoutputmodel.h" #include "grepoutputdelegate.h" #include "grepjob.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(GrepViewFactory, registerPlugin(); ) K_EXPORT_PLUGIN(GrepViewFactory(KAboutData("kdevgrepview","kdevgrepview", ki18n("Find/Replace In Files"), "0.1", ki18n("Support for running grep over a list of files"), KAboutData::License_GPL))) GrepViewPlugin::GrepViewPlugin( QObject *parent, const QVariantList & ) : KDevelop::IPlugin( GrepViewFactory::componentData(), parent ), m_currentJob(0) { setXMLFile("kdevgrepview.rc"); KAction *action = actionCollection()->addAction("edit_grep"); action->setText(i18n("Find/replace in Fi&les...")); action->setShortcut( i18n("Ctrl+Alt+f") ); connect(action, SIGNAL(triggered(bool)), this, SLOT(showDialogFromMenu())); action->setToolTip( i18n("Search for expressions over several files") ); action->setWhatsThis( i18n("Find/Replace in files

" "Opens the 'Find/Replace in files' dialog. There you " "can enter a regular expression which is then " "searched for within all files in the directories " "you specify. Matches will be displayed, you " "can switch to a match directly. You can also do replacement.

") ); action->setIcon(KIcon("edit-find")); // instantiate delegate, it's supposed to be deleted via QObject inheritance new GrepOutputDelegate(this); } GrepViewPlugin::~GrepViewPlugin() { } KDevelop::ContextMenuExtension GrepViewPlugin::contextMenuExtension(KDevelop::Context* context) { KDevelop::ContextMenuExtension extension = KDevelop::IPlugin::contextMenuExtension(context); if( context->type() == KDevelop::Context::ProjectItemContext ) { KDevelop::ProjectItemContext* ctx = dynamic_cast( context ); QList items = ctx->items(); // verify if there is only one folder selected if ((items.count() == 1) && (items.first()->folder())) { KAction* action = new KAction( i18n( "Find and replace in this folder" ), this ); action->setIcon(KIcon("edit-find")); m_contextMenuDirectory = items.at(0)->folder()->url().toLocalFile(); connect( action, SIGNAL(triggered()), this, SLOT(showDialogFromProject())); extension.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, action ); } } if ( context->type() == KDevelop::Context::EditorContext ) { KDevelop::EditorContext *econtext = dynamic_cast(context); if ( econtext->view()->selection() ) { QAction* action = new QAction(KIcon("edit-find"), i18n("&Find/Replace in Files"), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(showDialogFromMenu())); extension.addAction(KDevelop::ContextMenuExtension::ExtensionGroup, action); } } + if(context->type() == KDevelop::Context::FileContext) { + KDevelop::FileContext *fcontext = dynamic_cast(context); + KMimeType::Ptr mimetype = KMimeType::findByUrl( fcontext->urls().first() ); + if(mimetype->is("inode/directory")) { + KAction* action = new KAction( i18n( "Find and replace in this folder" ), this ); + action->setIcon(KIcon("edit-find")); + m_contextMenuDirectory = fcontext->urls().first().toLocalFile(); + connect( action, SIGNAL(triggered()), this, SLOT(showDialogFromProject())); + extension.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, action ); + } + } return extension; } void GrepViewPlugin::showDialog(bool setLastUsed) { GrepDialog* dlg = new GrepDialog( this, core()->uiController()->activeMainWindow(), setLastUsed ); KDevelop::IDocument* doc = core()->documentController()->activeDocument(); if(!setLastUsed) { QString pattern; if( doc ) { KTextEditor::Range range = doc->textSelection(); if( range.isValid() ) { pattern = doc->textDocument()->text( range ); } if( pattern.isEmpty() ) { pattern = doc->textWord(); } } // Before anything, this removes line feeds from the // beginning and the end. int len = pattern.length(); if (len > 0 && pattern[0] == '\n') { pattern.remove(0, 1); len--; } if (len > 0 && pattern[len-1] == '\n') pattern.truncate(len-1); if (!pattern.isEmpty()) { dlg->setPattern( pattern ); } dlg->enableButtonOk( !pattern.isEmpty() ); } if (!m_directory.isEmpty() && QFileInfo(m_directory).isDir()) { dlg->setDirectory(m_directory); } else { KUrl currentUrl; KDevelop::IDocument *document = core()->documentController()->activeDocument(); dlg->setEnableProjectBox(false); if( document ) { currentUrl = document->url(); } if( currentUrl.isValid() ) { KDevelop::IProject *proj = core()->projectController()->findProjectForUrl( currentUrl ); if( proj && proj->folder().isLocalFile() ) { dlg->setEnableProjectBox(! proj->files().isEmpty() ); if (!m_directory.startsWith(proj->folder().toLocalFile())) { dlg->setDirectory( proj->folder().toLocalFile() ); } } } } dlg->show(); } void GrepViewPlugin::showDialogFromMenu() { showDialog(); } void GrepViewPlugin::showDialogFromProject() { rememberSearchDirectory(m_contextMenuDirectory); showDialog(); } void GrepViewPlugin::rememberSearchDirectory(QString const & directory) { m_directory = directory; } GrepJob* GrepViewPlugin::grepJob() { if(m_currentJob != 0) { m_currentJob->kill(); } m_currentJob = new GrepJob(); connect(m_currentJob, SIGNAL(finished(KJob*)), this, SLOT(jobFinished(KJob*))); return m_currentJob; } void GrepViewPlugin::jobFinished(KJob* job) { if(job == m_currentJob) { m_currentJob = 0; } } #include "grepviewplugin.moc" diff --git a/plugins/openwith/openwithplugin.cpp b/plugins/openwith/openwithplugin.cpp index 0b3672a417..70b16093dd 100644 --- a/plugins/openwith/openwithplugin.cpp +++ b/plugins/openwith/openwithplugin.cpp @@ -1,206 +1,207 @@ /* * This file is part of KDevelop * Copyright 2009 Andreas Pakulat * * This program 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 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., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "openwithplugin.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include - using namespace KDevelop; K_PLUGIN_FACTORY(KDevOpenWithFactory, registerPlugin(); ) K_EXPORT_PLUGIN(KDevOpenWithFactory(KAboutData("kdevopenwith","kdevopenwith", ki18n("Open With"), "0.1", ki18n("Open files with external applications."), KAboutData::License_GPL))) OpenWithPlugin::OpenWithPlugin ( QObject* parent, const QVariantList& ) : IPlugin ( KDevOpenWithFactory::componentData(), parent ), m_actionMap( 0 ) { // setXMLFile( "kdevopenwithui.rc" ); KDEV_USE_EXTENSION_INTERFACE( IOpenWith ) } OpenWithPlugin::~OpenWithPlugin() { } KDevelop::ContextMenuExtension OpenWithPlugin::contextMenuExtension ( KDevelop::Context* context ) { if( m_actionMap ) { delete m_actionMap; m_actionMap = 0; } m_urls = QList(); FileContext* filectx = dynamic_cast( context ); ProjectItemContext* projctx = dynamic_cast( context ); if( filectx && filectx->urls().count() > 0 ) { m_urls = filectx->urls(); } else if ( projctx && projctx->items().count() > 0 ) { foreach( ProjectBaseItem* item, projctx->items() ) { if( item->file() ) { m_urls << item->file()->url(); } } } if( !m_urls.isEmpty() ) { m_actionMap = new QSignalMapper( this ); connect( m_actionMap, SIGNAL(mapped(const QString&)), SLOT(open(const QString&)) ); - + // Ok, lets fetch the mimetype for the !!first!! url and the relevant services // TODO: Think about possible alternatives to using the mimetype of the first url. KMimeType::Ptr mimetype = KMimeType::findByUrl( m_urls.first() ); - m_mimeType = mimetype->name(); - KService::List apps = KMimeTypeTrader::self()->query( m_mimeType ); - KService::Ptr preferredapp = KMimeTypeTrader::self()->preferredService( m_mimeType ); - KService::List parts = KMimeTypeTrader::self()->query( m_mimeType, "KParts/ReadOnlyPart" ); - KService::Ptr preferredpart = KMimeTypeTrader::self()->preferredService( m_mimeType, - "KParts/ReadOnlyPart" ); - - // Now setup a menu with actions for each part and app - KMenu* menu = new KMenu( i18n("Open With" ) ); - menu->setIcon( SmallIcon( "document-open" ) ); - - menu->addActions( actionsForServices( parts, preferredpart ) ); - menu->addActions( actionsForServices( apps, preferredapp ) ); - - KAction* openAction = new KAction( i18n( "Open" ), this ); - openAction->setIcon( SmallIcon( "document-open" ) ); - connect( openAction, SIGNAL( triggered() ), SLOT( openDefault() ) ); - - KDevelop::ContextMenuExtension ext; - ext.addAction( KDevelop::ContextMenuExtension::FileGroup, openAction ); - ext.addAction( KDevelop::ContextMenuExtension::FileGroup, menu->menuAction() ); - return ext; + if(!mimetype->is("inode/directory")){ + m_mimeType = mimetype->name(); + KService::List apps = KMimeTypeTrader::self()->query( m_mimeType ); + KService::Ptr preferredapp = KMimeTypeTrader::self()->preferredService( m_mimeType ); + KService::List parts = KMimeTypeTrader::self()->query( m_mimeType, "KParts/ReadOnlyPart" ); + KService::Ptr preferredpart = KMimeTypeTrader::self()->preferredService( m_mimeType, + "KParts/ReadOnlyPart" ); + + // Now setup a menu with actions for each part and app + KMenu* menu = new KMenu( i18n("Open With" ) ); + menu->setIcon( SmallIcon( "document-open" ) ); + + menu->addActions( actionsForServices( parts, preferredpart ) ); + menu->addActions( actionsForServices( apps, preferredapp ) ); + + KAction* openAction = new KAction( i18n( "Open" ), this ); + openAction->setIcon( SmallIcon( "document-open" ) ); + connect( openAction, SIGNAL( triggered() ), SLOT( openDefault() ) ); + + KDevelop::ContextMenuExtension ext; + ext.addAction( KDevelop::ContextMenuExtension::FileGroup, openAction ); + ext.addAction( KDevelop::ContextMenuExtension::FileGroup, menu->menuAction() ); + return ext; + } } return KDevelop::IPlugin::contextMenuExtension ( context ); } QList< QAction* > OpenWithPlugin::actionsForServices ( const KService::List& list, KService::Ptr pref ) { QList openactions; foreach( KService::Ptr svc, list ) { KAction* act = new KAction( svc->name(), this ); act->setIcon( SmallIcon( svc->icon() ) ); connect(act, SIGNAL(triggered()), m_actionMap, SLOT(map())); m_actionMap->setMapping( act, svc->storageId() ); if( svc->storageId() == pref->storageId() ) { openactions.prepend( act ); } else { openactions.append( act ); } } return openactions; } void OpenWithPlugin::openDefault() { KConfigGroup config = KGlobal::config()->group("Open With Defaults"); if (config.hasKey(m_mimeType)) { QString storageId = config.readEntry(m_mimeType, QString()); if (!storageId.isEmpty() && KService::serviceByStorageId(storageId)) { open(storageId); return; } } foreach( const KUrl& u, m_urls ) { ICore::self()->documentController()->openDocument( u ); } } void OpenWithPlugin::open ( const QString& storageid ) { KService::Ptr svc = KService::serviceByStorageId( storageid ); if( svc->isApplication() ) { KRun::run( *svc, m_urls, ICore::self()->uiController()->activeMainWindow() ); } else { QString prefName = svc->desktopEntryName(); if( svc->serviceTypes().contains( "KTextEditor/Document" ) ) { // If the user chose a KTE part, lets make sure we're creating a TextDocument instead of // a PartDocument by passing no preferredpart to the documentcontroller // TODO: Solve this rather inside DocumentController prefName = ""; } foreach( const KUrl& u, m_urls ) { ICore::self()->documentController()->openDocument( u, prefName ); } } KConfigGroup config = KGlobal::config()->group("Open With Defaults"); if (storageid != config.readEntry(m_mimeType, QString())) { int setDefault = KMessageBox::questionYesNo( qApp->activeWindow(), i18n("Do you want to open %1 files by default with %2?", m_mimeType, svc->name() ), i18n("Set as default?"), KStandardGuiItem::yes(), KStandardGuiItem::no(), QString("OpenWith-%1").arg(m_mimeType) ); if (setDefault == KMessageBox::Yes) { config.writeEntry(m_mimeType, storageid); } } } void OpenWithPlugin::openFilesInternal( const KUrl::List& files ) { if (files.isEmpty()) { return; } m_urls = files; m_mimeType = KMimeType::findByUrl( m_urls.first() )->name(); openDefault(); }