|
1 | 1 | import 'dart:io'; |
2 | 2 |
|
3 | | -import 'package:fluent_ui/fluent_ui.dart'; |
4 | | -import 'package:flutter/material.dart' as m; |
5 | 3 | import 'package:flutter_pty/flutter_pty.dart'; |
6 | 4 | import 'package:terminal/constants/constants.dart'; |
7 | | -import 'package:terminal/views/terminal_settings.dart'; |
8 | 5 | import 'package:xterm/frontend/terminal_view.dart'; |
9 | 6 | import 'package:xterm/xterm.dart'; |
| 7 | +import 'package:zenit_ui/zenit_ui.dart'; |
10 | 8 |
|
11 | 9 | class TerminalFrame extends StatefulWidget { |
12 | 10 | const TerminalFrame({Key? key}) : super(key: key); |
@@ -36,83 +34,44 @@ String get shell { |
36 | 34 | } |
37 | 35 |
|
38 | 36 | class _TerminalFrameState extends State<TerminalFrame> { |
39 | | - int index = 0; |
40 | | - List<Terminal> tabs = [Constants.terminal(_pty)]; |
41 | | - List<FocusNode> focusNodes = [FocusNode()]; |
42 | | - |
| 37 | + final Map<FocusNode, Terminal> tabs = { |
| 38 | + FocusNode(): Constants.terminal(_pty), |
| 39 | + }; |
43 | 40 | @override |
44 | | - void initState() { |
45 | | - super.initState(); |
46 | | - |
47 | | - focusNodes[index].requestFocus(); |
| 41 | + void didChangeDependencies() { |
| 42 | + super.didChangeDependencies(); |
| 43 | + tabs.entries.first.key.requestFocus(); |
48 | 44 | } |
49 | 45 |
|
50 | 46 | @override |
51 | 47 | Widget build(BuildContext context) { |
52 | | - return m.Material( |
| 48 | + return Material( |
53 | 49 | color: Colors.transparent, |
54 | | - child: m.Theme( |
55 | | - data: m.ThemeData( |
56 | | - brightness: m.Brightness.dark, |
57 | | - ), |
58 | | - child: TabView( |
59 | | - wheelScroll: true, |
60 | | - scrollController: ScrollPosController(), |
61 | | - tabWidthBehavior: TabWidthBehavior.equal, |
62 | | - showScrollButtons: true, |
63 | | - shortcutsEnabled: true, |
64 | | - currentIndex: index, |
65 | | - footer: m.IconButton( |
66 | | - onPressed: () { |
67 | | - m.Navigator.of(context).push( |
68 | | - m.MaterialPageRoute( |
69 | | - builder: (context) => const TerminalSettings(), |
70 | | - ), |
71 | | - ); |
72 | | - }, |
73 | | - icon: const m.Icon(m.Icons.settings_outlined), |
74 | | - padding: EdgeInsets.zero, |
75 | | - ), |
76 | | - onChanged: (newIndex) async { |
77 | | - setState(() { |
78 | | - index = newIndex; |
79 | | - }); |
80 | | - await Future.delayed(const Duration(milliseconds: 300)); |
81 | | - focusNodes[newIndex].requestFocus(); |
82 | | - }, |
83 | | - onNewPressed: () async { |
84 | | - setState(() { |
85 | | - tabs.add(Constants.terminal(_pty)); |
86 | | - focusNodes.add(FocusNode()); |
87 | | - index = tabs.length - 1; |
88 | | - }); |
89 | | - await Future.delayed(const Duration(milliseconds: 300)); |
90 | | - focusNodes[index].requestFocus(); |
91 | | - }, |
92 | | - tabs: List.generate( |
93 | | - tabs.length, |
94 | | - (mIndex) => Tab( |
95 | | - text: Row( |
96 | | - children: [ |
97 | | - Text("Terminal ${mIndex + 1}"), |
98 | | - ], |
99 | | - ), |
100 | | - icon: const Icon(m.Icons.computer), |
101 | | - onClosed: () { |
102 | | - setState(() { |
103 | | - tabs.removeAt(mIndex); |
104 | | - index = tabs.length - 1; |
105 | | - }); |
106 | | - }, |
107 | | - ), |
108 | | - ), |
109 | | - bodies: tabs |
110 | | - .map((Terminal terminal) => TerminalView( |
| 50 | + child: TabView( |
| 51 | + pages: tabs |
| 52 | + .map((FocusNode focusNode, Terminal terminal) => MapEntry( |
| 53 | + focusNode, |
| 54 | + TabViewPage( |
| 55 | + title: "Terminal", |
| 56 | + view: TerminalView( |
111 | 57 | terminal: terminal, |
112 | | - focusNode: focusNodes[index], |
113 | | - )) |
114 | | - .toList(), |
115 | | - ), |
| 58 | + focusNode: focusNode, |
| 59 | + ), |
| 60 | + ))) |
| 61 | + .values |
| 62 | + .toList(), |
| 63 | + onNewPage: () => setState(() { |
| 64 | + tabs.addEntries([MapEntry(FocusNode(), Constants.terminal(_pty))]); |
| 65 | + }), |
| 66 | + onPageClosed: (index) { |
| 67 | + tabs.removeWhere((key, value) => |
| 68 | + tabs.entries.elementAt(index).key == key && |
| 69 | + tabs.entries.elementAt(index).value == value); |
| 70 | + tabs.entries.elementAt(tabs.length - 1).key.requestFocus(); |
| 71 | + }, |
| 72 | + onPageChanged: (index) { |
| 73 | + tabs.entries.elementAt(index).key.requestFocus(); |
| 74 | + }, |
116 | 75 | ), |
117 | 76 | ); |
118 | 77 | } |
|
0 commit comments