forked from qt-creator/qt-creator
CMakePM: Copy the header file name to clipboard after adding class
Fixes: QTCREATORBUG-25212 Fixes: QTCREATORBUG-24301 Change-Id: Idf6104548223f6d26820bc395ee60c1a8c794c6d Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -78,27 +78,32 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void copySourcePathToClipboard(Utils::optional<QString> srcPath,
|
void copySourcePathsToClipboard(const QStringList &srcPaths,
|
||||||
const ProjectExplorer::ProjectNode *node)
|
const ProjectExplorer::ProjectNode *node)
|
||||||
{
|
{
|
||||||
QClipboard *clip = QGuiApplication::clipboard();
|
QClipboard *clip = QGuiApplication::clipboard();
|
||||||
|
|
||||||
QDir projDir{node->filePath().toFileInfo().absoluteFilePath()};
|
QDir projDir{node->filePath().toFileInfo().absoluteFilePath()};
|
||||||
clip->setText(QDir::cleanPath(projDir.relativeFilePath(srcPath.value())));
|
QString data = Utils::transform(srcPaths, [projDir](const QString &path) {
|
||||||
|
return QDir::cleanPath(projDir.relativeFilePath(path));
|
||||||
|
}).join(" ");
|
||||||
|
clip->setText(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::ProjectNode *node)
|
void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::ProjectNode *node)
|
||||||
{
|
{
|
||||||
Utils::optional<QString> srcPath{};
|
const QStringList srcPaths = Utils::filtered(filePaths, [](const QString& file) {
|
||||||
|
const auto mimeType = Utils::mimeTypeForFile(file).name();
|
||||||
|
return mimeType == CppTools::Constants::C_SOURCE_MIMETYPE ||
|
||||||
|
mimeType == CppTools::Constants::C_HEADER_MIMETYPE ||
|
||||||
|
mimeType == CppTools::Constants::CPP_SOURCE_MIMETYPE ||
|
||||||
|
mimeType == CppTools::Constants::CPP_HEADER_MIMETYPE ||
|
||||||
|
mimeType == ProjectExplorer::Constants::FORM_MIMETYPE ||
|
||||||
|
mimeType == ProjectExplorer::Constants::RESOURCE_MIMETYPE ||
|
||||||
|
mimeType == ProjectExplorer::Constants::SCXML_MIMETYPE;
|
||||||
|
});
|
||||||
|
|
||||||
for (const QString &file : filePaths) {
|
if (!srcPaths.empty()) {
|
||||||
if (Utils::mimeTypeForFile(file).name() == CppTools::Constants::CPP_SOURCE_MIMETYPE) {
|
|
||||||
srcPath = file;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (srcPath) {
|
|
||||||
CMakeProjectManager::Internal::CMakeSpecificSettings *settings
|
CMakeProjectManager::Internal::CMakeSpecificSettings *settings
|
||||||
= CMakeProjectManager::Internal::CMakeProjectPlugin::projectTypeSpecificSettings();
|
= CMakeProjectManager::Internal::CMakeProjectPlugin::projectTypeSpecificSettings();
|
||||||
switch (settings->afterAddFileSetting()) {
|
switch (settings->afterAddFileSetting()) {
|
||||||
@@ -126,13 +131,13 @@ void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::P
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (QDialogButtonBox::Yes == reply) {
|
if (QDialogButtonBox::Yes == reply) {
|
||||||
copySourcePathToClipboard(srcPath, node);
|
copySourcePathsToClipboard(srcPaths, node);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CMakeProjectManager::Internal::COPY_FILE_PATH: {
|
case CMakeProjectManager::Internal::COPY_FILE_PATH: {
|
||||||
copySourcePathToClipboard(srcPath, node);
|
copySourcePathsToClipboard(srcPaths, node);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user