2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projecttreewidget.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectexplorer.h"
|
2010-11-01 11:18:27 +01:00
|
|
|
#include "projectnodes.h"
|
2009-09-25 11:35:44 +02:00
|
|
|
#include "project.h"
|
|
|
|
|
#include "session.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectexplorerconstants.h"
|
|
|
|
|
#include "projectmodels.h"
|
|
|
|
|
|
2010-07-30 22:16:59 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2010-11-12 17:25:39 +01:00
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-07-16 11:18:30 +02:00
|
|
|
#include <utils/navigationtreeview.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
2008-12-11 14:35:14 +01:00
|
|
|
#include <QtCore/QSettings>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtGui/QHeaderView>
|
2010-11-02 16:14:00 +01:00
|
|
|
#include <QtGui/QTreeView>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
|
#include <QtGui/QFocusEvent>
|
2009-09-25 11:35:44 +02:00
|
|
|
#include <QtGui/QAction>
|
2009-01-27 12:49:44 +01:00
|
|
|
#include <QtGui/QPalette>
|
2009-09-29 11:39:55 +02:00
|
|
|
#include <QtGui/QMenu>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
bool debug = false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
class ProjectTreeView : public Utils::NavigationTreeView
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ProjectTreeView()
|
|
|
|
|
{
|
|
|
|
|
setEditTriggers(QAbstractItemView::EditKeyPressed);
|
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
// setExpandsOnDoubleClick(false);
|
2011-04-13 13:00:30 +02:00
|
|
|
m_context = new Core::IContext(this);
|
|
|
|
|
m_context->setContext(Core::Context(Constants::C_PROJECT_TREE));
|
2011-04-26 13:18:56 +02:00
|
|
|
m_context->setWidget(this);
|
2010-11-12 17:25:39 +01:00
|
|
|
Core::ICore::instance()->addContextObject(m_context);
|
|
|
|
|
}
|
|
|
|
|
~ProjectTreeView()
|
|
|
|
|
{
|
|
|
|
|
Core::ICore::instance()->removeContextObject(m_context);
|
|
|
|
|
delete m_context;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-11-12 17:25:39 +01:00
|
|
|
|
|
|
|
|
private:
|
2011-04-13 13:00:30 +02:00
|
|
|
Core::IContext *m_context;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
/class ProjectTreeWidget
|
|
|
|
|
|
|
|
|
|
Shows the projects in form of a tree.
|
|
|
|
|
*/
|
2009-01-20 17:14:00 +01:00
|
|
|
ProjectTreeWidget::ProjectTreeWidget(QWidget *parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
: QWidget(parent),
|
|
|
|
|
m_explorer(ProjectExplorerPlugin::instance()),
|
|
|
|
|
m_view(0),
|
|
|
|
|
m_model(0),
|
|
|
|
|
m_filterProjectsAction(0),
|
2010-01-07 20:35:23 +01:00
|
|
|
m_autoSync(false),
|
2011-07-04 11:16:30 +02:00
|
|
|
m_autoExpand(true)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_model = new FlatModel(m_explorer->session()->sessionNode(), this);
|
2010-07-08 15:37:34 +02:00
|
|
|
Project *pro = m_explorer->session()->startupProject();
|
|
|
|
|
if (pro)
|
|
|
|
|
m_model->setStartupProject(pro->rootProjectNode());
|
2009-03-31 15:05:52 +02:00
|
|
|
NodesWatcher *watcher = new NodesWatcher(this);
|
|
|
|
|
m_explorer->session()->sessionNode()->registerWatcher(watcher);
|
|
|
|
|
|
|
|
|
|
connect(watcher, SIGNAL(foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &)),
|
|
|
|
|
this, SLOT(foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &)));
|
|
|
|
|
connect(watcher, SIGNAL(filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &)),
|
|
|
|
|
this, SLOT(filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &)));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_view = new ProjectTreeView;
|
|
|
|
|
m_view->setModel(m_model);
|
|
|
|
|
setFocusProxy(m_view);
|
|
|
|
|
initView();
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout();
|
|
|
|
|
layout->addWidget(m_view);
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
2010-09-28 17:29:05 +02:00
|
|
|
m_filterProjectsAction = new QAction(tr("Simplify Tree"), this);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_filterProjectsAction->setCheckable(true);
|
|
|
|
|
m_filterProjectsAction->setChecked(false); // default is the traditional complex tree
|
|
|
|
|
connect(m_filterProjectsAction, SIGNAL(toggled(bool)), this, SLOT(setProjectFilter(bool)));
|
|
|
|
|
|
2010-09-28 17:29:05 +02:00
|
|
|
m_filterGeneratedFilesAction = new QAction(tr("Hide Generated Files"), this);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_filterGeneratedFilesAction->setCheckable(true);
|
|
|
|
|
m_filterGeneratedFilesAction->setChecked(true);
|
|
|
|
|
connect(m_filterGeneratedFilesAction, SIGNAL(toggled(bool)), this, SLOT(setGeneratedFilesFilter(bool)));
|
|
|
|
|
|
|
|
|
|
// connections
|
|
|
|
|
connect(m_model, SIGNAL(modelReset()),
|
|
|
|
|
this, SLOT(initView()));
|
|
|
|
|
connect(m_view, SIGNAL(activated(const QModelIndex&)),
|
|
|
|
|
this, SLOT(openItem(const QModelIndex&)));
|
|
|
|
|
connect(m_view->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
|
|
|
|
|
this, SLOT(handleCurrentItemChange(const QModelIndex&)));
|
|
|
|
|
connect(m_view, SIGNAL(customContextMenuRequested(const QPoint&)),
|
|
|
|
|
this, SLOT(showContextMenu(const QPoint&)));
|
|
|
|
|
connect(m_explorer->session(), SIGNAL(singleProjectAdded(ProjectExplorer::Project *)),
|
|
|
|
|
this, SLOT(handleProjectAdded(ProjectExplorer::Project *)));
|
|
|
|
|
connect(m_explorer->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
|
|
|
|
|
this, SLOT(startupProjectChanged(ProjectExplorer::Project *)));
|
|
|
|
|
|
2011-03-25 16:48:18 +01:00
|
|
|
connect(m_explorer->session(), SIGNAL(aboutToLoadSession()),
|
|
|
|
|
this, SLOT(disableAutoExpand()));
|
|
|
|
|
connect(m_explorer->session(), SIGNAL(sessionLoaded()),
|
|
|
|
|
this, SLOT(loadExpandData()));
|
|
|
|
|
connect(m_explorer->session(), SIGNAL(aboutToSaveSession()),
|
|
|
|
|
this, SLOT(saveExpandData()));
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
m_toggleSync = new QToolButton;
|
2010-07-30 22:16:59 +02:00
|
|
|
m_toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
|
2008-12-11 14:35:14 +01:00
|
|
|
m_toggleSync->setCheckable(true);
|
|
|
|
|
m_toggleSync->setChecked(autoSynchronization());
|
|
|
|
|
m_toggleSync->setToolTip(tr("Synchronize with Editor"));
|
|
|
|
|
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleAutoSynchronization()));
|
|
|
|
|
|
2009-01-20 17:06:46 +01:00
|
|
|
setAutoSynchronization(true);
|
2008-12-11 14:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-25 16:48:18 +01:00
|
|
|
void ProjectTreeWidget::disableAutoExpand()
|
|
|
|
|
{
|
|
|
|
|
m_autoExpand = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::loadExpandData()
|
|
|
|
|
{
|
|
|
|
|
m_autoExpand = true;
|
|
|
|
|
QStringList data = m_explorer->session()->value("ProjectTree.ExpandData").toStringList();
|
|
|
|
|
recursiveLoadExpandData(m_view->rootIndex(), data.toSet());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::recursiveLoadExpandData(const QModelIndex &index, const QSet<QString> &data)
|
|
|
|
|
{
|
|
|
|
|
if (data.contains(m_model->nodeForIndex(index)->path())) {
|
|
|
|
|
m_view->expand(index);
|
|
|
|
|
int count = m_model->rowCount(index);
|
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
|
recursiveLoadExpandData(index.child(i, 0), data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::saveExpandData()
|
|
|
|
|
{
|
|
|
|
|
QStringList data;
|
|
|
|
|
recursiveSaveExpandData(m_view->rootIndex(), &data);
|
|
|
|
|
// TODO if there are multiple ProjectTreeWidgets, the last one saves the data
|
|
|
|
|
m_explorer->session()->setValue("ProjectTree.ExpandData", data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::recursiveSaveExpandData(const QModelIndex &index, QStringList *data)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(data);
|
|
|
|
|
if (m_view->isExpanded(index)) {
|
|
|
|
|
data->append(m_model->nodeForIndex(index)->path());
|
|
|
|
|
int count = m_model->rowCount(index);
|
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
|
recursiveSaveExpandData(index.child(i, 0), data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-31 15:05:52 +02:00
|
|
|
void ProjectTreeWidget::foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &list)
|
|
|
|
|
{
|
|
|
|
|
Node *n = m_explorer->currentNode();
|
|
|
|
|
while(n) {
|
|
|
|
|
if (FolderNode *fn = qobject_cast<FolderNode *>(n)) {
|
|
|
|
|
if (list.contains(fn)) {
|
2009-06-26 16:50:49 +02:00
|
|
|
ProjectNode *pn = n->projectNode();
|
|
|
|
|
// Make sure the node we are switching too isn't going to be removed also
|
|
|
|
|
while (list.contains(pn))
|
|
|
|
|
pn = pn->parentFolderNode()->projectNode();
|
|
|
|
|
m_explorer->setCurrentNode(pn);
|
2009-03-31 15:05:52 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
n = n->parentFolderNode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &list)
|
|
|
|
|
{
|
|
|
|
|
if (FileNode *fileNode = qobject_cast<FileNode *>(m_explorer->currentNode())) {
|
|
|
|
|
if (list.contains(fileNode)) {
|
|
|
|
|
m_explorer->setCurrentNode(fileNode->projectNode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
QToolButton *ProjectTreeWidget::toggleSync()
|
|
|
|
|
{
|
|
|
|
|
return m_toggleSync;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::toggleAutoSynchronization()
|
|
|
|
|
{
|
|
|
|
|
setAutoSynchronization(!m_autoSync);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProjectTreeWidget::autoSynchronization() const
|
|
|
|
|
{
|
|
|
|
|
return m_autoSync;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::setAutoSynchronization(bool sync, bool syncNow)
|
|
|
|
|
{
|
2008-12-11 14:35:14 +01:00
|
|
|
m_toggleSync->setChecked(sync);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (sync == m_autoSync)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_autoSync = sync;
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << (m_autoSync ? "Enabling auto synchronization" : "Disabling auto synchronization");
|
|
|
|
|
if (m_autoSync) {
|
|
|
|
|
connect(m_explorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*, ProjectExplorer::Project*)),
|
|
|
|
|
this, SLOT(setCurrentItem(ProjectExplorer::Node*, ProjectExplorer::Project*)));
|
|
|
|
|
if (syncNow)
|
|
|
|
|
setCurrentItem(m_explorer->currentNode(), m_explorer->currentProject());
|
|
|
|
|
} else {
|
|
|
|
|
disconnect(m_explorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*, ProjectExplorer::Project*)),
|
|
|
|
|
this, SLOT(setCurrentItem(ProjectExplorer::Node*, ProjectExplorer::Project*)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-13 11:52:14 +02:00
|
|
|
void ProjectTreeWidget::collapseAll()
|
|
|
|
|
{
|
|
|
|
|
m_view->collapseAll();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void ProjectTreeWidget::editCurrentItem()
|
|
|
|
|
{
|
2011-06-09 17:43:41 +02:00
|
|
|
if (m_view->selectionModel()->currentIndex().isValid())
|
|
|
|
|
m_view->edit(m_view->selectionModel()->currentIndex());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::setCurrentItem(Node *node, Project *project)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
2010-01-07 18:17:24 +01:00
|
|
|
qDebug() << "ProjectTreeWidget::setCurrentItem(" << (project ? project->displayName() : "0")
|
2008-12-02 12:01:29 +01:00
|
|
|
<< ", " << (node ? node->path() : "0") << ")";
|
2010-02-25 15:15:41 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!project) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QModelIndex mainIndex = m_model->indexForNode(node);
|
|
|
|
|
|
2009-01-20 17:06:46 +01:00
|
|
|
if (mainIndex.isValid() && mainIndex != m_view->selectionModel()->currentIndex()) {
|
|
|
|
|
m_view->setCurrentIndex(mainIndex);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_view->scrollTo(mainIndex);
|
2009-01-20 17:06:46 +01:00
|
|
|
} else {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "clear selection";
|
|
|
|
|
m_view->clearSelection();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-01-20 17:06:46 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::handleCurrentItemChange(const QModelIndex ¤t)
|
|
|
|
|
{
|
|
|
|
|
Node *node = m_model->nodeForIndex(current);
|
2008-12-17 14:20:01 +01:00
|
|
|
// node might be 0. that's okay
|
2008-12-02 12:01:29 +01:00
|
|
|
bool autoSync = autoSynchronization();
|
|
|
|
|
setAutoSynchronization(false);
|
|
|
|
|
m_explorer->setCurrentNode(node);
|
|
|
|
|
setAutoSynchronization(autoSync, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::showContextMenu(const QPoint &pos)
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = m_view->indexAt(pos);
|
|
|
|
|
Node *node = m_model->nodeForIndex(index);
|
2011-07-13 11:52:14 +02:00
|
|
|
m_explorer->showContextMenu(this, m_view->mapToGlobal(pos), node);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::handleProjectAdded(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
Node *node = project->rootProjectNode();
|
|
|
|
|
QModelIndex idx = m_model->indexForNode(node);
|
2011-03-25 16:48:18 +01:00
|
|
|
if (m_autoExpand) // disabled while session restoring
|
|
|
|
|
m_view->setExpanded(idx, true);
|
2010-01-07 20:35:23 +01:00
|
|
|
m_view->setCurrentIndex(idx);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::startupProjectChanged(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
if (project) {
|
|
|
|
|
ProjectNode *node = project->rootProjectNode();
|
|
|
|
|
m_model->setStartupProject(node);
|
|
|
|
|
} else {
|
|
|
|
|
m_model->setStartupProject(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::initView()
|
|
|
|
|
{
|
|
|
|
|
QModelIndex sessionIndex = m_model->index(0, 0);
|
|
|
|
|
|
|
|
|
|
// hide root folder
|
|
|
|
|
m_view->setRootIndex(sessionIndex);
|
|
|
|
|
|
|
|
|
|
while (m_model->canFetchMore(sessionIndex))
|
|
|
|
|
m_model->fetchMore(sessionIndex);
|
|
|
|
|
|
|
|
|
|
// expand top level projects
|
2009-01-20 17:14:00 +01:00
|
|
|
for (int i = 0; i < m_model->rowCount(sessionIndex); ++i)
|
2008-12-02 12:01:29 +01:00
|
|
|
m_view->expand(m_model->index(i, 0, sessionIndex));
|
|
|
|
|
|
|
|
|
|
setCurrentItem(m_explorer->currentNode(), m_explorer->currentProject());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::openItem(const QModelIndex &mainIndex)
|
|
|
|
|
{
|
|
|
|
|
Node *node = m_model->nodeForIndex(mainIndex);
|
|
|
|
|
if (node->nodeType() == FileNodeType) {
|
2009-01-21 15:52:34 +01:00
|
|
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
2011-11-08 11:26:07 +01:00
|
|
|
editorManager->openEditor(node->path(), Core::Id(), Core::EditorManager::ModeSwitch);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::setProjectFilter(bool filter)
|
|
|
|
|
{
|
|
|
|
|
m_model->setProjectFilterEnabled(filter);
|
|
|
|
|
m_filterProjectsAction->setChecked(filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidget::setGeneratedFilesFilter(bool filter)
|
|
|
|
|
{
|
|
|
|
|
m_model->setGeneratedFilesFilterEnabled(filter);
|
|
|
|
|
m_filterGeneratedFilesAction->setChecked(filter);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
bool ProjectTreeWidget::generatedFilesFilter()
|
|
|
|
|
{
|
|
|
|
|
return m_model->generatedFilesFilterEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProjectTreeWidget::projectFilter()
|
|
|
|
|
{
|
|
|
|
|
return m_model->projectFilterEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-20 17:14:00 +01:00
|
|
|
ProjectTreeWidgetFactory::ProjectTreeWidgetFactory()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectTreeWidgetFactory::~ProjectTreeWidgetFactory()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-27 19:03:20 +01:00
|
|
|
QString ProjectTreeWidgetFactory::displayName() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return tr("Projects");
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-09 14:35:26 +02:00
|
|
|
int ProjectTreeWidgetFactory::priority() const
|
|
|
|
|
{
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-27 19:03:20 +01:00
|
|
|
QString ProjectTreeWidgetFactory::id() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("Projects");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QKeySequence ProjectTreeWidgetFactory::activationSequence() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return QKeySequence(Qt::ALT + Qt::Key_X);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::NavigationView ProjectTreeWidgetFactory::createWidget()
|
|
|
|
|
{
|
|
|
|
|
Core::NavigationView n;
|
2009-01-20 17:14:00 +01:00
|
|
|
ProjectTreeWidget *ptw = new ProjectTreeWidget;
|
2008-12-02 12:01:29 +01:00
|
|
|
n.widget = ptw;
|
|
|
|
|
|
|
|
|
|
QToolButton *filter = new QToolButton;
|
2010-07-30 22:16:59 +02:00
|
|
|
filter->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER)));
|
2010-09-28 17:29:05 +02:00
|
|
|
filter->setToolTip(tr("Filter Tree"));
|
2008-12-02 12:01:29 +01:00
|
|
|
filter->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
|
QMenu *filterMenu = new QMenu(filter);
|
|
|
|
|
filterMenu->addAction(ptw->m_filterProjectsAction);
|
|
|
|
|
filterMenu->addAction(ptw->m_filterGeneratedFilesAction);
|
|
|
|
|
filter->setMenu(filterMenu);
|
|
|
|
|
|
2009-10-09 17:41:09 +02:00
|
|
|
n.dockToolBarWidgets << filter << ptw->toggleSync();
|
2008-12-02 12:01:29 +01:00
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-11 14:35:14 +01:00
|
|
|
void ProjectTreeWidgetFactory::saveSettings(int position, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
ProjectTreeWidget *ptw = qobject_cast<ProjectTreeWidget *>(widget);
|
|
|
|
|
Q_ASSERT(ptw);
|
2009-01-20 17:14:00 +01:00
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
settings->setValue("ProjectTreeWidget."+QString::number(position)+".ProjectFilter", ptw->projectFilter());
|
|
|
|
|
settings->setValue("ProjectTreeWidget."+QString::number(position)+".GeneratedFilter", ptw->generatedFilesFilter());
|
|
|
|
|
settings->setValue("ProjectTreeWidget."+QString::number(position)+".SyncWithEditor", ptw->autoSynchronization());
|
2008-12-11 14:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectTreeWidgetFactory::restoreSettings(int position, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
ProjectTreeWidget *ptw = qobject_cast<ProjectTreeWidget *>(widget);
|
|
|
|
|
Q_ASSERT(ptw);
|
2009-01-20 17:14:00 +01:00
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
ptw->setProjectFilter(settings->value("ProjectTreeWidget."+QString::number(position)+".ProjectFilter", false).toBool());
|
|
|
|
|
ptw->setGeneratedFilesFilter(settings->value("ProjectTreeWidget."+QString::number(position)+".GeneratedFilter", true).toBool());
|
|
|
|
|
ptw->setAutoSynchronization(settings->value("ProjectTreeWidget."+QString::number(position)+".SyncWithEditor", true).toBool());
|
2008-12-11 14:35:14 +01:00
|
|
|
}
|