예제 #1
0
Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w,
                                                         QString *errorMessage) const
{
    Q_UNUSED(errorMessage)

    const GenericProjectWizardDialog *wizard = qobject_cast<const GenericProjectWizardDialog *>(w);
    const QString projectPath = wizard->path();
    const QDir dir(projectPath);
    const QString projectName = wizard->projectName();
    const QString creatorFileName = QFileInfo(dir, projectName + QLatin1String(".creator")).absoluteFilePath();
    const QString filesFileName = QFileInfo(dir, projectName + QLatin1String(".files")).absoluteFilePath();
    const QString includesFileName = QFileInfo(dir, projectName + QLatin1String(".includes")).absoluteFilePath();
    const QString configFileName = QFileInfo(dir, projectName + QLatin1String(".config")).absoluteFilePath();
    const QStringList paths = wizard->selectedPaths();

    Utils::MimeDatabase mdb;
    Utils::MimeType headerTy = mdb.mimeTypeForName(QLatin1String("text/x-chdr"));

    QStringList nameFilters = headerTy.globPatterns();

    QStringList includePaths;
    foreach (const QString &path, paths) {
        QFileInfo fileInfo(path);
        QDir thisDir(fileInfo.absoluteFilePath());

        if (! thisDir.entryList(nameFilters, QDir::Files).isEmpty()) {
            QString relative = dir.relativeFilePath(path);
            if (relative.isEmpty())
                relative = QLatin1Char('.');
            includePaths.append(relative);
        }
    }
예제 #2
0
// Switch between form ('ui') and source file ('cpp'):
// Find corresponding 'other' file, simply assuming it is in the same directory.
static QString otherFile()
{
    // Determine mime type of current file.
    const QString current = currentFile();
    if (current.isEmpty())
        return QString();
    Utils::MimeDatabase mdb;
    const Utils::MimeType currentMimeType = mdb.mimeTypeForFile(current);
    if (!currentMimeType.isValid())
        return QString();
    // Determine potential suffixes of candidate files
    // 'ui' -> 'cpp', 'cpp/h' -> 'ui'.
    QStringList candidateSuffixes;
    if (currentMimeType.matchesName(QLatin1String(FORM_MIMETYPE))) {
        candidateSuffixes += mdb.mimeTypeForName(
                    QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)).suffixes();
    } else if (currentMimeType.matchesName(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE))
               || currentMimeType.matchesName(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))) {
        candidateSuffixes += mdb.mimeTypeForName(QLatin1String(FORM_MIMETYPE)).suffixes();
    } else {
        return QString();
    }
    // Try to find existing file with desired suffix
    const QFileInfo currentFI(current);
    const QString currentBaseName = currentFI.path() + QLatin1Char('/')
            + currentFI.baseName() + QLatin1Char('.');
    foreach (const QString &candidateSuffix, candidateSuffixes) {
        const QFileInfo fi(currentBaseName + candidateSuffix);
        if (fi.isFile())
            return fi.absoluteFilePath();
    }
    return QString();
}
void CustomWizardContext::reset()
{
    // Basic replacement fields: Suffixes and date/time.
    const QDate currentDate = QDate::currentDate();
    const QTime currentTime = QTime::currentTime();
    baseReplacements.clear();
    Utils::MimeDatabase mdb;
    baseReplacements.insert(QLatin1String("CppSourceSuffix"),
                            mdb.mimeTypeForName(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE))
                            .preferredSuffix());
    baseReplacements.insert(QLatin1String("CppHeaderSuffix"),
                            mdb.mimeTypeForName(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))
                            .preferredSuffix());
    baseReplacements.insert(QLatin1String("CurrentDate"),
                            currentDate.toString(Qt::ISODate));
    baseReplacements.insert(QLatin1String("CurrentTime"),
                            currentTime.toString(Qt::ISODate));
    baseReplacements.insert(QLatin1String("CurrentDate:ISO"),
                            currentDate.toString(Qt::ISODate));
    baseReplacements.insert(QLatin1String("CurrentTime:ISO"),
                            currentTime.toString(Qt::ISODate));
    baseReplacements.insert(QLatin1String("CurrentDate:RFC"),
                            currentDate.toString(Qt::RFC2822Date));
    baseReplacements.insert(QLatin1String("CurrentTime:RFC"),
                            currentTime.toString(Qt::RFC2822Date));
    baseReplacements.insert(QLatin1String("CurrentDate:Locale"),
                            currentDate.toString(Qt::DefaultLocaleShortDate));
    baseReplacements.insert(QLatin1String("CurrentTime:Locale"),
                            currentTime.toString(Qt::DefaultLocaleShortDate));
    replacements.clear();
    path.clear();
    targetPath.clear();
}
int ROSBuildConfigurationFactory::priority(const Kit *k, const QString &projectPath) const
{
    Utils::MimeDatabase mdb;
    if (k && mdb.mimeTypeForFile(projectPath).matchesName(QLatin1String(Constants::ROSMIMETYPE)))
        return 0;
    return -1;
}
예제 #5
0
void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files)
{
    Project *project = 0;
    QList<IProjectManager *> managerList = ExtensionSystem::PluginManager::getObjects<IProjectManager>();

    foreach (const JsonWizard::GeneratorFile &f, files) {
        if (f.file.attributes() & GeneratedFile::OpenProjectAttribute) {
            QString errorMessage;
            QString path = f.file.path();
            const QFileInfo fi(path);

            if (fi.exists())
                path = fi.canonicalFilePath();

            Utils::MimeDatabase mdb;
            Utils::MimeType mt = mdb.mimeTypeForFile(fi);
            if (!mt.isValid())
                continue;

            auto manager = Utils::findOrDefault(managerList, Utils::equal(&IProjectManager::mimeType, mt.name()));
            project = manager ? manager->openProject(path, &errorMessage) : 0;
            if (project) {
                if (setupProject(project))
                    project->saveSettings();
                delete project;
                project = 0;
            }
        }
    }
}
int CMakeBuildConfigurationFactory::priority(const ProjectExplorer::Kit *k, const QString &projectPath) const
{
    Utils::MimeDatabase mdb;
    if (k && mdb.mimeTypeForFile(projectPath).matchesName(QLatin1String(Constants::CMAKEPROJECTMIMETYPE)))
        return 0;
    return -1;
}
예제 #7
0
void ProjectFileAdder::addMapping(const char *mimeName, ProjectFile::Kind kind)
{
    Utils::MimeDatabase mdb;
    Utils::MimeType mimeType = mdb.mimeTypeForName(QLatin1String(mimeName));
    if (mimeType.isValid())
        m_mimeNameMapping.insert(mimeType.name(), kind);
}
void QmlProjectRunConfiguration::updateEnabled()
{
    bool qmlFileFound = false;
    if (mainScriptSource() == FileInEditor) {
        Utils::MimeDatabase mimeDataBase;
        IDocument *document = EditorManager::currentDocument();
        Utils::MimeType mainScriptMimeType = mimeDataBase.mimeTypeForFile(mainScript());
        if (document) {
            m_currentFileFilename = document->filePath().toString();
            if (mainScriptMimeType.matchesName(QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE)))
                qmlFileFound = true;
        }
        if (!document
                || mainScriptMimeType.matchesName(QLatin1String(QmlJSTools::Constants::QMLPROJECT_MIMETYPE))) {
            // find a qml file with lowercase filename. This is slow, but only done
            // in initialization/other border cases.
            foreach (const QString &filename, target()->project()->files(Project::AllFiles)) {
                const QFileInfo fi(filename);

                if (!filename.isEmpty() && fi.baseName()[0].isLower()
                        && mimeDataBase.mimeTypeForFile(fi).matchesName(QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE)))
                {
                    m_currentFileFilename = filename;
                    qmlFileFound = true;
                    break;
                }

            }
        }
