view_ext.dart 2.3 KB

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