| 
									
										
										
										
											2022-08-08 16:36:26 +08:00
										 |  |  | import 'dart:io'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-09 13:27:23 +02:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  | import 'package:appflowy/generated/flowy_svgs.g.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/generated/locale_keys.g.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/workspace/application/home/home_setting_bloc.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/workspace/presentation/home/home_stack.dart'; | 
					
						
							| 
									
										
										
										
											2023-01-18 07:30:39 +01:00
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							| 
									
										
										
										
											2022-10-25 19:49:58 +08:00
										 |  |  | import 'package:flowy_infra/size.dart'; | 
					
						
							| 
									
										
										
										
											2021-11-05 14:23:30 +08:00
										 |  |  | import 'package:flowy_infra_ui/style_widget/icon_button.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-12 16:58:05 +08:00
										 |  |  | import 'package:flowy_infra_ui/style_widget/text.dart'; | 
					
						
							| 
									
										
										
										
											2023-10-04 15:04:44 +05:30
										 |  |  | import 'package:flowy_infra_ui/widget/flowy_tooltip.dart'; | 
					
						
							| 
									
										
										
										
											2023-01-18 07:30:39 +01:00
										 |  |  | import 'package:flutter_bloc/flutter_bloc.dart'; | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | import 'package:provider/provider.dart'; | 
					
						
							|  |  |  | import 'package:styled_widget/styled_widget.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef NaviAction = void Function(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 22:32:45 +08:00
										 |  |  | class NavigationNotifier with ChangeNotifier { | 
					
						
							| 
									
										
										
										
											2023-01-18 07:30:39 +01:00
										 |  |  |   NavigationNotifier({required this.navigationItems}); | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |   List<NavigationItem> navigationItems; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-12 13:13:18 +02:00
										 |  |  |   void update(PageNotifier notifier) { | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  |     if (navigationItems != notifier.plugin.widgetBuilder.navigationItems) { | 
					
						
							|  |  |  |       navigationItems = notifier.plugin.widgetBuilder.navigationItems; | 
					
						
							| 
									
										
										
										
											2021-11-05 14:23:30 +08:00
										 |  |  |       notifyListeners(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 15:58:57 +08:00
										 |  |  | class FlowyNavigation extends StatelessWidget { | 
					
						
							| 
									
										
										
										
											2023-12-08 20:01:54 +07:00
										 |  |  |   const FlowyNavigation({super.key}); | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2023-07-12 13:13:18 +02:00
										 |  |  |     return ChangeNotifierProxyProvider<PageNotifier, NavigationNotifier>( | 
					
						
							| 
									
										
										
										
											2021-10-28 21:55:22 +08:00
										 |  |  |       create: (_) { | 
					
						
							| 
									
										
										
										
											2023-07-12 13:13:18 +02:00
										 |  |  |         final notifier = Provider.of<PageNotifier>(context, listen: false); | 
					
						
							| 
									
										
										
										
											2021-10-28 21:55:22 +08:00
										 |  |  |         return NavigationNotifier( | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  |           navigationItems: notifier.plugin.widgetBuilder.navigationItems, | 
					
						
							| 
									
										
										
										
											2021-10-28 21:55:22 +08:00
										 |  |  |         ); | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |       update: (_, notifier, controller) => controller!..update(notifier), | 
					
						
							| 
									
										
										
										
											2021-11-10 18:26:38 +08:00
										 |  |  |       child: Expanded( | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |         child: Row( | 
					
						
							|  |  |  |           children: [ | 
					
						
							|  |  |  |             _renderCollapse(context), | 
					
						
							|  |  |  |             Selector<NavigationNotifier, List<NavigationItem>>( | 
					
						
							|  |  |  |               selector: (context, notifier) => notifier.navigationItems, | 
					
						
							|  |  |  |               builder: (ctx, items, child) => Expanded( | 
					
						
							|  |  |  |                 child: Row( | 
					
						
							|  |  |  |                   children: _renderNavigationItems(items), | 
					
						
							|  |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2021-11-10 18:26:38 +08:00
										 |  |  |               ), | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |           ], | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2021-11-10 18:26:38 +08:00
										 |  |  |       ), | 
					
						
							| 
									
										
										
										
											2021-11-05 14:23:30 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-18 07:30:39 +01:00
										 |  |  |   Widget _renderCollapse(BuildContext context) { | 
					
						
							|  |  |  |     return BlocBuilder<HomeSettingBloc, HomeSettingState>( | 
					
						
							|  |  |  |       buildWhen: (p, c) => p.isMenuCollapsed != c.isMenuCollapsed, | 
					
						
							|  |  |  |       builder: (context, state) { | 
					
						
							|  |  |  |         if (state.isMenuCollapsed) { | 
					
						
							|  |  |  |           return RotationTransition( | 
					
						
							|  |  |  |             turns: const AlwaysStoppedAnimation(180 / 360), | 
					
						
							| 
									
										
										
										
											2023-10-12 04:19:36 +02:00
										 |  |  |             child: FlowyTooltip( | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |               richMessage: sidebarTooltipTextSpan( | 
					
						
							|  |  |  |                 context, | 
					
						
							|  |  |  |                 LocaleKeys.sideBar_openSidebar.tr(), | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |               child: FlowyIconButton( | 
					
						
							|  |  |  |                 width: 24, | 
					
						
							|  |  |  |                 hoverColor: Colors.transparent, | 
					
						
							| 
									
										
										
										
											2024-04-09 13:27:23 +02:00
										 |  |  |                 onPressed: () => context | 
					
						
							|  |  |  |                     .read<HomeSettingBloc>() | 
					
						
							|  |  |  |                     .add(const HomeSettingEvent.collapseMenu()), | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |                 iconPadding: const EdgeInsets.fromLTRB(2, 2, 2, 2), | 
					
						
							| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  |                 icon: FlowySvg( | 
					
						
							|  |  |  |                   FlowySvgs.hide_menu_m, | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |                   color: Theme.of(context).iconTheme.color, | 
					
						
							| 
									
										
										
										
											2023-01-18 07:30:39 +01:00
										 |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |               ), | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2023-01-18 07:30:39 +01:00
										 |  |  |           ); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-04-09 13:27:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return const SizedBox.shrink(); | 
					
						
							| 
									
										
										
										
											2023-01-18 07:30:39 +01:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-05 14:23:30 +08:00
										 |  |  |   List<Widget> _renderNavigationItems(List<NavigationItem> items) { | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |     if (items.isEmpty) { | 
					
						
							|  |  |  |       return []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-07 13:55:37 +05:30
										 |  |  |     final List<NavigationItem> newItems = _filter(items); | 
					
						
							|  |  |  |     final Widget last = NaviItemWidget(newItems.removeLast()); | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-07 13:55:37 +05:30
										 |  |  |     final List<Widget> widgets = List.empty(growable: true); | 
					
						
							| 
									
										
										
										
											2021-11-10 18:26:38 +08:00
										 |  |  |     // widgets.addAll(newItems.map((item) => NaviItemDivider(child: NaviItemWidget(item))).toList());
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (final item in newItems) { | 
					
						
							|  |  |  |       widgets.add(NaviItemWidget(item)); | 
					
						
							|  |  |  |       widgets.add(const Text('/')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |     widgets.add(last); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return widgets; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 17:01:30 +08:00
										 |  |  |   List<NavigationItem> _filter(List<NavigationItem> items) { | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |     final length = items.length; | 
					
						
							|  |  |  |     if (length > 4) { | 
					
						
							|  |  |  |       final first = items[0]; | 
					
						
							|  |  |  |       final ellipsisItems = items.getRange(1, length - 2).toList(); | 
					
						
							|  |  |  |       final last = items.getRange(length - 2, length).toList(); | 
					
						
							|  |  |  |       return [ | 
					
						
							|  |  |  |         first, | 
					
						
							|  |  |  |         EllipsisNaviItem(items: ellipsisItems), | 
					
						
							|  |  |  |         ...last, | 
					
						
							|  |  |  |       ]; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return items; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NaviItemWidget extends StatelessWidget { | 
					
						
							| 
									
										
										
										
											2023-12-08 20:01:54 +07:00
										 |  |  |   const NaviItemWidget(this.item, {super.key}); | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |   final NavigationItem item; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2022-08-08 16:36:26 +08:00
										 |  |  |     return Expanded( | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |       child: item.leftBarItem.padding(horizontal: 2, vertical: 2), | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NaviItemDivider extends StatelessWidget { | 
					
						
							| 
									
										
										
										
											2023-09-11 21:32:26 -05:00
										 |  |  |   const NaviItemDivider({super.key, required this.child}); | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |   final Widget child; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return Row( | 
					
						
							| 
									
										
										
										
											2021-11-10 18:26:38 +08:00
										 |  |  |       children: [child, const Text('/')], | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 17:01:30 +08:00
										 |  |  | class EllipsisNaviItem extends NavigationItem { | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |   EllipsisNaviItem({required this.items}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 17:01:30 +08:00
										 |  |  |   final List<NavigationItem> items; | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-11-19 17:53:30 +08:00
										 |  |  |   Widget get leftBarItem => FlowyText.medium( | 
					
						
							|  |  |  |         '...', | 
					
						
							|  |  |  |         fontSize: FontSizes.s16, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-12 13:13:18 +02:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget tabBarItem(String pluginId) => leftBarItem; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2021-10-10 17:01:30 +08:00
										 |  |  |   NavigationCallback get action => (id) {}; | 
					
						
							| 
									
										
										
										
											2021-07-28 18:19:16 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-10-25 19:49:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-22 20:00:21 +08:00
										 |  |  | TextSpan sidebarTooltipTextSpan(BuildContext context, String hintText) => | 
					
						
							|  |  |  |     TextSpan( | 
					
						
							| 
									
										
										
										
											2022-10-25 19:49:58 +08:00
										 |  |  |       children: [ | 
					
						
							|  |  |  |         TextSpan( | 
					
						
							| 
									
										
										
										
											2022-11-10 14:22:18 +08:00
										 |  |  |           text: "$hintText\n", | 
					
						
							| 
									
										
										
										
											2022-10-25 19:49:58 +08:00
										 |  |  |         ), | 
					
						
							|  |  |  |         TextSpan( | 
					
						
							| 
									
										
										
										
											2024-02-07 05:18:13 +01:00
										 |  |  |           text: Platform.isMacOS ? "⌘+." : "Ctrl+\\", | 
					
						
							| 
									
										
										
										
											2022-10-25 19:49:58 +08:00
										 |  |  |         ), | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |     ); |