view_ext.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. Widget defaultIcon() {
  43. final iconName = switch (layout) {
  44. ViewLayoutPB.Board => 'editor/board',
  45. ViewLayoutPB.Calendar => 'editor/calendar',
  46. ViewLayoutPB.Grid => 'editor/grid',
  47. ViewLayoutPB.Document => 'editor/documents',
  48. _ => 'file_icon',
  49. };
  50. return FlowySvg(
  51. name: iconName,
  52. );
  53. }
  54. PluginType get pluginType {
  55. switch (layout) {
  56. case ViewLayoutPB.Board:
  57. return PluginType.board;
  58. case ViewLayoutPB.Calendar:
  59. return PluginType.calendar;
  60. case ViewLayoutPB.Document:
  61. return PluginType.editor;
  62. case ViewLayoutPB.Grid:
  63. return PluginType.grid;
  64. }
  65. throw UnimplementedError;
  66. }
  67. Plugin plugin({bool listenOnViewChanged = false}) {
  68. switch (layout) {
  69. case ViewLayoutPB.Board:
  70. case ViewLayoutPB.Calendar:
  71. case ViewLayoutPB.Grid:
  72. return DatabaseTabBarViewPlugin(
  73. view: this,
  74. pluginType: pluginType,
  75. );
  76. case ViewLayoutPB.Document:
  77. return DocumentPlugin(
  78. view: this,
  79. pluginType: pluginType,
  80. listenOnViewChanged: listenOnViewChanged,
  81. );
  82. }
  83. throw UnimplementedError;
  84. }
  85. DatabaseTabBarItemBuilder tarBarItem() {
  86. switch (layout) {
  87. case ViewLayoutPB.Board:
  88. return BoardPageTabBarBuilderImpl();
  89. case ViewLayoutPB.Calendar:
  90. return CalendarPageTabBarBuilderImpl();
  91. case ViewLayoutPB.Grid:
  92. return GridPageTabBarBuilderImpl();
  93. case ViewLayoutPB.Document:
  94. throw UnimplementedError;
  95. }
  96. throw UnimplementedError;
  97. }
  98. String get iconName {
  99. return layout.iconName;
  100. }
  101. }
  102. extension ViewLayoutExtension on ViewLayoutPB {
  103. String get iconName {
  104. switch (this) {
  105. case ViewLayoutPB.Grid:
  106. return 'editor/grid';
  107. case ViewLayoutPB.Board:
  108. return 'editor/board';
  109. case ViewLayoutPB.Calendar:
  110. return 'editor/calendar';
  111. case ViewLayoutPB.Document:
  112. return 'editor/documents';
  113. default:
  114. throw Exception('Unknown layout type');
  115. }
  116. }
  117. bool get isDatabaseView {
  118. switch (this) {
  119. case ViewLayoutPB.Grid:
  120. case ViewLayoutPB.Board:
  121. case ViewLayoutPB.Calendar:
  122. return true;
  123. case ViewLayoutPB.Document:
  124. return false;
  125. default:
  126. throw Exception('Unknown layout type');
  127. }
  128. }
  129. }