ProjectNodes: Add line information and act on it

Also allow for the path to be set. Qbs can move products from one
file to the next, so that is needed there.

Change-Id: Iebaf3be40fdb0e5e462d45b00cf46d58f985a163
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Tobias Hunger
2013-01-30 18:13:46 +01:00
committed by hjk
parent 1fda2111d4
commit f20b92f913
3 changed files with 46 additions and 5 deletions

View File

@@ -73,6 +73,16 @@ Node::Node(NodeType nodeType,
} }
/*!
* \brief The path of the file representing this node.
*
* This method does not emit any signals, that has to be done by the calling class!
*/
void Node::setPath(const QString &path)
{
m_path = path;
}
NodeType Node::nodeType() const NodeType Node::nodeType() const
{ {
return m_nodeType; return m_nodeType;
@@ -102,6 +112,11 @@ QString Node::path() const
return m_path; return m_path;
} }
int Node::line() const
{
return -1;
}
QString Node::displayName() const QString Node::displayName() const
{ {
return QFileInfo(path()).fileName(); return QFileInfo(path()).fileName();
@@ -241,6 +256,24 @@ void FolderNode::setIcon(const QIcon &icon)
m_icon = icon; m_icon = icon;
} }
FileNode *FolderNode::findFile(const QString &path)
{
foreach (FileNode *n, fileNodes()) {
if (n->path() == path)
return n;
}
return 0;
}
FolderNode *FolderNode::findSubFolder(const QString &path)
{
foreach (FolderNode *n, subFolderNodes()) {
if (n->path() == path)
return n;
}
return 0;
}
/*! /*!
\class ProjectExplorer::VirtualFolderNode \class ProjectExplorer::VirtualFolderNode

View File

@@ -85,11 +85,15 @@ public:
ProjectNode *projectNode() const; // managing project ProjectNode *projectNode() const; // managing project
FolderNode *parentFolderNode() const; // parent folder or project FolderNode *parentFolderNode() const; // parent folder or project
QString path() const; // file system path QString path() const; // file system path
virtual int line() const;
virtual QString displayName() const; virtual QString displayName() const;
virtual QString vcsTopic() const; virtual QString vcsTopic() const;
virtual QString tooltip() const; virtual QString tooltip() const;
virtual bool isEnabled() const; virtual bool isEnabled() const;
void setPath(const QString &path); // this does not call emitNodeUpdated!
void emitNodeUpdated();
protected: protected:
Node(NodeType nodeType, const QString &path); Node(NodeType nodeType, const QString &path);
@@ -97,8 +101,6 @@ protected:
void setProjectNode(ProjectNode *project); void setProjectNode(ProjectNode *project);
void setParentFolderNode(FolderNode *parentFolder); void setParentFolderNode(FolderNode *parentFolder);
void emitNodeUpdated();
private: private:
NodeType m_nodeType; NodeType m_nodeType;
ProjectNode *m_projectNode; ProjectNode *m_projectNode;
@@ -140,6 +142,9 @@ public:
void setDisplayName(const QString &name); void setDisplayName(const QString &name);
void setIcon(const QIcon &icon); void setIcon(const QIcon &icon);
FileNode *findFile(const QString &path);
FolderNode *findSubFolder(const QString &path);
protected: protected:
QList<FolderNode*> m_subFolderNodes; QList<FolderNode*> m_subFolderNodes;
QList<FileNode*> m_fileNodes; QList<FileNode*> m_fileNodes;
@@ -331,7 +336,6 @@ private:
friend class Node; friend class Node;
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer
// HACK: THERE SHOULD BE ONE PLACE TO MAKE THE FILE ENDING->FILE TYPE ASSOCIATION // HACK: THERE SHOULD BE ONE PLACE TO MAKE THE FILE ENDING->FILE TYPE ASSOCIATION

View File

@@ -40,6 +40,7 @@
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -374,8 +375,11 @@ void ProjectTreeWidget::initView()
void ProjectTreeWidget::openItem(const QModelIndex &mainIndex) void ProjectTreeWidget::openItem(const QModelIndex &mainIndex)
{ {
Node *node = m_model->nodeForIndex(mainIndex); Node *node = m_model->nodeForIndex(mainIndex);
if (node->nodeType() == FileNodeType) if (node->nodeType() != FileNodeType)
EditorManager::openEditor(node->path(), Id(), EditorManager::ModeSwitch); return;
IEditor *editor = EditorManager::openEditor(node->path(), Id(), EditorManager::ModeSwitch);
if (node->line() >= 0)
editor->gotoLine(node->line());
} }
void ProjectTreeWidget::setProjectFilter(bool filter) void ProjectTreeWidget::setProjectFilter(bool filter)