Changeset View
Changeset View
Standalone View
Standalone View
addons/openheader/plugin_kateopenheader.cpp
Show First 20 Lines • Show All 110 Lines • ▼ Show 20 Line(s) | 110 | { | |||
---|---|---|---|---|---|
111 | KTextEditor::Application *application=KTextEditor::Editor::instance()->application(); | 111 | KTextEditor::Application *application=KTextEditor::Editor::instance()->application(); | ||
112 | if (!application->activeMainWindow()) | 112 | if (!application->activeMainWindow()) | ||
113 | return false; | 113 | return false; | ||
114 | 114 | | |||
115 | qDebug() << "Trying to find already opened" << url.toString() << " with extensions " << extensions.join(QStringLiteral(" ")); | 115 | qDebug() << "Trying to find already opened" << url.toString() << " with extensions " << extensions.join(QStringLiteral(" ")); | ||
116 | QString basename = QFileInfo( url.path() ).baseName(); | 116 | QString basename = QFileInfo( url.path() ).baseName(); | ||
117 | QUrl newURL( url ); | 117 | QUrl newURL( url ); | ||
118 | 118 | | |||
119 | for( QStringList::ConstIterator it = extensions.begin(); it != extensions.end(); ++it ) { | 119 | for(const auto& extension : extensions) { | ||
120 | setFileName( &newURL,basename + QStringLiteral(".") + *it ); | 120 | setFileName( &newURL,basename + QStringLiteral(".") + extension ); | ||
121 | KTextEditor::Document *doc= application->findUrl(newURL); | 121 | KTextEditor::Document *doc= application->findUrl(newURL); | ||
122 | if (doc) { | 122 | if (doc) { | ||
123 | application->activeMainWindow()->openUrl(newURL); | 123 | application->activeMainWindow()->openUrl(newURL); | ||
124 | return true; | 124 | return true; | ||
125 | } | 125 | } | ||
126 | setFileName(&newURL, basename + QStringLiteral(".") + (*it).toUpper() ); | 126 | setFileName(&newURL, basename + QStringLiteral(".") + extension.toUpper() ); | ||
127 | doc= application->findUrl(newURL); | 127 | doc= application->findUrl(newURL); | ||
128 | if (doc) { | 128 | if (doc) { | ||
129 | application->activeMainWindow()->openUrl(newURL); | 129 | application->activeMainWindow()->openUrl(newURL); | ||
130 | return true; | 130 | return true; | ||
131 | } | 131 | } | ||
132 | } | 132 | } | ||
133 | return false; | 133 | return false; | ||
134 | } | 134 | } | ||
135 | 135 | | |||
136 | 136 | | |||
137 | void PluginKateOpenHeader::tryOpen( const QUrl& url, const QStringList& extensions ) | 137 | void PluginKateOpenHeader::tryOpen( const QUrl& url, const QStringList& extensions ) | ||
138 | { | 138 | { | ||
139 | KTextEditor::Application *application=KTextEditor::Editor::instance()->application(); | 139 | KTextEditor::Application *application=KTextEditor::Editor::instance()->application(); | ||
140 | if (!application->activeMainWindow()) | 140 | if (!application->activeMainWindow()) | ||
141 | return; | 141 | return; | ||
142 | 142 | | |||
143 | qDebug() << "Trying to open " << url.toString() << " with extensions " << extensions.join(QStringLiteral(" ")); | 143 | qDebug() << "Trying to open " << url.toString() << " with extensions " << extensions.join(QStringLiteral(" ")); | ||
144 | QString basename = QFileInfo( url.path() ).baseName(); | 144 | QString basename = QFileInfo( url.path() ).baseName(); | ||
145 | QUrl newURL( url ); | 145 | QUrl newURL( url ); | ||
146 | 146 | | |||
147 | 147 | | |||
148 | for( QStringList::ConstIterator it = extensions.begin(); it != extensions.end(); ++it ) { | 148 | for(const auto& extension : extensions) { | ||
149 | setFileName( &newURL,basename + QStringLiteral(".") + *it ); | 149 | setFileName( &newURL,basename + QStringLiteral(".") + extension ); | ||
150 | if( fileExists( newURL) ) { | 150 | if( fileExists( newURL) ) { | ||
151 | application->activeMainWindow()->openUrl( newURL ); | 151 | application->activeMainWindow()->openUrl( newURL ); | ||
152 | return; | 152 | return; | ||
153 | } | 153 | } | ||
154 | setFileName(&newURL, basename + QStringLiteral(".") + (*it).toUpper() ); | 154 | setFileName(&newURL, basename + QStringLiteral(".") + extension.toUpper() ); | ||
155 | if( fileExists( newURL) ) { | 155 | if( fileExists( newURL) ) { | ||
156 | application->activeMainWindow()->openUrl( newURL ); | 156 | application->activeMainWindow()->openUrl( newURL ); | ||
157 | return; | 157 | return; | ||
158 | } | 158 | } | ||
159 | } | 159 | } | ||
160 | } | 160 | } | ||
161 | 161 | | |||
162 | bool PluginKateOpenHeader::fileExists(const QUrl &url) | 162 | bool PluginKateOpenHeader::fileExists(const QUrl &url) | ||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |