1
This commit is contained in:
1 parent
6fd164fa6f
commit
27cdb00af2
7 files changed
+587
-187
No files matched your search
+4
-1
@@ -1009,5 +1009,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"chrootDisabledNoRoot": "Unavailable without Root permission",
|
"chrootDisabledNoRoot": "Unavailable without Root permission",
|
||||||
"chrootFailedFallbackToProot": "Chroot mount or permission failed, automatically fell back to PRoot"
|
"chrootFailedFallbackToProot": "Chroot mount or permission failed, automatically fell back to PRoot",
|
||||||
|
"drawerTabExplorer": "Explorer",
|
||||||
|
"drawerTabSearch": "Search",
|
||||||
|
"drawerTabGit": "Source Control"
|
||||||
}
|
}
|
||||||
@@ -3025,6 +3025,24 @@ abstract class AppLocalizations {
|
|||||||
/// In zh, this message translates to:
|
/// In zh, this message translates to:
|
||||||
/// **'Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式'**
|
/// **'Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式'**
|
||||||
String get chrootFailedFallbackToProot;
|
String get chrootFailedFallbackToProot;
|
||||||
|
|
||||||
|
/// No description provided for @drawerTabExplorer.
|
||||||
|
///
|
||||||
|
/// In zh, this message translates to:
|
||||||
|
/// **'文件'**
|
||||||
|
String get drawerTabExplorer;
|
||||||
|
|
||||||
|
/// No description provided for @drawerTabSearch.
|
||||||
|
///
|
||||||
|
/// In zh, this message translates to:
|
||||||
|
/// **'搜索'**
|
||||||
|
String get drawerTabSearch;
|
||||||
|
|
||||||
|
/// No description provided for @drawerTabGit.
|
||||||
|
///
|
||||||
|
/// In zh, this message translates to:
|
||||||
|
/// **'源代码管理'**
|
||||||
|
String get drawerTabGit;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AppLocalizationsDelegate
|
class _AppLocalizationsDelegate
|
||||||
|
|||||||
@@ -1827,4 +1827,13 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get chrootFailedFallbackToProot =>
|
String get chrootFailedFallbackToProot =>
|
||||||
'Chroot mount or permission failed, automatically fell back to PRoot';
|
'Chroot mount or permission failed, automatically fell back to PRoot';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get drawerTabExplorer => 'Explorer';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get drawerTabSearch => 'Search';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get drawerTabGit => 'Source Control';
|
||||||
}
|
}
|
||||||
@@ -1767,4 +1767,13 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get chrootFailedFallbackToProot => 'Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式';
|
String get chrootFailedFallbackToProot => 'Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get drawerTabExplorer => '文件';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get drawerTabSearch => '搜索';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get drawerTabGit => '源代码管理';
|
||||||
}
|
}
|
||||||
+4
-1
@@ -1009,5 +1009,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"chrootDisabledNoRoot": "未授予 Root 权限不可用",
|
"chrootDisabledNoRoot": "未授予 Root 权限不可用",
|
||||||
"chrootFailedFallbackToProot": "Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式"
|
"chrootFailedFallbackToProot": "Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式",
|
||||||
|
"drawerTabExplorer": "文件",
|
||||||
|
"drawerTabSearch": "搜索",
|
||||||
|
"drawerTabGit": "源代码管理"
|
||||||
}
|
}
|
||||||
+405
-185
@@ -19,9 +19,16 @@ enum _OpenProjectSource {
|
|||||||
fromExternal,
|
fromExternal,
|
||||||
}
|
}
|
||||||
|
|
||||||
class CodeEditorDrawer extends StatelessWidget {
|
class CodeEditorDrawer extends StatefulWidget {
|
||||||
const CodeEditorDrawer({super.key});
|
const CodeEditorDrawer({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CodeEditorDrawer> createState() => _CodeEditorDrawerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
|
||||||
|
int _selectedIndex = 0;
|
||||||
|
|
||||||
static ProjectProvider _getProjectProvider(
|
static ProjectProvider _getProjectProvider(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
bool listen = false,
|
bool listen = false,
|
||||||
@@ -126,6 +133,393 @@ class CodeEditorDrawer extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildActivityBarItem({
|
||||||
|
required BuildContext context,
|
||||||
|
required int index,
|
||||||
|
required IconData icon,
|
||||||
|
required String label,
|
||||||
|
}) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final isSelected = _selectedIndex == index;
|
||||||
|
final colorScheme = theme.colorScheme;
|
||||||
|
|
||||||
|
return Tooltip(
|
||||||
|
message: label,
|
||||||
|
preferBelow: false,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () {
|
||||||
|
if (_selectedIndex != index) {
|
||||||
|
setState(() {
|
||||||
|
_selectedIndex = index;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: SizedBox(
|
||||||
|
width: 48,
|
||||||
|
height: 48,
|
||||||
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
if (isSelected)
|
||||||
|
Positioned(
|
||||||
|
left: 0,
|
||||||
|
top: 10,
|
||||||
|
bottom: 10,
|
||||||
|
width: 3,
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: colorScheme.primary,
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
topRight: Radius.circular(2),
|
||||||
|
bottomRight: Radius.circular(2),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
size: 22,
|
||||||
|
color: isSelected
|
||||||
|
? colorScheme.primary
|
||||||
|
: colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildActivityBar(
|
||||||
|
BuildContext context,
|
||||||
|
AppLocalizations l10n,
|
||||||
|
ThemeData theme,
|
||||||
|
) {
|
||||||
|
return Container(
|
||||||
|
width: 48,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.surfaceContainerLow,
|
||||||
|
border: Border(
|
||||||
|
right: BorderSide(
|
||||||
|
color: theme.colorScheme.outlineVariant.withValues(alpha: 0.4),
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: SafeArea(
|
||||||
|
bottom: true,
|
||||||
|
right: false,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_buildActivityBarItem(
|
||||||
|
context: context,
|
||||||
|
index: 0,
|
||||||
|
icon: Icons.folder_copy_outlined,
|
||||||
|
label: l10n.drawerTabExplorer,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
_buildActivityBarItem(
|
||||||
|
context: context,
|
||||||
|
index: 1,
|
||||||
|
icon: Icons.search,
|
||||||
|
label: l10n.drawerTabSearch,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
_buildActivityBarItem(
|
||||||
|
context: context,
|
||||||
|
index: 2,
|
||||||
|
icon: Icons.alt_route_rounded,
|
||||||
|
label: l10n.drawerTabGit,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildExplorerPage(
|
||||||
|
BuildContext context,
|
||||||
|
AppLocalizations l10n,
|
||||||
|
ThemeData theme,
|
||||||
|
String? rootPath,
|
||||||
|
bool hasProject,
|
||||||
|
) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
),
|
||||||
|
child: SafeArea(
|
||||||
|
bottom: false,
|
||||||
|
left: false,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(12.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
l10n.fileDirectory,
|
||||||
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
icon: const Icon(Icons.refresh),
|
||||||
|
tooltip: l10n.refreshDirectory,
|
||||||
|
onPressed: () {
|
||||||
|
_getProjectProvider(context).refreshTree();
|
||||||
|
final runProvider = context.read<RunProvider?>();
|
||||||
|
final root = _getProjectProvider(context).rootPath;
|
||||||
|
if (root != null && root.isNotEmpty) {
|
||||||
|
runProvider?.onProjectOpened(
|
||||||
|
root,
|
||||||
|
systemName: context.read<DistroProvider?>()?.selectedSystem,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
PopupMenuButton<_OpenProjectSource>(
|
||||||
|
icon: const Icon(Icons.folder_open),
|
||||||
|
tooltip: l10n.openFileDirectory,
|
||||||
|
itemBuilder: (popupContext) => [
|
||||||
|
PopupMenuItem<_OpenProjectSource>(
|
||||||
|
value: _OpenProjectSource.fromApp,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.inventory_2_outlined, size: 20),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(l10n.openFromApp),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PopupMenuItem<_OpenProjectSource>(
|
||||||
|
value: _OpenProjectSource.fromExternal,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.folder_open_outlined, size: 20),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(l10n.openFromExternal),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
onSelected: (source) async {
|
||||||
|
switch (source) {
|
||||||
|
case _OpenProjectSource.fromApp:
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => const ProjectManagementView(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case _OpenProjectSource.fromExternal:
|
||||||
|
final hasPermission = await PermissionService
|
||||||
|
.instance
|
||||||
|
.ensureStoragePermission(context: context);
|
||||||
|
if (!hasPermission || !context.mounted) return;
|
||||||
|
final canProceed = await _getTabProvider(
|
||||||
|
context,
|
||||||
|
).checkUnsavedChanges(context);
|
||||||
|
if (!canProceed || !context.mounted) return;
|
||||||
|
_getProjectProvider(context).openDirectory();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
icon: const Icon(Icons.history),
|
||||||
|
tooltip: l10n.viewProjectHistory,
|
||||||
|
onPressed: () {
|
||||||
|
ProjectHistoryWidget.show(
|
||||||
|
context,
|
||||||
|
onSelectHistory: (selectedHistory) async {
|
||||||
|
final canProceed = await _getTabProvider(
|
||||||
|
context,
|
||||||
|
).checkUnsavedChanges(context);
|
||||||
|
if (!canProceed || !context.mounted) return;
|
||||||
|
_getProjectProvider(
|
||||||
|
context,
|
||||||
|
).switchProject(selectedHistory);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
hasProject
|
||||||
|
? (InternalProjectService.instance
|
||||||
|
.isInternalProject(rootPath!)
|
||||||
|
? p.basename(rootPath)
|
||||||
|
: rootPath)
|
||||||
|
: '',
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (hasProject) ...[
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
IconButton(
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
padding: const EdgeInsets.all(3),
|
||||||
|
),
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
minWidth: 24,
|
||||||
|
minHeight: 24,
|
||||||
|
),
|
||||||
|
iconSize: 18,
|
||||||
|
icon: const Icon(Icons.note_add_outlined),
|
||||||
|
tooltip: l10n.newFile,
|
||||||
|
onPressed: () => _handleNewFile(context, rootPath!),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 2),
|
||||||
|
IconButton(
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
padding: const EdgeInsets.all(3),
|
||||||
|
),
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
minWidth: 24,
|
||||||
|
minHeight: 24,
|
||||||
|
),
|
||||||
|
iconSize: 18,
|
||||||
|
icon: const Icon(Icons.create_new_folder_outlined),
|
||||||
|
tooltip: l10n.newFolder,
|
||||||
|
onPressed: () =>
|
||||||
|
_handleNewFolder(context, rootPath!),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 2),
|
||||||
|
IconButton(
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
style: IconButton.styleFrom(
|
||||||
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
padding: const EdgeInsets.all(3),
|
||||||
|
),
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
minWidth: 24,
|
||||||
|
minHeight: 24,
|
||||||
|
),
|
||||||
|
iconSize: 18,
|
||||||
|
icon: const Icon(Icons.file_upload_outlined),
|
||||||
|
tooltip: l10n.importFromExternal,
|
||||||
|
onPressed: () =>
|
||||||
|
_handleImportFiles(context, rootPath!),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Expanded(child: SafeArea(top: false, left: false, child: FileTreeWidget())),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildSearchPlaceholder(
|
||||||
|
BuildContext context,
|
||||||
|
AppLocalizations l10n,
|
||||||
|
ThemeData theme,
|
||||||
|
) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
),
|
||||||
|
child: SafeArea(
|
||||||
|
bottom: false,
|
||||||
|
left: false,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
l10n.drawerTabSearch,
|
||||||
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Expanded(child: SizedBox.shrink()),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildGitPlaceholder(
|
||||||
|
BuildContext context,
|
||||||
|
AppLocalizations l10n,
|
||||||
|
ThemeData theme,
|
||||||
|
) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
),
|
||||||
|
child: SafeArea(
|
||||||
|
bottom: false,
|
||||||
|
left: false,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
l10n.drawerTabGit,
|
||||||
|
style: theme.textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Expanded(child: SizedBox.shrink()),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
@@ -135,194 +529,20 @@ class CodeEditorDrawer extends StatelessWidget {
|
|||||||
final hasProject = rootPath != null && rootPath.trim().isNotEmpty;
|
final hasProject = rootPath != null && rootPath.trim().isNotEmpty;
|
||||||
|
|
||||||
return Drawer(
|
return Drawer(
|
||||||
child: Column(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
_buildActivityBar(context, l10n, theme),
|
||||||
decoration: BoxDecoration(
|
Expanded(
|
||||||
color: theme.colorScheme.primaryContainer,
|
child: IndexedStack(
|
||||||
),
|
index: _selectedIndex,
|
||||||
child: SafeArea(
|
children: [
|
||||||
bottom: false,
|
_buildExplorerPage(context, l10n, theme, rootPath, hasProject),
|
||||||
child: Padding(
|
_buildSearchPlaceholder(context, l10n, theme),
|
||||||
padding: const EdgeInsets.all(16.0),
|
_buildGitPlaceholder(context, l10n, theme),
|
||||||
child: Column(
|
],
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
l10n.fileDirectory,
|
|
||||||
style: theme.textTheme.titleMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.refresh),
|
|
||||||
tooltip: l10n.refreshDirectory,
|
|
||||||
onPressed: () {
|
|
||||||
_getProjectProvider(context).refreshTree();
|
|
||||||
final runProvider = context.read<RunProvider?>();
|
|
||||||
final root = _getProjectProvider(context).rootPath;
|
|
||||||
if (root != null && root.isNotEmpty) {
|
|
||||||
// 传入当前真实选中的系统,无系统时不进行任何任务探测
|
|
||||||
runProvider?.onProjectOpened(
|
|
||||||
root,
|
|
||||||
systemName: context.read<DistroProvider?>()?.selectedSystem,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
PopupMenuButton<_OpenProjectSource>(
|
|
||||||
icon: const Icon(Icons.folder_open),
|
|
||||||
tooltip: l10n.openFileDirectory,
|
|
||||||
itemBuilder: (popupContext) => [
|
|
||||||
PopupMenuItem<_OpenProjectSource>(
|
|
||||||
value: _OpenProjectSource.fromApp,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.inventory_2_outlined, size: 20),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(l10n.openFromApp),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuItem<_OpenProjectSource>(
|
|
||||||
value: _OpenProjectSource.fromExternal,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.folder_open_outlined, size: 20),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(l10n.openFromExternal),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
onSelected: (source) async {
|
|
||||||
switch (source) {
|
|
||||||
case _OpenProjectSource.fromApp:
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
Navigator.of(context).push(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => const ProjectManagementView(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case _OpenProjectSource.fromExternal:
|
|
||||||
final hasPermission = await PermissionService
|
|
||||||
.instance
|
|
||||||
.ensureStoragePermission(context: context);
|
|
||||||
if (!hasPermission || !context.mounted) return;
|
|
||||||
final canProceed = await _getTabProvider(
|
|
||||||
context,
|
|
||||||
).checkUnsavedChanges(context);
|
|
||||||
if (!canProceed || !context.mounted) return;
|
|
||||||
_getProjectProvider(context).openDirectory();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.history),
|
|
||||||
tooltip: l10n.viewProjectHistory,
|
|
||||||
onPressed: () {
|
|
||||||
ProjectHistoryWidget.show(
|
|
||||||
context,
|
|
||||||
onSelectHistory: (selectedHistory) async {
|
|
||||||
final canProceed = await _getTabProvider(
|
|
||||||
context,
|
|
||||||
).checkUnsavedChanges(context);
|
|
||||||
if (!canProceed || !context.mounted) return;
|
|
||||||
_getProjectProvider(
|
|
||||||
context,
|
|
||||||
).switchProject(selectedHistory);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
hasProject
|
|
||||||
? (InternalProjectService.instance
|
|
||||||
.isInternalProject(rootPath)
|
|
||||||
? p.basename(rootPath)
|
|
||||||
: rootPath)
|
|
||||||
: '',
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
|
||||||
color: theme.colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
maxLines: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (hasProject) ...[
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
IconButton(
|
|
||||||
visualDensity: VisualDensity.compact,
|
|
||||||
style: IconButton.styleFrom(
|
|
||||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
||||||
minimumSize: Size.zero,
|
|
||||||
padding: const EdgeInsets.all(3),
|
|
||||||
),
|
|
||||||
constraints: const BoxConstraints(
|
|
||||||
minWidth: 24,
|
|
||||||
minHeight: 24,
|
|
||||||
),
|
|
||||||
iconSize: 18,
|
|
||||||
icon: const Icon(Icons.note_add_outlined),
|
|
||||||
tooltip: l10n.newFile,
|
|
||||||
onPressed: () => _handleNewFile(context, rootPath),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 2),
|
|
||||||
IconButton(
|
|
||||||
visualDensity: VisualDensity.compact,
|
|
||||||
style: IconButton.styleFrom(
|
|
||||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
||||||
minimumSize: Size.zero,
|
|
||||||
padding: const EdgeInsets.all(3),
|
|
||||||
),
|
|
||||||
constraints: const BoxConstraints(
|
|
||||||
minWidth: 24,
|
|
||||||
minHeight: 24,
|
|
||||||
),
|
|
||||||
iconSize: 18,
|
|
||||||
icon: const Icon(Icons.create_new_folder_outlined),
|
|
||||||
tooltip: l10n.newFolder,
|
|
||||||
onPressed: () =>
|
|
||||||
_handleNewFolder(context, rootPath),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 2),
|
|
||||||
IconButton(
|
|
||||||
visualDensity: VisualDensity.compact,
|
|
||||||
style: IconButton.styleFrom(
|
|
||||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
||||||
minimumSize: Size.zero,
|
|
||||||
padding: const EdgeInsets.all(3),
|
|
||||||
),
|
|
||||||
constraints: const BoxConstraints(
|
|
||||||
minWidth: 24,
|
|
||||||
minHeight: 24,
|
|
||||||
),
|
|
||||||
iconSize: 18,
|
|
||||||
icon: const Icon(Icons.file_upload_outlined),
|
|
||||||
tooltip: l10n.importFromExternal,
|
|
||||||
onPressed: () =>
|
|
||||||
_handleImportFiles(context, rootPath),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Expanded(child: SafeArea(top: false, child: FileTreeWidget())),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'package:code_editor/l10n/app_localizations.dart';
|
||||||
|
import 'package:code_editor/models/project_history.dart';
|
||||||
|
import 'package:code_editor/providers/project_provider.dart';
|
||||||
|
import 'package:code_editor/providers/run_provider.dart';
|
||||||
|
import 'package:code_editor/providers/settings_provider.dart';
|
||||||
|
import 'package:code_editor/providers/tab_provider.dart';
|
||||||
|
import 'package:code_editor/services/internal_project_service.dart';
|
||||||
|
import 'package:code_editor/widgets/code_editor_drawer.dart';
|
||||||
|
import 'package:code_editor/widgets/file_tree_widget.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
late Directory tempBaseDir;
|
||||||
|
late Directory testProjectDir;
|
||||||
|
late ProjectProvider projectProvider;
|
||||||
|
late TabProvider tabProvider;
|
||||||
|
late SettingsProvider settingsProvider;
|
||||||
|
late RunProvider runProvider;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
tempBaseDir = Directory.systemTemp.createTempSync('drawer_tab_test_');
|
||||||
|
testProjectDir = Directory(p.join(tempBaseDir.path, 'my_project'))..createSync();
|
||||||
|
|
||||||
|
InternalProjectService.instance.customProjectsDir =
|
||||||
|
Directory(p.join(tempBaseDir.path, 'files', 'projects'));
|
||||||
|
|
||||||
|
projectProvider = ProjectProvider();
|
||||||
|
tabProvider = TabProvider()..bindProjectProvider(projectProvider);
|
||||||
|
settingsProvider = SettingsProvider();
|
||||||
|
runProvider = RunProvider();
|
||||||
|
|
||||||
|
await projectProvider.switchProject(
|
||||||
|
ProjectHistory(
|
||||||
|
rootPath: testProjectDir.path,
|
||||||
|
lastOpenedFilePath: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
InternalProjectService.instance.customProjectsDir = null;
|
||||||
|
if (tempBaseDir.existsSync()) {
|
||||||
|
tempBaseDir.deleteSync(recursive: true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Widget buildTestWidget({Locale locale = const Locale('zh')}) {
|
||||||
|
return MultiProvider(
|
||||||
|
providers: [
|
||||||
|
ChangeNotifierProvider<ProjectProvider>.value(value: projectProvider),
|
||||||
|
ChangeNotifierProvider<TabProvider>.value(value: tabProvider),
|
||||||
|
ChangeNotifierProvider<SettingsProvider>.value(value: settingsProvider),
|
||||||
|
ChangeNotifierProvider<RunProvider>.value(value: runProvider),
|
||||||
|
],
|
||||||
|
child: MaterialApp(
|
||||||
|
localizationsDelegates: const [
|
||||||
|
AppLocalizations.delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
],
|
||||||
|
supportedLocales: const [
|
||||||
|
Locale('zh'),
|
||||||
|
Locale('en'),
|
||||||
|
],
|
||||||
|
locale: locale,
|
||||||
|
home: const Scaffold(
|
||||||
|
drawer: CodeEditorDrawer(),
|
||||||
|
body: Center(child: Text('Editor Body')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('Activity Bar renders 3 vertical tab buttons and switches pages correctly', (tester) async {
|
||||||
|
await tester.pumpWidget(buildTestWidget(locale: const Locale('zh')));
|
||||||
|
final scaffoldState = tester.state<ScaffoldState>(find.byType(Scaffold));
|
||||||
|
scaffoldState.openDrawer();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// 1. Initial state: Explorer is active
|
||||||
|
expect(find.byIcon(Icons.folder_copy_outlined), findsOneWidget);
|
||||||
|
expect(find.byIcon(Icons.search), findsOneWidget);
|
||||||
|
expect(find.byIcon(Icons.alt_route_rounded), findsOneWidget);
|
||||||
|
|
||||||
|
// Initial page shows file tree and directory title ("项目")
|
||||||
|
expect(find.byType(FileTreeWidget), findsOneWidget);
|
||||||
|
expect(find.text('项目'), findsOneWidget);
|
||||||
|
|
||||||
|
// Tooltips
|
||||||
|
expect(find.byTooltip('文件'), findsOneWidget);
|
||||||
|
expect(find.byTooltip('搜索'), findsOneWidget);
|
||||||
|
expect(find.byTooltip('源代码管理'), findsOneWidget);
|
||||||
|
|
||||||
|
// 2. Tap Search tab
|
||||||
|
await tester.tap(find.byTooltip('搜索'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// IndexedStack index is 1 -> Search page header is visible
|
||||||
|
final searchHeader = find.text('搜索');
|
||||||
|
expect(searchHeader, findsWidgets); // tooltip & header title
|
||||||
|
|
||||||
|
// 3. Tap Git tab
|
||||||
|
await tester.tap(find.byTooltip('源代码管理'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// Git header is visible
|
||||||
|
final gitHeader = find.text('源代码管理');
|
||||||
|
expect(gitHeader, findsWidgets); // tooltip & header title
|
||||||
|
|
||||||
|
// 4. Tap back to Explorer
|
||||||
|
await tester.tap(find.byTooltip('文件'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(FileTreeWidget), findsOneWidget);
|
||||||
|
expect(find.text('项目'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Activity Bar tooltips follow English locale', (tester) async {
|
||||||
|
await tester.pumpWidget(buildTestWidget(locale: const Locale('en')));
|
||||||
|
final scaffoldState = tester.state<ScaffoldState>(find.byType(Scaffold));
|
||||||
|
scaffoldState.openDrawer();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byTooltip('Explorer'), findsOneWidget);
|
||||||
|
expect(find.byTooltip('Search'), findsOneWidget);
|
||||||
|
expect(find.byTooltip('Source Control'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user