summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Wenninger <jowenn@kde.org>2014-01-21 18:35:46 (GMT)
committerJoseph Wenninger <jowenn@kde.org>2014-01-21 18:35:46 (GMT)
commitcc573ab35fc9f08e5f58e1670eeb077a3475d11d (patch)
tree5a3adcce64f4e3aa7930e78f108ccc246c3baf34
parent2899f2ab5c2838c6d55737fe51194eb71a0e6977 (diff)
Before stating (especially important for network files) search in the list of opened documents
-rw-r--r--addons/kate/openheader/plugin_kateopenheader.cpp35
-rw-r--r--addons/kate/openheader/plugin_kateopenheader.h1
2 files changed, 34 insertions, 2 deletions
diff --git a/addons/kate/openheader/plugin_kateopenheader.cpp b/addons/kate/openheader/plugin_kateopenheader.cpp
index 35647b9..77224ab 100644
--- a/addons/kate/openheader/plugin_kateopenheader.cpp
+++ b/addons/kate/openheader/plugin_kateopenheader.cpp
@@ -110,16 +110,47 @@ void PluginKateOpenHeader::slotOpenHeader ()
QFileInfo info( url.path() );
QString extension = info.suffix().toLower();
- QStringList headers( QStringList() << QStringLiteral("h") << QStringLiteral("H") << QStringLiteral("hh") << QStringLiteral("hpp") );
- QStringList sources( QStringList() << QStringLiteral("c") << QStringLiteral("cpp") << QStringLiteral("cc") << QStringLiteral("cp") << QStringLiteral("cxx") );
+ QStringList headers( QStringList() << QStringLiteral("h") << QStringLiteral("H") << QStringLiteral("hh") << QStringLiteral("hpp") << QStringLiteral("cuh"));
+ QStringList sources( QStringList() << QStringLiteral("c") << QStringLiteral("cpp") << QStringLiteral("cc") << QStringLiteral("cp") << QStringLiteral("cxx") << QStringLiteral("m")<< QStringLiteral("cu"));
if( sources.contains( extension ) ) {
+ if (tryOpenInternal(url, headers)) return;
tryOpen( url, headers );
} else if ( headers.contains( extension ) ) {
+ if (tryOpenInternal(url, sources)) return;
tryOpen( url, sources );
}
}
+
+bool PluginKateOpenHeader::tryOpenInternal( const QUrl& url, const QStringList& extensions )
+{
+ KTextEditor::Application *application=KTextEditor::Editor::instance()->application();
+ if (!application->activeMainWindow())
+ return false;
+
+ qDebug() << "Trying to find already opened" << url.toString() << " with extensions " << extensions.join(QStringLiteral(" "));
+ QString basename = QFileInfo( url.path() ).baseName();
+ QUrl newURL( url );
+
+ for( QStringList::ConstIterator it = extensions.begin(); it != extensions.end(); ++it ) {
+ setFileName( &newURL,basename + QStringLiteral(".") + *it );
+ KTextEditor::Document *doc= application->findUrl(newURL);
+ if (doc) {
+ application->activeMainWindow()->openUrl(newURL);
+ return true;
+ }
+ setFileName(&newURL, basename + QStringLiteral(".") + (*it).toUpper() );
+ doc= application->findUrl(newURL);
+ if (doc) {
+ application->activeMainWindow()->openUrl(newURL);
+ return true;
+ }
+ }
+ return false;
+}
+
+
void PluginKateOpenHeader::tryOpen( const QUrl& url, const QStringList& extensions )
{
KTextEditor::Application *application=KTextEditor::Editor::instance()->application();
diff --git a/addons/kate/openheader/plugin_kateopenheader.h b/addons/kate/openheader/plugin_kateopenheader.h
index 9021488..ee76db4 100644
--- a/addons/kate/openheader/plugin_kateopenheader.h
+++ b/addons/kate/openheader/plugin_kateopenheader.h
@@ -42,6 +42,7 @@ class PluginKateOpenHeader : public KTextEditor::Plugin
public Q_SLOTS:
void slotOpenHeader ();
void tryOpen( const QUrl& url, const QStringList& extensions );
+ bool tryOpenInternal( const QUrl& url, const QStringList& extensions );
private:
bool fileExists(const QUrl &url);
void setFileName(QUrl *url,const QString &_txt);