view_ext.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import 'package:appflowy/generated/flowy_svgs.g.dart';
  2. import 'package:appflowy/plugins/database_view/board/presentation/board_page.dart';
  3. import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_page.dart';
  4. import 'package:appflowy/plugins/database_view/grid/presentation/grid_page.dart';
  5. import 'package:appflowy/plugins/database_view/tar_bar/tab_bar_view.dart';
  6. import 'package:appflowy/plugins/document/document.dart';
  7. import 'package:appflowy/startup/plugin/plugin.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 Widget widget = FlowySvg(FlowySvgs.page_s);
  39. return widget;
  40. }
  41. Widget defaultIcon() {
  42. return FlowySvg(
  43. switch (layout) {
  44. ViewLayoutPB.Board => FlowySvgs.board_s,
  45. ViewLayoutPB.Calendar => FlowySvgs.date_s,
  46. ViewLayoutPB.Grid => FlowySvgs.grid_s,
  47. ViewLayoutPB.Document => FlowySvgs.documents_s,
  48. _ => FlowySvgs.documents_s,
  49. },
  50. );
  51. }
  52. PluginType get pluginType {
  53. switch (layout) {
  54. case ViewLayoutPB.Board:
  55. return PluginType.board;
  56. case ViewLayoutPB.Calendar:
  57. return PluginType.calendar;
  58. case ViewLayoutPB.Document:
  59. return PluginType.editor;
  60. case ViewLayoutPB.Grid:
  61. return PluginType.grid;
  62. }
  63. throw UnimplementedError;
  64. }
  65. Plugin plugin({bool listenOnViewChanged = false}) {
  66. switch (layout) {
  67. case ViewLayoutPB.Board:
  68. case ViewLayoutPB.Calendar:
  69. case ViewLayoutPB.Grid:
  70. return DatabaseTabBarViewPlugin(
  71. view: this,
  72. pluginType: pluginType,
  73. );
  74. case ViewLayoutPB.Document:
  75. return DocumentPlugin(
  76. view: this,
  77. pluginType: pluginType,
  78. listenOnViewChanged: listenOnViewChanged,
  79. );
  80. }
  81. throw UnimplementedError;
  82. }
  83. DatabaseTabBarItemBuilder tarBarItem() {
  84. switch (layout) {
  85. case ViewLayoutPB.Board:
  86. return BoardPageTabBarBuilderImpl();
  87. case ViewLayoutPB.Calendar:
  88. return CalendarPageTabBarBuilderImpl();
  89. case ViewLayoutPB.Grid:
  90. return GridPageTabBarBuilderImpl();
  91. case ViewLayoutPB.Document:
  92. throw UnimplementedError;
  93. }
  94. throw UnimplementedError;
  95. }
  96. FlowySvgData get iconData => layout.icon;
  97. }
  98. extension ViewLayoutExtension on ViewLayoutPB {
  99. FlowySvgData get icon {
  100. switch (this) {
  101. case ViewLayoutPB.Grid:
  102. return FlowySvgs.grid_s;
  103. case ViewLayoutPB.Board:
  104. return FlowySvgs.board_s;
  105. case ViewLayoutPB.Calendar:
  106. return FlowySvgs.date_s;
  107. case ViewLayoutPB.Document:
  108. return FlowySvgs.documents_s;
  109. default:
  110. throw Exception('Unknown layout type');
  111. }
  112. }
  113. bool get isDatabaseView {
  114. switch (this) {
  115. case ViewLayoutPB.Grid:
  116. case ViewLayoutPB.Board:
  117. case ViewLayoutPB.Calendar:
  118. return true;
  119. case ViewLayoutPB.Document:
  120. return false;
  121. default:
  122. throw Exception('Unknown layout type');
  123. }
  124. }
  125. }