|
|
|
|
@@ -4,7 +4,6 @@
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/fileutils.h>
|
|
|
|
|
#include <coreplugin/navigationwidget.h>
|
|
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
|
|
|
|
@@ -17,10 +16,11 @@
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/projectnodes.h>
|
|
|
|
|
#include <projectexplorer/buildmanager.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/projectmanager.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
#include <utils/macroexpander.h>
|
|
|
|
|
#include <utils/fsengine/fileiconprovider.h>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDesktopServices>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
@@ -40,6 +40,15 @@ const int roleFullPath = Qt::UserRole;
|
|
|
|
|
const int roleItemType = Qt::UserRole + 1;
|
|
|
|
|
const int roleIsDir = Qt::UserRole + 2;
|
|
|
|
|
const int roleProject = Qt::UserRole + 3;
|
|
|
|
|
const int roleLabel = Qt::UserRole + 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setItemProjectName(ProjectExplorer::Project * pr, QTreeWidgetItem * item) {
|
|
|
|
|
if (!pr || !item) return;
|
|
|
|
|
QString dn = pr->displayName(), l = item->data(0, roleLabel).toString();
|
|
|
|
|
if (!l.isEmpty()) dn += " (" + l + ")";
|
|
|
|
|
item->setText(0, dn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QAction * newSeparator() {
|
|
|
|
|
@@ -48,6 +57,7 @@ QAction * newSeparator() {
|
|
|
|
|
return sep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(parent) {
|
|
|
|
|
setupUi(this);
|
|
|
|
|
item_target = nullptr;
|
|
|
|
|
@@ -59,7 +69,7 @@ ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(pare
|
|
|
|
|
buttonCollapse->setIcon(Utils::Icons::COLLAPSE.icon());
|
|
|
|
|
actionOpen_here->setIcon(Utils::Icons::OPENFILE.icon());
|
|
|
|
|
actionOpen_external->setIcon(Utils::Icons::OPENFILE.icon());
|
|
|
|
|
actionShow_external->setIcon(Core::FileIconProvider::icon(QFileIconProvider::Folder));
|
|
|
|
|
actionShow_external->setIcon(Utils::FileIconProvider::icon(QFileIconProvider::Folder));
|
|
|
|
|
actionCopy_name->setIcon(Utils::Icons::COPY.icon());
|
|
|
|
|
actionCopy_path->setIcon(Utils::Icons::COPY.icon());
|
|
|
|
|
actionBuild->setIcon(ProjectExplorer::Icons::BUILD_SMALL.icon());
|
|
|
|
|
@@ -77,23 +87,23 @@ ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(pare
|
|
|
|
|
this_actions << actionCopy_name << actionCopy_path;
|
|
|
|
|
proj_plug = 0;
|
|
|
|
|
//connect(ProjectExplorer::ProjectTree::instance(), SIGNAL(subtreeChanged(ProjectExplorer::FolderNode*)), this, SLOT(projectsChanged()));
|
|
|
|
|
connect(ProjectExplorer::SessionManager::instance(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)), this, SLOT(startupProjectChanged()));
|
|
|
|
|
connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::projectAdded, [this](ProjectExplorer::Project * p){
|
|
|
|
|
connect(ProjectExplorer::ProjectManager::instance(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)), this, SLOT(startupProjectChanged()));
|
|
|
|
|
connect(ProjectExplorer::ProjectManager::instance(), &ProjectExplorer::ProjectManager::projectAdded, [this](ProjectExplorer::Project * p){
|
|
|
|
|
createProjectTree(p);
|
|
|
|
|
filter();
|
|
|
|
|
startupProjectChanged();
|
|
|
|
|
});
|
|
|
|
|
connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::projectDisplayNameChanged, [this](ProjectExplorer::Project * p){
|
|
|
|
|
connect(ProjectExplorer::ProjectManager::instance(), &ProjectExplorer::ProjectManager::projectDisplayNameChanged, [this](ProjectExplorer::Project * p){
|
|
|
|
|
projectNameChanged();
|
|
|
|
|
});
|
|
|
|
|
connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::projectRemoved, [this](ProjectExplorer::Project * p){
|
|
|
|
|
connect(ProjectExplorer::ProjectManager::instance(), &ProjectExplorer::ProjectManager::projectRemoved, [this](ProjectExplorer::Project * p){
|
|
|
|
|
QTreeWidgetItem * pi = projectItem(p);
|
|
|
|
|
if (!pi) return;
|
|
|
|
|
delete pi;
|
|
|
|
|
cleanMappedItems();
|
|
|
|
|
startupProjectChanged();
|
|
|
|
|
});
|
|
|
|
|
//connect(ProjectExplorer::SessionManager::instance(), SIGNAL(), this, SLOT(startupProjectChanged()));
|
|
|
|
|
//connect(ProjectExplorer::ProjectManager::instance(), SIGNAL(), this, SLOT(startupProjectChanged()));
|
|
|
|
|
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(currentFileChanged()));
|
|
|
|
|
connect(&fs_watcher, SIGNAL(directoryChanged(const QString &)), this, SLOT(directoryChanged(const QString &)));
|
|
|
|
|
projectsChanged();
|
|
|
|
|
@@ -146,7 +156,7 @@ void ProjectFilesystemWidget::projectNameChanged() {
|
|
|
|
|
for (int i = 0; i < tree->topLevelItemCount(); ++i) {
|
|
|
|
|
ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(tree->topLevelItem(i));
|
|
|
|
|
if (!p) continue;
|
|
|
|
|
tree->topLevelItem(i)->setText(0, p->displayName());
|
|
|
|
|
setItemProjectName(p, tree->topLevelItem(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -170,7 +180,7 @@ void ProjectFilesystemWidget::createTree(QTreeWidgetItem * ti, const QString & d
|
|
|
|
|
}
|
|
|
|
|
QTreeWidgetItem * ni = new QTreeWidgetItem();
|
|
|
|
|
ni->setText(0, nit);
|
|
|
|
|
ni->setIcon(0, Core::FileIconProvider::icon(Utils::FilePath::fromString(i.absoluteFilePath())));
|
|
|
|
|
ni->setIcon(0, Utils::FileIconProvider::icon(Utils::FilePath::fromString(i.absoluteFilePath())));
|
|
|
|
|
ni->setData(0, roleFullPath, i.absoluteFilePath());
|
|
|
|
|
ni->setData(0, roleItemType, i.isDir() ? itDir : itFile);
|
|
|
|
|
ni->setData(0, roleIsDir, i.isDir());
|
|
|
|
|
@@ -276,7 +286,7 @@ void ProjectFilesystemWidget::projectsChanged() {
|
|
|
|
|
tree->clear();
|
|
|
|
|
fs_watcher.removePaths(fs_watcher.directories());
|
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
QList<ProjectExplorer::Project *> pl = ProjectExplorer::SessionManager::projects();
|
|
|
|
|
QList<ProjectExplorer::Project *> pl = ProjectExplorer::ProjectManager::projects();
|
|
|
|
|
for (ProjectExplorer::Project * p: pl) {
|
|
|
|
|
createProjectTree(p);
|
|
|
|
|
}
|
|
|
|
|
@@ -299,17 +309,23 @@ void ProjectFilesystemWidget::createProjectTree(void * p) {
|
|
|
|
|
if (!p) return;
|
|
|
|
|
ProjectExplorer::Project * pr = (ProjectExplorer::Project *)p;
|
|
|
|
|
QTreeWidgetItem * ri = new QTreeWidgetItem();
|
|
|
|
|
QString dir = pr->projectDirectory().toString();
|
|
|
|
|
ri->setText(0, pr->displayName());
|
|
|
|
|
QString dir = pr->projectDirectory().toUrlishString();
|
|
|
|
|
QFile logo(dir + "/logo.png");
|
|
|
|
|
if (logo.exists())
|
|
|
|
|
ri->setIcon(0, QIcon(logo.fileName()));
|
|
|
|
|
else
|
|
|
|
|
ri->setIcon(0, Core::FileIconProvider::icon(QFileIconProvider::Folder));
|
|
|
|
|
ri->setIcon(0, Utils::FileIconProvider::icon(QFileIconProvider::Folder));
|
|
|
|
|
QFile label(dir + "/label.txt");
|
|
|
|
|
if (label.exists()) {
|
|
|
|
|
label.open(QIODevice::ReadOnly);
|
|
|
|
|
ri->setData(0, roleLabel, QString::fromUtf8(label.readAll()).trimmed());
|
|
|
|
|
} else
|
|
|
|
|
ri->setData(0, roleLabel, QString());
|
|
|
|
|
ri->setData(0, roleProject, (qulonglong)pr);
|
|
|
|
|
ri->setData(0, roleFullPath, dir);
|
|
|
|
|
ri->setData(0, roleIsDir, true);
|
|
|
|
|
ri->setData(0, roleItemType, itProject);
|
|
|
|
|
setItemProjectName(pr, ri);
|
|
|
|
|
createTree(ri, dir);
|
|
|
|
|
tree->addTopLevelItem(ri);
|
|
|
|
|
}
|
|
|
|
|
@@ -325,7 +341,7 @@ void ProjectFilesystemWidget::filterClicked() {
|
|
|
|
|
void ProjectFilesystemWidget::currentFileChanged() {
|
|
|
|
|
Core::IDocument * cd = Core::EditorManager::instance()->currentDocument();
|
|
|
|
|
if (!cd) return;
|
|
|
|
|
QString np = cd->filePath().toString();
|
|
|
|
|
QString np = cd->filePath().toUrlishString();
|
|
|
|
|
QTreeWidgetItem * ti = item_map.value(np);
|
|
|
|
|
if (!ti) return;
|
|
|
|
|
tree->setCurrentItem(ti);
|
|
|
|
|
@@ -334,14 +350,14 @@ void ProjectFilesystemWidget::currentFileChanged() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesystemWidget::startupProjectChanged() {
|
|
|
|
|
ProjectExplorer::Project * sp = ProjectExplorer::SessionManager::startupProject();
|
|
|
|
|
ProjectExplorer::Project * sp = ProjectExplorer::ProjectManager::startupProject();
|
|
|
|
|
QFont f(tree->font()), bf(f);
|
|
|
|
|
bf.setBold(true);
|
|
|
|
|
for (int i = 0; i < tree->topLevelItemCount(); ++i) {
|
|
|
|
|
QTreeWidgetItem * ti = tree->topLevelItem(i);
|
|
|
|
|
ti->setFont(0, f);
|
|
|
|
|
if (!sp) continue;
|
|
|
|
|
if (sp->projectDirectory().toString() == ti->data(0, roleFullPath).toString())
|
|
|
|
|
if (sp->projectDirectory().toUrlishString() == ti->data(0, roleFullPath).toString())
|
|
|
|
|
ti->setFont(0, bf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -428,7 +444,7 @@ void ProjectFilesystemWidget::on_tree_customContextMenuRequested(const QPoint &
|
|
|
|
|
|
|
|
|
|
/*if (item->data(0, roleItemType).toInt() == itProject) {
|
|
|
|
|
QString proj_path = item->data(0, roleFullPath).toString();
|
|
|
|
|
ProjectExplorer::Project * project = Utils::findOrDefault(ProjectExplorer::SessionManager::projects(),
|
|
|
|
|
ProjectExplorer::Project * project = Utils::findOrDefault(ProjectExplorer::ProjectManager::projects(),
|
|
|
|
|
[proj_path](const ProjectExplorer::Project * p) {return p->containerNode()->path() == proj_path;});
|
|
|
|
|
//ProjectExplorer::ProjectTree::instance()->setCurrent
|
|
|
|
|
|
|
|
|
|
@@ -439,7 +455,7 @@ void ProjectFilesystemWidget::on_tree_customContextMenuRequested(const QPoint &
|
|
|
|
|
}*/
|
|
|
|
|
ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target);
|
|
|
|
|
if (p) {
|
|
|
|
|
actionSet_as_startup->setVisible(p != ProjectExplorer::SessionManager::startupProject());
|
|
|
|
|
actionSet_as_startup->setVisible(p != ProjectExplorer::ProjectManager::startupProject());
|
|
|
|
|
bool can_build = !p->needsConfiguration(), can_run = false;
|
|
|
|
|
if (p->activeTarget()) {
|
|
|
|
|
can_build = can_build && p->activeTarget()->activeBuildConfiguration();
|
|
|
|
|
@@ -480,13 +496,13 @@ void ProjectFilesystemWidget::on_actionOpen_external_triggered() {
|
|
|
|
|
|
|
|
|
|
void ProjectFilesystemWidget::on_actionShow_external_triggered() {
|
|
|
|
|
if (projectfs_menu_target.path().isEmpty()) return;
|
|
|
|
|
Core::FileUtils::showInGraphicalShell(Core::ICore::mainWindow(), Utils::FilePath::fromString(projectfs_menu_target.absoluteFilePath()));
|
|
|
|
|
Core::FileUtils::showInGraphicalShell(Utils::FilePath::fromString(projectfs_menu_target.absoluteFilePath()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesystemWidget::on_actionOpen_terminal_triggered() {
|
|
|
|
|
if (projectfs_menu_target.path().isEmpty()) return;
|
|
|
|
|
Core::FileUtils::openTerminal(Utils::FilePath::fromString(QDir(projectfs_menu_target.absoluteFilePath()).path()));
|
|
|
|
|
Core::FileUtils::openTerminal(Utils::FilePath::fromString(QDir(projectfs_menu_target.absoluteFilePath()).path()), {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -505,7 +521,7 @@ void ProjectFilesystemWidget::on_actionCopy_path_triggered() {
|
|
|
|
|
void ProjectFilesystemWidget::on_actionSet_as_startup_triggered() {
|
|
|
|
|
ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target);
|
|
|
|
|
if (!p) return;
|
|
|
|
|
ProjectExplorer::SessionManager::setStartupProject(p);
|
|
|
|
|
ProjectExplorer::ProjectManager::setStartupProject(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -542,5 +558,5 @@ void ProjectFilesystemWidget::on_actionClose_project_triggered() {
|
|
|
|
|
if (!p) return;
|
|
|
|
|
if (QMessageBox::question(0, "Project close", tr("Are you sure to close project \"%1\"?").arg(p->displayName())) != QMessageBox::Yes)
|
|
|
|
|
return;
|
|
|
|
|
ProjectExplorer::SessionManager::removeProject(p);
|
|
|
|
|
ProjectExplorer::ProjectManager::removeProject(p);
|
|
|
|
|
}
|
|
|
|
|
|