void ResourceEditorPlugin::removeFileContextMenu()
{
    ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());
    QString path = rfn->path().toString();
    FolderNode *parent = rfn->parentFolderNode();
    if (!parent->removeFiles(QStringList() << path))
        QMessageBox::warning(Core::ICore::mainWindow(),
                             tr("File Removal Failed"),
                             tr("Removing file %1 from the project failed.").arg(path));
}
void ResourceEditorPlugin::removePrefixContextMenu()
{
    ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());
    if (QMessageBox::question(Core::ICore::mainWindow(),
                              tr("Remove Prefix"),
                              tr("Remove prefix %1 and all its files?").arg(rfn->displayName()))
            == QMessageBox::Yes) {
        ResourceTopLevelNode *rn = rfn->resourceNode();
        rn->removePrefix(rfn->prefix(), rfn->lang());
    }
}
void ResourceEditorPlugin::renamePrefixContextMenu()
{
    ResourceFolderNode *node = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());

    PrefixLangDialog dialog(tr("Rename Prefix"), node->prefix(), node->lang(), Core::ICore::mainWindow());
    if (dialog.exec() != QDialog::Accepted)
        return;
    QString prefix = dialog.prefix();
    if (prefix.isEmpty())
        return;

    node->renamePrefix(prefix, dialog.lang());
}
Esempio n. 4
0
static bool sortByPrefixAndLang(ProjectExplorer::FolderNode *a, ProjectExplorer::FolderNode *b)
{
    ResourceFolderNode *aa = static_cast<ResourceFolderNode *>(a);
    ResourceFolderNode *bb = static_cast<ResourceFolderNode *>(b);

    if (aa->prefix() < bb->prefix())
        return true;
    if (bb->prefix() < aa->prefix())
        return false;
    return aa->lang() < bb->lang();
}
Esempio n. 5
0
void ResourceTopLevelNode::update()
{
    QList<ProjectExplorer::FolderNode *> newFolderList;
    QMap<QPair<QString, QString>, QList<ProjectExplorer::FileNode *> > filesToAdd;

    ResourceFile file(path().toString());
    if (file.load() == Core::IDocument::OpenResult::Success) {
        QSet<QPair<QString, QString > > prefixes;

        int prfxcount = file.prefixCount();
        for (int i = 0; i < prfxcount; ++i) {
            const QString &prefix = file.prefix(i);
            const QString &lang = file.lang(i);
            // ensure that we don't duplicate prefixes
            if (!prefixes.contains(qMakePair(prefix, lang))) {
                ProjectExplorer::FolderNode *fn = new ResourceFolderNode(file.prefix(i), file.lang(i), this);
                newFolderList << fn;

                prefixes.insert(qMakePair(prefix, lang));
            }

            QSet<QString> fileNames;
            int filecount = file.fileCount(i);
            for (int j = 0; j < filecount; ++j) {
                const QString &fileName = file.file(i, j);
                QString alias = file.alias(i, j);
                if (alias.isEmpty())
                    alias = path().toFileInfo().absoluteDir().relativeFilePath(fileName);
                if (fileNames.contains(fileName)) {
                    // The file name is duplicated, skip it
                    // Note: this is wrong, but the qrceditor doesn't allow it either
                    // only aliases need to be unique
                } else {
                    QString prefixWithSlash = prefix;
                    if (!prefixWithSlash.endsWith(QLatin1Char('/')))
                        prefixWithSlash.append(QLatin1Char('/'));
                    const QString qrcPath = QDir::cleanPath(prefixWithSlash + alias);
                    fileNames.insert(fileName);
                    filesToAdd[qMakePair(prefix, lang)]
                            << new ResourceFileNode(Utils::FileName::fromString(fileName),
                                                    qrcPath, this);
                }

            }
        }
    }

    QList<ProjectExplorer::FolderNode *> oldFolderList = subFolderNodes();
    QList<ProjectExplorer::FolderNode *> foldersToAdd;
    QList<ProjectExplorer::FolderNode *> foldersToRemove;

    std::sort(oldFolderList.begin(), oldFolderList.end(), sortByPrefixAndLang);
    std::sort(newFolderList.begin(), newFolderList.end(), sortByPrefixAndLang);

    ProjectExplorer::compareSortedLists(oldFolderList, newFolderList, foldersToRemove, foldersToAdd, sortByPrefixAndLang);

    removeFolderNodes(foldersToRemove);
    addFolderNodes(foldersToAdd);

    // delete nodes that weren't added
    qDeleteAll(ProjectExplorer::subtractSortedList(newFolderList, foldersToAdd, sortByPrefixAndLang));

    foreach (FolderNode *fn, subFolderNodes()) {
        ResourceFolderNode *rn = static_cast<ResourceFolderNode *>(fn);
        rn->updateFiles(filesToAdd.value(qMakePair(rn->prefix(), rn->lang())));
    }