2023-03-05 14:32:20 +00:00
|
|
|
|
#include "manager_docs.h"
|
|
|
|
|
#include "DocsManager.h"
|
2023-03-17 13:58:38 +00:00
|
|
|
|
#include "keywordshighlighter.h"
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
|
|
|
|
using namespace Components;
|
2023-03-10 13:01:19 +00:00
|
|
|
|
using namespace Core;
|
2023-03-17 13:58:38 +00:00
|
|
|
|
using namespace DataModel;
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
DocumentsManager::DocumentsManager(AppCore *src,
|
|
|
|
|
Project::ProjectManager *project,
|
|
|
|
|
PresentHost *direct_con)
|
|
|
|
|
: rtcore(src), pjtins(project), present_ui(direct_con) {}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
Project::ProjectManager *DocumentsManager::projectManager() const
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
return pjtins;
|
|
|
|
|
}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void DocumentsManager::newPackage(const Route &link)
|
|
|
|
|
{
|
|
|
|
|
pjtins->newPackage(link.links());
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void DocumentsManager::newPackage(const Route &group, const QString &name)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
newPackage(group|name);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QList<QString> DocumentsManager::fileTypes() const
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
|
|
|
|
QList<QString> all_types;
|
|
|
|
|
for(auto &it : rtcore->allViews())
|
|
|
|
|
all_types.append(it->suffixes());
|
2023-03-17 13:58:38 +00:00
|
|
|
|
|
|
|
|
|
all_types.removeAll("*");
|
2023-03-05 14:32:20 +00:00
|
|
|
|
return all_types;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void DocumentsManager::newFile(const Route &group_path, const QString &name, const QString &suffix)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
|
|
|
|
auto list = rtcore->extensions(suffix);
|
|
|
|
|
QDir root = pjtins->projectDir();
|
|
|
|
|
|
|
|
|
|
auto rst = list.first()->create(root, name, suffix);
|
|
|
|
|
if(std::get<0>(rst)){
|
|
|
|
|
auto rpath = root.relativeFilePath(std::get<1>(rst));
|
|
|
|
|
auto idx = pjtins->signFile(converter(group_path), name, rpath);
|
|
|
|
|
openFile(converter(idx));
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
throw new SimpleException("无法创建文件:" + name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QModelIndex DocumentsManager::converter(const Route &path)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
auto path_list = path.links();
|
2023-03-05 14:32:20 +00:00
|
|
|
|
auto itor_node = pjtins->model()->item(0);
|
2023-03-17 13:58:38 +00:00
|
|
|
|
while (path_list.size() > 1) {
|
|
|
|
|
auto item = path_list.takeAt(1);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
int idx = 0;
|
|
|
|
|
for(; idx<itor_node->rowCount(); ++idx){
|
|
|
|
|
if(itor_node->child(idx)->text() == item){
|
|
|
|
|
itor_node = itor_node->child(idx);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
if (idx == itor_node->parent()->rowCount())
|
2023-03-10 13:01:19 +00:00
|
|
|
|
throw new SimpleException("指定的path非法:/"+ path.links().join("/"));
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
return itor_node->index();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
Route DocumentsManager::converter(const QModelIndex &index)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
Route path;
|
2023-03-05 14:32:20 +00:00
|
|
|
|
auto item = pjtins->model()->itemFromIndex(index);
|
2023-03-17 13:58:38 +00:00
|
|
|
|
while (item != nullptr) {
|
|
|
|
|
path.prepend(item->text().trimmed());
|
2023-03-05 14:32:20 +00:00
|
|
|
|
item = item->parent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void DocumentsManager::removeNode(const Route &node_path)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
auto node_mindex = converter(node_path);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
|
|
|
|
auto activie_file_nodes = actives();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
auto file_nodes = pjtins->filesGather(node_mindex);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QList<Route> path_buff;
|
|
|
|
|
for(auto &n : file_nodes){
|
|
|
|
|
auto target = converter(n);
|
|
|
|
|
if(activie_file_nodes.contains(target))
|
|
|
|
|
path_buff << target;
|
|
|
|
|
}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
close(path_buff);
|
|
|
|
|
pjtins->deleteTarget(node_mindex);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void DocumentsManager::renameNode(const Route &node_path, const QString &name)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
|
|
|
|
pjtins->rename(converter(node_path), name);
|
|
|
|
|
|
|
|
|
|
auto activie_file_nodes = actives();
|
|
|
|
|
if(activie_file_nodes.contains(node_path)){
|
|
|
|
|
auto inst = activePresentOf(node_path);
|
2023-03-10 13:01:19 +00:00
|
|
|
|
inst->applySetting(name, rtcore);
|
2023-03-17 13:58:38 +00:00
|
|
|
|
present_ui->active(node_path);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void DocumentsManager::openFile(const Route &path_node)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
auto info = pjtins->queryInfo(converter(path_node));
|
2023-03-05 14:32:20 +00:00
|
|
|
|
if(!info.isFile())
|
|
|
|
|
throw new SimpleException("打开的节点不是文件节点");
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
if(actives().contains(path_node)){
|
2023-03-17 13:58:38 +00:00
|
|
|
|
doc_openning[path_node]->applySetting(path_node.links().last(), rtcore);
|
|
|
|
|
present_ui->active(path_node);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto list = rtcore->extensions(info.suffix());
|
|
|
|
|
auto nview = list.first()->newInst();
|
|
|
|
|
nview->load(info);
|
2023-03-17 13:58:38 +00:00
|
|
|
|
nview->applySetting(path_node.links().last(), rtcore);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
doc_openning[path_node] = nview;
|
|
|
|
|
present_ui->append(nview, path_node);
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
functions_build[nview] = [this, nview](const QString &file_path) {
|
|
|
|
|
auto nv = dynamic_cast<MakeTools::CompileFeature *>(nview);
|
|
|
|
|
auto content = nv->getText();
|
|
|
|
|
rtcore->getMakeCore()->compileSource(file_path, content, nview->name());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
functions_render[nview] = [nview, this](const QString &) {
|
|
|
|
|
QObject::disconnect(nview, &MakeTools::FilePresent::dataChanged, nullptr, nullptr);
|
|
|
|
|
|
|
|
|
|
auto nv = dynamic_cast<Enhancement::HighlightFeature *>(nview);
|
|
|
|
|
nv->renderRepeat();
|
|
|
|
|
|
|
|
|
|
auto func_build = functions_build[nview];
|
|
|
|
|
auto func_render = functions_render[nview];
|
|
|
|
|
QObject::connect(nview, &MakeTools::FilePresent::dataChanged, func_build);
|
|
|
|
|
QObject::connect(nview, &MakeTools::FilePresent::dataChanged, func_render);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto flags = nview->features();
|
|
|
|
|
// 编译机制 =========================================
|
|
|
|
|
if (flags.testFlag(MakeTools::FilePresent::Feature::Compile)) {
|
|
|
|
|
QObject::connect(nview, &MakeTools::FilePresent::dataChanged, functions_build[nview]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 高亮机制 =========================================
|
|
|
|
|
if (flags.testFlag(MakeTools::FilePresent::Feature::HighLight)) {
|
|
|
|
|
auto nv = dynamic_cast<Enhancement::HighlightFeature *>(nview);
|
|
|
|
|
nv->contexBinding(rtcore);
|
|
|
|
|
|
|
|
|
|
QObject::connect(nview, &MakeTools::FilePresent::dataChanged, functions_render[nview]);
|
|
|
|
|
}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
QList<Route> DocumentsManager::actives() const { return doc_openning.keys(); }
|
|
|
|
|
|
|
|
|
|
MakeTools::FilePresent *DocumentsManager::activePresentOf(const Route &node_path)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-17 13:58:38 +00:00
|
|
|
|
return doc_openning[node_path];
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void DocumentsManager::save(const QList<Route> &docs_path)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
auto actives_paths = this->actives();
|
|
|
|
|
for(auto &idx_path : docs_path)
|
|
|
|
|
if(actives_paths.contains(idx_path))
|
|
|
|
|
activePresentOf(idx_path)->saveAs();
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void DocumentsManager::close(const QList<Route> &doc_paths)
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
|
|
|
|
auto actives = this->actives();
|
|
|
|
|
for(auto &idx : doc_paths)
|
|
|
|
|
if(actives.contains(idx)){
|
|
|
|
|
auto inst = activePresentOf(idx);
|
|
|
|
|
inst->saveAs();
|
2023-03-17 13:58:38 +00:00
|
|
|
|
|
|
|
|
|
present_ui->remove(idx);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
delete inst;
|
2023-03-17 13:58:38 +00:00
|
|
|
|
doc_openning.remove(idx);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
Route DocumentsManager::pathOf(MakeTools::FilePresent *ins) const
|
2023-03-10 13:01:19 +00:00
|
|
|
|
{
|
2023-03-17 13:58:38 +00:00
|
|
|
|
return doc_openning.key(ins);
|
2023-03-10 13:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Route DocumentsManager::pathOf(const QModelIndex &p) const
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
if(!p.isValid())
|
|
|
|
|
throw new SimpleException("传入非法QModelIndex");
|
|
|
|
|
|
|
|
|
|
auto item = projectManager()->model()->itemFromIndex(p);
|
|
|
|
|
auto proot = projectManager()->model()->item(0);
|
|
|
|
|
|
|
|
|
|
Route retv;
|
|
|
|
|
while(proot != item){
|
|
|
|
|
retv = retv|item->text();
|
|
|
|
|
item = item->parent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentsManager::build(bool all_from_disk)
|
|
|
|
|
{
|
|
|
|
|
if(!all_from_disk)
|
|
|
|
|
save();
|
|
|
|
|
|
|
|
|
|
auto chains = pjtins->filesWithEnds("storychain");
|
|
|
|
|
for(auto &it : chains){
|
|
|
|
|
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto units = pjtins->filesWithEnds("storyunit");
|
|
|
|
|
for(auto &it : units)
|
|
|
|
|
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
|
|
|
|
|
|
|
|
|
auto storys = pjtins->filesWithEnds("storyboard");
|
|
|
|
|
for(auto &it : storys)
|
|
|
|
|
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
|
|
|
|
|
|
|
|
|
auto volumes = pjtins->filesWithEnds("storyvolume");
|
|
|
|
|
for(auto &it : volumes)
|
|
|
|
|
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
|
|
|
|
|
|
|
|
|
auto concepts = pjtins->filesWithEnds("storyconcept");
|
|
|
|
|
for(auto &it : concepts)
|
|
|
|
|
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QString DocumentsManager::name() const
|
2023-03-05 14:32:20 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
return NAME(DocumentsManager);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
void DocumentsManager::hasBeenAccepted(const Core::Route &key) {}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
void DocumentsManager::hasBeenRemoved(const Core::Route &key) {
|
|
|
|
|
|
|
|
|
|
}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
void DocumentsManager::hasBeenClosed(const Core::Route &key) {
|
|
|
|
|
if (!doc_openning.contains(key))
|
|
|
|
|
return;
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
auto inst = doc_openning[key];
|
|
|
|
|
inst->widget()->setVisible(false);
|
|
|
|
|
delete inst;
|
|
|
|
|
doc_openning.remove(key);
|
|
|
|
|
}
|