diff --git a/src/plugins/builder/mainframe/buildmanager.cpp b/src/plugins/builder/mainframe/buildmanager.cpp index 88e9e4400..d6f5db960 100644 --- a/src/plugins/builder/mainframe/buildmanager.cpp +++ b/src/plugins/builder/mainframe/buildmanager.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -391,6 +392,12 @@ void BuildManager::execBuildStep(QList menuTypelist) list.append(info); } execCommands(list, false); + } else { + DTK_WIDGET_NAMESPACE::DDialog dialog; + dialog.setWindowTitle(tr("Warning")); + dialog.setIcon(QIcon::fromTheme("dialog-warning")); + dialog.setMessage(tr("This Project does not support this operation")); + dialog.exec(); } } } diff --git a/src/plugins/cxx/ninja/project/ninjaasynparse.h b/src/plugins/cxx/ninja/project/ninjaasynparse.h deleted file mode 100644 index ee6b21459..000000000 --- a/src/plugins/cxx/ninja/project/ninjaasynparse.h +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef NINJAASYNPARSE_H -#define NINJAASYNPARSE_H - -#include "common/common.h" - -#include -#include -#include - -class QStandardItem; -class QAction; -class NinjaAsynParsePrivate; -class NinjaAsynParse : public QFileSystemWatcher -{ - Q_OBJECT - NinjaAsynParsePrivate *const d; -public: - template - struct ParseInfo{ - T result; - bool isNormal = true; - }; - - NinjaAsynParse(); - virtual ~NinjaAsynParse(); - -signals: - void itemsModified(const QList &info); - void parsedError(const ParseInfo &info); - -public slots: - void parseProject(const dpfservice::ProjectInfo &info); - -private slots: - void doDirectoryChanged(const QString &path); - -private: - void createRows(const QString &path); - QList rows(const QStandardItem *item) const; - QString itemDisplayName(const QStandardItem *item) const; - QStandardItem *findItem(const QString &path, QStandardItem *parent = nullptr) const; - int separatorSize() const; -}; - -#endif // NINJAASYNPARSE_H diff --git a/src/plugins/cxx/ninja/project/ninjaprojectgenerator.cpp b/src/plugins/cxx/ninja/project/ninjaprojectgenerator.cpp index c120e5c59..49cb79e64 100644 --- a/src/plugins/cxx/ninja/project/ninjaprojectgenerator.cpp +++ b/src/plugins/cxx/ninja/project/ninjaprojectgenerator.cpp @@ -3,29 +3,13 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "ninjaprojectgenerator.h" -#include "ninjaasynparse.h" #include "common/dialog/propertiesdialog.h" #include "services/window/windowservice.h" #include "services/builder/builderservice.h" #include "services/option/optionmanager.h" -#include -#include -#include - -class NinjaProjectGeneratorPrivate -{ - friend class NinjaProjectGenerator; - QStandardItem* configureRootItem {nullptr}; - QMenu *ninjaMenu {nullptr}; - QProcess *menuGenProcess {nullptr}; - QHash projectParses {}; - dpfservice::ProjectInfo prjInfo; -}; - NinjaProjectGenerator::NinjaProjectGenerator() - : d(new NinjaProjectGeneratorPrivate()) { qRegisterMetaType>("QList"); using namespace dpfservice; @@ -40,9 +24,6 @@ NinjaProjectGenerator::NinjaProjectGenerator() NinjaProjectGenerator::~NinjaProjectGenerator() { qInfo() << __FUNCTION__; - - if (d) - delete d; } QStringList NinjaProjectGenerator::supportLanguages() @@ -55,87 +36,8 @@ QStringList NinjaProjectGenerator::supportFileNames() return {"build.ninja"}; } -DWidget *NinjaProjectGenerator::configureWidget(const QString &language, - const QString &projectPath) -{ - d->prjInfo.setLanguage(language); - d->prjInfo.setKitName(NinjaProjectGenerator::toolKitName()); - d->prjInfo.setWorkspaceFolder(projectPath); - - return nullptr; -} - -void NinjaProjectGenerator::acceptConfigure() -{ - configure(d->prjInfo); -} - -bool NinjaProjectGenerator::configure(const dpfservice::ProjectInfo &info) -{ - dpfservice::ProjectGenerator::configure(info); - - auto root = createRootItem(info); - using namespace dpfservice; - auto &ctx = dpfInstance.serviceContext(); - ProjectService *projectService = ctx.service(ProjectService::name()); - if (projectService && root) { - projectService->addRootItem(root); - projectService->expandedDepth(root, 1); - } - - dpfservice::ProjectGenerator::configure(info); - - return true; -} - -QStandardItem *NinjaProjectGenerator::createRootItem(const dpfservice::ProjectInfo &info) -{ - using namespace dpfservice; - QStandardItem * rootItem = ProjectGenerator::createRootItem(info); - dpfservice::ProjectInfo::set(rootItem, info); - d->projectParses[rootItem] = new NinjaAsynParse(); - QObject::connect(d->projectParses[rootItem], &NinjaAsynParse::itemsModified, - this, &NinjaProjectGenerator::doProjectChildsModified); - QMetaObject::invokeMethod(d->projectParses[rootItem], "parseProject", - Q_ARG(const dpfservice::ProjectInfo &, info)); - return rootItem; -} - -void NinjaProjectGenerator::removeRootItem(QStandardItem *root) -{ - if (!root) - return; - auto parser = d->projectParses[root]; - - while (root->hasChildren()) { - root->takeRow(0); - } - d->projectParses.remove(root); - - delete root; - - if (parser) - delete parser; -} - QMenu *NinjaProjectGenerator::createItemMenu(const QStandardItem *item) { Q_UNUSED(item) return nullptr; } - -void NinjaProjectGenerator::doProjectChildsModified(const QList &items) -{ - auto rootItem = d->projectParses.key(qobject_cast(sender())); - if (rootItem) { - while (rootItem->hasChildren()) { - rootItem->takeRow(0); - } - for (auto &item : items) { - item->setIcon(CustomIcons::icon(item->toolTip())); - } - - rootItem->appendRows(items); - } - rootItem->setData(ParsingState::Done, Parsing_State_Role); -} diff --git a/src/plugins/cxx/ninja/project/ninjaprojectgenerator.h b/src/plugins/cxx/ninja/project/ninjaprojectgenerator.h index bab56b950..dc01e860c 100644 --- a/src/plugins/cxx/ninja/project/ninjaprojectgenerator.h +++ b/src/plugins/cxx/ninja/project/ninjaprojectgenerator.h @@ -5,33 +5,23 @@ #ifndef NINJAPROJECTGENERATOR_H #define NINJAPROJECTGENERATOR_H -#include "ninjaasynparse.h" #include "services/project/projectservice.h" +#include "services/project/directorygenerator.h" #include #include -class NinjaProjectGeneratorPrivate; -class NinjaProjectGenerator : public dpfservice::ProjectGenerator +class NinjaProjectGenerator : public dpfservice::DirectoryGenerator { Q_OBJECT - NinjaProjectGeneratorPrivate *const d; public: explicit NinjaProjectGenerator(); virtual ~NinjaProjectGenerator() override; static QString toolKitName() { return "ninja"; } + virtual QString configureKitName() { return "ninja"; } virtual QStringList supportLanguages() override; virtual QStringList supportFileNames() override; - virtual DWidget* configureWidget(const QString &language, - const QString &projectPath) override; - virtual void acceptConfigure() override; - virtual bool configure(const dpfservice::ProjectInfo &info = {}) override; - virtual QStandardItem *createRootItem(const dpfservice::ProjectInfo &info) override; - virtual void removeRootItem(QStandardItem* root) override; virtual QMenu* createItemMenu(const QStandardItem *item) override; - -private slots: - void doProjectChildsModified(const QList &items); }; #endif // NINJAPROJECTGENERATOR_H diff --git a/src/plugins/debugger/debugmanager.cpp b/src/plugins/debugger/debugmanager.cpp index 1d893a56f..43e6f7557 100644 --- a/src/plugins/debugger/debugmanager.cpp +++ b/src/plugins/debugger/debugmanager.cpp @@ -105,6 +105,12 @@ void DebugManager::run() currentDebugger = debuggers[debugger]; connect(currentDebugger, &AbstractDebugger::runStateChanged, this, &DebugManager::handleRunStateChanged); } + } else { + DTK_WIDGET_NAMESPACE::DDialog dialog; + dialog.setWindowTitle(tr("Warning")); + dialog.setIcon(QIcon::fromTheme("dialog-warning")); + dialog.setMessage(tr("This Project does not support this operation")); + dialog.exec(); } } AsynInvoke(currentDebugger->startDebug()); diff --git a/src/plugins/debugger/runner/runner.cpp b/src/plugins/debugger/runner/runner.cpp index 3e52c1e48..2fb27a2bf 100644 --- a/src/plugins/debugger/runner/runner.cpp +++ b/src/plugins/debugger/runner/runner.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -100,6 +101,12 @@ void Runner::run() } else { running(); } + } else { + DTK_WIDGET_NAMESPACE::DDialog dialog; + dialog.setWindowTitle(tr("Warning")); + dialog.setIcon(QIcon::fromTheme("dialog-warning")); + dialog.setMessage(tr("This Project does not support this operation")); + dialog.exec(); } } } diff --git a/src/plugins/javascript/CMakeLists.txt b/src/plugins/javascript/CMakeLists.txt index 33dcac4b2..b0f80a1e5 100644 --- a/src/plugins/javascript/CMakeLists.txt +++ b/src/plugins/javascript/CMakeLists.txt @@ -8,7 +8,6 @@ set(javascript_CPP javascriptplugin.cpp jsgenerator.cpp javascriptplugin.json - project/jsasynparse.cpp project/jsprojectgenerator.cpp project/properties/configpropertywidget.cpp project/properties/configutil.cpp @@ -18,7 +17,6 @@ set(javascript_CPP set(javascript_H javascriptplugin.h jsgenerator.h - project/jsasynparse.h project/jsprojectgenerator.h project/properties/configpropertywidget.h project/properties/configutil.h diff --git a/src/plugins/javascript/jsgenerator.cpp b/src/plugins/javascript/jsgenerator.cpp index 9fcbade12..483d14ff2 100644 --- a/src/plugins/javascript/jsgenerator.cpp +++ b/src/plugins/javascript/jsgenerator.cpp @@ -45,7 +45,7 @@ bool JSGenerator::requestDAPPort(const QString &ppid, const QMap ¶m, QString &retMsg) override; diff --git a/src/plugins/javascript/project/jsasynparse.cpp b/src/plugins/javascript/project/jsasynparse.cpp deleted file mode 100644 index f56dae189..000000000 --- a/src/plugins/javascript/project/jsasynparse.cpp +++ /dev/null @@ -1,190 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "jsasynparse.h" -#include "services/project/projectgenerator.h" - -#include "common/common.h" - -#include -#include -#include - -class JSAsynParsePrivate -{ - friend class JSAsynParse; - QDomDocument xmlDoc; - QThread *thread {nullptr}; - QString rootPath; - QList rows {}; -}; - -JSAsynParse::JSAsynParse() - : d(new JSAsynParsePrivate) -{ - QObject::connect(this, &QFileSystemWatcher::directoryChanged, - this, &JSAsynParse::doDirectoryChanged); - d->thread = new QThread(); - this->moveToThread(d->thread); - d->thread->start(); -} - -JSAsynParse::~JSAsynParse() -{ - if (d) { - if (d->thread) { - if (d->thread->isRunning()) - d->thread->quit(); - d->thread->wait(); - d->thread->deleteLater(); - d->thread = nullptr; - } - delete d; - } -} - -void JSAsynParse::parseProject(dpfservice::ProjectInfo &info) -{ - createRows(info.workspaceFolder()); - QSet jsFiles; - for (auto row : d->rows) { - QString fileName = row->text(); - if (fileName.endsWith(".js", Qt::CaseInsensitive)) { - jsFiles.insert(info.workspaceFolder() + "/" + fileName); - } - qInfo() << fileName; - } - info.setSourceFiles(jsFiles); - emit itemsModified(d->rows); -} - -void JSAsynParse::doDirectoryChanged(const QString &path) -{ - if (!path.startsWith(d->rootPath)) - return; - - d->rows.clear(); - - createRows(d->rootPath); - - emit itemsModified(d->rows); -} - -QString JSAsynParse::itemDisplayName(const QStandardItem *item) const -{ - if (!item) - return ""; - return item->data(Qt::DisplayRole).toString(); -} - -void JSAsynParse::iteratorDirectory(const QString &rootPath) -{ - QDir dir; - dir.setPath(rootPath); - dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs); - dir.setSorting(QDir::Name); - QDirIterator dirItera(dir, QDirIterator::Subdirectories); - while (dirItera.hasNext()) { - QString childPath = dirItera.next().remove(0, rootPath.size()); - QFileSystemWatcher::addPath(dirItera.filePath()); - QStandardItem *item = findItem(childPath); - QIcon icon = CustomIcons::icon(dirItera.fileInfo()); - auto newItem = new QStandardItem(icon, dirItera.fileName()); - newItem->setToolTip(dirItera.filePath()); - if (!item) { - d->rows.append(newItem); - } else { - item->appendRow(newItem); - } - } -} - -void JSAsynParse::iteratorFiles(const QString &rootPath) -{ - QDir dir; - dir.setPath(rootPath); - dir.setFilter(QDir::NoDotAndDotDot | QDir::Files); - dir.setSorting(QDir::Name); - QDirIterator fileItera(dir, QDirIterator::Subdirectories); - while (fileItera.hasNext()) { - QString childPath = fileItera.next().remove(0, rootPath.size()); - QStandardItem *item = findItem(childPath); - QIcon icon = CustomIcons::icon(fileItera.fileInfo()); - auto newItem = new QStandardItem(icon, fileItera.fileName()); - newItem->setToolTip(fileItera.filePath()); - if (!item) { - d->rows.append(newItem); - } else { - item->appendRow(newItem); - } - } -} - -void JSAsynParse::createRows(const QString &path) -{ - QString rootPath = path; - if (rootPath.endsWith(QDir::separator())) { - int separatorSize = QString(QDir::separator()).size(); - rootPath = rootPath.remove(rootPath.size() - separatorSize, separatorSize); - } - d->rootPath = rootPath; - QFileSystemWatcher::addPath(d->rootPath); - - iteratorDirectory(rootPath); - iteratorFiles(rootPath); -} - -QList JSAsynParse::rows(const QStandardItem *item) const -{ - QList result; - for (int i = 0; i < item->rowCount(); i++) { - result << item->child(i); - } - return result; -} - -QStandardItem *JSAsynParse::findItem(const QString &path, - QStandardItem *parent) const -{ - QString pathTemp = path; - if (pathTemp.endsWith(QDir::separator())) { - pathTemp = pathTemp.remove(pathTemp.size() - separatorSize(), separatorSize()); - } - - if (pathTemp.startsWith(QDir::separator())) - pathTemp.remove(0, separatorSize()); - - if (pathTemp.endsWith(QDir::separator())) - pathTemp.remove(pathTemp.size() - separatorSize(), separatorSize()); - - if (pathTemp.isEmpty()) - return parent; - - QStringList splitPaths = pathTemp.split(QDir::separator()); - QString name = splitPaths.takeFirst(); - - QList currRows{}; - if (parent) { - currRows = rows(parent); - } else { - currRows = d->rows; - } - - for (int i = 0; i < currRows.size(); i++) { - QStandardItem *child = currRows[i]; - if (name == itemDisplayName(child)) { - if (splitPaths.isEmpty()) { - return child; - } else { - return findItem(splitPaths.join(QDir::separator()), child); - } - } - } - return parent; -} - -int JSAsynParse::separatorSize() const -{ - return QString(QDir::separator()).size(); -} diff --git a/src/plugins/javascript/project/jsasynparse.h b/src/plugins/javascript/project/jsasynparse.h deleted file mode 100644 index a2a2d04cf..000000000 --- a/src/plugins/javascript/project/jsasynparse.h +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef JSAsynParse_H -#define JSAsynParse_H - -#include "common/common.h" - -#include -#include - -class QStandardItem; -class QAction; -class JSAsynParsePrivate; -class JSAsynParse : public QFileSystemWatcher -{ - Q_OBJECT - friend class JSProjectGenerator; - JSAsynParsePrivate *const d; -public: - template - struct ParseInfo{ - T result; - bool isNormal = true; - }; - - JSAsynParse(); - virtual ~JSAsynParse(); - -signals: - void itemsModified(const QList &info); - void parsedError(const ParseInfo &info); - -public slots: - void parseProject(dpfservice::ProjectInfo &info); - -private slots: - void doDirectoryChanged(const QString &path); - -private: - void createRows(const QString &path); - QString itemDisplayName(const QStandardItem *item) const; - QStandardItem *findItem(const QString &path, QStandardItem *parent = nullptr) const; - QList rows(const QStandardItem *item) const; - int separatorSize() const; - void iteratorDirectory(const QString &rootPath); - void iteratorFiles(const QString &rootPath); -}; - -#endif // JSAsynParse_H diff --git a/src/plugins/javascript/project/jsprojectgenerator.cpp b/src/plugins/javascript/project/jsprojectgenerator.cpp index 7461900b2..b8551ad6c 100644 --- a/src/plugins/javascript/project/jsprojectgenerator.cpp +++ b/src/plugins/javascript/project/jsprojectgenerator.cpp @@ -3,25 +3,18 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "jsprojectgenerator.h" -#include "jsasynparse.h" #include "properties/configpropertywidget.h" #include "common/dialog/propertiesdialog.h" #include "services/window/windowservice.h" -#include "services/builder/builderservice.h" -#include "services/option/optionmanager.h" #include -#include #include using namespace dpfservice; class JSProjectGeneratorPrivate { friend class JSProjectGenerator; - QStandardItem* configureRootItem {nullptr}; QMenu *jsMenu {nullptr}; - QProcess *menuGenProcess {nullptr}; - QHash projectParses {}; ProjectInfo prjInfo; }; @@ -48,70 +41,6 @@ QStringList JSProjectGenerator::supportLanguages() return {"JS"}; } -DWidget *JSProjectGenerator::configureWidget(const QString &language, - const QString &projectPath) -{ - d->prjInfo.setLanguage(language); - d->prjInfo.setKitName(JSProjectGenerator::toolKitName()); - d->prjInfo.setWorkspaceFolder(projectPath); - - return nullptr; -} - -void JSProjectGenerator::acceptConfigure() -{ - configure(d->prjInfo); -} - -bool JSProjectGenerator::configure(const ProjectInfo &info) -{ - ProjectGenerator::configure(info); - - auto root = createRootItem(info); - auto &ctx = dpfInstance.serviceContext(); - ProjectService *projectService = ctx.service(ProjectService::name()); - if (projectService && root) { - projectService->addRootItem(root); - projectService->expandedDepth(root, 1); - } - - return true; -} - -QStandardItem *JSProjectGenerator::createRootItem(const ProjectInfo &info) -{ - QStandardItem * rootItem = ProjectGenerator::createRootItem(info); - - d->projectParses[rootItem] = new JSAsynParse(); - QObject::connect(d->projectParses[rootItem], - &JSAsynParse::itemsModified, - this, &JSProjectGenerator::doProjectChildsModified, - Qt::ConnectionType::UniqueConnection); - - ProjectInfo tempInfo = info; - d->projectParses[rootItem]->parseProject(tempInfo); - ProjectInfo::set(rootItem, tempInfo); - - return rootItem; -} - -void JSProjectGenerator::removeRootItem(QStandardItem *root) -{ - if (!root) - return; - auto parser = d->projectParses[root]; - - while (root->hasChildren()) { - root->takeRow(0); - } - d->projectParses.remove(root); - - delete root; - - if (parser) - delete parser; -} - QMenu *JSProjectGenerator::createItemMenu(const QStandardItem *item) { if (item->parent()) @@ -135,17 +64,6 @@ QMenu *JSProjectGenerator::createItemMenu(const QStandardItem *item) return menu; } -void JSProjectGenerator::doProjectChildsModified(const QList &info) -{ - auto rootItem = d->projectParses.key(qobject_cast(sender())); - if (rootItem) { - while (rootItem->hasChildren()) { - rootItem->takeRow(0); - } - rootItem->appendRows(info); - } -} - void JSProjectGenerator::doJSCleanMenu() { if (d->jsMenu) { diff --git a/src/plugins/javascript/project/jsprojectgenerator.h b/src/plugins/javascript/project/jsprojectgenerator.h index 4f7bbc818..cb9e88fa1 100644 --- a/src/plugins/javascript/project/jsprojectgenerator.h +++ b/src/plugins/javascript/project/jsprojectgenerator.h @@ -5,32 +5,25 @@ #ifndef JSProjectGenerator_H #define JSProjectGenerator_H -#include "jsasynparse.h" #include "services/project/projectservice.h" +#include "services/project/directorygenerator.h" #include -#include class JSProjectGeneratorPrivate; -class JSProjectGenerator : public dpfservice::ProjectGenerator +class JSProjectGenerator : public dpfservice::DirectoryGenerator { Q_OBJECT JSProjectGeneratorPrivate *const d; public: explicit JSProjectGenerator(); virtual ~JSProjectGenerator() override; - static QString toolKitName() { return "jsdirectory"; } + static QString toolKitName() { return "javascript"; } + virtual QString configureKitName() override { return "javascript"; } virtual QStringList supportLanguages() override; - virtual DWidget* configureWidget(const QString &language, - const QString &projectPath) override; - virtual void acceptConfigure() override; - virtual bool configure(const dpfservice::ProjectInfo &info = {}) override; - virtual QStandardItem *createRootItem(const dpfservice::ProjectInfo &info) override; - virtual void removeRootItem(QStandardItem* root) override; virtual QMenu* createItemMenu(const QStandardItem *item) override; private slots: - void doProjectChildsModified(const QList &info); void doJSCleanMenu(); void actionProperties(const dpfservice::ProjectInfo &info, QStandardItem *item); }; diff --git a/src/plugins/linglong/project/llasynparse.cpp b/src/plugins/linglong/project/llasynparse.cpp deleted file mode 100644 index 1c4b3a913..000000000 --- a/src/plugins/linglong/project/llasynparse.cpp +++ /dev/null @@ -1,189 +0,0 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "llasynparse.h" - -class LLAsynParsePrivate -{ - friend class LLAsynParse; - QThread *thread { nullptr }; - QString rootPath; - QSet fileList {}; - QList rows {}; - - QStandardItem *rootItem { nullptr }; - - bool stop { false }; -}; - -LLAsynParse::LLAsynParse(QStandardItem *root) - : d(new LLAsynParsePrivate) -{ - d->rootItem = root; - QObject::connect(this, &QFileSystemWatcher::directoryChanged, - this, &LLAsynParse::doDirectoryChanged); - d->thread = new QThread(); - this->moveToThread(d->thread); - d->thread->start(); -} - -LLAsynParse::~LLAsynParse() -{ - if (d) { - if (d->thread) { - d->stop = true; - if (d->thread->isRunning()) - d->thread->quit(); - d->thread->wait(); - d->thread->deleteLater(); - d->thread = nullptr; - } - delete d; - } -} - -void LLAsynParse::parseProject(const dpfservice::ProjectInfo &info) -{ - createRows(info.workspaceFolder()); - emit itemsModified(d->rows); -} - -QSet LLAsynParse::getFilelist() -{ - return d->fileList; -} - -void LLAsynParse::doDirectoryChanged(const QString &path) -{ - if (!path.startsWith(d->rootPath)) - return; - - if (d->rootItem) { - while (d->rootItem->hasChildren()) - d->rootItem->takeRow(0); - } - - d->rows.clear(); - - createRows(d->rootPath); - - emit itemsModified(d->rows); -} - -QString LLAsynParse::itemDisplayName(const QStandardItem *item) const -{ - if (!item) - return ""; - return item->data(Qt::DisplayRole).toString(); -} - -void LLAsynParse::createRows(const QString &path) -{ - QString rootPath = path; - d->fileList.clear(); - if (rootPath.endsWith(QDir::separator())) { - int separatorSize = QString(QDir::separator()).size(); - rootPath = rootPath.remove(rootPath.size() - separatorSize, separatorSize); - } - - d->rootPath = rootPath; - QFileSystemWatcher::addPath(d->rootPath); - - { - QDir dir; - dir.setPath(rootPath); - dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs); - dir.setSorting(QDir::Name); - QDirIterator dirItera(dir, QDirIterator::Subdirectories); - while (dirItera.hasNext()) { - if (d->stop) - return; - QString childPath = dirItera.next().remove(0, rootPath.size()); - QFileSystemWatcher::addPath(dirItera.filePath()); - QStandardItem *item = findItem(childPath); - auto newItem = new QStandardItem(dirItera.fileName()); - newItem->setToolTip(dirItera.filePath()); - if (item) - item->appendRow(newItem); - else - d->rootItem->appendRow(newItem); - d->rows.append(newItem); - } - } - { - QDir dir; - dir.setPath(rootPath); - dir.setFilter(QDir::NoDotAndDotDot | QDir::Files); - dir.setSorting(QDir::Name); - QDirIterator fileItera(dir, QDirIterator::Subdirectories); - while (fileItera.hasNext()) { - if (d->stop) - return; - QString childPath = fileItera.next().remove(0, rootPath.size()); - QStandardItem *item = findItem(childPath); - auto newItem = new QStandardItem(fileItera.fileName()); - newItem->setToolTip(fileItera.filePath()); - if (item) - item->appendRow(newItem); - else - d->rootItem->appendRow(newItem); - d->rows.append(newItem); - d->fileList.insert(fileItera.filePath()); - } - } -} - -QList LLAsynParse::rows(const QStandardItem *item) const -{ - QList result; - for (int i = 0; i < item->rowCount(); i++) { - result << item->child(i); - } - return result; -} - -QStandardItem *LLAsynParse::findItem(const QString &path, - QStandardItem *parent) const -{ - QString pathTemp = path; - if (pathTemp.endsWith(QDir::separator())) { - pathTemp = pathTemp.remove(pathTemp.size() - separatorSize(), separatorSize()); - } - - if (pathTemp.startsWith(QDir::separator())) - pathTemp.remove(0, separatorSize()); - - if (pathTemp.endsWith(QDir::separator())) - pathTemp.remove(pathTemp.size() - separatorSize(), separatorSize()); - - if (pathTemp.isEmpty()) - return parent; - - QStringList splitPaths = pathTemp.split(QDir::separator()); - QString name = splitPaths.takeFirst(); - - QList currRows {}; - if (parent) { - currRows = rows(parent); - } else { - currRows = d->rows; - } - - for (int i = 0; i < currRows.size(); i++) { - QStandardItem *child = currRows[i]; - if (name == itemDisplayName(child)) { - if (splitPaths.isEmpty()) { - return child; - } else { - return findItem(splitPaths.join(QDir::separator()), child); - } - } - } - return parent; -} - -int LLAsynParse::separatorSize() const -{ - return QString(QDir::separator()).size(); -} diff --git a/src/plugins/linglong/project/llprojectgenerator.cpp b/src/plugins/linglong/project/llprojectgenerator.cpp index d8034f1d6..9261e5139 100644 --- a/src/plugins/linglong/project/llprojectgenerator.cpp +++ b/src/plugins/linglong/project/llprojectgenerator.cpp @@ -7,27 +7,12 @@ using namespace dpfservice; -class LLProjectGeneratorPrivate -{ - friend class LLProjectGenerator; - QHash projectParses {}; - ProjectInfo prjInfo; -}; - LLProjectGenerator::LLProjectGenerator() - : d(new LLProjectGeneratorPrivate) { } LLProjectGenerator::~LLProjectGenerator() { - if (d) { - for (auto parser : d->projectParses.values()) { - if (parser) - delete parser; - } - delete d; - } } QStringList LLProjectGenerator::supportLanguages() @@ -40,68 +25,17 @@ DWidget *LLProjectGenerator::configureWidget(const QString &language, { using namespace dpfservice; - d->prjInfo.setLanguage(language); - d->prjInfo.setKitName(LLProjectGenerator::toolKitName()); - d->prjInfo.setWorkspaceFolder(projectPath); - d->prjInfo.setExePrograms({ "LingLong" }); + prjInfo.setLanguage(language); + prjInfo.setKitName(LLProjectGenerator::toolKitName()); + prjInfo.setWorkspaceFolder(projectPath); + prjInfo.setExePrograms({ "LingLong" }); return nullptr; } void LLProjectGenerator::acceptConfigure() { - configure(d->prjInfo); -} - -bool LLProjectGenerator::configure(const dpfservice::ProjectInfo &projectInfo) -{ - dpfservice::ProjectGenerator::configure(projectInfo); - - auto root = createRootItem(projectInfo); - ProjectService *projectService = dpfGetService(ProjectService); - if (projectService && root) { - projectService->addRootItem(root); - projectService->expandedDepth(root, 1); - } - - return true; -} - -QStandardItem *LLProjectGenerator::createRootItem(const dpfservice::ProjectInfo &info) -{ - using namespace dpfservice; - - QStandardItem *rootItem = ProjectGenerator::createRootItem(info); - d->projectParses[rootItem] = new LLAsynParse(rootItem); - QObject::connect(d->projectParses[rootItem], - &LLAsynParse::itemsModified, - this, &LLProjectGenerator::doProjectChildsModified, - Qt::ConnectionType::UniqueConnection); - QMetaObject::invokeMethod(d->projectParses[rootItem], "parseProject", - Q_ARG(const dpfservice::ProjectInfo &, info)); - auto sourceFiles = d->projectParses[rootItem]->getFilelist(); - dpfservice::ProjectInfo tempInfo = info; - tempInfo.setSourceFiles(sourceFiles); - dpfservice::ProjectInfo::set(rootItem, tempInfo); - - return rootItem; -} - -void LLProjectGenerator::removeRootItem(QStandardItem *root) -{ - if (!root) - return; - auto parser = d->projectParses[root]; - - while (root->hasChildren()) { - root->takeRow(0); - } - d->projectParses.remove(root); - - delete root; - - if (parser) - delete parser; + configure(prjInfo); } QMenu *LLProjectGenerator::createItemMenu(const QStandardItem *item) @@ -127,23 +61,7 @@ QMenu *LLProjectGenerator::createItemMenu(const QStandardItem *item) return menu; } -void LLProjectGenerator::doProjectChildsModified(const QList &items) -{ - auto rootItem = d->projectParses.key(qobject_cast(sender())); - if (!rootItem) - return; - - for (auto &item : items) { - item->setIcon(CustomIcons::icon(item->toolTip())); - } - - rootItem->setData(ParsingState::Done, Parsing_State_Role); -} - void LLProjectGenerator::actionProperties(const ProjectInfo &info, QStandardItem *item) { - //PropertiesDialog dlg; - // ConfigPropertyWidget *property = new ConfigPropertyWidget(info, item); - // dlg.insertPropertyPanel("Config", property); - // dlg.exec(); + } diff --git a/src/plugins/linglong/project/llprojectgenerator.h b/src/plugins/linglong/project/llprojectgenerator.h index ce750c023..9566205d0 100644 --- a/src/plugins/linglong/project/llprojectgenerator.h +++ b/src/plugins/linglong/project/llprojectgenerator.h @@ -5,12 +5,11 @@ #ifndef LLPROJECTGENERATOR_H #define LLPROJECTGENERATOR_H -#include "llasynparse.h" #include "llglobal.h" #include "services/project/projectservice.h" +#include "services/project/directorygenerator.h" -class LLProjectGeneratorPrivate; -class LLProjectGenerator : public dpfservice::ProjectGenerator +class LLProjectGenerator : public dpfservice::DirectoryGenerator { Q_OBJECT public: @@ -18,21 +17,16 @@ class LLProjectGenerator : public dpfservice::ProjectGenerator virtual ~LLProjectGenerator(); static QString toolKitName() { return LL_TOOLKIT; } + virtual QString configureKitName() override { return LL_TOOLKIT; } virtual QStringList supportLanguages() override; + virtual QStringList supportFileNames() override { return {"linglong.yaml"}; } virtual DWidget *configureWidget(const QString &language, const QString &projectPath) override; - virtual bool configure(const dpfservice::ProjectInfo &info = {}) override; virtual void acceptConfigure() override; - virtual QStandardItem *createRootItem(const dpfservice::ProjectInfo &items) override; - virtual void removeRootItem(QStandardItem *root) override; virtual QMenu *createItemMenu(const QStandardItem *item) override; private slots: - void doProjectChildsModified(const QList &items); void actionProperties(const dpfservice::ProjectInfo &info, QStandardItem *item); - -private: - LLProjectGeneratorPrivate *const d; }; #endif // LLPROJECTGENERATOR_H diff --git a/src/plugins/project/projectcore.cpp b/src/plugins/project/projectcore.cpp index f06d52155..aff807dbc 100644 --- a/src/plugins/project/projectcore.cpp +++ b/src/plugins/project/projectcore.cpp @@ -13,6 +13,7 @@ #include "base/abstractaction.h" #include "base/abstractwidget.h" #include "services/project/projectservice.h" +#include "services/project/directorygenerator.h" #include "services/locator/locatorservice.h" #include "services/editor/editorservice.h" #include "locator/allprojectfilelocator.h" @@ -227,6 +228,9 @@ void ProjectCore::pluginsStartedMain() ProjectService *projectService = ctx.service(ProjectService::name()); WindowService *windowService = ctx.service(WindowService::name()); if (projectService && windowService) { + QString errorString; + if (!projectService->implGenerator(DirectoryGenerator::toolKitName(), &errorString)) + qWarning() << errorString; QStringList kitNames = projectService->supportGeneratorName(); for (auto kitName : kitNames) { auto generator = projectService->createGenerator(kitName); @@ -307,7 +311,8 @@ void ProjectCore::confirmProjectKit(const QString &path) DStackedWidget *configureWidget = new DStackedWidget; dialog.addContent(configureWidget); - // check defualt kit + // check defualt kit by supportNames + bool hasDefault = false; for (auto kit : allKits) { auto generator = projectService->createGenerator(kit); QStringList fileNames = generator->supportFileNames(); @@ -319,11 +324,32 @@ void ProjectCore::confirmProjectKit(const QString &path) auto widget = generator->configureWidget(generator->supportLanguages().first(), path); if (widget) configureWidget->addWidget(widget); + hasDefault = true; break; } } } + if (!hasDefault) { + // Apply language-specific processing by suffix + QString kit = DirectoryGenerator::toolKitName(); + for (auto fileInfo : QDir(path).entryInfoList()) { + if (fileInfo.suffix() == "py") + kit = "python"; + else if (fileInfo.suffix() == "js") + kit = "javascript"; + } + auto generator = projectService->createGenerator(kit); + if (!generator) { + kit = DirectoryGenerator::toolKitName(); + generator = projectService->createGenerator(DirectoryGenerator::toolKitName()); + } + cbBox->setCurrentText(kit); + auto widget = generator->configureWidget(generator->supportLanguages().first(), path); + if (widget) + configureWidget->addWidget(widget); + } + // select kit connect(cbBox, &QComboBox::currentTextChanged, this, [=, &dialog, &originalSize](const QString &text) { auto generator = projectService->createGenerator(text); diff --git a/src/plugins/python/CMakeLists.txt b/src/plugins/python/CMakeLists.txt index ad165465d..33df2213b 100644 --- a/src/plugins/python/CMakeLists.txt +++ b/src/plugins/python/CMakeLists.txt @@ -10,7 +10,6 @@ include_directories(${CPPDAP_DIR}/include) set(CXX_CPP python/pythondebug.cpp python/pythongenerator.cpp - python/project/pythonasynparse.cpp python/project/pythonprojectgenerator.cpp python/project/properties/configpropertywidget.cpp python/project/properties/configutil.cpp @@ -25,7 +24,6 @@ set(CXX_CPP set(CXX_H python/pythondebug.h python/pythongenerator.h - python/project/pythonasynparse.h python/project/pythonprojectgenerator.h python/project/properties/configpropertywidget.h python/project/properties/configutil.h diff --git a/src/plugins/python/python/project/pythonasynparse.cpp b/src/plugins/python/python/project/pythonasynparse.cpp deleted file mode 100644 index bf07091b2..000000000 --- a/src/plugins/python/python/project/pythonasynparse.cpp +++ /dev/null @@ -1,184 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "pythonasynparse.h" -#include "services/project/projectgenerator.h" - -#include "common/common.h" - -#include -#include - -class PythonAsynParsePrivate -{ - friend class PythonAsynParse; - QDomDocument xmlDoc; - QThread *thread {nullptr}; - QString rootPath; - QSet fileList {}; - QList rows {}; -}; - -PythonAsynParse::PythonAsynParse() - : d(new PythonAsynParsePrivate) -{ - QObject::connect(this, &QFileSystemWatcher::directoryChanged, - this, &PythonAsynParse::doDirectoryChanged); - d->thread = new QThread(); - this->moveToThread(d->thread); - d->thread->start(); -} - -PythonAsynParse::~PythonAsynParse() -{ - if (d) { - if (d->thread) { - if (d->thread->isRunning()) - d->thread->quit(); - d->thread->wait(); - d->thread->deleteLater(); - d->thread = nullptr; - } - delete d; - } -} - -void PythonAsynParse::parseProject(const dpfservice::ProjectInfo &info) -{ - createRows(info.workspaceFolder()); - emit itemsModified(d->rows); -} - -QSet PythonAsynParse::getFilelist() -{ - return d->fileList; -} - -void PythonAsynParse::doDirectoryChanged(const QString &path) -{ - if (!path.startsWith(d->rootPath)) - return; - - d->rows.clear(); - - createRows(d->rootPath); - - emit itemsModified(d->rows); -} - -QString PythonAsynParse::itemDisplayName(const QStandardItem *item) const -{ - if (!item) - return ""; - return item->data(Qt::DisplayRole).toString(); -} - -void PythonAsynParse::createRows(const QString &path) -{ - QString rootPath = path; - d->fileList.clear(); - if (rootPath.endsWith(QDir::separator())) { - int separatorSize = QString(QDir::separator()).size(); - rootPath = rootPath.remove(rootPath.size() - separatorSize, separatorSize); - } - - // 缓存当前工程目录 - d->rootPath = rootPath; - QFileSystemWatcher::addPath(d->rootPath); - - {// 避免变量冲突 迭代文件夹 - QDir dir; - dir.setPath(rootPath); - dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs); - dir.setSorting(QDir::Name); - QDirIterator dirItera(dir, QDirIterator::Subdirectories); - while (dirItera.hasNext()) { - QString childPath = dirItera.next().remove(0, rootPath.size()); - QFileSystemWatcher::addPath(dirItera.filePath()); - QStandardItem *item = findItem(childPath); - QIcon icon = CustomIcons::icon(dirItera.fileInfo()); - auto newItem = new QStandardItem(icon, dirItera.fileName()); - newItem->setToolTip(dirItera.filePath()); - if (!item) { - d->rows.append(newItem); - } else { - item->appendRow(newItem); - } - } - } - {// 避免变量冲突 迭代文件 - QDir dir; - dir.setPath(rootPath); - dir.setFilter(QDir::NoDotAndDotDot | QDir::Files); - dir.setSorting(QDir::Name); - QDirIterator fileItera(dir, QDirIterator::Subdirectories); - while (fileItera.hasNext()) { - QString childPath = fileItera.next().remove(0, rootPath.size()); - QStandardItem *item = findItem(childPath); - QIcon icon = CustomIcons::icon(fileItera.fileInfo()); - auto newItem = new QStandardItem(icon, fileItera.fileName()); - newItem->setToolTip(fileItera.filePath()); - if (!item) { - d->rows.append(newItem); - } else { - item->appendRow(newItem); - } - d->fileList.insert(fileItera.filePath()); - } - } -} - -QList PythonAsynParse::rows(const QStandardItem *item) const -{ - QList result; - for (int i = 0; i < item->rowCount(); i++) { - result << item->child(i); - } - return result; -} - -QStandardItem *PythonAsynParse::findItem(const QString &path, - QStandardItem *parent) const -{ - QString pathTemp = path; - if (pathTemp.endsWith(QDir::separator())) { - pathTemp = pathTemp.remove(pathTemp.size() - separatorSize(), separatorSize()); - } - - if (pathTemp.startsWith(QDir::separator())) - pathTemp.remove(0, separatorSize()); - - if (pathTemp.endsWith(QDir::separator())) - pathTemp.remove(pathTemp.size() - separatorSize(), separatorSize()); - - if (pathTemp.isEmpty()) - return parent; - - QStringList splitPaths = pathTemp.split(QDir::separator()); - QString name = splitPaths.takeFirst(); - - QList currRows{}; - if (parent) { - currRows = rows(parent); - } else { - currRows = d->rows; - } - - for (int i = 0; i < currRows.size(); i++) { - QStandardItem *child = currRows[i]; - if (name == itemDisplayName(child)) { - if (splitPaths.isEmpty()) { - return child; - } else { - return findItem(splitPaths.join(QDir::separator()), child); - } - } - } - return parent; -} - -int PythonAsynParse::separatorSize() const -{ - return QString(QDir::separator()).size(); -} diff --git a/src/plugins/python/python/project/pythonasynparse.h b/src/plugins/python/python/project/pythonasynparse.h deleted file mode 100644 index 5677bc983..000000000 --- a/src/plugins/python/python/project/pythonasynparse.h +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef PYTHONASYNPARSE_H -#define PYTHONASYNPARSE_H - -#include "common/common.h" - -#include -#include -#include - -class QStandardItem; -class QAction; -class PythonAsynParsePrivate; -class PythonAsynParse : public QFileSystemWatcher -{ - Q_OBJECT - friend class PythonGenerator; - PythonAsynParsePrivate *const d; -public: - template - struct ParseInfo{ - T result; - bool isNormal = true; - }; - - PythonAsynParse(); - QSet getFilelist(); - virtual ~PythonAsynParse(); - -signals: - void itemsModified(const QList &info); - void parsedError(const ParseInfo &info); - -public slots: - void parseProject(const dpfservice::ProjectInfo &info); - -private slots: - void doDirectoryChanged(const QString &path); - -private: - void createRows(const QString &path); - QString itemDisplayName(const QStandardItem *item) const; - QStandardItem *findItem(const QString &path, QStandardItem *parent = nullptr) const; - QList rows(const QStandardItem *item) const; - int separatorSize() const; -}; - -#endif // PYTHONASYNPARSE_H diff --git a/src/plugins/python/python/project/pythonprojectgenerator.cpp b/src/plugins/python/python/project/pythonprojectgenerator.cpp index bc497f754..82e803045 100644 --- a/src/plugins/python/python/project/pythonprojectgenerator.cpp +++ b/src/plugins/python/python/project/pythonprojectgenerator.cpp @@ -3,27 +3,16 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "pythonprojectgenerator.h" -#include "pythonasynparse.h" #include "python/project/properties/configpropertywidget.h" #include "python/project/properties/configutil.h" #include "common/dialog/propertiesdialog.h" #include "services/window/windowservice.h" -#include "services/builder/builderservice.h" -#include "services/option/optionmanager.h" - -#include -#include -#include using namespace config; class PythonProjectGeneratorPrivate { friend class PythonProjectGenerator; - QStandardItem* configureRootItem {nullptr}; - QMenu *pythonMenu {nullptr}; - QProcess *menuGenProcess {nullptr}; - QHash projectParses {}; - dpfservice::ProjectInfo prjInfo; + QMenu *pythonMenu { nullptr }; }; PythonProjectGenerator::PythonProjectGenerator() @@ -48,81 +37,31 @@ PythonProjectGenerator::~PythonProjectGenerator() QStringList PythonProjectGenerator::supportLanguages() { - return {dpfservice::MWMFA_PYTHON}; + return { dpfservice::MWMFA_PYTHON }; } DWidget *PythonProjectGenerator::configureWidget(const QString &language, - const QString &projectPath) + const QString &projectPath) { using namespace dpfservice; - d->prjInfo.setLanguage(language); - d->prjInfo.setKitName(PythonProjectGenerator::toolKitName()); - d->prjInfo.setWorkspaceFolder(projectPath); - d->prjInfo.setExePrograms({exeCurrent, exeEntry}); + prjInfo.setLanguage(language); + prjInfo.setKitName(PythonProjectGenerator::toolKitName()); + prjInfo.setWorkspaceFolder(projectPath); + prjInfo.setExePrograms({ exeCurrent, exeEntry }); return nullptr; } -void PythonProjectGenerator::acceptConfigure() -{ - configure(d->prjInfo); -} - bool PythonProjectGenerator::configure(const dpfservice::ProjectInfo &projectInfo) { - dpfservice::ProjectGenerator::configure(projectInfo); - - auto root = createRootItem(projectInfo); - using namespace dpfservice; - auto &ctx = dpfInstance.serviceContext(); - ProjectService *projectService = ctx.service(ProjectService::name()); - if (projectService && root) { - projectService->addRootItem(root); - projectService->expandedDepth(root, 1); - } + DirectoryGenerator::configure(projectInfo); ProjectConfigure *param = ConfigUtil::instance()->getConfigureParamPointer(); ConfigUtil::instance()->readConfig(ConfigUtil::instance()->getConfigPath(projectInfo.workspaceFolder()), *param); return true; } -QStandardItem *PythonProjectGenerator::createRootItem(const dpfservice::ProjectInfo &info) -{ - using namespace dpfservice; - - QStandardItem * rootItem = ProjectGenerator::createRootItem(info); - d->projectParses[rootItem] = new PythonAsynParse(); - QObject::connect(d->projectParses[rootItem], - &PythonAsynParse::itemsModified, - this, &PythonProjectGenerator::doProjectChildsModified, - Qt::ConnectionType::UniqueConnection); - d->projectParses[rootItem]->parseProject(info); - auto sourceFiles = d->projectParses[rootItem]->getFilelist(); - dpfservice::ProjectInfo tempInfo = info; - tempInfo.setSourceFiles(sourceFiles); - dpfservice::ProjectInfo::set(rootItem, tempInfo); - - return rootItem; -} - -void PythonProjectGenerator::removeRootItem(QStandardItem *root) -{ - if (!root) - return; - auto parser = d->projectParses[root]; - - while (root->hasChildren()) { - root->takeRow(0); - } - d->projectParses.remove(root); - - delete root; - - if (parser) - delete parser; -} - QMenu *PythonProjectGenerator::createItemMenu(const QStandardItem *item) { if (item->parent()) @@ -139,26 +78,13 @@ QMenu *PythonProjectGenerator::createItemMenu(const QStandardItem *item) QAction *action = new QAction(tr("Properties")); menu->addAction(action); - QObject::connect(action, &QAction::triggered, [=](){ + QObject::connect(action, &QAction::triggered, [=]() { actionProperties(info, itemTemp); }); return menu; } -void PythonProjectGenerator::doProjectChildsModified(const QList &info) -{ - auto rootItem = d->projectParses.key(qobject_cast(sender())); - if (rootItem) { - while (rootItem->hasChildren()) { - rootItem->takeRow(0); - } - rootItem->appendRows(info); - } - - rootItem->setData(ParsingState::Done, Parsing_State_Role); -} - void PythonProjectGenerator::doPythonCleanMenu() { if (d->pythonMenu) { diff --git a/src/plugins/python/python/project/pythonprojectgenerator.h b/src/plugins/python/python/project/pythonprojectgenerator.h index 8c035a5d4..1d3843f20 100644 --- a/src/plugins/python/python/project/pythonprojectgenerator.h +++ b/src/plugins/python/python/project/pythonprojectgenerator.h @@ -5,34 +5,32 @@ #ifndef PYTHONPROJECTGENERATOR_H #define PYTHONPROJECTGENERATOR_H -#include "pythonasynparse.h" #include "services/project/projectservice.h" +#include "services/project/directorygenerator.h" #include #include class PythonProjectGeneratorPrivate; -class PythonProjectGenerator : public dpfservice::ProjectGenerator +class PythonProjectGenerator : public dpfservice::DirectoryGenerator { Q_OBJECT PythonProjectGeneratorPrivate *const d; + public: explicit PythonProjectGenerator(); virtual ~PythonProjectGenerator(); static QString toolKitName() { return "python"; } + virtual QString configureKitName() override { return "python"; } virtual QStringList supportLanguages() override; - virtual DWidget* configureWidget(const QString &language, + virtual DWidget *configureWidget(const QString &language, const QString &projectPath) override; - virtual void acceptConfigure() override; virtual bool configure(const dpfservice::ProjectInfo &info = {}) override; - virtual QStandardItem *createRootItem(const dpfservice::ProjectInfo &info) override; - virtual void removeRootItem(QStandardItem* root) override; - virtual QMenu* createItemMenu(const QStandardItem *item) override; + virtual QMenu *createItemMenu(const QStandardItem *item) override; private slots: - void doProjectChildsModified(const QList &info); void doPythonCleanMenu(); void actionProperties(const dpfservice::ProjectInfo &info, QStandardItem *item); }; -#endif // PYTHONPROJECTGENERATOR_H +#endif // PYTHONPROJECTGENERATOR_H diff --git a/src/plugins/recent/mainframe/recentdisplay.cpp b/src/plugins/recent/mainframe/recentdisplay.cpp index c610405e4..099fba94c 100644 --- a/src/plugins/recent/mainframe/recentdisplay.cpp +++ b/src/plugins/recent/mainframe/recentdisplay.cpp @@ -263,7 +263,6 @@ void RecentDisplay::addProject(const QString &kitName, void RecentDisplay::doDoubleClickedProject(const QModelIndex &index) { - QString filePath = index.data(Qt::DisplayRole).toString(); QString kitName = index.data(ProjectKitName).toString(); QString language = index.data(ProjectLanguage).toString(); QString workspace = index.data(ProjectWorkspace).toString(); diff --git a/src/plugins/cxx/ninja/project/ninjaasynparse.cpp b/src/services/project/directoryasynparse.cpp similarity index 71% rename from src/plugins/cxx/ninja/project/ninjaasynparse.cpp rename to src/services/project/directoryasynparse.cpp index 00971b563..347a2ac8b 100644 --- a/src/plugins/cxx/ninja/project/ninjaasynparse.cpp +++ b/src/services/project/directoryasynparse.cpp @@ -1,57 +1,48 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later -#include "ninjaasynparse.h" -#include "services/project/projectgenerator.h" +#include "directoryasynparse.h" +#include "projectgenerator.h" #include "common/common.h" #include -#include -#include -class NinjaAsynParsePrivate +class DirectoryAsynParsePrivate { - friend class NinjaAsynParse; - QDomDocument xmlDoc; - QThread *thread { nullptr }; + friend class DirectoryAsynParse; QString rootPath; + QSet fileList {}; QList rows {}; }; -NinjaAsynParse::NinjaAsynParse() - : d(new NinjaAsynParsePrivate) +DirectoryAsynParse::DirectoryAsynParse() + : d(new DirectoryAsynParsePrivate) { QObject::connect(this, &QFileSystemWatcher::directoryChanged, - this, &NinjaAsynParse::doDirectoryChanged); - - d->thread = new QThread(); - this->moveToThread(d->thread); - d->thread->start(); + this, &DirectoryAsynParse::doDirectoryChanged); } -NinjaAsynParse::~NinjaAsynParse() +DirectoryAsynParse::~DirectoryAsynParse() { if (d) { - if (d->thread) { - if (d->thread->isRunning()) - d->thread->quit(); - d->thread->wait(); - d->thread->deleteLater(); - d->thread = nullptr; - } delete d; } } -void NinjaAsynParse::parseProject(const dpfservice::ProjectInfo &info) +void DirectoryAsynParse::parseProject(const dpfservice::ProjectInfo &info) { createRows(info.workspaceFolder()); emit itemsModified(d->rows); } -void NinjaAsynParse::doDirectoryChanged(const QString &path) +QSet DirectoryAsynParse::getFilelist() +{ + return d->fileList; +} + +void DirectoryAsynParse::doDirectoryChanged(const QString &path) { if (!path.startsWith(d->rootPath)) return; @@ -63,16 +54,17 @@ void NinjaAsynParse::doDirectoryChanged(const QString &path) emit itemsModified(d->rows); } -QString NinjaAsynParse::itemDisplayName(const QStandardItem *item) const +QString DirectoryAsynParse::itemDisplayName(const QStandardItem *item) const { if (!item) return ""; return item->data(Qt::DisplayRole).toString(); } -void NinjaAsynParse::createRows(const QString &path) +void DirectoryAsynParse::createRows(const QString &path) { QString rootPath = path; + d->fileList.clear(); if (rootPath.endsWith(QDir::separator())) { int separatorSize = QString(QDir::separator()).size(); rootPath = rootPath.remove(rootPath.size() - separatorSize, separatorSize); @@ -92,7 +84,8 @@ void NinjaAsynParse::createRows(const QString &path) QString childPath = dirItera.next().remove(0, rootPath.size()); QFileSystemWatcher::addPath(dirItera.filePath()); QStandardItem *item = findItem(childPath); - auto newItem = new QStandardItem(dirItera.fileName()); + QIcon icon = CustomIcons::icon(dirItera.fileInfo()); + auto newItem = new QStandardItem(icon, dirItera.fileName()); newItem->setToolTip(dirItera.filePath()); if (!item) { d->rows.append(newItem); @@ -110,18 +103,20 @@ void NinjaAsynParse::createRows(const QString &path) while (fileItera.hasNext()) { QString childPath = fileItera.next().remove(0, rootPath.size()); QStandardItem *item = findItem(childPath); - auto newItem = new QStandardItem(fileItera.fileName()); + QIcon icon = CustomIcons::icon(fileItera.fileInfo()); + auto newItem = new QStandardItem(icon, fileItera.fileName()); newItem->setToolTip(fileItera.filePath()); if (!item) { d->rows.append(newItem); } else { item->appendRow(newItem); } + d->fileList.insert(fileItera.filePath()); } } } -QList NinjaAsynParse::rows(const QStandardItem *item) const +QList DirectoryAsynParse::rows(const QStandardItem *item) const { QList result; for (int i = 0; i < item->rowCount(); i++) { @@ -130,8 +125,8 @@ QList NinjaAsynParse::rows(const QStandardItem *item) const return result; } -QStandardItem *NinjaAsynParse::findItem(const QString &path, - QStandardItem *parent) const +QStandardItem *DirectoryAsynParse::findItem(const QString &path, + QStandardItem *parent) const { QString pathTemp = path; if (pathTemp.endsWith(QDir::separator())) { @@ -170,7 +165,7 @@ QStandardItem *NinjaAsynParse::findItem(const QString &path, return parent; } -int NinjaAsynParse::separatorSize() const +int DirectoryAsynParse::separatorSize() const { return QString(QDir::separator()).size(); } diff --git a/src/plugins/linglong/project/llasynparse.h b/src/services/project/directoryasynparse.h similarity index 69% rename from src/plugins/linglong/project/llasynparse.h rename to src/services/project/directoryasynparse.h index d4eb09b0d..105632f93 100644 --- a/src/plugins/linglong/project/llasynparse.h +++ b/src/services/project/directoryasynparse.h @@ -2,16 +2,23 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -#ifndef LLASYNPARSE_H -#define LLASYNPARSE_H +#ifndef PYTHONASYNPARSE_H +#define PYTHONASYNPARSE_H #include "common/common.h" -class LLAsynParsePrivate; -class LLAsynParse : public QFileSystemWatcher +#include +#include +#include + +class QStandardItem; +class QAction; +class DirectoryAsynParsePrivate; +class DirectoryAsynParse : public QFileSystemWatcher { Q_OBJECT - LLAsynParsePrivate *const d; + friend class DirectoryAsynParse; + DirectoryAsynParsePrivate *const d; public: template @@ -21,10 +28,9 @@ class LLAsynParse : public QFileSystemWatcher bool isNormal = true; }; + DirectoryAsynParse(); QSet getFilelist(); - - LLAsynParse(QStandardItem *rootItem); - virtual ~LLAsynParse(); + virtual ~DirectoryAsynParse(); signals: void itemsModified(const QList &info); @@ -44,4 +50,4 @@ private slots: int separatorSize() const; }; -#endif // LLASYNPARSE_H +#endif // PYTHONASYNPARSE_H diff --git a/src/services/project/directorygenerator.cpp b/src/services/project/directorygenerator.cpp new file mode 100644 index 000000000..73aab33f5 --- /dev/null +++ b/src/services/project/directorygenerator.cpp @@ -0,0 +1,116 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "directorygenerator.h" +#include "directoryasynparse.h" +#include "projectservice.h" + +using namespace dpfservice; +class DirectoryGeneratorPrivate +{ + friend class dpfservice::DirectoryGenerator; + QStandardItem *configureRootItem { nullptr }; + QHash projectParses {}; + dpfservice::ProjectInfo prjInfo; +}; + +DirectoryGenerator::DirectoryGenerator() + : d(new DirectoryGeneratorPrivate()) +{ +} + +DirectoryGenerator::~DirectoryGenerator() +{ + qInfo() << __FUNCTION__; + for (auto parser : d->projectParses.values()) + if(parser) + delete parser; + + if (d) + delete d; +} + +DWidget *DirectoryGenerator::configureWidget(const QString &language, + const QString &projectPath) +{ + using namespace dpfservice; + + prjInfo.setLanguage(language); + prjInfo.setKitName(configureKitName()); + prjInfo.setWorkspaceFolder(projectPath); + + return nullptr; +} + +void DirectoryGenerator::acceptConfigure() +{ + configure(prjInfo); +} + +bool DirectoryGenerator::configure(const dpfservice::ProjectInfo &projectInfo) +{ + dpfservice::ProjectGenerator::configure(projectInfo); + + auto root = createRootItem(projectInfo); + ProjectService *projectService = dpfGetService(ProjectService); + if (projectService && root) { + projectService->addRootItem(root); + projectService->expandedDepth(root, 1); + } + + return true; +} + +QStandardItem *DirectoryGenerator::createRootItem(const dpfservice::ProjectInfo &info) +{ + using namespace dpfservice; + + QStandardItem *rootItem = ProjectGenerator::createRootItem(info); + d->configureRootItem = rootItem; + auto parser = new DirectoryAsynParse(); + d->projectParses[rootItem] = parser; + QObject::connect(d->projectParses[rootItem], + &DirectoryAsynParse::itemsModified, + this, &DirectoryGenerator::doProjectChildsModified, + Qt::ConnectionType::UniqueConnection); + QtConcurrent::run(parser, &DirectoryAsynParse::parseProject, info); + + return rootItem; +} + +void DirectoryGenerator::removeRootItem(QStandardItem *root) +{ + if (!root) + return; + auto parser = d->projectParses[root]; + + while (root->hasChildren()) { + root->takeRow(0); + } + d->projectParses.remove(root); + + delete root; + + if (parser) + delete parser; +} + +void DirectoryGenerator::doProjectChildsModified(const QList &info) +{ + auto sourceFiles = d->projectParses[d->configureRootItem]->getFilelist(); + ProjectInfo tempInfo = prjInfo; + tempInfo.setSourceFiles(sourceFiles); + ProjectInfo::set(d->configureRootItem, tempInfo); + project.activeProject(tempInfo.kitName(), tempInfo.language(), tempInfo.workspaceFolder()); + + auto rootItem = d->projectParses.key(qobject_cast(sender())); + if (rootItem) { + while (rootItem->hasChildren()) { + rootItem->takeRow(0); + } + rootItem->appendRows(info); + } + + rootItem->setData(ParsingState::Done, Parsing_State_Role); +} diff --git a/src/services/project/directorygenerator.h b/src/services/project/directorygenerator.h new file mode 100644 index 000000000..ace2d0a9c --- /dev/null +++ b/src/services/project/directorygenerator.h @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef DIRECTORYPROJECTGENERATOR_H +#define DIRECTORYPROJECTGENERATOR_H + +#include "projectgenerator.h" +class DirectoryGeneratorPrivate; +namespace dpfservice { + +class DirectoryGenerator : public ProjectGenerator +{ + Q_OBJECT + DirectoryGeneratorPrivate *const d; + +public: + explicit DirectoryGenerator(); + virtual ~DirectoryGenerator(); + static QString toolKitName() { return "directory"; } + virtual QString configureKitName() { return "directory"; } + virtual DWidget *configureWidget(const QString &language, + const QString &projectPath) override; + virtual void acceptConfigure() override; + virtual bool configure(const dpfservice::ProjectInfo &info = {}) override; + virtual QStandardItem *createRootItem(const dpfservice::ProjectInfo &info) override; + virtual void removeRootItem(QStandardItem *root) override; +protected: + dpfservice::ProjectInfo prjInfo; +public slots: + void doProjectChildsModified(const QList &info); +}; + +} +#endif // DIRECTORYPROJECTGENERATOR_H diff --git a/src/services/project/projectgenerator.cpp b/src/services/project/projectgenerator.cpp index bf457d711..f1fd8694f 100644 --- a/src/services/project/projectgenerator.cpp +++ b/src/services/project/projectgenerator.cpp @@ -25,7 +25,7 @@ QStringList dpfservice::ProjectGenerator::supportLanguages() { - return {}; + return { "Unknown" }; } QStringList dpfservice::ProjectGenerator::supportFileNames()