Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
53 lines
1.7 KiB
Dart
53 lines
1.7 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../shared/widgets/presentation_list.dart';
|
|
import '../../workspace/project_state.dart';
|
|
import '../../workspace/projects.dart';
|
|
|
|
final projectTabsProvider =
|
|
NotifierProvider<ProjectTabsController, List<RecentProject>>(
|
|
ProjectTabsController.new,
|
|
);
|
|
|
|
/// Open tabs are separate from the recent-project history.
|
|
class ProjectTabsController extends Notifier<List<RecentProject>> {
|
|
@override
|
|
List<RecentProject> build() {
|
|
ref.listen(
|
|
projectsProvider.select(
|
|
(value) => (
|
|
value.value?.activeProject,
|
|
PresentationList(value.value?.recent ?? const <RecentProject>[]),
|
|
),
|
|
),
|
|
(_, next) {
|
|
final (active, recent) = next;
|
|
final metadata = {for (final project in recent) project.id: project};
|
|
if (active != null) metadata[active.id] = active;
|
|
final updated = [
|
|
for (final project in state) metadata[project.id] ?? project,
|
|
if (active != null && !state.any((tab) => tab.id == active.id))
|
|
active,
|
|
];
|
|
if (!listEquals(state, updated)) state = List.unmodifiable(updated);
|
|
},
|
|
);
|
|
final active = ref.read(projectsProvider).value?.activeProject;
|
|
return List.unmodifiable([?active]);
|
|
}
|
|
|
|
void remove(String id) => state = List.unmodifiable([
|
|
for (final tab in state)
|
|
if (tab.id != id) tab,
|
|
]);
|
|
|
|
void updateProject(RecentProject project) {
|
|
final updated = [
|
|
for (final tab in state)
|
|
if (tab.id == project.id) project else tab,
|
|
];
|
|
if (!listEquals(state, updated)) state = List.unmodifiable(updated);
|
|
}
|
|
}
|