Skip to content

Commit 371814d

Browse files
authored
Merge pull request #56 from mbpcoder/claude/bold-mendel-nxf923
Branch counts in folder view; file explorer and terminal toolbar buttons
2 parents 04871d6 + e55af33 commit 371814d

5 files changed

Lines changed: 89 additions & 2 deletions

File tree

‎flutter/lib/l10n/translations.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ const Map<String, Map<String, String>> translations = {
450450
'report_ownership_shared': 'shared',
451451
'update_folder': 'Update all repositories in a folder',
452452
'folder_update_repo_count': '{n} repositories',
453+
'folder_update_branch_totals': '{local} local · {remote} remote branches',
454+
'folder_update_branch_counts': '{local} local · {remote} remote',
453455
'folder_update_last_run': 'last updated {time}',
454456
'folder_update_change_folder': 'Change folder',
455457
'folder_update_update_all': 'Update all',
@@ -910,6 +912,8 @@ const Map<String, Map<String, String>> translations = {
910912
'report_ownership_shared': 'مشترك',
911913
'update_folder': 'تحديث جميع المستودعات في مجلد',
912914
'folder_update_repo_count': '{n} مستودعات',
915+
'folder_update_branch_totals': 'الفروع: {local} محلي · {remote} بعيد',
916+
'folder_update_branch_counts': '{local} محلي · {remote} بعيد',
913917
'folder_update_last_run': 'آخر تحديث {time}',
914918
'folder_update_change_folder': 'تغيير المجلد',
915919
'folder_update_update_all': 'تحديث الكل',
@@ -1370,6 +1374,8 @@ const Map<String, Map<String, String>> translations = {
13701374
'report_ownership_shared': 'مشترک',
13711375
'update_folder': 'به‌روزرسانی همه مخزن‌های یک پوشه',
13721376
'folder_update_repo_count': '{n} مخزن',
1377+
'folder_update_branch_totals': 'برنچ‌ها: {local} محلی · {remote} ریموت',
1378+
'folder_update_branch_counts': '{local} محلی · {remote} ریموت',
13731379
'folder_update_last_run': 'آخرین به‌روزرسانی {time}',
13741380
'folder_update_change_folder': 'تغییر پوشه',
13751381
'folder_update_update_all': 'به‌روزرسانی همه',

‎flutter/lib/repo/folder_update_controller.dart‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class FolderRepo {
2828
String? branch;
2929
bool isDetached = false;
3030

31+
/// Branch counts; `null` until loaded. Remote excludes `<remote>/HEAD`.
32+
int? localBranchCount;
33+
int? remoteBranchCount;
34+
3135
FolderRepoStatus status = FolderRepoStatus.idle;
3236

3337
/// Translation key for the detail column (e.g. why it was skipped).
@@ -64,6 +68,12 @@ class FolderUpdateController extends ChangeNotifier {
6468
int countOf(FolderRepoStatus status) =>
6569
repos.where((r) => r.status == status).length;
6670

71+
/// Sum of the loaded branch counts of all repositories.
72+
int get totalLocalBranches =>
73+
repos.fold(0, (sum, r) => sum + (r.localBranchCount ?? 0));
74+
int get totalRemoteBranches =>
75+
repos.fold(0, (sum, r) => sum + (r.remoteBranchCount ?? 0));
76+
6777
int get doneCount => repos
6878
.where(
6979
(r) => const {
@@ -121,6 +131,10 @@ class FolderUpdateController extends ChangeNotifier {
121131
final head = branches.where((b) => b.isHead && !b.isRemote);
122132
repo.isDetached = head.isEmpty;
123133
repo.branch = head.isEmpty ? null : head.first.name;
134+
repo.localBranchCount = branches.where((b) => !b.isRemote).length;
135+
repo.remoteBranchCount = branches
136+
.where((b) => b.isRemote && !b.name.endsWith('/HEAD'))
137+
.length;
124138
} catch (_) {
125139
// Branch is shown for information only; the run reports real errors.
126140
}
@@ -201,6 +215,8 @@ class FolderUpdateController extends ChangeNotifier {
201215
branch,
202216
isRemote: false,
203217
);
218+
// The fetch may have added or pruned remote branches.
219+
await _loadBranch(repo);
204220
if (!result.isSuccess) {
205221
final error = result.error!;
206222
if (error.contains('has diverged')) {

‎flutter/lib/welcome/folder_update_view.dart‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class _FolderUpdateViewState extends State<FolderUpdateView> {
9393
translate(
9494
'folder_update_repo_count',
9595
).replaceAll('{n}', '${controller.repos.length}'),
96+
translate('folder_update_branch_totals')
97+
.replaceAll('{local}', '${controller.totalLocalBranches}')
98+
.replaceAll('{remote}', '${controller.totalRemoteBranches}'),
9699
];
97100
final last = controller.lastRunAt;
98101
if (last != null) {
@@ -447,7 +450,7 @@ class _RepoTable extends StatelessWidget {
447450
),
448451
const SizedBox(height: 2),
449452
Text(
450-
repo.isDetached ? 'HEAD' : (repo.branch ?? ' '),
453+
_branchLine(repo),
451454
style: b.mono(fontSize: 12, color: b.muted),
452455
overflow: TextOverflow.ellipsis,
453456
),
@@ -507,6 +510,23 @@ class _RepoTable extends StatelessWidget {
507510
);
508511
}
509512

513+
/// Current branch, then the branch counts once loaded.
514+
static String _branchLine(FolderRepo repo) {
515+
final current = repo.isDetached ? 'HEAD' : repo.branch;
516+
final local = repo.localBranchCount;
517+
final remote = repo.remoteBranchCount;
518+
final counts = local == null || remote == null
519+
? null
520+
: translate('folder_update_branch_counts')
521+
.replaceAll('{local}', '$local')
522+
.replaceAll('{remote}', '$remote');
523+
final parts = [
524+
if (current != null) current,
525+
if (counts != null) counts,
526+
];
527+
return parts.isEmpty ? ' ' : parts.join(' · ');
528+
}
529+
510530
static String _detailText(FolderRepo repo) {
511531
if (repo.status == FolderRepoStatus.updating) {
512532
return translate('folder_update_updating_detail');

‎flutter/lib/welcome/welcome_screen.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
411411
onToggleTheme: AppTheme.toggle,
412412
isPinned: _isPinned,
413413
onTogglePin: _togglePin,
414+
repoPath: tab.path,
415+
onOpenTerminal: tab.path == null ? null : _openNewTerminal,
414416
),
415417
const UpdateBanner(),
416418
Expanded(

‎flutter/lib/widgets/app_top_bar.dart‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22

33
import '../l10n/app_locale.dart';
44
import '../models/repo_tab.dart';
5+
import '../repo/file_explorer.dart';
56
import '../repo/git_actions.dart';
67
import '../repo/repo_controller.dart';
78
import '../shortcuts/app_shortcuts.dart';
@@ -20,7 +21,7 @@ const double kRepoToolbarHeight = 46;
2021
/// 1. `Branchi [tab] [tab] [+] … ☾ 📌 ⚙` - the open tabs, with the
2122
/// app-wide buttons.
2223
/// 2. `[branch] [History | Changes N | Files | Report] …
23-
/// [● Auto 1:42 ▾] Fetch Pull [Push]` - the selected tab's
24+
/// 📁 >_ [● Auto 1:42 ▾] Fetch Pull [Push]` - the selected tab's
2425
/// repository toolbar; only when that tab has a repository open
2526
/// ([controller] non-null).
2627
///
@@ -39,6 +40,8 @@ class AppTopBar extends StatelessWidget {
3940
required this.onToggleTheme,
4041
required this.isPinned,
4142
required this.onTogglePin,
43+
this.repoPath,
44+
this.onOpenTerminal,
4245
});
4346

4447
final List<RepoTab> tabs;
@@ -56,6 +59,13 @@ class AppTopBar extends StatelessWidget {
5659
final bool isPinned;
5760
final VoidCallback onTogglePin;
5861

62+
/// The active tab's repository folder, opened by the file explorer button.
63+
final String? repoPath;
64+
65+
/// Opens a new terminal in the repository (same as the branch menu's
66+
/// "Open in terminal").
67+
final VoidCallback? onOpenTerminal;
68+
5969
@override
6070
Widget build(BuildContext context) {
6171
final controller = this.controller;
@@ -130,6 +140,14 @@ class AppTopBar extends StatelessWidget {
130140
);
131141
}
132142

143+
Future<void> _openFileExplorer(BuildContext context, String path) async {
144+
final messenger = ScaffoldMessenger.maybeOf(context);
145+
final error = await openInFileExplorer(path);
146+
if (error != null) {
147+
messenger?.showSnackBar(SnackBar(content: Text(error)));
148+
}
149+
}
150+
133151
Widget _buildRepoToolbar(BuildContext context, RepoController controller) {
134152
final b = context.branchi;
135153
return Container(
@@ -150,6 +168,31 @@ class AppTopBar extends StatelessWidget {
150168
],
151169
),
152170
),
171+
if (repoPath != null) ...[
172+
_HoverBox(
173+
tooltip: translate('bs_open_explorer'),
174+
onTap: () => _openFileExplorer(context, repoPath!),
175+
padding: const EdgeInsets.all(6),
176+
child: Icon(Icons.folder_open_outlined, size: 16, color: b.muted),
177+
),
178+
const SizedBox(width: 4),
179+
],
180+
if (onOpenTerminal != null) ...[
181+
_HoverBox(
182+
tooltip: translate('bs_open_terminal'),
183+
onTap: onOpenTerminal,
184+
padding: const EdgeInsets.all(6),
185+
child: Icon(Icons.terminal, size: 16, color: b.muted),
186+
),
187+
const SizedBox(width: 4),
188+
],
189+
if (repoPath != null || onOpenTerminal != null)
190+
Container(
191+
width: 1,
192+
height: 18,
193+
margin: const EdgeInsets.symmetric(horizontal: 8),
194+
color: b.line,
195+
),
153196
AutoPullButton(
154197
watcher: controller.watcher,
155198
isBusy: controller.isPulling,

0 commit comments

Comments
 (0)