2022-08-10 17:59:28 +08:00
|
|
|
library document_plugin;
|
2022-03-01 16:05:45 +08:00
|
|
|
|
2022-05-17 20:25:35 +02:00
|
|
|
import 'package:app_flowy/generated/locale_keys.g.dart';
|
2022-11-28 10:37:37 +08:00
|
|
|
import 'package:app_flowy/plugins/document/document_page.dart';
|
|
|
|
import 'package:app_flowy/plugins/document/presentation/more/more_button.dart';
|
|
|
|
import 'package:app_flowy/plugins/document/presentation/share/share_button.dart';
|
2022-09-22 13:08:48 +08:00
|
|
|
import 'package:app_flowy/plugins/util.dart';
|
2022-08-09 10:35:27 +08:00
|
|
|
import 'package:app_flowy/startup/plugin/plugin.dart';
|
2022-03-01 16:05:45 +08:00
|
|
|
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
|
2022-08-09 10:35:27 +08:00
|
|
|
import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart';
|
2021-12-07 23:01:23 +05:30
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-07-04 15:00:54 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
2021-07-24 14:05:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2022-11-28 10:37:37 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2022-11-28 15:34:55 +08:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-05-17 20:25:35 +02:00
|
|
|
|
2022-03-01 11:22:39 +08:00
|
|
|
class DocumentPluginBuilder extends PluginBuilder {
|
2022-02-28 22:38:53 +08:00
|
|
|
@override
|
|
|
|
Plugin build(dynamic data) {
|
2022-07-19 14:11:29 +08:00
|
|
|
if (data is ViewPB) {
|
2022-02-28 22:38:53 +08:00
|
|
|
return DocumentPlugin(pluginType: pluginType, view: data);
|
|
|
|
} else {
|
|
|
|
throw FlowyPluginException.invalidData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-05-17 20:25:35 +02:00
|
|
|
String get menuName => LocaleKeys.document_menuName.tr();
|
2022-02-28 22:38:53 +08:00
|
|
|
|
2022-11-15 11:45:23 +08:00
|
|
|
@override
|
|
|
|
String get menuIcon => "editor/documents";
|
|
|
|
|
2022-02-28 22:38:53 +08:00
|
|
|
@override
|
2022-08-18 19:32:08 +08:00
|
|
|
PluginType get pluginType => PluginType.editor;
|
2022-02-28 22:38:53 +08:00
|
|
|
|
|
|
|
@override
|
2022-10-22 21:57:44 +08:00
|
|
|
ViewDataFormatPB get dataFormatType => ViewDataFormatPB.TreeFormat;
|
2022-02-28 22:38:53 +08:00
|
|
|
}
|
|
|
|
|
2022-11-28 10:37:37 +08:00
|
|
|
class DocumentStyle with ChangeNotifier {
|
2022-11-28 15:34:55 +08:00
|
|
|
DocumentStyle() {
|
|
|
|
sync();
|
|
|
|
}
|
2022-11-28 10:37:37 +08:00
|
|
|
|
|
|
|
double _fontSize = 14.0;
|
|
|
|
double get fontSize => _fontSize;
|
|
|
|
set fontSize(double fontSize) {
|
|
|
|
_fontSize = fontSize;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2022-11-28 15:34:55 +08:00
|
|
|
|
|
|
|
void sync() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
fontSize = prefs.getDouble('kSelectFontSize') ?? _fontSize;
|
|
|
|
}
|
2022-11-28 10:37:37 +08:00
|
|
|
}
|
|
|
|
|
2022-09-22 13:08:48 +08:00
|
|
|
class DocumentPlugin extends Plugin<int> {
|
2022-02-28 22:38:53 +08:00
|
|
|
late PluginType _pluginType;
|
2022-11-28 10:37:37 +08:00
|
|
|
late final DocumentStyle _documentStyle;
|
2021-10-28 21:55:22 +08:00
|
|
|
|
2021-10-10 15:58:57 +08:00
|
|
|
@override
|
2022-09-22 13:08:48 +08:00
|
|
|
final ViewPluginNotifier notifier;
|
|
|
|
|
|
|
|
DocumentPlugin({
|
|
|
|
required PluginType pluginType,
|
|
|
|
required ViewPB view,
|
|
|
|
Key? key,
|
|
|
|
}) : notifier = ViewPluginNotifier(view: view) {
|
|
|
|
_pluginType = pluginType;
|
2022-11-28 10:37:37 +08:00
|
|
|
_documentStyle = DocumentStyle();
|
2022-02-28 22:38:53 +08:00
|
|
|
}
|
2021-11-09 23:13:04 +08:00
|
|
|
|
|
|
|
@override
|
2022-11-28 10:37:37 +08:00
|
|
|
void dispose() {
|
|
|
|
_documentStyle.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
PluginDisplay get display {
|
|
|
|
return DocumentPluginDisplay(
|
|
|
|
notifier: notifier,
|
|
|
|
documentStyle: _documentStyle,
|
|
|
|
);
|
|
|
|
}
|
2021-11-09 23:13:04 +08:00
|
|
|
|
2021-10-10 15:58:57 +08:00
|
|
|
@override
|
2022-03-02 11:38:22 +08:00
|
|
|
PluginType get ty => _pluginType;
|
2022-02-28 22:38:53 +08:00
|
|
|
|
|
|
|
@override
|
2022-09-22 13:08:48 +08:00
|
|
|
PluginId get id => notifier.view.id;
|
2022-02-28 22:38:53 +08:00
|
|
|
}
|
|
|
|
|
2022-09-22 13:08:48 +08:00
|
|
|
class DocumentPluginDisplay extends PluginDisplay with NavigationItem {
|
|
|
|
final ViewPluginNotifier notifier;
|
|
|
|
ViewPB get view => notifier.view;
|
2022-09-26 16:59:58 +08:00
|
|
|
int? deletedViewIndex;
|
2022-11-28 10:37:37 +08:00
|
|
|
DocumentStyle documentStyle;
|
2022-02-28 22:38:53 +08:00
|
|
|
|
2022-11-28 10:37:37 +08:00
|
|
|
DocumentPluginDisplay({
|
|
|
|
required this.notifier,
|
|
|
|
required this.documentStyle,
|
|
|
|
Key? key,
|
|
|
|
});
|
2021-10-10 15:58:57 +08:00
|
|
|
|
|
|
|
@override
|
2022-09-26 16:59:58 +08:00
|
|
|
Widget buildWidget(PluginContext context) {
|
|
|
|
notifier.isDeleted.addListener(() {
|
|
|
|
notifier.isDeleted.value.fold(() => null, (deletedView) {
|
|
|
|
if (deletedView.hasIndex()) {
|
|
|
|
deletedViewIndex = deletedView.index;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-28 10:37:37 +08:00
|
|
|
return ChangeNotifierProvider.value(
|
|
|
|
value: documentStyle,
|
|
|
|
child: DocumentPage(
|
|
|
|
view: view,
|
|
|
|
onDeleted: () => context.onDeleted(view, deletedViewIndex),
|
|
|
|
key: ValueKey(view.id),
|
|
|
|
),
|
2022-09-26 16:59:58 +08:00
|
|
|
);
|
|
|
|
}
|
2021-10-10 17:01:30 +08:00
|
|
|
|
|
|
|
@override
|
2022-09-22 13:08:48 +08:00
|
|
|
Widget get leftBarItem => ViewLeftBarItem(view: view);
|
2021-10-28 21:55:22 +08:00
|
|
|
|
|
|
|
@override
|
2022-11-28 10:37:37 +08:00
|
|
|
Widget? get rightBarItem {
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
DocumentShareButton(view: view),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
ChangeNotifierProvider.value(
|
|
|
|
value: documentStyle,
|
|
|
|
child: const DocumentMoreButton(),
|
2021-11-10 14:46:59 +08:00
|
|
|
),
|
2022-11-28 10:37:37 +08:00
|
|
|
],
|
2021-11-09 23:13:04 +08:00
|
|
|
);
|
|
|
|
}
|
2021-07-24 22:27:24 +08:00
|
|
|
|
2021-11-09 23:13:04 +08:00
|
|
|
@override
|
2022-11-28 10:37:37 +08:00
|
|
|
List<NavigationItem> get navigationItems => [this];
|
2021-11-09 23:13:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extension QuestionBubbleExtension on ShareAction {
|
|
|
|
String get name {
|
|
|
|
switch (this) {
|
|
|
|
case ShareAction.markdown:
|
2021-12-07 23:01:23 +05:30
|
|
|
return LocaleKeys.shareAction_markdown.tr();
|
2021-11-09 23:13:04 +08:00
|
|
|
case ShareAction.copyLink:
|
2021-12-07 23:01:23 +05:30
|
|
|
return LocaleKeys.shareAction_copyLink.tr();
|
2021-11-09 23:13:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|