#include "mainwindow.h" #include "srcedit_defaulttext.h" #include "srcedit_storyboard.h" #include "xapp.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "command_list.h" using namespace Project; using namespace Components; using namespace Core; using namespace Tools; using namespace CommandList; using namespace bridge; MainWindow::MainWindow(const QString &layout, QWidget *parent) : QMainWindow(parent), layout_name_store(layout), sync_kernel(new StatusSyncCore(this)), parse_service(new ParseBridge()), project_manager(new XMLProjectManager(this)), active_docscollect(new DocumentsManager(project_manager)), present_host(new SplitFrame::ViewPresent(this)), session_service(new ViewSession(XApp::global_configration, this)), views_bar(new ViewStackedBar(present_host, this)), center_frame(new PresentContainerView(present_host, this)), project_present(new ProjectView(present_host, XApp::disp_core, active_docscollect, this)) { QApplication::instance()->installEventFilter(this); initial_commandlist(XApp::disp_core); XApp::disp_core->registerMember(active_docscollect); setMinimumSize(1000, 600); setWindowTitle(tr("提线木偶")); setCentralWidget(present_host->bind()); addToolBar(Qt::LeftToolBarArea, views_bar); present_host->addListener(views_bar); session_service->initPresentView(center_frame, project_present, parse_service->errorsPresentModel()); auto mbar = menuBar(); initial_menubar(mbar); project_present->setVisible(true); this->active_docscollect->appendPresent(center_frame); session_service->viewStatesRestore(this, present_host); } MainWindow::~MainWindow() { active_docscollect->removePresent(center_frame); } SplitFrame::ViewPresent *MainWindow::bindPresent() const { return present_host; } QString MainWindow::layoutName() const { return layout_name_store; } void MainWindow::initial_menubar(QMenuBar *mbar) { // 项目菜单树 auto project = mbar->addMenu("项目"); auto opnp = project->addAction("打开项目", [this]() { auto file = QFileDialog::getOpenFileName(this, "打开项目", QString(), "小说项目(*.nsf)"); if (file == "") return; XApp::disp_core->postCommand(OpenProject(file)); }); sync_kernel->actionEnableSync(opnp, [this]() -> bool { return !project_manager->isOpenning(); }); auto newp = project->addAction("新建项目", [this]() { auto name = QInputDialog::getText(this, "输入项目名称", "项目名称"); if (name == "") return; auto dir_path = QFileDialog::getExistingDirectory(this, "指定项目存储路径"); if (dir_path == "") return; XApp::disp_core->postCommand(NewProject(QDir(dir_path), name)); }); sync_kernel->actionEnableSync(newp, [this]() -> bool { return !project_manager->isOpenning(); }); auto clsp = project->addAction("关闭项目", [this]() { XApp::disp_core->postCommand(CloseProject()); }); sync_kernel->actionEnableSync(clsp, [this]() -> bool { return project_manager->isOpenning(); }); project->addSeparator(); auto pnew = project->addAction("新建路径", [this]() { auto packages = QInputDialog::getText(this, "输入包路径名称/PackA/PackB/PackC", "包路径:"); if (packages != "") XApp::disp_core->postCommand(NewPackage(packages)); }); sync_kernel->actionEnableSync(pnew, [this]() -> bool { return project_manager->isOpenning(); }); auto _xnew = project->addMenu("新建文件"); _xnew->setEnabled(project_manager->isOpenning()); auto types = active_docscollect->fileTypes(); for (auto &t : types) { _xnew->addAction(t, [this, &t]() { auto name = QInputDialog::getText(this, "输入名称", "名称:"); if (name == "") return; auto idx = project_present->currentIndex(); if (!idx.isValid()) idx = project_manager->model()->item(0)->index(); auto group_path = active_docscollect->convertPath(idx); XApp::disp_core->postCommand(NewFile(group_path, name, t)); }); } sync_kernel->widgetEnableSync(_xnew, [this]() -> bool { return project_manager->isOpenning(); }); project->addSeparator(); auto sav = project->addAction("保存全部", [this]() { XApp::disp_core->postCommand(SaveAll()); }); sav->setShortcut(QKeySequence::StandardKey::Save); sync_kernel->actionEnableSync(sav, [this]() -> bool { return project_manager->isOpenning(); }); project->addSeparator(); project->addAction("退出", [this]() { XApp::disp_core->postCommand(SaveAll()); QApplication::exit(0); }); // 编辑菜单 auto edit = mbar->addMenu("编辑"); edit->addAction("撤销一步"); edit->addAction("重做一步"); edit->addSeparator(); edit->addAction("查找关键词"); edit->addAction("替换关键词"); // 视图菜单 auto view = mbar->addMenu("视图"); auto area = view->addMenu("区域管理"); auto xtool = new QToolBar(this); xtool->setVisible(false); addToolBar(Qt::ToolBarArea::TopToolBarArea, xtool); auto act_tool = area->addAction("工具栏"); sync_kernel->actionCheckSync(act_tool, [xtool]() -> bool { return xtool->isVisible(); }); connect(act_tool, &QAction::triggered, [xtool](bool v) { xtool->setVisible(v); }); auto xstatus = statusBar(); xstatus->setVisible(false); xstatus->addWidget(new QLabel("文本消息", this)); auto act_status = area->addAction("状态栏"); sync_kernel->actionCheckSync(act_status, [xstatus]() -> bool { return xstatus->isVisible(); }); connect(act_status, &QAction::triggered, [xstatus](bool v) { xstatus->setVisible(v); }); view->addSeparator(); auto change = view->addMenu("内容切换"); change->addAction("序列视图"); change->addAction("编辑视图"); view->addSeparator(); auto func = view->addMenu("功能视图"); sync_kernel->widgetEnableSync(func, [this]() { return this->project_manager->isOpenning(); }); // 项目管理 // 工具菜单 auto tool = mbar->addMenu("工具"); auto word = tool->addMenu("敏感词检测"); word->addAction("工具配置"); word->addAction("敏感词编辑"); auto vcs = tool->addMenu("版本管理"); vcs->addAction("工具配置"); vcs->addAction("启用"); auto exp = tool->addMenu("导入导出"); exp->addAction("导入WsOutlines"); exp->addSeparator(); exp->addAction("导出TXT大纲"); exp->addAction("导出Web大纲"); exp->addAction("导出WsOutlines"); exp->addSeparator(); exp->addAction("导出TXT内容"); // 窗口菜单 auto window = mbar->addMenu("窗口"); window->addAction("新建窗口"); window->addAction("关闭窗口"); window->addSeparator(); window->addAction("布局管理"); window->addMenu("布局切换"); window->addMenu("窗口切换"); // 系统 auto sys = mbar->addMenu("系统"); sys->addAction("软件激活"); sys->addAction("系统信息"); sys->addSeparator(); sys->addAction("关于……"); } void MainWindow::initial_commandlist(Schedule::CommandsDispatcher *host) { host->registerCommand(new CloseProject()); host->registerCommand(new NewFile(Route(), "", "txt")); host->registerCommand(new NewPackage("")); host->registerCommand(new NewProject(QDir(), "")); host->registerCommand(new OpenFile(Route())); host->registerCommand(new OpenProject("")); host->registerCommand(new SaveAll()); } void MainWindow::closeEvent(QCloseEvent *event) { // 关闭事件 if (project_manager->isOpenning()) { XApp::disp_core->postCommand(CloseProject()); } session_service->viewStatesSave(this, present_host); XApp::global_configration->save(); QMainWindow::closeEvent(event); } bool MainWindow::eventFilter(QObject *watched, QEvent *event) { auto ev = event->type(); switch (ev) { case QEvent::Type::MouseButtonPress: case QEvent::Type::MouseButtonRelease: case QEvent::Type::Wheel: case QEvent::Type::MouseMove: case QEvent::Type::KeyPress: case QEvent::Type::KeyRelease: sync_kernel->sync(); break; default: break; } return QMainWindow::eventFilter(watched, event); }