Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: tabs lr 0.7.6 (#6899)

Mathias Mogensen1851721d9ad7
diff --git a/frontend/appflowy_flutter/integration_test/desktop/uncategorized/tabs_test.dart b/frontend/appflowy_flutter/integration_test/desktop/uncategorized/tabs_test.dart
index 08e37f8b94..d0bc391987 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/uncategorized/tabs_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/uncategorized/tabs_test.dart
@@ -1,9 +1,9 @@
import 'dart:io';
-import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/presentation/home/tabs/flowy_tab.dart';
import 'package:appflowy/workspace/presentation/home/tabs/tabs_manager.dart';
+import 'package:appflowy/workspace/presentation/widgets/tab_bar_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/gestures.dart';
@@ -176,62 +176,159 @@ void main() {
findsNWidgets(3),
);
- final firstTabFinder = find.descendant(
- of: find.byType(FlowyTab),
- matching: find.text(_documentTwoName),
- );
- final secondTabFinder = find.descendant(
- of: find.byType(FlowyTab),
- matching: find.text(gettingStarted),
- );
- final thirdTabFinder = find.descendant(
- of: find.byType(FlowyTab),
- matching: find.text(_documentName),
- );
+ const firstTab = _documentTwoName;
+ const secondTab = gettingStarted;
+ const thirdTab = _documentName;
- expect(firstTabFinder, findsOneWidget);
- expect(secondTabFinder, findsOneWidget);
- expect(thirdTabFinder, findsOneWidget);
+ expect(tester.isTabAtIndex(firstTab, 0), isTrue);
+ expect(tester.isTabAtIndex(secondTab, 1), isTrue);
+ expect(tester.isTabAtIndex(thirdTab, 2), isTrue);
- // We expect not to see the pinned svg
- expect(find.byFlowySvg(FlowySvgs.pinned_s), findsNothing);
+ expect(tester.isTabPinned(gettingStarted), isFalse);
// Right click on second tab
- await tester.tap(
- buttons: kSecondaryButton,
- find.descendant(
- of: find.byType(FlowyTab),
- matching: find.text(gettingStarted),
- ),
- );
- await tester.pumpAndSettle();
+ await tester.openTabMenu(gettingStarted);
expect(find.byType(TabMenu), findsOneWidget);
// Pin second tab
await tester.tap(find.text(LocaleKeys.tabMenu_pinTab.tr()));
await tester.pumpAndSettle();
- // We expect to see the pinned svg
- expect(find.byFlowySvg(FlowySvgs.pinned_s), findsOneWidget);
+ expect(tester.isTabPinned(gettingStarted), isTrue);
- /// Right click on first tab
- await tester.tap(
- buttons: kSecondaryButton,
+ /// Right click on first unpinned tab (second tab)
+ await tester.openTabMenu(_documentTwoName);
+
+ // Close others
+ await tester.tap(find.text(LocaleKeys.tabMenu_closeOthers.tr()));
+ await tester.pumpAndSettle();
+
+ // We expect to find 2 tabs, the first pinned tab and the second tab
+ expect(find.byType(FlowyTab), findsNWidgets(2));
+ expect(tester.isTabAtIndex(gettingStarted, 0), isTrue);
+ expect(tester.isTabAtIndex(_documentTwoName, 1), isTrue);
+ });
+
+ testWidgets('pin/unpin tabs proper order', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ expect(
find.descendant(
- of: find.byType(FlowyTab),
- matching: find.text(_documentTwoName),
+ of: find.byType(TabsManager),
+ matching: find.byType(TabBar),
),
+ findsNothing,
);
+
+ await tester.createNewPageWithNameUnderParent(name: _documentName);
+ await tester.createNewPageWithNameUnderParent(name: _documentTwoName);
+
+ // Open second menu item in a new tab
+ await tester.openAppInNewTab(gettingStarted, ViewLayoutPB.Document);
+
+ // Open third menu item in a new tab
+ await tester.openAppInNewTab(_documentName, ViewLayoutPB.Document);
+
+ expect(
+ find.descendant(
+ of: find.byType(TabsManager),
+ matching: find.byType(FlowyTab),
+ ),
+ findsNWidgets(3),
+ );
+
+ const firstTabName = _documentTwoName;
+ const secondTabName = gettingStarted;
+ const thirdTabName = _documentName;
+
+ // Expect correct order
+ expect(tester.isTabAtIndex(firstTabName, 0), isTrue);
+ expect(tester.isTabAtIndex(secondTabName, 1), isTrue);
+ expect(tester.isTabAtIndex(thirdTabName, 2), isTrue);
+
+ // Pin second tab
+ await tester.openTabMenu(secondTabName);
+ await tester.tap(find.text(LocaleKeys.tabMenu_pinTab.tr()));
await tester.pumpAndSettle();
- // Close others than first tab
- await tester.tap(find.text(LocaleKeys.tabMenu_closeOthers.tr()));
+ expect(tester.isTabPinned(secondTabName), isTrue);
+
+ // Expect correct order
+ expect(tester.isTabAtIndex(secondTabName, 0), isTrue);
+ expect(tester.isTabAtIndex(firstTabName, 1), isTrue);
+ expect(tester.isTabAtIndex(thirdTabName, 2), isTrue);
+
+ // Pin new second tab (first tab)
+ await tester.openTabMenu(firstTabName);
+ await tester.tap(find.text(LocaleKeys.tabMenu_pinTab.tr()));
await tester.pumpAndSettle();
- // We expect to find 2 tabs, the first tab and the pinned second tab
- expect(firstTabFinder, findsOneWidget);
- expect(secondTabFinder, findsOneWidget);
- expect(thirdTabFinder, findsNothing);
+ expect(tester.isTabPinned(firstTabName), isTrue);
+ expect(tester.isTabPinned(secondTabName), isTrue);
+ expect(tester.isTabPinned(thirdTabName), isFalse);
+
+ expect(tester.isTabAtIndex(secondTabName, 0), isTrue);
+ expect(tester.isTabAtIndex(firstTabName, 1), isTrue);
+ expect(tester.isTabAtIndex(thirdTabName, 2), isTrue);
+
+ // Unpin second tab
+ await tester.openTabMenu(secondTabName);
+ await tester.tap(find.text(LocaleKeys.tabMenu_unpinTab.tr()));
+ await tester.pumpAndSettle();
+
+ expect(tester.isTabPinned(firstTabName), isTrue);
+ expect(tester.isTabPinned(secondTabName), isFalse);
+ expect(tester.isTabPinned(thirdTabName), isFalse);
+
+ expect(tester.isTabAtIndex(firstTabName, 0), isTrue);
+ expect(tester.isTabAtIndex(secondTabName, 1), isTrue);
+ expect(tester.isTabAtIndex(thirdTabName, 2), isTrue);
});
});
}
+
+extension _TabsTester on WidgetTester {
+ bool isTabPinned(String tabName) {
+ final tabFinder = find.ancestor(
+ of: find.byWidgetPredicate(
+ (w) => w is ViewTabBarItem && w.view.name == tabName,
+ ),
+ matching: find.byType(FlowyTab),
+ );
+
+ final FlowyTab tabWidget = widget(tabFinder);
+ return tabWidget.pageManager.isPinned;
+ }
+
+ bool isTabAtIndex(String tabName, int index) {
+ final tabFinder = find.ancestor(
+ of: find.byWidgetPredicate(
+ (w) => w is ViewTabBarItem && w.view.name == tabName,
+ ),
+ matching: find.byType(FlowyTab),
+ );
+
+ final pluginId = (widget(tabFinder) as FlowyTab).pageManager.plugin.id;
+
+ final pluginIds = find
+ .byType(FlowyTab)
+ .evaluate()
+ .map((e) => (e.widget as FlowyTab).pageManager.plugin.id);
+
+ return pluginIds.elementAt(index) == pluginId;
+ }
+
+ Future<void> openTabMenu(String tabName) async {
+ await tap(
+ buttons: kSecondaryButton,
+ find.ancestor(
+ of: find.byWidgetPredicate(
+ (w) => w is ViewTabBarItem && w.view.name == tabName,
+ ),
+ matching: find.byType(FlowyTab),
+ ),
+ );
+ await pumpAndSettle();
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart
index d87f691038..568f31b714 100644
--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart
+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart
@@ -2,6 +2,7 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/plugins/ai_chat/chat_page.dart';
import 'package:appflowy/plugins/util.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
+import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy/workspace/presentation/widgets/tab_bar_item.dart';
@@ -85,12 +86,16 @@ class AIChatPagePluginWidgetBuilder extends PluginWidgetBuilder
final ViewPluginNotifier notifier;
int? deletedViewIndex;
+ @override
+ String? get viewName => notifier.view.nameOrDefault;
+
@override
Widget get leftBarItem =>
ViewTitleBar(key: ValueKey(notifier.view.id), view: notifier.view);
@override
- Widget tabBarItem(String pluginId) => ViewTabBarItem(view: notifier.view);
+ Widget tabBarItem(String pluginId, [bool shortForm = false]) =>
+ ViewTabBarItem(view: notifier.view, shortForm: shortForm);
@override
Widget buildWidget({
diff --git a/frontend/appflowy_flutter/lib/plugins/blank/blank.dart b/frontend/appflowy_flutter/lib/plugins/blank/blank.dart
index a74f8d7ee0..b25bb5af06 100644
--- a/frontend/appflowy_flutter/lib/plugins/blank/blank.dart
+++ b/frontend/appflowy_flutter/lib/plugins/blank/blank.dart
@@ -44,11 +44,14 @@ class BlankPagePlugin extends Plugin {
class BlankPagePluginWidgetBuilder extends PluginWidgetBuilder
with NavigationItem {
+ @override
+ String? get viewName => LocaleKeys.blankPageTitle.tr();
+
@override
Widget get leftBarItem => FlowyText.medium(LocaleKeys.blankPageTitle.tr());
@override
- Widget tabBarItem(String pluginId) => leftBarItem;
+ Widget tabBarItem(String pluginId, [bool shortForm = false]) => leftBarItem;
@override
Widget buildWidget({
diff --git a/frontend/appflowy_flutter/lib/plugins/database/tab_bar/tab_bar_view.dart b/frontend/appflowy_flutter/lib/plugins/database/tab_bar/tab_bar_view.dart
index 546430bd11..8d8a1446ad 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/tab_bar/tab_bar_view.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/tab_bar/tab_bar_view.dart
@@ -257,12 +257,16 @@ class DatabasePluginWidgetBuilder extends PluginWidgetBuilder {
///
final String? initialRowId;
+ @override
+ String? get viewName => notifier.view.nameOrDefault;
+
@override
Widget get leftBarItem =>
ViewTitleBar(key: ValueKey(notifier.view.id), view: notifier.view);
@override
- Widget tabBarItem(String pluginId) => ViewTabBarItem(view: notifier.view);
+ Widget tabBarItem(String pluginId, [bool shortForm = false]) =>
+ ViewTabBarItem(view: notifier.view, shortForm: shortForm);
@override
Widget buildWidget({
diff --git a/frontend/appflowy_flutter/lib/plugins/database_document/database_document_plugin.dart b/frontend/appflowy_flutter/lib/plugins/database_document/database_document_plugin.dart
index 3e5b40396a..07c2a4b5dc 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_document/database_document_plugin.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_document/database_document_plugin.dart
@@ -4,6 +4,7 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
+import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
@@ -97,6 +98,9 @@ class DatabaseDocumentPluginWidgetBuilder extends PluginWidgetBuilder
final String documentId;
final Selection? initialSelection;
+ @override
+ String? get viewName => view.nameOrDefault;
+
@override
EdgeInsets get contentPadding => EdgeInsets.zero;
@@ -123,7 +127,8 @@ class DatabaseDocumentPluginWidgetBuilder extends PluginWidgetBuilder
ViewTitleBarWithRow(view: view, databaseId: databaseId, rowId: rowId);
@override
- Widget tabBarItem(String pluginId) => const SizedBox.shrink();
+ Widget tabBarItem(String pluginId, [bool shortForm = false]) =>
+ const SizedBox.shrink();
@override
Widget? get rightBarItem => const SizedBox.shrink();
diff --git a/frontend/appflowy_flutter/lib/plugins/document/document.dart b/frontend/appflowy_flutter/lib/plugins/document/document.dart
index f41a2476b5..dcfc1906a3 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/document.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/document.dart
@@ -10,6 +10,7 @@ import 'package:appflowy/plugins/shared/share/share_button.dart';
import 'package:appflowy/plugins/util.dart';
import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
+import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy/workspace/presentation/widgets/favorite_button.dart';
@@ -145,11 +146,15 @@ class DocumentPluginWidgetBuilder extends PluginWidgetBuilder
);
}
+ @override
+ String? get viewName => notifier.view.nameOrDefault;
+
@override
Widget get leftBarItem => ViewTitleBar(key: ValueKey(view.id), view: view);
@override
- Widget tabBarItem(String pluginId) => ViewTabBarItem(view: notifier.view);
+ Widget tabBarItem(String pluginId, [bool shortForm = false]) =>
+ ViewTabBarItem(view: notifier.view, shortForm: shortForm);
@override
Widget? get rightBarItem {
diff --git a/frontend/appflowy_flutter/lib/plugins/trash/trash.dart b/frontend/appflowy_flutter/lib/plugins/trash/trash.dart
index 22bb1b37d7..f3fb4a8bbe 100644
--- a/frontend/appflowy_flutter/lib/plugins/trash/trash.dart
+++ b/frontend/appflowy_flutter/lib/plugins/trash/trash.dart
@@ -53,11 +53,14 @@ class TrashPlugin extends Plugin {
}
class TrashPluginDisplay extends PluginWidgetBuilder {
+ @override
+ String? get viewName => LocaleKeys.trash_text.tr();
+
@override
Widget get leftBarItem => FlowyText.medium(LocaleKeys.trash_text.tr());
@override
- Widget tabBarItem(String pluginId) => leftBarItem;
+ Widget tabBarItem(String pluginId, [bool shortForm = false]) => leftBarItem;
@override
Widget? get rightBarItem => null;
@@ -68,9 +71,7 @@ class TrashPluginDisplay extends PluginWidgetBuilder {
required bool shrinkWrap,
Map<String, dynamic>? data,
}) =>
- const TrashPage(
- key: ValueKey('TrashPage'),
- );
+ const TrashPage(key: ValueKey('TrashPage'));
@override
List<NavigationItem> get navigationItems => [this];
diff --git a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart
index 1ed12d9278..d9f5571f91 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart
@@ -33,7 +33,7 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
if (index != state.currentIndex &&
index >= 0 &&
index < state.pages) {
- emit(state.copyWith(newIndex: index));
+ emit(state.copyWith(currentIndex: index));
_setLatestOpenView();
}
},
@@ -57,7 +57,7 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
_setLatestOpenView();
},
openTab: (Plugin plugin, ViewPB view) {
- emit(state.openView(plugin, view));
+ emit(state.openView(plugin));
_setLatestOpenView(view);
},
openPlugin: (Plugin plugin, ViewPB? view, bool setLatest) {
@@ -67,24 +67,105 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
}
},
closeOtherTabs: (String pluginId) {
- final pagesToClose = [
+ final pageManagers = [
...state._pageManagers
- .where((pm) => pm.plugin.id != pluginId && !pm.isPinned),
+ .where((pm) => pm.plugin.id == pluginId || pm.isPinned),
];
- final newstate = state;
- for (final pm in pagesToClose) {
- newstate.closeView(pm.plugin.id);
+ int newIndex;
+ if (state.currentPageManager.isPinned) {
+ // Retain current index if it's already pinned
+ newIndex = state.currentIndex;
+ } else {
+ final pm = state._pageManagers
+ .firstWhereOrNull((pm) => pm.plugin.id == pluginId);
+ newIndex = pm != null ? pageManagers.indexOf(pm) : 0;
}
- emit(newstate.copyWith(newIndex: 0));
+
+ emit(
+ state.copyWith(
+ currentIndex: newIndex,
+ pageManagers: pageManagers,
+ ),
+ );
+
_setLatestOpenView();
},
togglePin: (String pluginId) {
final pm = state._pageManagers
.firstWhereOrNull((pm) => pm.plugin.id == pluginId);
if (pm != null) {
+ final index = state._pageManagers.indexOf(pm);
+
+ int newIndex = state.currentIndex;
+ if (pm.isPinned) {
+ // Unpinning logic
+ final indexOfFirstUnpinnedTab =
+ state._pageManagers.indexWhere((tab) => !tab.isPinned);
+
+ // Determine the correct insertion point
+ final newUnpinnedIndex = indexOfFirstUnpinnedTab != -1
+ ? indexOfFirstUnpinnedTab // Insert before the first unpinned tab
+ : state._pageManagers
+ .length; // Append at the end if no unpinned tabs exist
+
+ state._pageManagers.removeAt(index);
+
+ final adjustedUnpinnedIndex = newUnpinnedIndex > index
+ ? newUnpinnedIndex - 1
+ : newUnpinnedIndex;
+
+ state._pageManagers.insert(adjustedUnpinnedIndex, pm);
+ newIndex = _adjustCurrentIndex(
+ currentIndex: state.currentIndex,
+ tabIndex: index,
+ newIndex: adjustedUnpinnedIndex,
+ );
+ } else {
+ // Pinning logic
+ final indexOfLastPinnedTab =
+ state._pageManagers.lastIndexWhere((tab) => tab.isPinned);
+ final newPinnedIndex = indexOfLastPinnedTab + 1;
+
+ state._pageManagers.removeAt(index);
+
+ final adjustedPinnedIndex = newPinnedIndex > index
+ ? newPinnedIndex - 1
+ : newPinnedIndex;
+
+ state._pageManagers.insert(adjustedPinnedIndex, pm);
+ newIndex = _adjustCurrentIndex(
+ currentIndex: state.currentIndex,
+ tabIndex: index,
+ newIndex: adjustedPinnedIndex,
+ );
+ }
+
pm.isPinned = !pm.isPinned;
- emit(state.copyWith(pageManagers: [...state._pageManagers]));
+
+ emit(
+ state.copyWith(
+ currentIndex: newIndex,
+ pageManagers: [...state._pageManagers],
+ ),
+ );
+ }
+ },
+ switchWorkspace: (workspaceId) {
+ final pluginId = state.currentPageManager.plugin.id;
+
+ // Close all tabs except current
+ final pagesToClose = [
+ ...state._pageManagers
+ .where((pm) => pm.plugin.id != pluginId && !pm.isPinned),
+ ];
+
+ if (pagesToClose.isNotEmpty) {
+ final newstate = state;
+ for (final pm in pagesToClose) {
+ newstate.closeView(pm.plugin.id);
+ }
+ emit(newstate.copyWith(currentIndex: 0));
}
},
);
@@ -105,6 +186,22 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
}
}
+ int _adjustCurrentIndex({
+ required int currentIndex,
+ required int tabIndex,
+ required int newIndex,
+ }) {
+ if (tabIndex < currentIndex && newIndex >= currentIndex) {
+ return currentIndex - 1; // Tab moved forward, shift currentIndex back
+ } else if (tabIndex > currentIndex && newIndex <= currentIndex) {
+ return currentIndex + 1; // Tab moved backward, shift currentIndex forward
+ } else if (tabIndex == currentIndex) {
+ return newIndex; // Tab is the current tab, update to newIndex
+ }
+
+ return currentIndex;
+ }
+
/// Adds a [TabsEvent.openTab] event for the provided [ViewPB]
void openTab(ViewPB view) =>
add(TabsEvent.openTab(plugin: view.plugin(), view: view));
@@ -140,6 +237,8 @@ class TabsEvent with _$TabsEvent {
ViewPB? view,
@Default(true) bool setLatest,
}) = _OpenPlugin;
+ const factory TabsEvent.switchWorkspace(String workspaceId) =
+ _SwitchWorkspace;
}
class TabsState {
@@ -154,18 +253,23 @@ class TabsState {
PageManager get currentPageManager => _pageManagers[currentIndex];
List<PageManager> get pageManagers => _pageManagers;
- /// This opens a new tab given a [Plugin] and a [View].
+ bool get isAllPinned => _pageManagers.every((pm) => pm.isPinned);
+
+ /// This opens a new tab given a [Plugin].
///
/// If the [Plugin.id] is already associated with an open tab,
/// then it selects that tab.
///
- TabsState openView(Plugin plugin, ViewPB view) {
+ TabsState openView(Plugin plugin) {
final selectExistingPlugin = _selectPluginIfOpen(plugin.id);
if (selectExistingPlugin == null) {
_pageManagers.add(PageManager()..setPlugin(plugin, true));
- return copyWith(newIndex: pages - 1, pageManagers: [..._pageManagers]);
+ return copyWith(
+ currentIndex: pages - 1,
+ pageManagers: [..._pageManagers],
+ );
}
return selectExistingPlugin;
@@ -188,7 +292,7 @@ class TabsState {
: currentIndex;
return copyWith(
- newIndex: newIndex,
+ currentIndex: newIndex,
pageManagers: [..._pageManagers],
);
}
@@ -229,15 +333,15 @@ class TabsState {
return this;
}
- return copyWith(newIndex: index);
+ return copyWith(currentIndex: index);
}
TabsState copyWith({
- int? newIndex,
+ int? currentIndex,
List<PageManager>? pageManagers,
}) =>
TabsState(
- currentIndex: newIndex ?? currentIndex,
+ currentIndex: currentIndex ?? this.currentIndex,
pageManagers: pageManagers ?? _pageManagers,
);
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart
index 15de10f07a..0e63792faa 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart
@@ -58,7 +58,10 @@ class _HomeStackState extends State<HomeStack> {
return BlocProvider<TabsBloc>.value(
value: getIt<TabsBloc>(),
child: BlocBuilder<TabsBloc, TabsState>(
- buildWhen: (prev, curr) => prev.currentIndex != curr.currentIndex,
+ buildWhen: (prev, curr) =>
+ prev.currentIndex != curr.currentIndex &&
+ prev.currentPageManager.plugin.id !=
+ curr.currentPageManager.plugin.id,
builder: (context, state) => Column(
children: [
if (Platform.isWindows)
@@ -239,9 +242,10 @@ class FadingIndexedStackState extends State<FadingIndexedStack> {
}
abstract mixin class NavigationItem {
+ String? get viewName;
Widget get leftBarItem;
Widget? get rightBarItem => null;
- Widget tabBarItem(String pluginId);
+ Widget tabBarItem(String pluginId, [bool shortForm = false]);
NavigationCallback get action => (id) => throw UnimplementedError();
}
@@ -254,8 +258,11 @@ class PageNotifier extends ChangeNotifier {
Widget get titleWidget => _plugin.widgetBuilder.leftBarItem;
- Widget tabBarWidget(String pluginId) =>
- _plugin.widgetBuilder.tabBarItem(pluginId);
+ Widget tabBarWidget(
+ String pluginId, [
+ bool shortForm = false,
+ ]) =>
+ _plugin.widgetBuilder.tabBarItem(pluginId, shortForm);
/// This is the only place where the plugin is set.
/// No need compare the old plugin with the new plugin. Just set it.
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
index fc3c53e260..cfb86b8832 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
@@ -298,15 +298,14 @@ class _WorkspaceInfo extends StatelessWidget {
void _openWorkspace(BuildContext context) {
if (!isSelected) {
- // close the other tabs before opening another workspace.
- getIt<TabsBloc>().add(const TabsEvent.closeOtherTabs(''));
-
Log.info('open workspace: ${workspace.workspaceId}');
- context.read<UserWorkspaceBloc>().add(
- UserWorkspaceEvent.openWorkspace(
- workspace.workspaceId,
- ),
- );
+
+ // Persist and close other tabs when switching workspace, restore tabs for new workspace
+ getIt<TabsBloc>().add(TabsEvent.switchWorkspace(workspace.workspaceId));
+
+ context
+ .read<UserWorkspaceBloc>()
+ .add(UserWorkspaceEvent.openWorkspace(workspace.workspaceId));
PopoverContainer.of(context).closeAll();
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/navigation.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/navigation.dart
index 619699f420..d588e512b0 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/navigation.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/navigation.dart
@@ -162,13 +162,13 @@ class EllipsisNaviItem extends NavigationItem {
final List<NavigationItem> items;
@override
- Widget get leftBarItem => FlowyText.medium(
- '...',
- fontSize: FontSizes.s16,
- );
+ String? get viewName => null;
@override
- Widget tabBarItem(String pluginId) => leftBarItem;
+ Widget get leftBarItem => FlowyText.medium('...', fontSize: FontSizes.s16);
+
+ @override
+ Widget tabBarItem(String pluginId, [bool shortForm = false]) => leftBarItem;
@override
NavigationCallback get action => (id) {};
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/flowy_tab.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/flowy_tab.dart
index cc24e3a9b5..7e4a5f8df1 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/flowy_tab.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/flowy_tab.dart
@@ -18,12 +18,17 @@ class FlowyTab extends StatefulWidget {
required this.pageManager,
required this.isCurrent,
required this.onTap,
+ required this.isAllPinned,
});
final PageManager pageManager;
final bool isCurrent;
final VoidCallback onTap;
+ /// Signifies whether all tabs are pinned
+ ///
+ final bool isAllPinned;
+
@override
State<FlowyTab> createState() => _FlowyTabState();
}
@@ -33,80 +38,84 @@ class _FlowyTabState extends State<FlowyTab> {
@override
Widget build(BuildContext context) {
- return FlowyHover(
- resetHoverOnRebuild: false,
- style: HoverStyle(
- borderRadius: BorderRadius.zero,
- backgroundColor: widget.isCurrent
- ? Theme.of(context).colorScheme.surface
- : Theme.of(context).colorScheme.surfaceContainerHighest,
- hoverColor:
- widget.isCurrent ? Theme.of(context).colorScheme.surface : null,
- ),
- builder: (context, isHovering) => AppFlowyPopover(
- controller: controller,
- offset: const Offset(4, 4),
- triggerActions: PopoverTriggerFlags.secondaryClick,
- showAtCursor: true,
- popupBuilder: (_) => BlocProvider.value(
- value: context.read<TabsBloc>(),
- child: TabMenu(
- controller: controller,
- pageId: widget.pageManager.plugin.id,
- isPinned: widget.pageManager.isPinned,
+ return SizedBox(
+ width: widget.pageManager.isPinned ? 54 : null,
+ child: _wrapInTooltip(
+ widget.pageManager.plugin.widgetBuilder.viewName,
+ child: FlowyHover(
+ resetHoverOnRebuild: false,
+ style: HoverStyle(
+ borderRadius: BorderRadius.zero,
+ backgroundColor: widget.isCurrent
+ ? Theme.of(context).colorScheme.surface
+ : Theme.of(context).colorScheme.surfaceContainerHighest,
+ hoverColor:
+ widget.isCurrent ? Theme.of(context).colorScheme.surface : null,
),
- ),
- child: ChangeNotifierProvider.value(
- value: widget.pageManager.notifier,
- child: Consumer<PageNotifier>(
- builder: (context, value, _) => Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16.0),
- // We use a Listener to avoid gesture detector onPanStart debounce
- child: Listener(
- onPointerDown: (event) {
- if (event.buttons == kPrimaryButton) {
- widget.onTap();
- }
- },
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- // Stop move window detector
- onPanStart: (_) {},
- child: Container(
- constraints: const BoxConstraints(
- maxWidth: HomeSizes.tabBarWidth,
- minWidth: 100,
- ),
- height: HomeSizes.tabBarHeight,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Flexible(
- child: widget.pageManager.notifier
- .tabBarWidget(widget.pageManager.plugin.id),
+ builder: (context, isHovering) => AppFlowyPopover(
+ controller: controller,
+ offset: const Offset(4, 4),
+ triggerActions: PopoverTriggerFlags.secondaryClick,
+ showAtCursor: true,
+ popupBuilder: (_) => BlocProvider.value(
+ value: context.read<TabsBloc>(),
+ child: TabMenu(
+ controller: controller,
+ pageId: widget.pageManager.plugin.id,
+ isPinned: widget.pageManager.isPinned,
+ isAllPinned: widget.isAllPinned,
+ ),
+ ),
+ child: ChangeNotifierProvider.value(
+ value: widget.pageManager.notifier,
+ child: Consumer<PageNotifier>(
+ builder: (context, value, _) => Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ // We use a Listener to avoid gesture detector onPanStart debounce
+ child: Listener(
+ onPointerDown: (event) {
+ if (event.buttons == kPrimaryButton) {
+ widget.onTap();
+ }
+ },
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ // Stop move window detector
+ onPanStart: (_) {},
+ child: Container(
+ constraints: BoxConstraints(
+ maxWidth: HomeSizes.tabBarWidth,
+ minWidth: widget.pageManager.isPinned ? 54 : 100,
),
- if (widget.pageManager.isPinned) ...[
- const FlowySvg(
- FlowySvgs.pinned_s,
- size: Size.square(16),
- ),
- ] else ...[
- Visibility(
- visible: isHovering,
- child: SizedBox(
- width: 26,
- height: 26,
- child: FlowyIconButton(
- onPressed: () => _closeTab(context),
- icon: const FlowySvg(
- FlowySvgs.close_s,
- size: Size.square(22),
- ),
+ height: HomeSizes.tabBarHeight,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Flexible(
+ child: widget.pageManager.notifier.tabBarWidget(
+ widget.pageManager.plugin.id,
+ widget.pageManager.isPinned,
),
),
- ),
- ],
- ],
+ if (!widget.pageManager.isPinned) ...[
+ Visibility(
+ visible: isHovering,
+ child: SizedBox(
+ width: 26,
+ height: 26,
+ child: FlowyIconButton(
+ onPressed: () => _closeTab(context),
+ icon: const FlowySvg(
+ FlowySvgs.close_s,
+ size: Size.square(22),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
),
),
),
@@ -121,6 +130,17 @@ class _FlowyTabState extends State<FlowyTab> {
void _closeTab(BuildContext context) => context
.read<TabsBloc>()
.add(TabsEvent.closeTab(widget.pageManager.plugin.id));
+
+ Widget _wrapInTooltip(String? viewName, {required Widget child}) {
+ if (viewName != null) {
+ return FlowyTooltip(
+ message: viewName,
+ child: child,
+ );
+ }
+
+ return child;
+ }
}
@visibleForTesting
@@ -130,11 +150,13 @@ class TabMenu extends StatelessWidget {
required this.controller,
required this.pageId,
required this.isPinned,
+ required this.isAllPinned,
});
final PopoverController controller;
final String pageId;
final bool isPinned;
+ final bool isAllPinned;
@override
Widget build(BuildContext context) {
@@ -142,15 +164,33 @@ class TabMenu extends StatelessWidget {
separatorBuilder: () => const VSpace(4),
mainAxisSize: MainAxisSize.min,
children: [
- FlowyButton(
- text: FlowyText.regular(LocaleKeys.tabMenu_close.tr()),
- onTap: () => _closeTab(context),
+ Opacity(
+ opacity: isPinned ? 0.5 : 1,
+ child: _wrapInTooltip(
+ shouldWrap: isPinned,
+ message: LocaleKeys.tabMenu_closeDisabledHint.tr(),
+ child: FlowyButton(
+ text: FlowyText.regular(LocaleKeys.tabMenu_close.tr()),
+ onTap: () => _closeTab(context),
+ disable: isPinned,
+ ),
+ ),
),
- FlowyButton(
- text: FlowyText.regular(
- LocaleKeys.tabMenu_closeOthers.tr(),
+ Opacity(
+ opacity: isAllPinned ? 0.5 : 1,
+ child: _wrapInTooltip(
+ shouldWrap: true,
+ message: isAllPinned
+ ? LocaleKeys.tabMenu_closeOthersDisabledHint.tr()
+ : LocaleKeys.tabMenu_closeOthersHint.tr(),
+ child: FlowyButton(
+ text: FlowyText.regular(
+ LocaleKeys.tabMenu_closeOthers.tr(),
+ ),
+ onTap: () => _closeOtherTabs(context),
+ disable: isAllPinned,
+ ),
),
- onTap: () => _closeOtherTabs(context),
),
const Divider(height: 0.5),
FlowyButton(
@@ -165,11 +205,30 @@ class TabMenu extends StatelessWidget {
);
}
- void _closeTab(BuildContext context) =>
- context.read<TabsBloc>().add(TabsEvent.closeTab(pageId));
+ Widget _wrapInTooltip({
+ required bool shouldWrap,
+ String? message,
+ required Widget child,
+ }) {
+ if (shouldWrap) {
+ return FlowyTooltip(
+ message: message,
+ child: child,
+ );
+ }
- void _closeOtherTabs(BuildContext context) =>
- context.read<TabsBloc>().add(TabsEvent.closeOtherTabs(pageId));
+ return child;
+ }
+
+ void _closeTab(BuildContext context) {
+ context.read<TabsBloc>().add(TabsEvent.closeTab(pageId));
+ controller.close();
+ }
+
+ void _closeOtherTabs(BuildContext context) {
+ context.read<TabsBloc>().add(TabsEvent.closeOtherTabs(pageId));
+ controller.close();
+ }
void _togglePin(BuildContext context) {
context.read<TabsBloc>().add(TabsEvent.togglePin(pageId));
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/tabs_manager.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/tabs_manager.dart
index 6ae3edba8a..08d9a478c1 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/tabs_manager.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/tabs_manager.dart
@@ -25,6 +25,8 @@ class TabsManager extends StatelessWidget {
return const SizedBox.shrink();
}
+ final isAllPinned = state.isAllPinned;
+
return Container(
alignment: Alignment.bottomLeft,
height: HomeSizes.tabBarHeight,
@@ -43,6 +45,7 @@ class TabsManager extends StatelessWidget {
key: ValueKey('tab-${pm.plugin.id}'),
pageManager: pm,
isCurrent: state.currentPageManager == pm,
+ isAllPinned: isAllPinned,
onTap: () {
if (state.currentPageManager != pm) {
final index = state.pageManagers.indexOf(pm);
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/tab_bar_item.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/tab_bar_item.dart
index e4f3098c39..4ce5a93ab0 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/tab_bar_item.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/tab_bar_item.dart
@@ -6,9 +6,14 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
class ViewTabBarItem extends StatefulWidget {
- const ViewTabBarItem({super.key, required this.view});
+ const ViewTabBarItem({
+ super.key,
+ required this.view,
+ this.shortForm = false,
+ });
final ViewPB view;
+ final bool shortForm;
@override
State<ViewTabBarItem> createState() => _ViewTabBarItemState();
@@ -39,8 +44,28 @@ class _ViewTabBarItemState extends State<ViewTabBarItem> {
}
@override
- Widget build(BuildContext context) => FlowyText.medium(
- view.nameOrDefault,
- overflow: TextOverflow.ellipsis,
- );
+ Widget build(BuildContext context) {
+ return Row(
+ mainAxisAlignment:
+ widget.shortForm ? MainAxisAlignment.center : MainAxisAlignment.start,
+ children: [
+ if (widget.view.icon.value.isNotEmpty)
+ FlowyText.emoji(
+ widget.view.icon.value,
+ fontSize: 16.0,
+ figmaLineHeight: 20.0,
+ optimizeEmojiAlign: true,
+ ),
+ if (!widget.shortForm && view.icon.value.isNotEmpty) const HSpace(6),
+ if (!widget.shortForm || view.icon.value.isEmpty) ...[
+ Flexible(
+ child: FlowyText.medium(
+ view.nameOrDefault,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ ],
+ ],
+ );
+ }
}
diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json
index ae6e3b0a03..dc93847dd6 100644
--- a/frontend/resources/translations/en.json
+++ b/frontend/resources/translations/en.json
@@ -2887,11 +2887,14 @@
},
"tabMenu": {
"close": "Close",
+ "closeDisabledHint": "Cannot close a pinned tab, please unpin first",
"closeOthers": "Close other tabs",
+ "closeOthersHint": "This will close all unpinned tabs except this one",
+ "closeOthersDisabledHint": "All tabs are pinned, cannot find any tabs to close",
"favorite": "Favorite",
"unfavorite": "Unfavorite",
"favoriteDisabledHint": "Cannot favorite this view",
"pinTab": "Pin",
"unpinTab": "Unpin"
}
-}
+}
\ No newline at end of file