Skip to content

Commit

Permalink
Fix window buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Jul 23, 2022
1 parent f2383e9 commit 565f810
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 106 deletions.
70 changes: 31 additions & 39 deletions app/lib/views/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,45 +197,37 @@ class PadAppBar extends StatelessWidget with PreferredSizeWidget {
})),
actions: [
BlocBuilder<DocumentBloc, DocumentState>(
builder: (context, state) =>
BlocBuilder<SettingsCubit, ButterflySettings>(
buildWhen: (previous, current) =>
previous.nativeWindowTitleBar !=
current.nativeWindowTitleBar,
builder: (context, settings) => Row(
children: [
if (!isMobile) ...[
IconButton(
icon: const Icon(PhosphorIcons
.arrowCounterClockwiseLight),
tooltip: AppLocalizations.of(context)!.undo,
onPressed: !bloc.canUndo
? null
: () {
Actions.maybeInvoke<UndoIntent>(
context, UndoIntent(context));
},
),
IconButton(
icon: const Icon(
PhosphorIcons.arrowClockwiseLight),
tooltip: AppLocalizations.of(context)!.redo,
onPressed: !bloc.canRedo
? null
: () {
Actions.maybeInvoke<RedoIntent>(
context, RedoIntent(context));
},
),
],
if (isWindow() &&
kIsWeb &&
!settings.nativeWindowTitleBar) ...[
const VerticalDivider(),
const WindowButtons()
]
],
)),
builder: (context, state) => Row(
children: [
if (!isMobile) ...[
IconButton(
icon: const Icon(
PhosphorIcons.arrowCounterClockwiseLight),
tooltip: AppLocalizations.of(context)!.undo,
onPressed: !bloc.canUndo
? null
: () {
Actions.maybeInvoke<UndoIntent>(
context, UndoIntent(context));
},
),
IconButton(
icon: const Icon(PhosphorIcons.arrowClockwiseLight),
tooltip: AppLocalizations.of(context)!.redo,
onPressed: !bloc.canRedo
? null
: () {
Actions.maybeInvoke<RedoIntent>(
context, RedoIntent(context));
},
),
],
if (!kIsWeb && isWindow()) ...[
const VerticalDivider(),
const WindowButtons()
]
],
),
)
]);
},
Expand Down
138 changes: 71 additions & 67 deletions app/lib/views/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,74 +426,78 @@ class _WindowButtonsState extends State<WindowButtons> with WindowListener {
@override
@override
Widget build(BuildContext context) {
if (isWindow() &&
!context.read<SettingsCubit>().state.nativeWindowTitleBar) {
return LayoutBuilder(
builder: (context, constraints) => Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (!fullScreen)
IconButton(
icon: Icon(alwaysOnTop
? PhosphorIcons.pushPinFill
: PhosphorIcons.pushPinLight),
tooltip: alwaysOnTop
? AppLocalizations.of(context)!.exitAlwaysOnTop
: AppLocalizations.of(context)!.alwaysOnTop,
onPressed: () async {
await windowManager.setAlwaysOnTop(!alwaysOnTop);
setState(() => alwaysOnTop = !alwaysOnTop);
},
return BlocBuilder<SettingsCubit, ButterflySettings>(
buildWhen: (previous, current) =>
previous.nativeWindowTitleBar != current.nativeWindowTitleBar,
builder: (context, settings) {
if (!kIsWeb && isWindow() && !settings.nativeWindowTitleBar) {
return LayoutBuilder(
builder: (context, constraints) => Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (!fullScreen)
IconButton(
icon: Icon(alwaysOnTop
? PhosphorIcons.pushPinFill
: PhosphorIcons.pushPinLight),
tooltip: alwaysOnTop
? AppLocalizations.of(context)!.exitAlwaysOnTop
: AppLocalizations.of(context)!.alwaysOnTop,
onPressed: () async {
await windowManager.setAlwaysOnTop(!alwaysOnTop);
setState(() => alwaysOnTop = !alwaysOnTop);
},
),
IconButton(
icon: Icon(fullScreen
? PhosphorIcons.arrowsInLight
: PhosphorIcons.arrowsOutLight),
tooltip: fullScreen
? AppLocalizations.of(context)!.exitFullScreen
: AppLocalizations.of(context)!.enterFullScreen,
onPressed: () async {
setState(() => fullScreen = !fullScreen);
await windowManager.setFullScreen(fullScreen);
},
),
if (!fullScreen) ...[
const VerticalDivider(),
IconButton(
icon: const Icon(PhosphorIcons.minusLight),
tooltip: AppLocalizations.of(context)!.minimize,
iconSize: 16,
splashRadius: 20,
onPressed: () => windowManager.minimize(),
),
IconButton(
icon: Icon(PhosphorIcons.squareLight,
size: maximized ? 14 : 20),
tooltip: maximized
? AppLocalizations.of(context)!.restore
: AppLocalizations.of(context)!.maximize,
iconSize: 16,
splashRadius: 20,
onPressed: () async => await windowManager.isMaximized()
? windowManager.unmaximize()
: windowManager.maximize(),
),
IconButton(
icon: const Icon(PhosphorIcons.xLight),
tooltip: AppLocalizations.of(context)!.close,
hoverColor: Colors.red,
iconSize: 16,
splashRadius: 20,
onPressed: () => windowManager.close(),
)
]
],
),
IconButton(
icon: Icon(fullScreen
? PhosphorIcons.arrowsInLight
: PhosphorIcons.arrowsOutLight),
tooltip: fullScreen
? AppLocalizations.of(context)!.exitFullScreen
: AppLocalizations.of(context)!.enterFullScreen,
onPressed: () async {
setState(() => fullScreen = !fullScreen);
await windowManager.setFullScreen(fullScreen);
},
),
if (!fullScreen) ...[
const VerticalDivider(),
IconButton(
icon: const Icon(PhosphorIcons.minusLight),
tooltip: AppLocalizations.of(context)!.minimize,
iconSize: 16,
splashRadius: 20,
onPressed: () => windowManager.minimize(),
),
IconButton(
icon: Icon(PhosphorIcons.squareLight,
size: maximized ? 14 : 20),
tooltip: maximized
? AppLocalizations.of(context)!.restore
: AppLocalizations.of(context)!.maximize,
iconSize: 16,
splashRadius: 20,
onPressed: () async => await windowManager.isMaximized()
? windowManager.unmaximize()
: windowManager.maximize(),
),
IconButton(
icon: const Icon(PhosphorIcons.xLight),
tooltip: AppLocalizations.of(context)!.close,
hoverColor: Colors.red,
iconSize: 16,
splashRadius: 20,
onPressed: () => windowManager.close(),
)
]
],
),
),
);
}
return Container();
);
}
return Container();
});
}
}

0 comments on commit 565f810

Please sign in to comment.