2023-02-26 16:27:17 +08:00
|
|
|
import 'package:appflowy/generated/locale_keys.g.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';
|
2022-05-17 20:25:35 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2023-04-04 08:41:16 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
2022-03-04 08:22:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-08-09 10:35:27 +08:00
|
|
|
import 'presentation/grid_page.dart';
|
2022-03-04 08:22:49 +08:00
|
|
|
|
2022-03-06 09:03:02 +08:00
|
|
|
class GridPluginBuilder implements PluginBuilder {
|
2022-03-04 08:22:49 +08:00
|
|
|
@override
|
|
|
|
Plugin build(dynamic data) {
|
2022-07-19 14:11:29 +08:00
|
|
|
if (data is ViewPB) {
|
2022-03-04 08:22:49 +08:00
|
|
|
return GridPlugin(pluginType: pluginType, view: data);
|
|
|
|
} else {
|
|
|
|
throw FlowyPluginException.invalidData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-05-17 20:25:35 +02:00
|
|
|
String get menuName => LocaleKeys.grid_menuName.tr();
|
2022-03-04 08:22:49 +08:00
|
|
|
|
2022-11-15 11:45:23 +08:00
|
|
|
@override
|
|
|
|
String get menuIcon => "editor/grid";
|
|
|
|
|
2022-03-04 08:22:49 +08:00
|
|
|
@override
|
2022-08-18 19:32:08 +08:00
|
|
|
PluginType get pluginType => PluginType.grid;
|
2022-03-06 09:03:02 +08:00
|
|
|
|
2022-08-10 17:59:28 +08:00
|
|
|
@override
|
2023-04-04 14:08:50 +08:00
|
|
|
ViewLayoutPB? get layoutType => ViewLayoutPB.Grid;
|
2022-03-04 08:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class GridPluginConfig implements PluginConfig {
|
|
|
|
@override
|
2022-04-08 14:31:33 +08:00
|
|
|
bool get creatable => true;
|
2022-03-04 08:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class GridPlugin extends Plugin {
|
2022-09-22 13:08:48 +08:00
|
|
|
@override
|
|
|
|
final ViewPluginNotifier notifier;
|
2022-03-04 08:22:49 +08:00
|
|
|
final PluginType _pluginType;
|
|
|
|
|
|
|
|
GridPlugin({
|
2022-07-19 14:11:29 +08:00
|
|
|
required ViewPB view,
|
2022-03-04 08:22:49 +08:00
|
|
|
required PluginType pluginType,
|
|
|
|
}) : _pluginType = pluginType,
|
2022-09-22 13:08:48 +08:00
|
|
|
notifier = ViewPluginNotifier(view: view);
|
2022-03-04 08:22:49 +08:00
|
|
|
|
|
|
|
@override
|
2023-06-01 20:23:27 +08:00
|
|
|
PluginWidgetBuilder get widgetBuilder =>
|
|
|
|
GridPluginWidgetBuilder(notifier: notifier);
|
2022-03-04 08:22:49 +08:00
|
|
|
|
|
|
|
@override
|
2022-09-22 13:08:48 +08:00
|
|
|
PluginId get id => notifier.view.id;
|
2022-03-04 08:22:49 +08:00
|
|
|
|
|
|
|
@override
|
2023-06-01 20:23:27 +08:00
|
|
|
PluginType get pluginType => _pluginType;
|
2022-03-04 08:22:49 +08:00
|
|
|
}
|
|
|
|
|
2023-06-01 20:23:27 +08:00
|
|
|
class GridPluginWidgetBuilder extends PluginWidgetBuilder {
|
2022-09-22 13:08:48 +08:00
|
|
|
final ViewPluginNotifier notifier;
|
|
|
|
ViewPB get view => notifier.view;
|
|
|
|
|
2023-06-01 20:23:27 +08:00
|
|
|
GridPluginWidgetBuilder({required this.notifier, Key? key});
|
2022-03-04 08:22:49 +08:00
|
|
|
|
|
|
|
@override
|
2022-09-22 13:08:48 +08:00
|
|
|
Widget get leftBarItem => ViewLeftBarItem(view: view);
|
2022-03-04 08:22:49 +08:00
|
|
|
|
|
|
|
@override
|
2022-09-22 13:08:48 +08:00
|
|
|
Widget buildWidget(PluginContext context) {
|
|
|
|
notifier.isDeleted.addListener(() {
|
2022-09-26 16:59:58 +08:00
|
|
|
notifier.isDeleted.value.fold(() => null, (deletedView) {
|
|
|
|
if (deletedView.hasIndex()) {
|
|
|
|
context.onDeleted(view, deletedView.index);
|
|
|
|
}
|
|
|
|
});
|
2022-09-22 13:08:48 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return GridPage(key: ValueKey(view.id), view: view);
|
|
|
|
}
|
2022-03-04 08:22:49 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<NavigationItem> get navigationItems => [this];
|
|
|
|
}
|