add project actions Clean and Rebuild
now watch for all directories and update tree immediately
This commit is contained in:
7
project_fs/CMakeLists.txt
Normal file
7
project_fs/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
#cmake_minimum_required(VERSION 3.17)
|
||||
#project(ProjectFilesystemPlugin)
|
||||
#include($ENV{SDK_QTCREATOR_SRC}/cmake/QtCreatorAPI.cmake)
|
||||
file(GLOB SRC "*.h" "*.cpp" "*.ui" "*.qrc")
|
||||
add_qtc_plugin(ProjectFilesystemPlugin
|
||||
PLUGIN_DEPENDS Core ProjectExplorer
|
||||
SOURCES ${SRC})
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <QClipboard>
|
||||
|
||||
QFileInfo projectfs_menu_target;
|
||||
QTreeWidgetItem * item_target = nullptr;
|
||||
|
||||
enum ItemType {
|
||||
itProject = 1,
|
||||
@@ -50,6 +49,7 @@ QAction * newSeparator() {
|
||||
|
||||
ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(parent) {
|
||||
setupUi(this);
|
||||
item_target = nullptr;
|
||||
in_proc = need_rebuild = false;
|
||||
int is = style()->pixelMetric(QStyle::PM_ButtonIconSize, 0, this);
|
||||
label->setFixedSize(is, is);
|
||||
@@ -62,10 +62,13 @@ ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(pare
|
||||
actionCopy_name->setIcon(Utils::Icons::COPY.icon());
|
||||
actionCopy_path->setIcon(Utils::Icons::COPY.icon());
|
||||
actionBuild->setIcon(ProjectExplorer::Icons::BUILD_SMALL.icon());
|
||||
actionClean->setIcon(Utils::Icons::CLEAN.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 << actionRebuild << actionClean;
|
||||
this_actions << newSeparator();
|
||||
this_actions << actionClose_project;
|
||||
this_actions << newSeparator();
|
||||
this_actions << actionOpen_here << actionOpen_external << actionShow_external << actionOpen_terminal;
|
||||
@@ -78,7 +81,8 @@ ProjectFilesystemWidget::ProjectFilesystemWidget(QWidget * parent): QWidget(pare
|
||||
connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)), this, SLOT(projectsChanged()));
|
||||
connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)), this, SLOT(projectsChanged()));
|
||||
//connect(ProjectExplorer::SessionManager::instance(), SIGNAL(), this, SLOT(startupProjectChanged()));
|
||||
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(fileChanged()));
|
||||
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(currentFileChanged()));
|
||||
connect(&fs_watcher, SIGNAL(directoryChanged(const QString &)), this, SLOT(directoryChanged(const QString &)));
|
||||
projectsChanged();
|
||||
}
|
||||
|
||||
@@ -102,8 +106,13 @@ void ProjectFilesystemWidget::changeEvent(QEvent *e) {
|
||||
|
||||
|
||||
void ProjectFilesystemWidget::createTree(QTreeWidgetItem * ti, const QString & dir) {
|
||||
if (ti->childCount() > 0) {
|
||||
qDeleteAll(ti->takeChildren());
|
||||
}
|
||||
QFileInfoList fl = QDir(dir).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::LocaleAware | QDir::DirsFirst);
|
||||
checkProcEvents();
|
||||
fs_watcher.addPath(dir);
|
||||
item_map[dir] = ti;
|
||||
for (QFileInfo i: fl) {
|
||||
QString nit = i.fileName();
|
||||
if (i.isDir()) {
|
||||
@@ -121,7 +130,7 @@ void ProjectFilesystemWidget::createTree(QTreeWidgetItem * ti, const QString & d
|
||||
ni->setData(0, roleIsDir, i.isDir());
|
||||
item_map[i.absoluteFilePath()] = ni;
|
||||
if (i.isDir()) {
|
||||
createTree(ni, dir + QDir::separator() + i.fileName());
|
||||
createTree(ni, dir + "/" + i.fileName());
|
||||
}
|
||||
ti->addChild(ni);
|
||||
}
|
||||
@@ -219,6 +228,7 @@ void ProjectFilesystemWidget::projectsChanged() {
|
||||
int spos = tree->verticalScrollBar()->value();
|
||||
rememberExpanded(tree->invisibleRootItem());
|
||||
tree->clear();
|
||||
fs_watcher.removePaths(fs_watcher.directories());
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
QList<ProjectExplorer::Project *> pl = ProjectExplorer::SessionManager::projects();
|
||||
for (ProjectExplorer::Project * p: pl) {
|
||||
@@ -238,7 +248,7 @@ void ProjectFilesystemWidget::projectsChanged() {
|
||||
tree->addTopLevelItem(ri);
|
||||
}
|
||||
startupProjectChanged();
|
||||
fileChanged();
|
||||
currentFileChanged();
|
||||
filter();
|
||||
restoreExpanded(tree->invisibleRootItem());
|
||||
QApplication::restoreOverrideCursor();
|
||||
@@ -259,7 +269,7 @@ void ProjectFilesystemWidget::filterClicked() {
|
||||
}
|
||||
|
||||
|
||||
void ProjectFilesystemWidget::fileChanged() {
|
||||
void ProjectFilesystemWidget::currentFileChanged() {
|
||||
Core::IDocument * cd = Core::EditorManager::instance()->currentDocument();
|
||||
if (!cd) return;
|
||||
QString np = cd->filePath().toString();
|
||||
@@ -284,6 +294,29 @@ void ProjectFilesystemWidget::startupProjectChanged() {
|
||||
}
|
||||
|
||||
|
||||
void ProjectFilesystemWidget::directoryChanged(const QString & path) {
|
||||
QTreeWidgetItem * ti = item_map.value(path);
|
||||
//QMessageBox::information(0, "", "changed " + path + " " + QString::number((qulonglong)ti));
|
||||
if (!ti) return;
|
||||
int spos = tree->verticalScrollBar()->value();
|
||||
rememberExpanded(tree->invisibleRootItem());
|
||||
createTree(ti, path);
|
||||
filter();
|
||||
restoreExpanded(tree->invisibleRootItem());
|
||||
QList<QTreeWidgetItem*> ail = tree->findItems("", Qt::MatchContains | Qt::MatchRecursive), map_values = item_map.values();
|
||||
QSet<QTreeWidgetItem*> ais;
|
||||
//QString removed;
|
||||
for (auto * i: ail) ais << i;
|
||||
for (auto * i: map_values)
|
||||
if (!ais.contains(i)) {
|
||||
//removed += item_map.key(i) + "\n";
|
||||
item_map.remove(item_map.key(i));
|
||||
}
|
||||
//QMessageBox::information(0, "", "map " + QString::number(ais.size()));
|
||||
//QMessageBox::information(0, "", "remove " + removed);
|
||||
}
|
||||
|
||||
|
||||
void ProjectFilesystemWidget::on_tree_itemDoubleClicked(QTreeWidgetItem * item, int) {
|
||||
if (!item) return;
|
||||
QString afp = item->data(0, roleFullPath).toString();
|
||||
@@ -346,10 +379,14 @@ void ProjectFilesystemWidget::on_tree_customContextMenuRequested(const QPoint &
|
||||
can_run = p->activeTarget()->activeRunConfiguration();
|
||||
}
|
||||
actionBuild->setVisible(can_build);
|
||||
actionClean->setVisible(can_build);
|
||||
actionRebuild->setVisible(can_build);
|
||||
actionRun->setVisible(can_run);
|
||||
} else {
|
||||
actionSet_as_startup->setVisible(false);
|
||||
actionBuild->setVisible(false);
|
||||
actionClean->setVisible(false);
|
||||
actionRebuild->setVisible(false);
|
||||
actionRun->setVisible(false);
|
||||
}
|
||||
actionClose_project->setVisible(p);
|
||||
@@ -412,6 +449,20 @@ void ProjectFilesystemWidget::on_actionBuild_triggered() {
|
||||
}
|
||||
|
||||
|
||||
void ProjectFilesystemWidget::on_actionRebuild_triggered() {
|
||||
ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target);
|
||||
if (!p) return;
|
||||
ProjectExplorer::BuildManager::rebuildProjectWithDependencies(p, ProjectExplorer::ConfigSelection::Active);
|
||||
}
|
||||
|
||||
|
||||
void ProjectFilesystemWidget::on_actionClean_triggered() {
|
||||
ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target);
|
||||
if (!p) return;
|
||||
ProjectExplorer::BuildManager::cleanProjectWithoutDependencies(p);
|
||||
}
|
||||
|
||||
|
||||
void ProjectFilesystemWidget::on_actionRun_triggered() {
|
||||
ProjectExplorer::Project * p = (ProjectExplorer::Project *)itemProject(item_target);
|
||||
if (!p) return;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QFileSystemModel>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QElapsedTimer>
|
||||
#include <QMenu>
|
||||
|
||||
@@ -45,14 +46,17 @@ protected:
|
||||
FilterDialog filter_dialog;
|
||||
FilterDialog::Filter cur_filter;
|
||||
QElapsedTimer tm;
|
||||
QFileSystemWatcher fs_watcher;
|
||||
QTreeWidgetItem * item_target;
|
||||
|
||||
public slots:
|
||||
void projectsChanged();
|
||||
void filterClicked();
|
||||
|
||||
private slots:
|
||||
void fileChanged();
|
||||
void currentFileChanged();
|
||||
void startupProjectChanged();
|
||||
void directoryChanged(const QString & path);
|
||||
|
||||
void on_tree_itemDoubleClicked(QTreeWidgetItem * item, int );
|
||||
void on_lineFilter_textChanged(const QString &);
|
||||
@@ -66,6 +70,8 @@ private slots:
|
||||
void on_actionCopy_path_triggered();
|
||||
void on_actionSet_as_startup_triggered();
|
||||
void on_actionBuild_triggered();
|
||||
void on_actionRebuild_triggered();
|
||||
void on_actionClean_triggered();
|
||||
void on_actionRun_triggered();
|
||||
void on_actionClose_project_triggered();
|
||||
|
||||
|
||||
@@ -146,6 +146,16 @@
|
||||
<string>Close project</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClean">
|
||||
<property name="text">
|
||||
<string>Clean</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRebuild">
|
||||
<property name="text">
|
||||
<string>Rebuild</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="projectfilesystem.qrc"/>
|
||||
|
||||
Reference in New Issue
Block a user