forked from qt-creator/qt-creator
Fix context menu for the QML virtual folder.
That is: a) Figure out a suitable default location for Add New on a virtual folder. b) If that default location is deployed, don't show a Add Existing Files option, since that is confusing.
This commit is contained in:
@@ -2002,8 +2002,23 @@ void ProjectExplorerPlugin::updateContextMenuActions(Node *node)
|
|||||||
void ProjectExplorerPlugin::addNewFile()
|
void ProjectExplorerPlugin::addNewFile()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->m_currentNode, return)
|
QTC_ASSERT(d->m_currentNode, return)
|
||||||
QFileInfo fi(d->m_currentNode->path());
|
QString path = d->m_currentNode->path();
|
||||||
const QString location = (fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath());
|
QString location;
|
||||||
|
FolderNode *folder = qobject_cast<FolderNode *>(d->m_currentNode);
|
||||||
|
if (path.contains("#") && folder) {
|
||||||
|
// Virtual Folder case
|
||||||
|
// We figure out a commonPath from the subfolders
|
||||||
|
QStringList list;
|
||||||
|
foreach (FolderNode *f, folder->subFolderNodes())
|
||||||
|
list << f->path() + "/";
|
||||||
|
if (list.isEmpty())
|
||||||
|
location = path.left(path.indexOf('#'));
|
||||||
|
else
|
||||||
|
location = Utils::commonPath(list);
|
||||||
|
} else {
|
||||||
|
QFileInfo fi(path);
|
||||||
|
location = (fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath());
|
||||||
|
}
|
||||||
Core::ICore::instance()->showNewItemDialog(tr("New File", "Title of dialog"),
|
Core::ICore::instance()->showNewItemDialog(tr("New File", "Title of dialog"),
|
||||||
Core::IWizard::wizardsOfKind(Core::IWizard::FileWizard)
|
Core::IWizard::wizardsOfKind(Core::IWizard::FileWizard)
|
||||||
+ Core::IWizard::wizardsOfKind(Core::IWizard::ClassWizard),
|
+ Core::IWizard::wizardsOfKind(Core::IWizard::ClassWizard),
|
||||||
|
@@ -53,6 +53,7 @@
|
|||||||
#include <projectexplorer/buildmanager.h>
|
#include <projectexplorer/buildmanager.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
@@ -728,7 +729,7 @@ QList<ProjectNode::ProjectAction> Qt4PriFileNode::supportedActions(Node *node) c
|
|||||||
|
|
||||||
switch (proFileNode->projectType()) {
|
switch (proFileNode->projectType()) {
|
||||||
case ApplicationTemplate:
|
case ApplicationTemplate:
|
||||||
case LibraryTemplate:
|
case LibraryTemplate: {
|
||||||
actions << AddNewFile;
|
actions << AddNewFile;
|
||||||
if (m_recursiveEnumerateFiles.contains(node->path())) {
|
if (m_recursiveEnumerateFiles.contains(node->path())) {
|
||||||
actions << EraseFile;
|
actions << EraseFile;
|
||||||
@@ -736,11 +737,26 @@ QList<ProjectNode::ProjectAction> Qt4PriFileNode::supportedActions(Node *node) c
|
|||||||
actions << RemoveFile;
|
actions << RemoveFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only enable 'add existing file' if we don't deploy the folder
|
bool addExistingFiles = true;
|
||||||
if (!deploysFolder(node->path()))
|
if (node->path().contains('#')) {
|
||||||
|
// A virtual folder, we do what the projectexplorer does
|
||||||
|
FolderNode *folder = qobject_cast<FolderNode *>(node);
|
||||||
|
if (folder) {
|
||||||
|
QStringList list;
|
||||||
|
foreach (FolderNode *f, folder->subFolderNodes())
|
||||||
|
list << f->path() + '/';
|
||||||
|
if (deploysFolder(Utils::commonPath(list)))
|
||||||
|
addExistingFiles = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addExistingFiles = addExistingFiles && deploysFolder(node->path());
|
||||||
|
|
||||||
|
if (addExistingFiles)
|
||||||
actions << AddExistingFile;
|
actions << AddExistingFile;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SubDirsTemplate:
|
case SubDirsTemplate:
|
||||||
actions << AddSubProject << RemoveSubProject;
|
actions << AddSubProject << RemoveSubProject;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user