fix: move title bar on top of tabs on Windows (#6116)

This commit is contained in:
Mathias Mogensen 2024-08-30 10:12:26 +02:00 committed by GitHub
parent 0fd0900b41
commit 47c2ae23ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 65 additions and 74 deletions

View File

@ -1,15 +1,7 @@
import 'dart:io'; import 'dart:io';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/window_title_bar.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CocoaWindowChannel { class CocoaWindowChannel {
CocoaWindowChannel._(); CocoaWindowChannel._();
@ -38,11 +30,9 @@ class MoveWindowDetector extends StatefulWidget {
const MoveWindowDetector({ const MoveWindowDetector({
super.key, super.key,
this.child, this.child,
this.showTitleBar = false,
}); });
final Widget? child; final Widget? child;
final bool showTitleBar;
@override @override
MoveWindowDetectorState createState() => MoveWindowDetectorState(); MoveWindowDetectorState createState() => MoveWindowDetectorState();
@ -54,28 +44,10 @@ class MoveWindowDetectorState extends State<MoveWindowDetector> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (!Platform.isMacOS && !Platform.isWindows) { if (!Platform.isMacOS) {
return widget.child ?? const SizedBox.shrink(); return widget.child ?? const SizedBox.shrink();
} }
if (Platform.isWindows) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
if (widget.showTitleBar) ...[
WindowTitleBar(
leftChildren: [
_buildToggleMenuButton(context),
],
),
] else ...[
const SizedBox(height: 5),
],
widget.child ?? const SizedBox.shrink(),
],
);
}
return GestureDetector( return GestureDetector(
// https://stackoverflow.com/questions/52965799/flutter-gesturedetector-not-working-with-containers-in-stack // https://stackoverflow.com/questions/52965799/flutter-gesturedetector-not-working-with-containers-in-stack
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
@ -96,45 +68,4 @@ class MoveWindowDetectorState extends State<MoveWindowDetector> {
child: widget.child, child: widget.child,
); );
} }
Widget _buildToggleMenuButton(BuildContext context) {
if (!context.read<HomeSettingBloc>().state.isMenuCollapsed) {
return const SizedBox.shrink();
}
final textSpan = TextSpan(
children: [
TextSpan(
text: '${LocaleKeys.sideBar_openSidebar.tr()}\n',
style: context.tooltipTextStyle(),
),
TextSpan(
text: Platform.isMacOS ? '⌘+.' : 'Ctrl+\\',
style: context
.tooltipTextStyle()
?.copyWith(color: Theme.of(context).hintColor),
),
],
);
return FlowyTooltip(
richMessage: textSpan,
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (_) => context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.collapseMenu()),
child: FlowyHover(
child: Container(
width: 24,
padding: const EdgeInsets.all(4),
child: const RotatedBox(
quarterTurns: 2,
child: FlowySvg(FlowySvgs.hide_menu_s),
),
),
),
),
);
}
} }

View File

@ -1,8 +1,16 @@
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart'; import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:appflowy/core/frameless_window.dart'; import 'package:appflowy/core/frameless_window.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/blank/blank.dart'; import 'package:appflowy/plugins/blank/blank.dart';
import 'package:appflowy/shared/window_title_bar.dart';
import 'package:appflowy/startup/plugin/plugin.dart'; import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart'; import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart'; import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/home/navigation.dart'; import 'package:appflowy/workspace/presentation/home/navigation.dart';
@ -10,9 +18,10 @@ import 'package:appflowy/workspace/presentation/home/tabs/tabs_manager.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart'; import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart'; import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart'; import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:time/time.dart'; import 'package:time/time.dart';
@ -47,6 +56,17 @@ class HomeStack extends StatelessWidget {
builder: (context, state) { builder: (context, state) {
return Column( return Column(
children: [ children: [
if (Platform.isWindows)
Column(
mainAxisSize: MainAxisSize.min,
children: [
WindowTitleBar(
leftChildren: [
_buildToggleMenuButton(context),
],
),
],
),
Padding( Padding(
padding: EdgeInsets.only(left: layout.menuSpacing), padding: EdgeInsets.only(left: layout.menuSpacing),
child: TabsManager(pageController: pageController), child: TabsManager(pageController: pageController),
@ -73,6 +93,47 @@ class HomeStack extends StatelessWidget {
), ),
); );
} }
Widget _buildToggleMenuButton(BuildContext context) {
if (!context.read<HomeSettingBloc>().state.isMenuCollapsed) {
return const SizedBox.shrink();
}
final textSpan = TextSpan(
children: [
TextSpan(
text: '${LocaleKeys.sideBar_openSidebar.tr()}\n',
style: context.tooltipTextStyle(),
),
TextSpan(
text: Platform.isMacOS ? '⌘+.' : 'Ctrl+\\',
style: context
.tooltipTextStyle()
?.copyWith(color: Theme.of(context).hintColor),
),
],
);
return FlowyTooltip(
richMessage: textSpan,
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (_) => context
.read<HomeSettingBloc>()
.add(const HomeSettingEvent.collapseMenu()),
child: FlowyHover(
child: Container(
width: 24,
padding: const EdgeInsets.all(4),
child: const RotatedBox(
quarterTurns: 2,
child: FlowySvg(FlowySvgs.hide_menu_s),
),
),
),
),
);
}
} }
class PageStack extends StatefulWidget { class PageStack extends StatefulWidget {
@ -230,7 +291,6 @@ class PageManager {
child: Selector<PageNotifier, Widget>( child: Selector<PageNotifier, Widget>(
selector: (context, notifier) => notifier.titleWidget, selector: (context, notifier) => notifier.titleWidget,
builder: (_, __, child) => MoveWindowDetector( builder: (_, __, child) => MoveWindowDetector(
showTitleBar: true,
child: HomeTopBar(layout: layout), child: HomeTopBar(layout: layout),
), ),
), ),