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 | 84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch) | |
tree | 2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /kate/openheader/plugin_kateopenheader.cpp | |
download | tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.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/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kate/openheader/plugin_kateopenheader.cpp')
-rw-r--r-- | kate/openheader/plugin_kateopenheader.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/kate/openheader/plugin_kateopenheader.cpp b/kate/openheader/plugin_kateopenheader.cpp new file mode 100644 index 0000000..f404022 --- /dev/null +++ b/kate/openheader/plugin_kateopenheader.cpp @@ -0,0 +1,117 @@ +/*************************************************************************** + plugin_katetextfilter.cpp - description + ------------------- + begin : FRE Feb 23 2001 + copyright : (C) 2001 by Joseph Wenninger + email : [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 "plugin_kateopenheader.h" +#include "plugin_kateopenheader.moc" + +#include <qfileinfo.h> +#include <kgenericfactory.h> +#include <kaction.h> +#include <klocale.h> +#include <kdebug.h> +#include <kurl.h> +#include <kio/netaccess.h> + +class PluginView : public KXMLGUIClient +{ + friend class PluginKateOpenHeader; + + public: + Kate::MainWindow *win; +}; + +K_EXPORT_COMPONENT_FACTORY( kateopenheaderplugin, KGenericFactory<PluginKateOpenHeader>( "kateopenheader" ) ) + +PluginKateOpenHeader::PluginKateOpenHeader( QObject* parent, const char* name, const QStringList& ) + : Kate::Plugin ( (Kate::Application *)parent, name ) +{ +} + +PluginKateOpenHeader::~PluginKateOpenHeader() +{ +} + +void PluginKateOpenHeader::addView(Kate::MainWindow *win) +{ + // TODO: doesn't this have to be deleted? + PluginView *view = new PluginView (); + + (void) new KAction( i18n("Open .h/.cpp/.c"), Key_F12, + this, SLOT( slotOpenHeader() ), + view->actionCollection(), "file_openheader" ); + + view->setInstance (new KInstance("kate")); + view->setXMLFile( "plugins/kateopenheader/ui.rc" ); + win->guiFactory()->addClient (view); + view->win = win; + + m_views.append (view); +} + +void PluginKateOpenHeader::removeView(Kate::MainWindow *win) +{ + for (uint z=0; z < m_views.count(); z++) + if (m_views.at(z)->win == win) + { + PluginView *view = m_views.at(z); + m_views.remove (view); + win->guiFactory()->removeClient (view); + delete view; + } +} + +void PluginKateOpenHeader::slotOpenHeader () +{ + if (!application()->activeMainWindow()) + return; + + Kate::View * kv (application()->activeMainWindow()->viewManager()->activeView()); + if (!kv) return; + + KURL url=kv->document()->url(); + if ((!url.isValid()) || (url.isEmpty())) return; + + QFileInfo info( url.path() ); + QString extension = info.extension().lower(); + + QStringList headers( QStringList() << "h" << "H" << "hh" << "hpp" ); + QStringList sources( QStringList() << "c" << "cpp" << "cc" << "cp" << "cxx" ); + + if( sources.find( extension ) != sources.end() ) { + tryOpen( url, headers ); + } else if ( headers.find( extension ) != headers.end() ) { + tryOpen( url, sources ); + } +} + +void PluginKateOpenHeader::tryOpen( const KURL& url, const QStringList& extensions ) +{ + if (!application()->activeMainWindow()) + return; + + kdDebug() << "Trying to open " << url.prettyURL() << " with extensions " << extensions.join(" ") << endl; + QString basename = QFileInfo( url.path() ).baseName(); + KURL newURL( url ); + for( QStringList::ConstIterator it = extensions.begin(); it != extensions.end(); ++it ) { + newURL.setFileName( basename + "." + *it ); + if( KIO::NetAccess::exists( newURL ) ) + application()->activeMainWindow()->viewManager()->openURL( newURL ); + newURL.setFileName( basename + "." + (*it).upper() ); + if( KIO::NetAccess::exists( newURL ) ) + application()->activeMainWindow()->viewManager()->openURL( newURL ); + } +} |