예제 #9
0
bool ProjectFileAdder::maybeAdd(const QString &path)
{
    Utils::MimeDatabase mdb;
    const Utils::MimeType mt = mdb.mimeTypeForFile(path);
    if (m_mimeNameMapping.contains(mt.name())) {
        m_files << ProjectFile(path, m_mimeNameMapping.value(mt.name()));
        return true;
    }
    return false;
}
CppFileSettingsWidget::CppFileSettingsWidget(QWidget *parent) :
    QWidget(parent),
    m_ui(new Internal::Ui::CppFileSettingsPage)
{
    m_ui->setupUi(this);
    // populate suffix combos
    Utils::MimeDatabase mdb;
    const Utils::MimeType sourceMt = mdb.mimeTypeForName(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE));
    if (sourceMt.isValid()) {
        foreach (const QString &suffix, sourceMt.suffixes())
            m_ui->sourceSuffixComboBox->addItem(suffix);
    }
예제 #11
0
static bool priority(const QStringList &files)
{
    if (files.isEmpty())
        return false;
    Utils::MimeDatabase mdb;
    QString type = mdb.mimeTypeForFile(files.at(0)).name();
    if (type.startsWith(QLatin1String("image/"))
            || type == QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
            || type == QLatin1String(QmlJSTools::Constants::JS_MIMETYPE))
        return true;
    return false;
}
QString BaseFileWizardFactory::preferredSuffix(const QString &mimeType)
{
    QString rc;
    Utils::MimeDatabase mdb;
    Utils::MimeType mt = mdb.mimeTypeForName(mimeType);
    if (mt.isValid())
        rc = mt.preferredSuffix();
    if (rc.isEmpty())
        qWarning("%s: WARNING: Unable to find a preferred suffix for %s.",
                 Q_FUNC_INFO, mimeType.toUtf8().constData());
    return rc;
}
예제 #13
0
bool AbstractSettings::isApplicable(const Core::IDocument *document) const
{
    if (!document)
        return false;

    if (m_supportedMimeTypes.isEmpty())
        return true;

    const Utils::MimeDatabase mdb;
    const Utils::MimeType documentMimeType = mdb.mimeTypeForName(document->mimeType());
    return Utils::anyOf(m_supportedMimeTypes, [&documentMimeType](const QString &mime) {
        return documentMimeType.inherits(mime);
    });
}
예제 #14
0
// Return the suffixes that should be checked when trying to find a
// source belonging to a header and vice versa
static QStringList matchingCandidateSuffixes(ProjectFile::Kind kind)
{
    Utils::MimeDatabase mdb;
    switch (kind) {
     // Note that C/C++ headers are undistinguishable
    case ProjectFile::CHeader:
    case ProjectFile::CXXHeader:
    case ProjectFile::ObjCHeader:
    case ProjectFile::ObjCXXHeader:
        return mdb.mimeTypeForName(QLatin1String(Constants::C_SOURCE_MIMETYPE)).suffixes()
                + mdb.mimeTypeForName(QLatin1String(Constants::CPP_SOURCE_MIMETYPE)).suffixes()
                + mdb.mimeTypeForName(QLatin1String(Constants::OBJECTIVE_C_SOURCE_MIMETYPE)).suffixes()
                + mdb.mimeTypeForName(QLatin1String(Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)).suffixes();
    case ProjectFile::CSource:
    case ProjectFile::ObjCSource:
        return mdb.mimeTypeForName(QLatin1String(Constants::C_HEADER_MIMETYPE)).suffixes();
    case ProjectFile::CXXSource:
    case ProjectFile::ObjCXXSource:
    case ProjectFile::CudaSource:
    case ProjectFile::OpenCLSource:
        return mdb.mimeTypeForName(QLatin1String(Constants::CPP_HEADER_MIMETYPE)).suffixes();
    default:
        return QStringList();
    }
}
예제 #15
0
QString Manager::definitionIdByMimeType(const Utils::MimeType &mimeType) const
{
    Utils::MimeDatabase mdb;
    QList<Utils::MimeType> queue;
    queue.append(mimeType);
    while (!queue.isEmpty()) {
        const Utils::MimeType mt = queue.takeFirst();
        const QString id = m_register.m_idByMimeType.value(mt.name());
        if (!id.isEmpty())
            return id;
        foreach (const QString &parent, mt.parentMimeTypes()) {
            const Utils::MimeType parentMt = mdb.mimeTypeForName(parent);
            if (parentMt.isValid())
                queue.append(parentMt);
        }
    }
    return QString();
}
예제 #16
0
void AbstractSettings::setSupportedMimeTypes(const QString &mimes)
{
    const QStringList stringTypes = mimes.split(';');
    const Utils::MimeDatabase mdb;
    QStringList types;
    for (const QString &type : stringTypes) {
        const Utils::MimeType mime = mdb.mimeTypeForName(type.trimmed());
        if (!mime.isValid())
            continue;
        const QString canonicalName = mime.name();
        if (!types.contains(canonicalName))
            types << canonicalName;
    }

    if (m_supportedMimeTypes != types) {
        m_supportedMimeTypes = types;
        emit supportedMimeTypesChanged();
    }
}
예제 #17
0
ProjectFile::Kind ProjectFile::classify(const QString &file)
{
    Utils::MimeDatabase mdb;
    const Utils::MimeType mimeType = mdb.mimeTypeForFile(file);
    if (!mimeType.isValid())
        return Unclassified;
    const QString mt = mimeType.name();
    if (mt == QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE))
        return CSource;
    if (mt == QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE))
        return CHeader;
    if (mt == QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE))
        return CXXSource;
    if (mt == QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))
        return CXXHeader;
    if (mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE))
        return ObjCSource;
    if (mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE))
        return ObjCXXSource;
    return Unclassified;
}
예제 #18
0
void CppEditorDocument::onFilePathChanged(const Utils::FileName &oldPath,
        const Utils::FileName &newPath)
{
    Q_UNUSED(oldPath);

    if (!newPath.isEmpty()) {
        Utils::MimeDatabase mdb;
        setMimeType(mdb.mimeTypeForFile(newPath.toFileInfo()).name());

        disconnect(this, SIGNAL(contentsChanged()), this, SLOT(scheduleProcessDocument()));
        connect(this, SIGNAL(contentsChanged()), this, SLOT(scheduleProcessDocument()));

        // Un-Register/Register in ModelManager
        m_editorDocumentHandle.reset();
        m_editorDocumentHandle.reset(new CppEditorDocumentHandleImpl(this));

        resetProcessor();
        updatePreprocessorSettings();
        m_processorRevision = document()->revision();
        processDocument();
    }
}
예제 #19
0
            .arg(loc.functionName(), QDir::toNativeSeparators(loc.fileName()));
        d->engine->showMessage(msg);
        setContentsToDocument(d->cache.at(index).second);
        d->resetLocationScheduled = false; // In case reset from previous run still pending.
    } else {
        d->engine->fetchDisassembler(this);
    }
}

void DisassemblerAgentPrivate::configureMimeType()
{
    QTC_ASSERT(document, return);

    document->setMimeType(mimeType);

    Utils::MimeDatabase mdb;
    Utils::MimeType mtype = mdb.mimeTypeForName(mimeType);
    if (mtype.isValid()) {
        foreach (IEditor *editor, DocumentModel::editorsForDocument(document))
            if (TextEditorWidget *widget = qobject_cast<TextEditorWidget *>(editor->widget()))
                widget->configureGenericHighlighter();
    } else {
        qWarning("Assembler mimetype '%s' not found.", qPrintable(mimeType));
    }
}

QString DisassemblerAgent::mimeType() const
{
    return d->mimeType;
}