diff --git a/project_fs/projectfilesystemwidget.cpp b/project_fs/projectfilesystemwidget.cpp index c2276ae..adf844c 100644 --- a/project_fs/projectfilesystemwidget.cpp +++ b/project_fs/projectfilesystemwidget.cpp @@ -10,11 +10,14 @@ #include #include #include +#include #include #include #include #include +#include #include +#include #include #include #include @@ -25,6 +28,7 @@ #include QFileInfo projectfs_menu_target; +QTreeWidgetItem * item_target = nullptr; enum ItemType { itProject = 1, @@ -35,8 +39,15 @@ enum ItemType { const int roleFullPath = Qt::UserRole; const int roleItemType = Qt::UserRole + 1; const int roleIsDir = Qt::UserRole + 2; +const int roleProject = Qt::UserRole + 3; +QAction * newSeparator() { + QAction * sep = new QAction(); + sep->setSeparator(true); + return sep; +} + ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(parent) { setupUi(this); in_proc = need_rebuild = false; @@ -50,13 +61,15 @@ ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(pare actionShow_external->setIcon(Core::FileIconProvider::icon(QFileIconProvider::Folder)); actionCopy_name->setIcon(Utils::Icons::COPY.icon()); actionCopy_path->setIcon(Utils::Icons::COPY.icon()); - QAction * sep = new QAction(); - sep->setSeparator(true); - //this_actions << sep; + actionBuild->setIcon(ProjectExplorer::Icons::BUILD_SMALL.icon()); + actionRun->setIcon(ProjectExplorer::Icons::RUN_FLAT.icon()); + actionClose_project->setIcon(Utils::Icons::CLOSE_TOOLBAR.icon()); + this_actions << actionSet_as_startup << actionBuild << actionRun; + this_actions << newSeparator(); + this_actions << actionClose_project; + this_actions << newSeparator(); this_actions << actionOpen_here << actionOpen_external << actionShow_external << actionOpen_terminal; - //sep = new QAction(); - //sep->setSeparator(true); - this_actions << sep; + this_actions << newSeparator(); this_actions << actionCopy_name << actionCopy_path; proj_plug = 0; //connect(ProjectExplorer::ProjectTree::instance(), SIGNAL(subtreeChanged(ProjectExplorer::FolderNode*)), this, SLOT(projectsChanged())); @@ -188,6 +201,12 @@ void ProjectFilesystemWidget::checkProcEvents() { } +void * ProjectFilesystemWidget::itemProject(QTreeWidgetItem * ti) { + if (!ti) return nullptr; + return (void*)(ti->data(0, roleProject).toULongLong()); +} + + void ProjectFilesystemWidget::projectsChanged() { if (in_proc) { need_rebuild = true; @@ -211,6 +230,7 @@ void ProjectFilesystemWidget::projectsChanged() { ri->setIcon(0, QIcon(logo.fileName())); else ri->setIcon(0, Core::FileIconProvider::icon(QFileIconProvider::Folder)); + ri->setData(0, roleProject, (qulonglong)p); ri->setData(0, roleFullPath, dir); ri->setData(0, roleIsDir, true); ri->setData(0, roleItemType, itProject); @@ -294,10 +314,12 @@ void ProjectFilesystemWidget::on_tree_customContextMenuRequested(const QPoint & projectfs_menu_target = QFileInfo(); QTreeWidgetItem * item = tree->itemAt(pos); //QMessageBox::information(this, "", QString::number(index.row())); + item_target = nullptr; if (!item) { setExtVariable(); return; } + item_target = item; projectfs_menu_target = QFileInfo(item->data(0, roleFullPath).toString()); setExtVariable(); actionOpen_here->setEnabled(!projectfs_menu_target.isDir()); @@ -315,6 +337,22 @@ void ProjectFilesystemWidget::on_tree_customContextMenuRequested(const QPoint & //contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu(); popup_menu.addActions(contextMenu->actions()); }*/ + ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target); + if (p) { + actionSet_as_startup->setVisible(p != ProjectExplorer::SessionManager::startupProject()); + bool can_build = !p->needsConfiguration(), can_run = false; + if (p->activeTarget()) { + can_build = can_build && p->activeTarget()->activeBuildConfiguration(); + can_run = p->activeTarget()->activeRunConfiguration(); + } + actionBuild->setVisible(can_build); + actionRun->setVisible(can_run); + } else { + actionSet_as_startup->setVisible(false); + actionBuild->setVisible(false); + actionRun->setVisible(false); + } + actionClose_project->setVisible(p); popup_menu.addActions(this_actions); popup_menu.popup(tree->mapToGlobal(pos)); @@ -358,3 +396,33 @@ void ProjectFilesystemWidget::on_actionCopy_path_triggered() { if (projectfs_menu_target.path().isEmpty()) return; QApplication::clipboard()->setText(projectfs_menu_target.absoluteFilePath()); } + + +void ProjectFilesystemWidget::on_actionSet_as_startup_triggered() { + ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target); + if (!p) return; + ProjectExplorer::SessionManager::setStartupProject(p); +} + + +void ProjectFilesystemWidget::on_actionBuild_triggered() { + ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target); + if (!p) return; + ProjectExplorer::BuildManager::buildProjectWithDependencies(p); +} + + +void ProjectFilesystemWidget::on_actionRun_triggered() { + ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target); + if (!p) return; + ProjectExplorer::ProjectExplorerPlugin::runProject(p, ProjectExplorer::Constants::NORMAL_RUN_MODE); +} + + +void ProjectFilesystemWidget::on_actionClose_project_triggered() { + ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target); + 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); +} diff --git a/project_fs/projectfilesystemwidget.h b/project_fs/projectfilesystemwidget.h index cd967fd..6a15b9b 100644 --- a/project_fs/projectfilesystemwidget.h +++ b/project_fs/projectfilesystemwidget.h @@ -34,6 +34,7 @@ protected: void restoreExpanded(QTreeWidgetItem * ti); void setExtVariable(); void checkProcEvents(); + void * itemProject(QTreeWidgetItem * ti); bool in_proc, need_rebuild; ExtensionSystem::IPlugin * proj_plug; @@ -63,6 +64,10 @@ private slots: void on_actionOpen_terminal_triggered(); void on_actionCopy_name_triggered(); void on_actionCopy_path_triggered(); + void on_actionSet_as_startup_triggered(); + void on_actionBuild_triggered(); + void on_actionRun_triggered(); + void on_actionClose_project_triggered(); }; diff --git a/project_fs/projectfilesystemwidget.ui b/project_fs/projectfilesystemwidget.ui index 06dbeb2..9021953 100644 --- a/project_fs/projectfilesystemwidget.ui +++ b/project_fs/projectfilesystemwidget.ui @@ -6,7 +6,7 @@ 0 0 - 386 + 437 390 @@ -126,6 +126,26 @@ Open terminal ... + + + Set as startup + + + + + Build + + + + + Run + + + + + Close project + +