project actions (set as startup, build, run and close)
This commit is contained in:
@@ -10,11 +10,14 @@
|
|||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
|
#include <projectexplorer/projectexplorericons.h>
|
||||||
#include <projectexplorer/projecttreewidget.h>
|
#include <projectexplorer/projecttreewidget.h>
|
||||||
#include <projectexplorer/projecttree.h>
|
#include <projectexplorer/projecttree.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
|
#include <projectexplorer/buildmanager.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
|
#include <projectexplorer/target.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
#include <utils/macroexpander.h>
|
#include <utils/macroexpander.h>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@@ -25,6 +28,7 @@
|
|||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
|
||||||
QFileInfo projectfs_menu_target;
|
QFileInfo projectfs_menu_target;
|
||||||
|
QTreeWidgetItem * item_target = nullptr;
|
||||||
|
|
||||||
enum ItemType {
|
enum ItemType {
|
||||||
itProject = 1,
|
itProject = 1,
|
||||||
@@ -35,8 +39,15 @@ enum ItemType {
|
|||||||
const int roleFullPath = Qt::UserRole;
|
const int roleFullPath = Qt::UserRole;
|
||||||
const int roleItemType = Qt::UserRole + 1;
|
const int roleItemType = Qt::UserRole + 1;
|
||||||
const int roleIsDir = Qt::UserRole + 2;
|
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) {
|
ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(parent) {
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
in_proc = need_rebuild = false;
|
in_proc = need_rebuild = false;
|
||||||
@@ -50,13 +61,15 @@ ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(pare
|
|||||||
actionShow_external->setIcon(Core::FileIconProvider::icon(QFileIconProvider::Folder));
|
actionShow_external->setIcon(Core::FileIconProvider::icon(QFileIconProvider::Folder));
|
||||||
actionCopy_name->setIcon(Utils::Icons::COPY.icon());
|
actionCopy_name->setIcon(Utils::Icons::COPY.icon());
|
||||||
actionCopy_path->setIcon(Utils::Icons::COPY.icon());
|
actionCopy_path->setIcon(Utils::Icons::COPY.icon());
|
||||||
QAction * sep = new QAction();
|
actionBuild->setIcon(ProjectExplorer::Icons::BUILD_SMALL.icon());
|
||||||
sep->setSeparator(true);
|
actionRun->setIcon(ProjectExplorer::Icons::RUN_FLAT.icon());
|
||||||
//this_actions << sep;
|
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;
|
this_actions << actionOpen_here << actionOpen_external << actionShow_external << actionOpen_terminal;
|
||||||
//sep = new QAction();
|
this_actions << newSeparator();
|
||||||
//sep->setSeparator(true);
|
|
||||||
this_actions << sep;
|
|
||||||
this_actions << actionCopy_name << actionCopy_path;
|
this_actions << actionCopy_name << actionCopy_path;
|
||||||
proj_plug = 0;
|
proj_plug = 0;
|
||||||
//connect(ProjectExplorer::ProjectTree::instance(), SIGNAL(subtreeChanged(ProjectExplorer::FolderNode*)), this, SLOT(projectsChanged()));
|
//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() {
|
void ProjectFilesystemWidget::projectsChanged() {
|
||||||
if (in_proc) {
|
if (in_proc) {
|
||||||
need_rebuild = true;
|
need_rebuild = true;
|
||||||
@@ -211,6 +230,7 @@ void ProjectFilesystemWidget::projectsChanged() {
|
|||||||
ri->setIcon(0, QIcon(logo.fileName()));
|
ri->setIcon(0, QIcon(logo.fileName()));
|
||||||
else
|
else
|
||||||
ri->setIcon(0, Core::FileIconProvider::icon(QFileIconProvider::Folder));
|
ri->setIcon(0, Core::FileIconProvider::icon(QFileIconProvider::Folder));
|
||||||
|
ri->setData(0, roleProject, (qulonglong)p);
|
||||||
ri->setData(0, roleFullPath, dir);
|
ri->setData(0, roleFullPath, dir);
|
||||||
ri->setData(0, roleIsDir, true);
|
ri->setData(0, roleIsDir, true);
|
||||||
ri->setData(0, roleItemType, itProject);
|
ri->setData(0, roleItemType, itProject);
|
||||||
@@ -294,10 +314,12 @@ void ProjectFilesystemWidget::on_tree_customContextMenuRequested(const QPoint &
|
|||||||
projectfs_menu_target = QFileInfo();
|
projectfs_menu_target = QFileInfo();
|
||||||
QTreeWidgetItem * item = tree->itemAt(pos);
|
QTreeWidgetItem * item = tree->itemAt(pos);
|
||||||
//QMessageBox::information(this, "", QString::number(index.row()));
|
//QMessageBox::information(this, "", QString::number(index.row()));
|
||||||
|
item_target = nullptr;
|
||||||
if (!item) {
|
if (!item) {
|
||||||
setExtVariable();
|
setExtVariable();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
item_target = item;
|
||||||
projectfs_menu_target = QFileInfo(item->data(0, roleFullPath).toString());
|
projectfs_menu_target = QFileInfo(item->data(0, roleFullPath).toString());
|
||||||
setExtVariable();
|
setExtVariable();
|
||||||
actionOpen_here->setEnabled(!projectfs_menu_target.isDir());
|
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();
|
//contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu();
|
||||||
popup_menu.addActions(contextMenu->actions());
|
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.addActions(this_actions);
|
||||||
popup_menu.popup(tree->mapToGlobal(pos));
|
popup_menu.popup(tree->mapToGlobal(pos));
|
||||||
@@ -358,3 +396,33 @@ void ProjectFilesystemWidget::on_actionCopy_path_triggered() {
|
|||||||
if (projectfs_menu_target.path().isEmpty()) return;
|
if (projectfs_menu_target.path().isEmpty()) return;
|
||||||
QApplication::clipboard()->setText(projectfs_menu_target.absoluteFilePath());
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ protected:
|
|||||||
void restoreExpanded(QTreeWidgetItem * ti);
|
void restoreExpanded(QTreeWidgetItem * ti);
|
||||||
void setExtVariable();
|
void setExtVariable();
|
||||||
void checkProcEvents();
|
void checkProcEvents();
|
||||||
|
void * itemProject(QTreeWidgetItem * ti);
|
||||||
|
|
||||||
bool in_proc, need_rebuild;
|
bool in_proc, need_rebuild;
|
||||||
ExtensionSystem::IPlugin * proj_plug;
|
ExtensionSystem::IPlugin * proj_plug;
|
||||||
@@ -63,6 +64,10 @@ private slots:
|
|||||||
void on_actionOpen_terminal_triggered();
|
void on_actionOpen_terminal_triggered();
|
||||||
void on_actionCopy_name_triggered();
|
void on_actionCopy_name_triggered();
|
||||||
void on_actionCopy_path_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();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>386</width>
|
<width>437</width>
|
||||||
<height>390</height>
|
<height>390</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -126,6 +126,26 @@
|
|||||||
<string>Open terminal ...</string>
|
<string>Open terminal ...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionSet_as_startup">
|
||||||
|
<property name="text">
|
||||||
|
<string>Set as startup</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionBuild">
|
||||||
|
<property name="text">
|
||||||
|
<string>Build</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRun">
|
||||||
|
<property name="text">
|
||||||
|
<string>Run</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionClose_project">
|
||||||
|
<property name="text">
|
||||||
|
<string>Close project</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="projectfilesystem.qrc"/>
|
<include location="projectfilesystem.qrc"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user