2022-08-10 09:59:28 +00:00
|
|
|
library document_plugin;
|
2022-03-01 08:05:45 +00:00
|
|
|
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
|
|
import 'package:appflowy/plugins/document/document_page.dart';
|
|
|
|
import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
|
|
|
|
import 'package:appflowy/plugins/document/presentation/more/more_button.dart';
|
|
|
|
import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
|
|
|
|
import 'package:appflowy/plugins/util.dart';
|
|
|
|
import 'package:appflowy/startup/plugin/plugin.dart';
|
|
|
|
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
|
|
|
|
import 'package:appflowy/workspace/presentation/widgets/left_bar_item.dart';
|
2021-12-07 17:31:23 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2023-01-08 04:10:53 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
2021-07-24 06:05:49 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-11-28 10:02:05 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2022-05-17 18:25:35 +00:00
|
|
|
|
2022-03-01 03:22:39 +00:00
|
|
|
class DocumentPluginBuilder extends PluginBuilder {
|
2022-02-28 14:38:53 +00:00
|
|
|
@override
|
|
|
|
Plugin build(dynamic data) {
|
2022-07-19 06:11:29 +00:00
|
|
|
if (data is ViewPB) {
|
2022-02-28 14:38:53 +00:00
|
|
|
return DocumentPlugin(pluginType: pluginType, view: data);
|
|
|
|
} else {
|
|
|
|
throw FlowyPluginException.invalidData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-05-17 18:25:35 +00:00
|
|
|
String get menuName => LocaleKeys.document_menuName.tr();
|
2022-02-28 14:38:53 +00:00
|
|
|
|
2022-11-15 03:45:23 +00:00
|
|
|
@override
|
|
|
|
String get menuIcon => "editor/documents";
|
|
|
|
|
2022-02-28 14:38:53 +00:00
|
|
|
@override
|
2022-08-18 11:32:08 +00:00
|
|
|
PluginType get pluginType => PluginType.editor;
|
2022-02-28 14:38:53 +00:00
|
|
|
|
|
|
|
@override
|
2023-02-26 08:27:17 +00:00
|
|
|
ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Document;
|
2022-02-28 14:38:53 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 05:08:48 +00:00
|
|
|
class DocumentPlugin extends Plugin<int> {
|
2022-02-28 14:38:53 +00:00
|
|
|
late PluginType _pluginType;
|
2022-11-28 10:20:30 +00:00
|
|
|
final DocumentAppearanceCubit _documentAppearanceCubit =
|
|
|
|
DocumentAppearanceCubit();
|
2021-10-28 13:55:22 +00:00
|
|
|
|
2021-10-10 07:58:57 +00:00
|
|
|
@override
|
2022-09-22 05:08:48 +00:00
|
|
|
final ViewPluginNotifier notifier;
|
|
|
|
|
|
|
|
DocumentPlugin({
|
|
|
|
required PluginType pluginType,
|
|
|
|
required ViewPB view,
|
|
|
|
Key? key,
|
|
|
|
}) : notifier = ViewPluginNotifier(view: view) {
|
|
|
|
_pluginType = pluginType;
|
2022-11-28 10:20:30 +00:00
|
|
|
_documentAppearanceCubit.fetch();
|
2022-02-28 14:38:53 +00:00
|
|
|
}
|
2021-11-09 15:13:04 +00:00
|
|
|
|
|
|
|
@override
|
2022-11-28 02:37:37 +00:00
|
|
|
void dispose() {
|
2022-11-28 10:02:05 +00:00
|
|
|
_documentAppearanceCubit.close();
|
2022-11-28 02:37:37 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
PluginDisplay get display {
|
|
|
|
return DocumentPluginDisplay(
|
|
|
|
notifier: notifier,
|
2022-11-28 10:02:05 +00:00
|
|
|
documentAppearanceCubit: _documentAppearanceCubit,
|
2022-11-28 02:37:37 +00:00
|
|
|
);
|
|
|
|
}
|
2021-11-09 15:13:04 +00:00
|
|
|
|
2021-10-10 07:58:57 +00:00
|
|
|
@override
|
2022-03-02 03:38:22 +00:00
|
|
|
PluginType get ty => _pluginType;
|
2022-02-28 14:38:53 +00:00
|
|
|
|
|
|
|
@override
|
2022-09-22 05:08:48 +00:00
|
|
|
PluginId get id => notifier.view.id;
|
2022-02-28 14:38:53 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 05:08:48 +00:00
|
|
|
class DocumentPluginDisplay extends PluginDisplay with NavigationItem {
|
|
|
|
final ViewPluginNotifier notifier;
|
|
|
|
ViewPB get view => notifier.view;
|
2022-09-26 08:59:58 +00:00
|
|
|
int? deletedViewIndex;
|
2022-11-28 10:02:05 +00:00
|
|
|
DocumentAppearanceCubit documentAppearanceCubit;
|
2022-02-28 14:38:53 +00:00
|
|
|
|
2022-11-28 02:37:37 +00:00
|
|
|
DocumentPluginDisplay({
|
|
|
|
required this.notifier,
|
2022-11-28 10:02:05 +00:00
|
|
|
required this.documentAppearanceCubit,
|
2022-11-28 02:37:37 +00:00
|
|
|
Key? key,
|
|
|
|
});
|
2021-10-10 07:58:57 +00:00
|
|
|
|
|
|
|
@override
|
2022-09-26 08:59:58 +00:00
|
|
|
Widget buildWidget(PluginContext context) {
|
|
|
|
notifier.isDeleted.addListener(() {
|
|
|
|
notifier.isDeleted.value.fold(() => null, (deletedView) {
|
|
|
|
if (deletedView.hasIndex()) {
|
|
|
|
deletedViewIndex = deletedView.index;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-28 10:02:05 +00:00
|
|
|
return BlocProvider.value(
|
|
|
|
value: documentAppearanceCubit,
|
|
|
|
child: BlocBuilder<DocumentAppearanceCubit, DocumentAppearance>(
|
|
|
|
builder: (_, state) {
|
|
|
|
return DocumentPage(
|
|
|
|
view: view,
|
|
|
|
onDeleted: () => context.onDeleted(view, deletedViewIndex),
|
|
|
|
key: ValueKey(view.id),
|
|
|
|
);
|
|
|
|
},
|
2022-11-28 02:37:37 +00:00
|
|
|
),
|
2022-09-26 08:59:58 +00:00
|
|
|
);
|
|
|
|
}
|
2021-10-10 09:01:30 +00:00
|
|
|
|
|
|
|
@override
|
2022-09-22 05:08:48 +00:00
|
|
|
Widget get leftBarItem => ViewLeftBarItem(view: view);
|
2021-10-28 13:55:22 +00:00
|
|
|
|
|
|
|
@override
|
2022-11-28 02:37:37 +00:00
|
|
|
Widget? get rightBarItem {
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
DocumentShareButton(view: view),
|
|
|
|
const SizedBox(width: 10),
|
2022-11-28 10:02:05 +00:00
|
|
|
BlocProvider.value(
|
|
|
|
value: documentAppearanceCubit,
|
2022-11-28 02:37:37 +00:00
|
|
|
child: const DocumentMoreButton(),
|
2021-11-10 06:46:59 +00:00
|
|
|
),
|
2022-11-28 02:37:37 +00:00
|
|
|
],
|
2021-11-09 15:13:04 +00:00
|
|
|
);
|
|
|
|
}
|
2021-07-24 14:27:24 +00:00
|
|
|
|
2021-11-09 15:13:04 +00:00
|
|
|
@override
|
2022-11-28 02:37:37 +00:00
|
|
|
List<NavigationItem> get navigationItems => [this];
|
2021-11-09 15:13:04 +00:00
|
|
|
}
|