Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui] Open and close terminal tabs keyboard shortcuts #3853

Draft
wants to merge 1 commit into
base: copy-paste-improvements
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/client/gui/lib/platform/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart';

import '../settings/autostart_notifiers.dart';
import '../vm_details/terminal.dart';
import '../vm_details/terminal_tabs.dart';
import 'platform.dart';

class LinuxPlatform extends MpPlatform {
Expand Down Expand Up @@ -37,6 +38,10 @@ class LinuxPlatform extends MpPlatform {
PasteTextIntent(SelectionChangedCause.keyboard),
SingleActivator(LogicalKeyboardKey.insert, shift: true):
PasteTextIntent(SelectionChangedCause.keyboard),
SingleActivator(LogicalKeyboardKey.keyW, control: true):
CloseTerminalIntent(),
SingleActivator(LogicalKeyboardKey.keyT, control: true):
AddTerminalIntent(),
SingleActivator(LogicalKeyboardKey.equal, control: true):
IncreaseTerminalFontIntent(),
SingleActivator(LogicalKeyboardKey.equal, control: true, shift: true):
Expand Down
5 changes: 5 additions & 0 deletions src/client/gui/lib/platform/macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart';

import '../settings/autostart_notifiers.dart';
import '../vm_details/terminal.dart';
import '../vm_details/terminal_tabs.dart';
import 'platform.dart';

class MacOSPlatform extends MpPlatform {
Expand Down Expand Up @@ -32,6 +33,10 @@ class MacOSPlatform extends MpPlatform {
CopySelectionTextIntent.copy,
SingleActivator(LogicalKeyboardKey.keyV, meta: true):
PasteTextIntent(SelectionChangedCause.keyboard),
SingleActivator(LogicalKeyboardKey.keyW, meta: true):
CloseTerminalIntent(),
SingleActivator(LogicalKeyboardKey.keyT, meta: true):
AddTerminalIntent(),
SingleActivator(LogicalKeyboardKey.equal, meta: true):
IncreaseTerminalFontIntent(),
SingleActivator(LogicalKeyboardKey.equal, meta: true, shift: true):
Expand Down
5 changes: 5 additions & 0 deletions src/client/gui/lib/platform/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:win32/win32.dart';

import '../settings/autostart_notifiers.dart';
import '../vm_details/terminal.dart';
import '../vm_details/terminal_tabs.dart';
import 'platform.dart';

class WindowsPlatform extends MpPlatform {
Expand Down Expand Up @@ -39,6 +40,10 @@ class WindowsPlatform extends MpPlatform {
PasteTextIntent(SelectionChangedCause.keyboard),
SingleActivator(LogicalKeyboardKey.insert, shift: true):
PasteTextIntent(SelectionChangedCause.keyboard),
SingleActivator(LogicalKeyboardKey.keyW, control: true):
CloseTerminalIntent(),
SingleActivator(LogicalKeyboardKey.keyT, control: true):
AddTerminalIntent(),
SingleActivator(LogicalKeyboardKey.equal, control: true):
IncreaseTerminalFontIntent(),
SingleActivator(LogicalKeyboardKey.equal, control: true, shift: true):
Expand Down
46 changes: 36 additions & 10 deletions src/client/gui/lib/vm_details/terminal_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ class Tab extends StatelessWidget {
}
}

class CloseTerminalIntent extends Intent {
const CloseTerminalIntent();
}

class AddTerminalIntent extends Intent {
const AddTerminalIntent();
}

class TerminalTabs extends ConsumerWidget {
final String name;

Expand All @@ -136,6 +144,14 @@ class TerminalTabs extends ConsumerWidget {
final notifier = provider.notifier;
final (:ids, :currentIndex) = ref.watch(provider);

void closeTab(int index) {
ref.read(notifier).remove(index);
}

void addTab() {
ref.read(notifier).add();
}

final tabsAndShells = ids.mapIndexed((index, shellId) {
final tab = ReorderableDragStartListener(
key: ValueKey(shellId.id),
Expand All @@ -144,7 +160,7 @@ class TerminalTabs extends ConsumerWidget {
title: 'Shell ${shellId.id}',
selected: index == currentIndex,
onTap: () => ref.read(notifier).setCurrent(index),
onClose: () => ref.read(notifier).remove(index),
onClose: () => closeTab(index),
),
);

Expand All @@ -164,7 +180,7 @@ class TerminalTabs extends ConsumerWidget {
hoverColor: Colors.white24,
splashRadius: 10,
icon: const Icon(Icons.add, color: Colors.white, size: 20),
onPressed: () => ref.read(notifier).add(),
onPressed: () => addTab(),
),
);

Expand All @@ -187,13 +203,23 @@ class TerminalTabs extends ConsumerWidget {
),
);

return Column(children: [
Container(
color: const Color(0xff222222),
height: 35,
child: tabList,
),
Expanded(child: shellStack),
]);
return Actions(
actions: {
CloseTerminalIntent: CallbackAction<CloseTerminalIntent>(
onInvoke: (_) => closeTab(currentIndex),
),
AddTerminalIntent: CallbackAction<AddTerminalIntent>(
onInvoke: (_) => addTab(),
),
},
child: Column(children: [
Container(
color: const Color(0xff222222),
height: 35,
child: tabList,
),
Expanded(child: shellStack),
]),
);
}
}
Loading