From 0b764bf30a2d5c647fd826b003123386bb262da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=AE=87=E6=B8=85=E9=9F=B3?= <2422523675@qq.com> Date: Fri, 10 Mar 2023 20:53:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8route=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=8A=82=E7=82=B9=E8=B7=AF=E5=BE=84=EF=BC=8C?= =?UTF-8?q?libProjectManager=E6=B7=BB=E5=8A=A0=E5=AE=9E=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8CprojectPresent=E6=A0=B7=E6=9D=BF=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WordsIDE/projectpresent.cpp | 68 +++++++++++++++++++++++++ WordsIDE/projectpresent.h | 38 ++++++++++++++ WordsIDE/route.cpp | 41 +++++++++++++++ WordsIDE/route.h | 26 ++++++++++ libProjectManager/libProjectManager.h | 7 +++ libProjectManager/xmlprojectmanager.cpp | 34 +++++++++++++ libProjectManager/xmlprojectmanager.h | 4 ++ 7 files changed, 218 insertions(+) create mode 100644 WordsIDE/projectpresent.cpp create mode 100644 WordsIDE/projectpresent.h create mode 100644 WordsIDE/route.cpp create mode 100644 WordsIDE/route.h diff --git a/WordsIDE/projectpresent.cpp b/WordsIDE/projectpresent.cpp new file mode 100644 index 0000000..0cfe7e2 --- /dev/null +++ b/WordsIDE/projectpresent.cpp @@ -0,0 +1,68 @@ +#include "projectpresent.h" +#include "command_list.h" + +#include +#include +#include + +using namespace Components; +using namespace CommandList; + +ProjectPresent::ProjectPresent(Core::AppCore *core, QWidget *parent) + : QWidget(parent), source(core), view_present(new QTreeView(this)) +{ + auto layout = new QVBoxLayout(this); + + layout->addWidget(view_present); + auto mgr = core->disp_core->get(NAME(DocumentsManager)); + view_present->setModel(mgr->projectManager()->model()); + + connect(view_present, &QTreeView::customContextMenuRequested, + this, &ProjectPresent::menu_popup); + connect(view_present, &QTreeView::doubleClicked, + this, &ProjectPresent::open_target); +} + +QString ProjectPresent::name() const +{ + return NAME(ProjectPresent); +} + +void ProjectPresent::menu_popup(const QPoint &p) +{ + QMenu m; + m.addAction("新建路径", [this](){ + auto path_string = QInputDialog::getText(this, "输入路径定义/packa/packb/packc", "路径定义:"); + if(path_string.isEmpty()) + return; + + source->disp_core->postCommand(NewPackage(path_string)); + }); + + auto index = this->view_present->currentIndex(); + if(index.isValid()){ + auto mgr = source->disp_core->get(NAME(DocumentsManager)); + auto menu = m.addMenu("新建文件"); + auto views = mgr->fileTypes(); + for(auto &it : views){ + menu->addAction(it, [this, &it, &index, mgr](){ + auto name = QInputDialog::getText(this, "输入文件名称", "文件名称"); + auto path = mgr->converter(index); + source->disp_core->postCommand(NewFile(path, name, it)); + }); + } + + m.addSeparator(); + m.addAction("移除节点"); + } + + + m.exec(mapToGlobal(p)); +} + +void ProjectPresent::open_target(const QModelIndex &t) +{ + auto mgr = source->disp_core->get(NAME(DocumentsManager)); + auto path = mgr->converter(t); + source->disp_core->postCommand(OpenFile(path)); +} diff --git a/WordsIDE/projectpresent.h b/WordsIDE/projectpresent.h new file mode 100644 index 0000000..39594b6 --- /dev/null +++ b/WordsIDE/projectpresent.h @@ -0,0 +1,38 @@ +#ifndef PROJECTPRESENT_H +#define PROJECTPRESENT_H + +#include "manager_docs.h" + +#include +#include +#include +#include + +namespace Components { + /** + * @brief 项目视图 + */ + class ProjectPresent : public QWidget, public Schedule::AccessibleObject + { + Q_OBJECT + public: + explicit ProjectPresent(Core::AppCore *core, + QWidget *parent = nullptr); + + signals: + + // AccessibleObject interface + public: + virtual QString name() const override; + + private: + Core::AppCore *const source; + QTreeView *const view_present; + + void menu_popup(const QPoint &p); + void open_target(const QModelIndex &t); + }; +} + + +#endif // PROJECTPRESENT_H diff --git a/WordsIDE/route.cpp b/WordsIDE/route.cpp new file mode 100644 index 0000000..b7b1974 --- /dev/null +++ b/WordsIDE/route.cpp @@ -0,0 +1,41 @@ +#include "route.h" + +using namespace Core; + +Route::Route() +{ + +} + +Route::Route(const Route &other) + : links_store(other.links_store) {} + +QStringList Route::links() const +{ + return links_store; +} + +Route Route::operator |(const QString &node) const +{ + Route exlink(*this); + exlink.links_store.append(node); + return exlink; +} + +bool Route::operator==(const Route &other) const +{ + if(links_store.size() == other.links_store.size()){ + for(auto idx=0; idx &list) +{ + Route v; + v.links_store.append(list); + return v; +} diff --git a/WordsIDE/route.h b/WordsIDE/route.h new file mode 100644 index 0000000..e031b91 --- /dev/null +++ b/WordsIDE/route.h @@ -0,0 +1,26 @@ +#ifndef ROUTE_H +#define ROUTE_H + +#include + + +namespace Core { + class Route + { + public: + Route(); + Route(const Route& other); + + QStringList links() const; + Route operator|(const QString &node) const; + bool operator==(const Route &other) const; + + static Route collect(const QList &list); + + private: + QStringList links_store; + }; + +} + +#endif // ROUTE_H diff --git a/libProjectManager/libProjectManager.h b/libProjectManager/libProjectManager.h index b14791c..7c94c24 100644 --- a/libProjectManager/libProjectManager.h +++ b/libProjectManager/libProjectManager.h @@ -163,6 +163,13 @@ namespace Project { */ virtual QFileInfo queryInfo(const QModelIndex &path) = 0; + /** + * @brief 通过文件反查获取ModelIndex + * @param file + * @return + */ + virtual QModelIndex queryIndex(const QFileInfo &file) = 0; + }; diff --git a/libProjectManager/xmlprojectmanager.cpp b/libProjectManager/xmlprojectmanager.cpp index e332267..c650150 100644 --- a/libProjectManager/xmlprojectmanager.cpp +++ b/libProjectManager/xmlprojectmanager.cpp @@ -357,6 +357,16 @@ QFileInfo XMLProjectManager::queryInfo(const QModelIndex &path) return QFileInfo(QFileInfo(filepath_store).dir().filePath(item->file())); } +QModelIndex XMLProjectManager::queryIndex(const QFileInfo &file) +{ + auto xinfo = query_index(file, project_structure->item(0)->index()); + + if(xinfo.isValid()) + return xinfo; + + return QModelIndex(); +} + ProjectNode *XMLProjectManager::node_follows(ProjectNode *pnode, const QList &path_remains) { if(path_remains.size()==0) @@ -419,6 +429,30 @@ QModelIndex XMLProjectManager::groups_rebuild(ProjectNode *pnode, const QListindex(); } +QModelIndex XMLProjectManager::query_index(const QFileInfo &file, const QModelIndex &base) +{ + if(!base.isValid()) + return QModelIndex(); + + auto item = static_cast(project_structure->itemFromIndex(base)); + if(item->nodeType() == NodeType::FILE) { + auto dir = QFileInfo(filepath_store).absoluteDir(); + auto target_info = QFileInfo(dir.filePath(item->file())); + if(target_info == file) + return item->index(); + } + else { + for(auto idx=0; idxrowCount(); ++idx) + { + auto idx_m = query_index(file, item->child(idx)->index()); + if(idx_m.isValid()) + return idx_m; + } + } + + return QModelIndex(); +} + void XMLProjectManager::moveTo(const QModelIndex &item_path, const QModelIndex &target_group, int index) { diff --git a/libProjectManager/xmlprojectmanager.h b/libProjectManager/xmlprojectmanager.h index 57fbc32..6116444 100644 --- a/libProjectManager/xmlprojectmanager.h +++ b/libProjectManager/xmlprojectmanager.h @@ -68,6 +68,7 @@ namespace Project { virtual QList> filesWithEnds(const QString &suffix) const override; virtual QFileInfo queryInfo(const QModelIndex &path) override; + virtual QModelIndex queryIndex(const QFileInfo &file) override; private: Config::Configration *const project_config; @@ -83,6 +84,9 @@ namespace Project { QList> nodes_search(ProjectNode *pnode, const QString &suffix) const; QModelIndex groups_rebuild(ProjectNode *pnode, const QList &path_remains); + + + virtual QModelIndex query_index(const QFileInfo &file, const QModelIndex &base); }; }