view_ext.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import 'package:appflowy/plugins/database_view/board/presentation/board_page.dart';
  2. import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_page.dart';
  3. import 'package:appflowy/plugins/database_view/grid/presentation/grid_page.dart';
  4. import 'package:appflowy/plugins/database_view/tar_bar/tab_bar_view.dart';
  5. import 'package:appflowy/plugins/document/document.dart';
  6. import 'package:appflowy/startup/plugin/plugin.dart';
  7. import 'package:flowy_infra/image.dart';
  8. import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
  9. import 'package:flutter/material.dart';
  10. enum FlowyPlugin {
  11. editor,
  12. kanban,
  13. }
  14. extension FlowyPluginExtension on FlowyPlugin {
  15. String displayName() {
  16. switch (this) {
  17. case FlowyPlugin.editor:
  18. return "Doc";
  19. case FlowyPlugin.kanban:
  20. return "Kanban";
  21. default:
  22. return "";
  23. }
  24. }
  25. bool enable() {
  26. switch (this) {
  27. case FlowyPlugin.editor:
  28. return true;
  29. case FlowyPlugin.kanban:
  30. return false;
  31. default:
  32. return false;
  33. }
  34. }
  35. }
  36. extension ViewExtension on ViewPB {
  37. Widget renderThumbnail({Color? iconColor}) {
  38. const String thumbnail = "file_icon";
  39. const Widget widget = FlowySvg(name: thumbnail);
  40. return widget;
  41. }
  42. PluginType get pluginType {
  43. switch (layout) {
  44. case ViewLayoutPB.Board:
  45. return PluginType.board;
  46. case ViewLayoutPB.Calendar:
  47. return PluginType.calendar;
  48. case ViewLayoutPB.Document:
  49. return PluginType.editor;
  50. case ViewLayoutPB.Grid:
  51. return PluginType.grid;
  52. }
  53. throw UnimplementedError;
  54. }
  55. Plugin plugin({bool listenOnViewChanged = false}) {
  56. switch (layout) {
  57. case ViewLayoutPB.Board:
  58. case ViewLayoutPB.Calendar:
  59. case ViewLayoutPB.Grid:
  60. return DatabaseTabBarViewPlugin(
  61. view: this,
  62. pluginType: pluginType,
  63. );
  64. case ViewLayoutPB.Document:
  65. return DocumentPlugin(
  66. view: this,
  67. pluginType: pluginType,
  68. listenOnViewChanged: listenOnViewChanged,
  69. );
  70. }
  71. throw UnimplementedError;
  72. }
  73. DatabaseTabBarItemBuilder tarBarItem() {
  74. switch (layout) {
  75. case ViewLayoutPB.Board:
  76. return BoardPageTabBarBuilderImpl();
  77. case ViewLayoutPB.Calendar:
  78. return CalendarPageTabBarBuilderImpl();
  79. case ViewLayoutPB.Grid:
  80. return GridPageTabBarBuilderImpl();
  81. case ViewLayoutPB.Document:
  82. throw UnimplementedError;
  83. }
  84. throw UnimplementedError;
  85. }
  86. String get iconName {
  87. switch (layout) {
  88. case ViewLayoutPB.Grid:
  89. return 'editor/grid';
  90. case ViewLayoutPB.Board:
  91. return 'editor/board';
  92. case ViewLayoutPB.Calendar:
  93. return 'editor/calendar';
  94. default:
  95. throw Exception('Unknown layout type');
  96. }
  97. }
  98. }