Commit e5f8a31b authored by dt's avatar dt
Browse files

Fix File/New in the deployment folders.



That is tell the user that those files need not be added to any project,
and show "<Implicitly Add>" for them on the last wizard page.
This fixes Add/New for the QML/OTHER_FILES folder structure, except for
the virtual folder itself.
Reviewed-By: default avatarJarek Kobus <jaroslaw.kobus@nokia.com>
parent 6bc34644
......@@ -174,7 +174,8 @@ QList<ProjectExplorer::ProjectNode::ProjectAction> GenericProjectNode::supported
{
Q_UNUSED(node);
return QList<ProjectAction>()
<< AddFile
<< AddNewFile
<< AddExistingFile
<< RemoveFile;
}
......
......@@ -162,12 +162,12 @@ struct ProjectExplorerPluginPrivate {
QAction *m_debugAction;
QAction *m_addNewFileAction;
QAction *m_addExistingFilesAction;
QAction *m_openFileAction;
QAction *m_showInGraphicalShell;
QAction *m_openTerminalHere;
QAction *m_removeFileAction;
QAction *m_deleteFileAction;
QAction *m_renameFileAction;
QAction *m_openFileAction;
QAction *m_showInGraphicalShell;
QAction *m_openTerminalHere;
QAction *m_projectSelectorAction;
QAction *m_projectSelectorActionMenu;
......@@ -724,6 +724,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
globalcontext);
mfilec->addAction(cmd, Constants::G_FILE_OTHER);
// delete file action
d->m_deleteFileAction = new QAction(tr("Delete File..."), this);
cmd = am->registerAction(d->m_deleteFileAction, ProjectExplorer::Constants::DELETEFILE,
globalcontext);
......@@ -1968,6 +1969,7 @@ void ProjectExplorerPlugin::updateContextMenuActions(Node *node)
d->m_removeFileAction->setEnabled(false);
d->m_deleteFileAction->setEnabled(false);
d->m_addExistingFilesAction->setVisible(true);
d->m_removeFileAction->setVisible(true);
d->m_deleteFileAction->setVisible(true);
......@@ -1976,9 +1978,8 @@ void ProjectExplorerPlugin::updateContextMenuActions(Node *node)
d->m_currentNode->projectNode()->supportedActions(node);
if (qobject_cast<FolderNode*>(d->m_currentNode)) {
bool addFilesEnabled = actions.contains(ProjectNode::AddFile);
d->m_addExistingFilesAction->setEnabled(addFilesEnabled);
d->m_addNewFileAction->setEnabled(addFilesEnabled);
d->m_addNewFileAction->setEnabled(actions.contains(ProjectNode::AddNewFile));
d->m_addExistingFilesAction->setEnabled(actions.contains(ProjectNode::AddExistingFile));
d->m_renameFileAction->setEnabled(actions.contains(ProjectNode::Rename));
} else if (qobject_cast<FileNode*>(d->m_currentNode)) {
// Enable and show remove / delete in magic ways:
......
......@@ -65,24 +65,29 @@ namespace Internal {
class AllProjectNodesVisitor : public NodesVisitor
{
public:
static ProjectNodeList allProjects();
AllProjectNodesVisitor(ProjectNode::ProjectAction action)
: m_action(action)
{}
static ProjectNodeList allProjects(ProjectNode::ProjectAction action);
virtual void visitProjectNode(ProjectNode *node);
private:
ProjectNodeList m_projectNodes;
ProjectNode::ProjectAction m_action;
};
ProjectNodeList AllProjectNodesVisitor::allProjects()
ProjectNodeList AllProjectNodesVisitor::allProjects(ProjectNode::ProjectAction action)
{
AllProjectNodesVisitor visitor;
AllProjectNodesVisitor visitor(action);
ProjectExplorerPlugin::instance()->session()->sessionNode()->accept(&visitor);
return visitor.m_projectNodes;
}
void AllProjectNodesVisitor::visitProjectNode(ProjectNode *node)
{
if (node->supportedActions(node).contains(ProjectNode::AddFile))
if (node->supportedActions(node).contains(m_action))
m_projectNodes.push_back(node);
}
......@@ -179,6 +184,16 @@ ProjectFileWizardExtension::~ProjectFileWizardExtension()
delete m_context;
}
static QList<ProjectEntry> findDeployProject(const QList<ProjectEntry> &projects,
QString &commonPath)
{
QList<ProjectEntry> filtered;
foreach (const ProjectEntry &project, projects)
if (project.node->deploysFolder(commonPath))
filtered << project;
return filtered;
}
// Find the project the new files should be added to given their common
// path. Either a direct match on the directory or the directory with
// the longest matching path (list containing"/project/subproject1" matching
......@@ -219,7 +234,28 @@ void ProjectFileWizardExtension::firstExtensionPageShown(const QList<Core::Gener
m_context->commonDirectory = Utils::commonPath(fileNames);
m_context->page->setFilesDisplay(m_context->commonDirectory, fileNames);
// Find best project (Entry at 0 is 'None').
const int bestProjectIndex = findMatchingProject(m_context->projects, m_context->commonDirectory);
int bestProjectIndex = -1;
QList<ProjectEntry> deployingProjects = findDeployProject(m_context->projects, m_context->commonDirectory);
if (!deployingProjects.isEmpty()) {
// Oh we do have someone that deploys it
// then the best match is NONE
// We display a label explaining that and rename <None> to
// <Implictly Add>
m_context->page->setNoneLabel(tr("<Implictly Add>"));
QString text = tr("The files are implicitly added to the projects:\n");
foreach (ProjectEntry project, deployingProjects)
text += project.fileName + "\n";
m_context->page->setAdditionalInfo(text);
bestProjectIndex = -1;
} else {
bestProjectIndex = findMatchingProject(m_context->projects, m_context->commonDirectory);
m_context->page->setNoneLabel(tr("<None>"));
}
if (bestProjectIndex == -1) {
m_context->page->setCurrentProjectIndex(0);
} else {
......@@ -290,7 +326,8 @@ void ProjectFileWizardExtension::initProjectChoices(bool enabled)
// Sort by base name and purge duplicated entries (resulting from dependencies)
// via Map.
ProjectEntryMap entryMap;
foreach(ProjectNode *n, AllProjectNodesVisitor::allProjects())
foreach(ProjectNode *n, AllProjectNodesVisitor::allProjects(ProjectNode::AddNewFile))
entryMap.insert(ProjectEntry(n), true);
// Collect names
const ProjectEntryMap::const_iterator cend = entryMap.constEnd();
......
......@@ -261,6 +261,12 @@ QList<ProjectNode*> ProjectNode::subProjectNodes() const
\function bool ProjectNode::renameFile(const FileType, const QString &, const QString &)
*/
bool ProjectNode::deploysFolder(const QString &folder) const
{
Q_UNUSED(folder);
return false;
}
QList<NodesWatcher*> ProjectNode::watchers() const
{
return m_watchers;
......
......@@ -159,8 +159,15 @@ public:
enum ProjectAction {
AddSubProject,
RemoveSubProject,
AddFile,
// Let's the user select to which project file
// the file is added
AddNewFile,
AddExistingFile,
// Removes a file from the project, optionally also
// delete it on disc
RemoveFile,
// Deletes a file from the file system, informs the project
// that a file was deleted
// DeleteFile is a define on windows...
EraseFile,
Rename
......@@ -191,6 +198,8 @@ public:
virtual bool renameFile(const FileType fileType,
const QString &filePath,
const QString &newFilePath) = 0;
// by default returns false
virtual bool deploysFolder(const QString &folder) const;
QList<NodesWatcher*> watchers() const;
......
......@@ -74,6 +74,17 @@ void ProjectWizardPage::setCurrentProjectIndex(int idx)
m_ui->projectComboBox->setCurrentIndex(idx);
}
void ProjectWizardPage::setNoneLabel(const QString &label)
{
m_ui->projectComboBox->setItemText(0, label);
}
void ProjectWizardPage::setAdditionalInfo(const QString &text)
{
m_ui->additionalInfo->setText(text);
m_ui->additionalInfo->setVisible(!text.isEmpty());
}
void ProjectWizardPage::setVersionControls(const QStringList &vcs)
{
m_ui->addToVersionControlComboBox->clear();
......
......@@ -52,6 +52,9 @@ public:
int currentProjectIndex() const;
void setCurrentProjectIndex(int);
void setNoneLabel(const QString &label);
void setAdditionalInfo(const QString &text);
void setVersionControls(const QStringList &);
int versionControlIndex() const;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>619</width>
<height>414</height>
<width>226</width>
<height>184</height>
</rect>
</property>
<property name="title">
......@@ -37,9 +37,12 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="addToVersionControlLabel">
<property name="text">
<string>Add to &amp;version control:</string>
......@@ -49,9 +52,19 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="addToVersionControlComboBox"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="additionalInfo">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
......@@ -89,8 +102,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>611</width>
<height>328</height>
<width>218</width>
<height>83</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
......
......@@ -176,7 +176,7 @@ QList<ProjectExplorer::ProjectNode::ProjectAction> QmlProjectNode::supportedActi
{
Q_UNUSED(node);
QList<ProjectAction> actions;
actions.append(AddFile);
actions.append(AddNewFile);
return actions;
}
......
......@@ -702,6 +702,20 @@ void Qt4PriFileNode::folderChanged(const QString &)
contents.updateSubFolders(this, this);
}
bool Qt4PriFileNode::deploysFolder(const QString &folder) const
{
QString f = folder;
if (!f.endsWith('/'))
f.append('/');
foreach (const QString &wf, m_watchedFolders) {
if (f.startsWith(wf)
&& (wf.endsWith('/')
|| (wf.length() < f.length() && f.at(wf.length()) == '/')))
return true;
}
return false;
}
QList<ProjectNode::ProjectAction> Qt4PriFileNode::supportedActions(Node *node) const
{
QList<ProjectAction> actions;
......@@ -715,11 +729,17 @@ QList<ProjectNode::ProjectAction> Qt4PriFileNode::supportedActions(Node *node) c
switch (proFileNode->projectType()) {
case ApplicationTemplate:
case LibraryTemplate:
actions << AddFile;
if (m_recursiveEnumerateFiles.contains(node->path()))
actions << AddNewFile;
if (m_recursiveEnumerateFiles.contains(node->path())) {
actions << EraseFile;
else
} else {
actions << RemoveFile;
}
// Only enable 'add existing file' if we don't deploy the folder
if (!deploysFolder(node->path()))
actions << AddExistingFile;
break;
case SubDirsTemplate:
actions << AddSubProject << RemoveSubProject;
......
......@@ -154,6 +154,8 @@ public:
void folderChanged(const QString &folder);
bool deploysFolder(const QString &folder) const;
protected:
void clear();
static QStringList varNames(FileType type);
......
......@@ -100,7 +100,6 @@ bool QtSingleApplication::isRunning()
return peer->isClient();
}
bool QtSingleApplication::sendMessage(const QString &message, int timeout)
{
return peer->sendMessage(message, timeout);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment