131 lines
3.9 KiB
Dart
131 lines
3.9 KiB
Dart
|
|
/// 架构图设计模块:手绘识别、系统架构图与参数化草图。
|
||
|
|
///
|
||
|
|
/// 模块入口:`lib/modules/architecture/`。新增模块请参考本文件与
|
||
|
|
/// `lib/modules/README.md`,然后在 `lib/modules/registry.dart` 注册。
|
||
|
|
library;
|
||
|
|
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:flutter/services.dart';
|
||
|
|
|
||
|
|
import 'package:sequence_diagram/modules/architecture/domain/arch_models.dart';
|
||
|
|
import 'package:sequence_diagram/modules/architecture/ui/architecture_ui.dart';
|
||
|
|
import 'package:sequence_diagram/modules/module.dart';
|
||
|
|
import 'package:sequence_diagram/state/app_controller.dart';
|
||
|
|
|
||
|
|
/// 架构图模块单例。
|
||
|
|
const ArchitectureModule architectureModule = ArchitectureModule();
|
||
|
|
|
||
|
|
/// 架构图设计模块。
|
||
|
|
class ArchitectureModule extends EdcModule {
|
||
|
|
/// 构造模块。
|
||
|
|
const ArchitectureModule();
|
||
|
|
|
||
|
|
/// 稳定 id。
|
||
|
|
static const String moduleId = 'architecture';
|
||
|
|
|
||
|
|
@override
|
||
|
|
String get id => moduleId;
|
||
|
|
@override
|
||
|
|
String get name => '架构图';
|
||
|
|
@override
|
||
|
|
String get shortName => '架构图';
|
||
|
|
@override
|
||
|
|
IconData get icon => Icons.account_tree_outlined;
|
||
|
|
@override
|
||
|
|
int get accent => 0xFF34D399;
|
||
|
|
@override
|
||
|
|
String get suffix => '.arch.json';
|
||
|
|
@override
|
||
|
|
bool get available => true;
|
||
|
|
@override
|
||
|
|
String get defaultName => '未命名-架构图';
|
||
|
|
@override
|
||
|
|
String get blurb => '手绘识别 · 图形库';
|
||
|
|
|
||
|
|
@override
|
||
|
|
String get enterStatus => '架构图设计 · 手绘识别';
|
||
|
|
|
||
|
|
@override
|
||
|
|
void newDocument(AppController controller) {
|
||
|
|
controller.newArchProject();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void loadDocument(AppController controller, String source, {String? path}) {
|
||
|
|
controller.loadArchDoc(ArchDoc.decode(source), path: path);
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
String encodeDocument(AppController controller) => controller.arch.encode();
|
||
|
|
|
||
|
|
@override
|
||
|
|
String documentName(AppController controller) => controller.project.name;
|
||
|
|
|
||
|
|
@override
|
||
|
|
String? filePath(AppController controller) => controller.archFilePath;
|
||
|
|
|
||
|
|
@override
|
||
|
|
bool isDirty(AppController controller) => controller.dirty;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Future<void> saveTo(AppController controller, String path) =>
|
||
|
|
controller.saveArchAs(path);
|
||
|
|
|
||
|
|
@override
|
||
|
|
Future<void> markSaved(AppController controller, String displayPath) =>
|
||
|
|
controller.markArchSaved(displayPath);
|
||
|
|
|
||
|
|
@override
|
||
|
|
bool isReadOnly(AppController controller) => false;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Map<ShortcutActivator, VoidCallback> buildShortcuts(ModuleUiContext ui) {
|
||
|
|
final AppController c = ui.controller;
|
||
|
|
return <ShortcutActivator, VoidCallback>{
|
||
|
|
const SingleActivator(LogicalKeyboardKey.keyA, control: true): () {
|
||
|
|
if (c.sketchMode) {
|
||
|
|
c.selectAllSketch();
|
||
|
|
} else {
|
||
|
|
c.selectAllArch();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
const SingleActivator(LogicalKeyboardKey.delete): () {
|
||
|
|
if (c.sketchMode) {
|
||
|
|
c.deleteSketchSelection();
|
||
|
|
} else {
|
||
|
|
c.removeArchSelection();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
const SingleActivator(LogicalKeyboardKey.escape): () {
|
||
|
|
if (c.sketchMode &&
|
||
|
|
(c.sketchPendingCons != null || c.sketchPendingDim != null)) {
|
||
|
|
c.cancelSketchCommand();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget buildWorkspace(ModuleUiContext ui) => ArchitectureUi(ui).buildWorkspace();
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget? buildLeftPanel(ModuleUiContext ui, {bool floating = false}) =>
|
||
|
|
ArchitectureUi(ui).buildLeftPanel(ui.tokens, floating: floating);
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget? buildRightPanel(ModuleUiContext ui, {bool floating = false}) =>
|
||
|
|
ArchitectureUi(ui).buildRightPanel(ui.tokens, floating: floating);
|
||
|
|
|
||
|
|
@override
|
||
|
|
List<Widget> buildToolbarCenter(ModuleUiContext ui, {required bool compact}) =>
|
||
|
|
ArchitectureUi(ui).buildToolbarCenter(ui.tokens, compact: compact);
|
||
|
|
|
||
|
|
@override
|
||
|
|
List<Widget> buildToolbarRight(ModuleUiContext ui) =>
|
||
|
|
ArchitectureUi(ui).buildToolbarRight(ui.tokens, compact: ui.compact);
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget buildStatusBar(ModuleUiContext ui) =>
|
||
|
|
ArchitectureUi(ui).buildStatusBar(ui.tokens);
|
||
|
|
}
|