|
64 | 64 | #define PLATFORM_LINE_ENDING "\n" |
65 | 65 | #endif |
66 | 66 |
|
67 | | -auto static getCorrespondingFile(const QString &fileName) -> QFuture<QString> { |
68 | | - return QtConcurrent::run([fileName]() { |
69 | | - auto static const cExtensions = QStringList{"c", "cpp", "cxx", "cc", "c++"}; |
70 | | - auto static const headerExtensions = QStringList{"h", "hpp", "hh"}; |
71 | | - |
72 | | - auto fileInfo = QFileInfo(fileName); |
73 | | - auto baseName = fileInfo.baseName(); |
74 | | - auto dirPath = fileInfo.absolutePath(); |
75 | | - |
76 | | - if (cExtensions.contains(fileInfo.suffix(), Qt::CaseInsensitive)) { |
77 | | - for (const auto &headerExt : headerExtensions) { |
78 | | - auto headerFileName = dirPath + QDir::separator() + baseName + "." + headerExt; |
79 | | - if (QFileInfo::exists(headerFileName)) { |
80 | | - return headerFileName; |
81 | | - } |
| 67 | +auto static const cExtensions = QStringList{"c", "cpp", "cxx", "cc", "c++"}; |
| 68 | +auto static const headerExtensions = QStringList{"h", "hpp", "hh"}; |
| 69 | + |
| 70 | +auto static getCorrespondingFile(PluginManager *manager, const QString &fileName) |
| 71 | + -> QFuture<QString> { |
| 72 | + |
| 73 | + // First - choose easy solution, file aside the original one |
| 74 | + auto fileInfo = QFileInfo(fileName); |
| 75 | + auto baseName = fileInfo.baseName(); |
| 76 | + auto dirPath = fileInfo.absolutePath(); |
| 77 | + |
| 78 | + if (cExtensions.contains(fileInfo.suffix(), Qt::CaseInsensitive)) { |
| 79 | + for (const auto &headerExt : headerExtensions) { |
| 80 | + auto headerFileName = dirPath + QDir::separator() + baseName + "." + headerExt; |
| 81 | + if (QFileInfo::exists(headerFileName)) { |
| 82 | + return QtFuture::makeReadyValueFuture(headerFileName); |
82 | 83 | } |
83 | | - } else if (headerExtensions.contains(fileInfo.suffix(), Qt::CaseInsensitive)) { |
84 | | - for (const auto &cExt : cExtensions) { |
85 | | - auto cFileName = dirPath + QDir::separator() + baseName + "." + cExt; |
86 | | - if (QFileInfo::exists(cFileName)) { |
87 | | - return cFileName; |
88 | | - } |
| 84 | + } |
| 85 | + } else if (headerExtensions.contains(fileInfo.suffix(), Qt::CaseInsensitive)) { |
| 86 | + for (const auto &cExt : cExtensions) { |
| 87 | + auto cFileName = dirPath + QDir::separator() + baseName + "." + cExt; |
| 88 | + if (QFileInfo::exists(cFileName)) { |
| 89 | + return QtFuture::makeReadyValueFuture(cFileName); |
89 | 90 | } |
90 | 91 | } |
91 | | - return QString{}; |
92 | | - }); |
| 92 | + } |
| 93 | + |
| 94 | + // Did not work, lets ask someone - find me the corresponding file |
| 95 | + // This should be the project manager replying to this, from currently |
| 96 | + // active project. Or maybe from all active projects. |
| 97 | + return manager->handleCommandAsync(GlobalCommands::FindMatchingFile, |
| 98 | + { |
| 99 | + {GlobalArguments::FileName, fileName}, |
| 100 | + }) |
| 101 | + .then([](const CommandArgs &args) { return args.value(GlobalArguments::FileName).toString(); }); |
93 | 102 | } |
94 | 103 |
|
95 | 104 | auto static runningUnderGnome() -> bool { |
@@ -1365,7 +1374,8 @@ void qmdiEditor::fileMessage_clicked(const QString &s) { |
1365 | 1374 | } |
1366 | 1375 |
|
1367 | 1376 | void qmdiEditor::toggleHeaderImpl() { |
1368 | | - getCorrespondingFile(fileName).then(this, [this](const QString &otherFile) { |
| 1377 | + auto manager = dynamic_cast<PluginManager *>(mdiServer->mdiHost); |
| 1378 | + getCorrespondingFile(manager, fileName).then(this, [this](const QString &otherFile) { |
1369 | 1379 | auto nativeFile = QDir::toNativeSeparators(otherFile); |
1370 | 1380 | if (!nativeFile.isEmpty()) { |
1371 | 1381 | auto pluginManager = dynamic_cast<PluginManager *>(mdiServer->mdiHost); |
|
0 commit comments