project actions (set as startup, build, run and close)

This commit is contained in:
2021-05-20 21:06:24 +03:00
parent e3f19521be
commit 83cf72d9a3
3 changed files with 100 additions and 7 deletions

View File

@@ -10,11 +10,14 @@
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorericons.h>
#include <projectexplorer/projecttreewidget.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <utils/utilsicons.h>
#include <utils/macroexpander.h>
#include <QApplication>
@@ -25,6 +28,7 @@
#include <QClipboard>
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);
}