2022-11-17 08:26:05 +00:00
|
|
|
#include "projectview.h"
|
|
|
|
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
2022-11-22 03:42:48 +00:00
|
|
|
#include <QVBoxLayout>
|
2022-11-17 08:26:05 +00:00
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
Components::ProjectView::ProjectView(Core::AppCore *src, Project::ProjectManager *project, QWidget *parent)
|
|
|
|
: QTreeView(parent), rtcore(src), pjtins(project)
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
2022-11-22 03:42:48 +00:00
|
|
|
setModel(pjtins->model());
|
2022-11-17 08:26:05 +00:00
|
|
|
setHeaderHidden(true);
|
|
|
|
setIconSize(QSize(24, 24));
|
|
|
|
|
|
|
|
// 右键菜单
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, &QWidget::customContextMenuRequested, this, &ProjectView::contexMenuPopup);
|
|
|
|
|
|
|
|
// 双击打开
|
|
|
|
connect(this, &QTreeView::doubleClicked, this, &ProjectView::explicit_active_document);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Components::ProjectView::explicit_active_document(const QModelIndex &curr)
|
|
|
|
{
|
|
|
|
if(!curr.isValid())
|
|
|
|
return;
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
auto root = pjtins->model()->item(0);
|
|
|
|
auto item = pjtins->model()->itemFromIndex(curr);
|
2022-11-17 08:26:05 +00:00
|
|
|
QList<QString> path;
|
|
|
|
while (item != root){
|
|
|
|
path.insert(0, item->text());
|
|
|
|
item = item->parent();
|
|
|
|
}
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
auto xinfo = pjtins->queryWith(path);
|
2022-11-17 08:26:05 +00:00
|
|
|
if(xinfo.isFile() && xinfo.exists()){
|
|
|
|
emit this->activeDocument(xinfo.absoluteFilePath(), curr.data().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Components::ProjectView::contexMenuPopup(const QPoint &pos)
|
|
|
|
{
|
|
|
|
auto idx_it = indexAt(pos);
|
|
|
|
if(!idx_it.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QMenu popup;
|
|
|
|
auto npath = popup.addAction("新建路径");
|
|
|
|
connect(npath, &QAction::triggered, [this](){
|
|
|
|
auto packages = QInputDialog::getText(this, "输入包路径名称", "名称A#名称B#名称C");
|
|
|
|
if(packages == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
QList<QString> names;
|
|
|
|
QRegExp exp("([^#]+)");
|
|
|
|
auto idx=0;
|
|
|
|
while ((idx = exp.indexIn(packages, idx)) != -1) {
|
|
|
|
names << exp.capturedTexts()[1];
|
|
|
|
idx += names.last().length();
|
|
|
|
}
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
pjtins->newPath(names);
|
2022-11-17 08:26:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
popup.addSeparator();
|
|
|
|
auto newm = popup.addMenu("新建文件");
|
2022-11-22 03:42:48 +00:00
|
|
|
newm->addAction("新建章节", [this, &idx_it](){ alloc_file(idx_it, "章节", "txt"); });
|
2022-11-17 08:26:05 +00:00
|
|
|
newm->addSeparator();
|
2022-11-22 03:42:48 +00:00
|
|
|
newm->addAction("新建脉络", [this, &idx_it](){ alloc_file(idx_it, "脉络", "storychain"); });
|
|
|
|
newm->addAction("新建单元", [this, &idx_it](){ alloc_file(idx_it, "单元", "storyunit"); });
|
|
|
|
newm->addAction("新建故事", [this, &idx_it](){ alloc_file(idx_it, "故事", "storyboard"); });
|
|
|
|
newm->addAction("新建行文", [this, &idx_it](){ alloc_file(idx_it, "行文", "storyvolume"); });
|
2022-11-25 01:18:54 +00:00
|
|
|
newm->addAction("新建概念", [this, &idx_it](){ alloc_file(idx_it, "概念", "storyconcept"); });
|
2022-11-17 08:26:05 +00:00
|
|
|
popup.addSeparator();
|
|
|
|
popup.addAction("修改名称", [this, &idx_it](){
|
|
|
|
if(!idx_it.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto name = QInputDialog::getText(this, "输入名称", "节点名称");
|
|
|
|
if(name == "")
|
|
|
|
return;
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
auto item = pjtins->model()->itemFromIndex(idx_it);
|
2022-11-17 08:26:05 +00:00
|
|
|
auto pnode = item->parent();
|
|
|
|
if(pnode == nullptr){
|
|
|
|
item->setText(name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(auto idx=0; idx<pnode->rowCount(); ++idx)
|
|
|
|
if(pnode->child(idx)->text() == name)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, "系统提示", "发现重名节点");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
item->setText(name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
popup.addSeparator();
|
|
|
|
popup.addAction("删除节点与文件", [this, &idx_it](){
|
|
|
|
auto btn = QMessageBox::warning(this, "系统提示", "删除操作涉及文件变更,无法找回,请慎重对待!\n"
|
|
|
|
"是否坚持删除指定节点以及包含的所有文件?", QMessageBox::Yes|QMessageBox::No);
|
|
|
|
if(btn == QMessageBox::No)
|
|
|
|
return;
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
auto root = pjtins->model()->item(0);
|
|
|
|
auto seli = pjtins->model()->itemFromIndex(idx_it);
|
2022-11-17 08:26:05 +00:00
|
|
|
QList<QString> paths;
|
|
|
|
while (root != seli) {
|
|
|
|
paths.insert(0, seli->text());
|
|
|
|
seli = seli->parent();
|
|
|
|
}
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
this->pjtins->deletePath(paths);
|
2022-11-17 08:26:05 +00:00
|
|
|
});
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
auto item = this->pjtins->model()->itemFromIndex(idx_it);
|
|
|
|
if(item->parent() == nullptr){
|
|
|
|
popup.addSeparator();
|
|
|
|
popup.addAction("项目配置", this, &ProjectView::project_configration);
|
|
|
|
}
|
|
|
|
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
|
|
popup.exec(mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
void Components::ProjectView::alloc_file(const QModelIndex &idx_it, const QString &type, const QString &suffix)
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
2022-11-22 03:42:48 +00:00
|
|
|
auto name = QInputDialog::getText(this, "输入" + type + "名称", type + "名称:");
|
2022-11-17 08:26:05 +00:00
|
|
|
if(name == "")
|
|
|
|
return;
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
auto root = pjtins->model()->item(0);
|
|
|
|
auto seli = pjtins->model()->itemFromIndex(idx_it);
|
2022-11-17 08:26:05 +00:00
|
|
|
QList<QString> paths;
|
|
|
|
while (root != seli) {
|
|
|
|
paths.insert(0, seli->text());
|
|
|
|
seli = seli->parent();
|
|
|
|
}
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
auto indi = this->pjtins->createFile(paths, name, suffix);
|
2022-11-17 08:26:05 +00:00
|
|
|
switch (indi) {
|
|
|
|
case -1:
|
|
|
|
QMessageBox::critical(this, "系统错误", "传入的指定路径无效");
|
|
|
|
return;
|
|
|
|
case -2:
|
|
|
|
QMessageBox::critical(this, "系统错误", "在文件下建立文件");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-11-22 03:42:48 +00:00
|
|
|
|
|
|
|
void Components::ProjectView::project_configration()
|
|
|
|
{
|
|
|
|
QDialog dia(this);
|
|
|
|
auto layout = new QVBoxLayout(&dia);
|
|
|
|
auto tab = new QTabWidget(&dia);
|
|
|
|
tab->setTabPosition(QTabWidget::West);
|
|
|
|
layout->addWidget(tab);
|
|
|
|
|
|
|
|
auto extions = rtcore->extensions();
|
|
|
|
auto project = pjtins;
|
|
|
|
for(auto &ext : extions){
|
|
|
|
auto widget = ext->getNewPanel(project->configraions());
|
|
|
|
if(widget)
|
|
|
|
tab->addTab(widget, ext->extensionName());
|
|
|
|
}
|
|
|
|
|
|
|
|
dia.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|