ProjectExplorer::New File Use addNewInformation also for context menu

So that the resourcenode can steal from it's parent

Change-Id: I97a21d94c0ddb0d217c48fd69dc808446763837b
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Daniel Teske
2014-03-07 16:23:04 +01:00
parent 5bb72be900
commit ca6efdcedc
8 changed files with 48 additions and 39 deletions

View File

@@ -166,7 +166,7 @@ void AddNewProjectNodesVisitor::visitProjectNode(ProjectNode *node)
// for quick sort and path search, provides operator<() for maps. // for quick sort and path search, provides operator<() for maps.
struct FolderEntry { struct FolderEntry {
FolderEntry() : node(0), priority(-1) {} FolderEntry() : node(0), priority(-1) {}
explicit FolderEntry(FolderNode *node, const QStringList &generatedFiles); explicit FolderEntry(FolderNode *node, const QStringList &generatedFiles, Node *contextNode);
int compare(const FolderEntry &rhs) const; int compare(const FolderEntry &rhs) const;
@@ -177,10 +177,10 @@ struct FolderEntry {
int priority; int priority;
}; };
FolderEntry::FolderEntry(FolderNode *n, const QStringList &generatedFiles) : FolderEntry::FolderEntry(FolderNode *n, const QStringList &generatedFiles, Node *contextNode) :
node(n) node(n)
{ {
FolderNode::AddNewInformation info = node->addNewInformation(generatedFiles); FolderNode::AddNewInformation info = node->addNewInformation(generatedFiles, contextNode);
displayName = info.displayName; displayName = info.displayName;
const QFileInfo fi(ProjectExplorerPlugin::pathFor(node)); const QFileInfo fi(ProjectExplorerPlugin::pathFor(node));
baseName = fi.baseName(); baseName = fi.baseName();
@@ -274,20 +274,12 @@ static QList<FolderEntry> findDeployProject(const QList<FolderEntry> &folders,
// the longest matching path (list containing"/project/subproject1" matching // the longest matching path (list containing"/project/subproject1" matching
// common path "/project/subproject1/newuserpath"). // common path "/project/subproject1/newuserpath").
static int findMatchingProject(const QList<FolderEntry> &projects, static int findMatchingProject(const QList<FolderEntry> &projects,
const QString &commonPath, const QString &commonPath)
Node *preferedProjectNode)
{ {
if (projects.isEmpty() || commonPath.isEmpty()) if (projects.isEmpty() || commonPath.isEmpty())
return -1; return -1;
const int count = projects.size(); const int count = projects.size();
if (preferedProjectNode) {
for (int p = 0; p < count; ++p) {
if (projects.at(p).node == preferedProjectNode)
return p;
}
}
int bestMatch = -1; int bestMatch = -1;
int bestMatchLength = 0; int bestMatchLength = 0;
int bestMatchPriority = -1; int bestMatchPriority = -1;
@@ -326,7 +318,7 @@ void ProjectFileWizardExtension::firstExtensionPageShown(
const QList<GeneratedFile> &files, const QList<GeneratedFile> &files,
const QVariantMap &extraValues) const QVariantMap &extraValues)
{ {
initProjectChoices(files); initProjectChoices(files, extraValues);
if (debugExtension) if (debugExtension)
qDebug() << Q_FUNC_INFO << files.size(); qDebug() << Q_FUNC_INFO << files.size();
@@ -360,8 +352,7 @@ void ProjectFileWizardExtension::firstExtensionPageShown(
m_context->page->setAdditionalInfo(text); m_context->page->setAdditionalInfo(text);
bestProjectIndex = -1; bestProjectIndex = -1;
} else { } else {
bestProjectIndex = findMatchingProject(m_context->projects, m_context->commonDirectory, bestProjectIndex = findMatchingProject(m_context->projects, m_context->commonDirectory);
extraValues.value(QLatin1String(Constants::PREFERED_PROJECT_NODE)).value<Node *>());
m_context->page->setNoneLabel(tr("<None>")); m_context->page->setNoneLabel(tr("<None>"));
} }
@@ -446,7 +437,8 @@ static inline void getProjectChoicesAndToolTips(QStringList *projectChoicesParam
QStringList *projectToolTipsParam, QStringList *projectToolTipsParam,
ProjectExplorer::ProjectAction *projectActionParam, ProjectExplorer::ProjectAction *projectActionParam,
const QList<GeneratedFile> &generatedFiles, const QList<GeneratedFile> &generatedFiles,
ProjectWizardContext *context) ProjectWizardContext *context,
Node *contextNode)
{ {
// Set up project list which remains the same over duration of wizard execution // Set up project list which remains the same over duration of wizard execution
// As tooltip, set the directory for disambiguation (should someone have // As tooltip, set the directory for disambiguation (should someone have
@@ -464,7 +456,7 @@ static inline void getProjectChoicesAndToolTips(QStringList *projectChoicesParam
const QString projectFilePath = generatedProjectFilePath(generatedFiles); const QString projectFilePath = generatedProjectFilePath(generatedFiles);
projectAction = ProjectExplorer::AddSubProject; projectAction = ProjectExplorer::AddSubProject;
foreach (ProjectNode *pn, AddNewProjectNodesVisitor::projectNodes(projectFilePath)) foreach (ProjectNode *pn, AddNewProjectNodesVisitor::projectNodes(projectFilePath))
entryMap.insert(FolderEntry(pn, QStringList() << projectFilePath), true); entryMap.insert(FolderEntry(pn, QStringList() << projectFilePath, contextNode), true);
} else { } else {
QStringList filePaths; QStringList filePaths;
@@ -473,7 +465,7 @@ static inline void getProjectChoicesAndToolTips(QStringList *projectChoicesParam
projectAction = ProjectExplorer::AddNewFile; projectAction = ProjectExplorer::AddNewFile;
foreach (FolderNode *fn, AddNewFileNodesVisitor::allFolders()) foreach (FolderNode *fn, AddNewFileNodesVisitor::allFolders())
entryMap.insert(FolderEntry(fn, filePaths), true); entryMap.insert(FolderEntry(fn, filePaths, contextNode), true);
} }
context->projects.clear(); context->projects.clear();
@@ -491,14 +483,15 @@ static inline void getProjectChoicesAndToolTips(QStringList *projectChoicesParam
*projectActionParam = projectAction; *projectActionParam = projectAction;
} }
void ProjectFileWizardExtension::initProjectChoices(const QList<GeneratedFile> generatedFiles) void ProjectFileWizardExtension::initProjectChoices(const QList<GeneratedFile> generatedFiles, const QVariantMap &extraValues)
{ {
QStringList projectChoices; QStringList projectChoices;
QStringList projectToolTips; QStringList projectToolTips;
ProjectExplorer::ProjectAction projectAction; ProjectExplorer::ProjectAction projectAction;
getProjectChoicesAndToolTips(&projectChoices, &projectToolTips, &projectAction, getProjectChoicesAndToolTips(&projectChoices, &projectToolTips, &projectAction,
generatedFiles, m_context); generatedFiles, m_context,
extraValues.value(QLatin1String(Constants::PREFERED_PROJECT_NODE)).value<Node *>());
m_context->page->setProjects(projectChoices); m_context->page->setProjects(projectChoices);
m_context->page->setProjectToolTips(projectToolTips); m_context->page->setProjectToolTips(projectToolTips);

View File

@@ -61,7 +61,7 @@ public slots:
void initializeVersionControlChoices(); void initializeVersionControlChoices();
private: private:
void initProjectChoices(const QList<Core::GeneratedFile> generatedFiles); void initProjectChoices(const QList<Core::GeneratedFile> generatedFiles, const QVariantMap &extraValues);
bool processProject(const QList<Core::GeneratedFile> &files, bool processProject(const QList<Core::GeneratedFile> &files,
bool *removeOpenProjectAttribute, QString *errorMessage); bool *removeOpenProjectAttribute, QString *errorMessage);
bool processVersionControl(const QList<Core::GeneratedFile> &files, QString *errorMessage); bool processVersionControl(const QList<Core::GeneratedFile> &files, QString *errorMessage);

View File

@@ -341,10 +341,10 @@ bool FolderNode::renameFile(const QString &filePath, const QString &newFilePath)
return false; return false;
} }
FolderNode::AddNewInformation FolderNode::addNewInformation(const QStringList &files) const FolderNode::AddNewInformation FolderNode::addNewInformation(const QStringList &files, Node *context) const
{ {
Q_UNUSED(files); Q_UNUSED(files);
return AddNewInformation(QFileInfo(path()).fileName(), 100); return AddNewInformation(QFileInfo(path()).fileName(), context == this ? 120 : 100);
} }
/*! /*!

View File

@@ -189,7 +189,7 @@ public:
int priority; int priority;
}; };
virtual AddNewInformation addNewInformation(const QStringList &files) const; virtual AddNewInformation addNewInformation(const QStringList &files, Node *context) const;
void addFileNodes(const QList<FileNode*> &files); void addFileNodes(const QList<FileNode*> &files);
void removeFileNodes(const QList<FileNode*> &files); void removeFileNodes(const QList<FileNode*> &files);

View File

@@ -1066,10 +1066,10 @@ bool QmakePriFileNode::renameFile(const QString &filePath, const QString &newFil
return true; return true;
} }
ProjectExplorer::FolderNode::AddNewInformation QmakePriFileNode::addNewInformation(const QStringList &files) const ProjectExplorer::FolderNode::AddNewInformation QmakePriFileNode::addNewInformation(const QStringList &files, Node *context) const
{ {
Q_UNUSED(files) Q_UNUSED(files)
return ProjectExplorer::FolderNode::AddNewInformation(QFileInfo(path()).fileName(), 90); return ProjectExplorer::FolderNode::AddNewInformation(QFileInfo(path()).fileName(), context == this ? 120 : 90);
} }
bool QmakePriFileNode::priFileWritable(const QString &path) bool QmakePriFileNode::priFileWritable(const QString &path)
@@ -1572,10 +1572,10 @@ bool QmakeProFileNode::hasBuildTargets() const
return hasBuildTargets(projectType()); return hasBuildTargets(projectType());
} }
ProjectExplorer::FolderNode::AddNewInformation QmakeProFileNode::addNewInformation(const QStringList &files) const ProjectExplorer::FolderNode::AddNewInformation QmakeProFileNode::addNewInformation(const QStringList &files, Node *context) const
{ {
Q_UNUSED(files) Q_UNUSED(files)
return AddNewInformation(QFileInfo(path()).fileName(), 100); return AddNewInformation(QFileInfo(path()).fileName(), context == this ? 120 : 100);
} }
bool QmakeProFileNode::hasBuildTargets(QmakeProjectType projectType) const bool QmakeProFileNode::hasBuildTargets(QmakeProjectType projectType) const

View File

@@ -158,7 +158,7 @@ public:
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0); bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
bool deleteFiles(const QStringList &filePaths); bool deleteFiles(const QStringList &filePaths);
bool renameFile(const QString &filePath, const QString &newFilePath); bool renameFile(const QString &filePath, const QString &newFilePath);
AddNewInformation addNewInformation(const QStringList &files) const; AddNewInformation addNewInformation(const QStringList &files, Node *context) const;
bool setProVariable(const QString &var, const QString &value); bool setProVariable(const QString &var, const QString &value);
@@ -368,7 +368,7 @@ public:
bool hasBuildTargets() const; bool hasBuildTargets() const;
AddNewInformation addNewInformation(const QStringList &files) const; AddNewInformation addNewInformation(const QStringList &files, Node *context) const;
QmakeProjectType projectType() const; QmakeProjectType projectType() const;

View File

@@ -45,7 +45,7 @@
using namespace ResourceEditor; using namespace ResourceEditor;
using namespace ResourceEditor::Internal; using namespace ResourceEditor::Internal;
static int priority(const QStringList &files) static bool priority(const QStringList &files)
{ {
if (files.isEmpty()) if (files.isEmpty())
return -1; return -1;
@@ -54,8 +54,8 @@ static int priority(const QStringList &files)
if (type.startsWith(QLatin1String("image/")) if (type.startsWith(QLatin1String("image/"))
|| type == QLatin1String(QmlJSTools::Constants::QML_MIMETYPE) || type == QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
|| type == QLatin1String(QmlJSTools::Constants::JS_MIMETYPE)) || type == QLatin1String(QmlJSTools::Constants::JS_MIMETYPE))
return 120; return true;
return 80; return false;
} }
static bool addFilesToResource(const QString &resourceFile, const QStringList &filePaths, QStringList *notAdded, static bool addFilesToResource(const QString &resourceFile, const QStringList &filePaths, QStringList *notAdded,
@@ -244,12 +244,21 @@ bool ResourceTopLevelNode::removePrefix(const QString &prefix, const QString &la
return false; return false;
} }
ProjectExplorer::FolderNode::AddNewInformation ResourceTopLevelNode::addNewInformation(const QStringList &files) const ProjectExplorer::FolderNode::AddNewInformation ResourceTopLevelNode::addNewInformation(const QStringList &files, Node *context) const
{ {
QString name = tr("%1 Prefix: %2") QString name = tr("%1 Prefix: %2")
.arg(QFileInfo(path()).fileName()) .arg(QFileInfo(path()).fileName())
.arg(QLatin1String("/")); .arg(QLatin1String("/"));
return AddNewInformation(name, priority(files) + 1);
int p = 80;
if (priority(files)) {
if (context == 0 || context == this)
p = 125;
else if (projectNode() == context)
p = 150; // steal from our project node
}
return AddNewInformation(name, p);
} }
ResourceFolderNode::ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent) ResourceFolderNode::ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent)
@@ -357,12 +366,19 @@ bool ResourceFolderNode::renamePrefix(const QString &prefix, const QString &lang
return true; return true;
} }
ProjectExplorer::FolderNode::AddNewInformation ResourceFolderNode::addNewInformation(const QStringList &files) const ProjectExplorer::FolderNode::AddNewInformation ResourceFolderNode::addNewInformation(const QStringList &files, Node *context) const
{ {
QString name = tr("%1 Prefix: %2") QString name = tr("%1 Prefix: %2")
.arg(QFileInfo(m_topLevelNode->path()).fileName()) .arg(QFileInfo(m_topLevelNode->path()).fileName())
.arg(displayName()); .arg(displayName());
return AddNewInformation(name, priority(files) + 1);
int p = 80;
if (priority(files)) {
if (context == 0 || context == this)
p = 120;
}
return AddNewInformation(name, p);
} }
QString ResourceFolderNode::displayName() const QString ResourceFolderNode::displayName() const

View File

@@ -59,7 +59,7 @@ public:
bool addPrefix(const QString &prefix, const QString &lang); bool addPrefix(const QString &prefix, const QString &lang);
bool removePrefix(const QString &prefix, const QString &lang); bool removePrefix(const QString &prefix, const QString &lang);
AddNewInformation addNewInformation(const QStringList &files) const; AddNewInformation addNewInformation(const QStringList &files, Node *context) const;
private: private:
Internal::ResourceFileWatcher *m_document; Internal::ResourceFileWatcher *m_document;
@@ -84,7 +84,7 @@ public:
bool renamePrefix(const QString &prefix, const QString &lang); bool renamePrefix(const QString &prefix, const QString &lang);
AddNewInformation addNewInformation(const QStringList &files) const; AddNewInformation addNewInformation(const QStringList &files, Node *context) const;
QString prefix() const; QString prefix() const;
QString lang() const; QString lang() const;