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-09-10 05:28:52 +00:00
|
|
|
|
#include "xapp.h"
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
using namespace Core;
|
2023-08-20 17:22:48 +00:00
|
|
|
|
using namespace Config;
|
2023-08-29 04:18:41 +00:00
|
|
|
|
using namespace Presents;
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-09-10 05:28:52 +00:00
|
|
|
|
DocumentsManager::DocumentsManager(XApp *host) : core_inst(host) { initContentViewPlugins(); }
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-29 04:31:29 +00:00
|
|
|
|
void DocumentsManager::appendPresent(PresentHost *container) {
|
2023-08-29 03:52:56 +00:00
|
|
|
|
if (present_ui.contains(container))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
present_ui << container;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 04:31:29 +00:00
|
|
|
|
void DocumentsManager::removePresent(PresentHost *container) {}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-09-10 05:28:52 +00:00
|
|
|
|
Project::ProjectManager *DocumentsManager::projectManager() const { return core_inst->pjtManager(); }
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-15 14:45:04 +00:00
|
|
|
|
#include "srcedit_defaulttext.h"
|
|
|
|
|
#include "srcedit_storyboard.h"
|
2023-08-29 03:52:56 +00:00
|
|
|
|
void DocumentsManager::initContentViewPlugins() {
|
2023-08-15 14:45:04 +00:00
|
|
|
|
registPresentType(new DefaultTextEditFactory);
|
|
|
|
|
registPresentType(new StorySourceEditFactory);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 05:28:52 +00:00
|
|
|
|
void DocumentsManager::loadViewConfigWidgets(QTabWidget *stacked) {
|
|
|
|
|
if (!projectManager()->isOpenning())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto keys = factory_map.keys();
|
|
|
|
|
for (auto &it : keys) {
|
|
|
|
|
auto panel = factory_map[it]->createTempConfigPanel(projectManager()->configraions());
|
|
|
|
|
if (panel)
|
|
|
|
|
stacked->addTab(panel, it + "配置");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
QList<QString> DocumentsManager::fileTypes() const {
|
2023-03-05 14:32:20 +00:00
|
|
|
|
QList<QString> all_types;
|
2023-08-15 14:14:00 +00:00
|
|
|
|
for (auto &it : factory_map.keys())
|
|
|
|
|
all_types.append(it);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
return all_types;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 05:28:52 +00:00
|
|
|
|
void DocumentsManager::createPackage(const Core::Route &link) { core_inst->pjtManager()->operateAccess()->newPackage(link.links()); }
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
void DocumentsManager::createFile(const Core::Route &group_path, const QString &name, const QString &suffix) {
|
|
|
|
|
auto all_types = fileTypes();
|
|
|
|
|
if (!all_types.contains(suffix))
|
2023-08-20 17:22:48 +00:00
|
|
|
|
throw new SimpleException<QString>("创建文件错误", "指定文件类型无法打开:" + suffix);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
auto midx = convertPath(group_path);
|
|
|
|
|
auto fidx = projectManager()->operateAccess()->newFile(midx, name, suffix);
|
|
|
|
|
auto fileinfo = projectManager()->queryAccess()->queryInfo(fidx);
|
|
|
|
|
factory_map[suffix]->create(fileinfo);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
void DocumentsManager::renameNode(const Core::Route &node_path, const QString &name) {
|
2023-09-10 05:28:52 +00:00
|
|
|
|
core_inst->pjtManager()->operateAccess()->rename(convertPath(node_path), name);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
|
|
|
|
auto activie_file_nodes = actives();
|
2023-08-15 14:14:00 +00:00
|
|
|
|
if (activie_file_nodes.contains(node_path)) {
|
|
|
|
|
auto inst = convertPresent(node_path);
|
2023-09-10 05:28:52 +00:00
|
|
|
|
inst->applySetting(name, core_inst->pjtManager()->configraions());
|
2023-08-15 14:14:00 +00:00
|
|
|
|
doc_openning.remove(node_path);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
auto old_link = node_path.links();
|
|
|
|
|
auto npath = Core::Route::collect(old_link.mid(0, old_link.size() - 1)) | name;
|
|
|
|
|
doc_openning[npath] = inst;
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
active(npath);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
2023-08-15 14:14:00 +00:00
|
|
|
|
}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
void DocumentsManager::deleteNode(const Core::Route &node_path) {
|
|
|
|
|
auto node_mindex = convertPath(node_path);
|
2023-09-10 05:28:52 +00:00
|
|
|
|
auto file_nodes = core_inst->pjtManager()->queryAccess()->filesGather(node_mindex);
|
2023-08-15 14:14:00 +00:00
|
|
|
|
auto activie_file_nodes = actives();
|
2023-03-17 13:58:38 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
QList<Core::Route> path_buff;
|
|
|
|
|
for (auto &n : file_nodes) {
|
|
|
|
|
auto target = convertPath(n);
|
|
|
|
|
if (activie_file_nodes.contains(target))
|
|
|
|
|
path_buff << target;
|
2023-03-17 13:58:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
closeFile(path_buff);
|
2023-09-10 05:28:52 +00:00
|
|
|
|
core_inst->pjtManager()->operateAccess()->deleteT(node_mindex);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
void DocumentsManager::openFile(const QList<Route> &doc_paths) {
|
|
|
|
|
for (auto &it : doc_paths) {
|
|
|
|
|
auto openning = actives();
|
|
|
|
|
if (openning.contains(it)) {
|
2023-09-10 05:28:52 +00:00
|
|
|
|
doc_openning[it]->applySetting(it.links().last(), core_inst->pjtManager()->configraions());
|
2023-08-15 14:14:00 +00:00
|
|
|
|
active(it);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-03-17 13:58:38 +00:00
|
|
|
|
|
2023-09-10 05:28:52 +00:00
|
|
|
|
auto info = core_inst->pjtManager()->queryAccess()->queryInfo(convertPath(it));
|
2023-08-15 14:14:00 +00:00
|
|
|
|
if (!info.isFile())
|
2023-08-20 17:22:48 +00:00
|
|
|
|
throw new SimpleException<QString>("打开文件错误", "指向的节点不是文件节点");
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-29 03:52:56 +00:00
|
|
|
|
auto view = factory_map[info.suffix()]->newInst(this, it);
|
2023-08-15 14:14:00 +00:00
|
|
|
|
doc_openning[it] = view;
|
|
|
|
|
view->load(info);
|
2023-09-10 05:28:52 +00:00
|
|
|
|
view->applySetting(it.links().last(), core_inst->pjtManager()->configraions());
|
2023-08-29 03:52:56 +00:00
|
|
|
|
|
2023-09-04 14:35:14 +00:00
|
|
|
|
for (auto &con : present_ui)
|
|
|
|
|
if (con->avaliable(view)) {
|
2023-08-29 03:52:56 +00:00
|
|
|
|
con->append(view);
|
2023-09-04 14:35:14 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 默认第一个打开
|
|
|
|
|
present_ui.first()->append(view);
|
2023-08-15 14:14:00 +00:00
|
|
|
|
}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
void DocumentsManager::closeFile(const QList<Core::Route> &doc_paths) {
|
2023-03-05 14:32:20 +00:00
|
|
|
|
auto actives = this->actives();
|
2023-08-15 14:14:00 +00:00
|
|
|
|
for (auto &idx : doc_paths)
|
|
|
|
|
if (actives.contains(idx)) {
|
|
|
|
|
auto inst = convertPresent(idx);
|
2023-03-05 14:32:20 +00:00
|
|
|
|
inst->saveAs();
|
2023-03-17 13:58:38 +00:00
|
|
|
|
|
2023-08-29 03:52:56 +00:00
|
|
|
|
for (auto vit : present_ui)
|
|
|
|
|
if (present_ui.contains(vit))
|
|
|
|
|
vit->remove(inst);
|
|
|
|
|
|
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-08-15 14:14:00 +00:00
|
|
|
|
QModelIndex DocumentsManager::convertPath(const Core::Route &path) {
|
|
|
|
|
auto path_list = path.links();
|
2023-09-10 05:28:52 +00:00
|
|
|
|
auto itor_node = core_inst->pjtManager()->model()->item(0);
|
2023-08-15 14:14:00 +00:00
|
|
|
|
while (path_list.size() > 1) {
|
|
|
|
|
auto item = path_list.takeAt(1);
|
|
|
|
|
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-10 13:01:19 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
if (idx == itor_node->parent()->rowCount())
|
2023-08-20 17:22:48 +00:00
|
|
|
|
throw new SimpleException<QString>("路径转换错误", "指定的path非法:/" + path.links().join("/"));
|
2023-03-10 13:01:19 +00:00
|
|
|
|
}
|
2023-08-15 14:14:00 +00:00
|
|
|
|
return itor_node->index();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
Route DocumentsManager::convertPath(const QModelIndex &index) {
|
|
|
|
|
Core::Route path;
|
2023-09-10 05:28:52 +00:00
|
|
|
|
auto item = core_inst->pjtManager()->model()->itemFromIndex(index);
|
2023-08-15 14:14:00 +00:00
|
|
|
|
while (item != nullptr) {
|
|
|
|
|
path.prepend(item->text().trimmed());
|
|
|
|
|
item = item->parent();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
return path;
|
|
|
|
|
}
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
2023-08-27 14:09:46 +00:00
|
|
|
|
Route DocumentsManager::convertPresent(FilePresent *ins) const { return doc_openning.key(ins); }
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
2023-08-27 14:09:46 +00:00
|
|
|
|
FilePresent *DocumentsManager::convertPresent(const Core::Route &node_path) { return doc_openning[node_path]; }
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
QList<Route> DocumentsManager::actives() const { return doc_openning.keys(); }
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
void DocumentsManager::active(const Core::Route &node_path) {
|
|
|
|
|
if (doc_openning.contains(node_path)) {
|
|
|
|
|
auto inst = convertPresent(node_path);
|
2023-09-04 14:35:14 +00:00
|
|
|
|
for (auto &vit : present_ui)
|
2023-08-29 03:52:56 +00:00
|
|
|
|
if (vit->contains(inst))
|
|
|
|
|
vit->active(inst);
|
2023-08-15 14:14:00 +00:00
|
|
|
|
}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
void DocumentsManager::save() {
|
|
|
|
|
auto actives_paths = this->actives();
|
|
|
|
|
for (auto &p : actives_paths)
|
|
|
|
|
convertPresent(p)->saveAs();
|
2023-09-10 05:28:52 +00:00
|
|
|
|
|
|
|
|
|
// files
|
|
|
|
|
auto pjt = core_inst->pjtManager();
|
|
|
|
|
auto list = pjt->queryAccess()->filesWithEnds("storyboard");
|
2023-03-17 13:58:38 +00:00
|
|
|
|
}
|
2023-03-05 14:32:20 +00:00
|
|
|
|
|
2023-08-15 14:14:00 +00:00
|
|
|
|
QString DocumentsManager::name() const { return NAME(DocumentsManager); }
|