refactor(desktop): reorganize workspace panels and navigation
Gitea CI / Windows x64 and Android (pull_request) Successful in 16m21s
Gitea CI / Gitea CI passed (pull_request) Successful in 3s

This commit is contained in:
lingjhf committed 2026-10-06 12:11:59 +08:00
1 parent 826745b407
commit 1f73765745
92 files changed
+5811 -2650

No files matched your search

@@ -0,0 +1,53 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
enum DesktopContent { workspace, library, settings }
typedef DesktopContentSelection = ({
DesktopContent surface,
int settingsTab,
int settingsRequest,
(String, String)? workspace,
bool settingsVisited,
bool resourcesSelected,
});
final desktopContentProvider =
NotifierProvider<DesktopContentController, DesktopContentSelection>(
DesktopContentController.new,
);
/// Navigation changes visibility without disposing any visited content.
class DesktopContentController extends Notifier<DesktopContentSelection> {
@override
DesktopContentSelection build() => (
surface: DesktopContent.workspace,
settingsTab: 0,
settingsRequest: 0,
workspace: null,
settingsVisited: false,
resourcesSelected: false,
);
void select(DesktopContent surface) {
state = (
surface: surface,
settingsTab: state.settingsTab,
settingsRequest: state.settingsRequest,
workspace: state.workspace,
settingsVisited:
state.settingsVisited || surface == DesktopContent.settings,
resourcesSelected: surface == DesktopContent.library,
);
}
void showSettings({int? tab, (String, String)? workspace}) {
state = (
surface: DesktopContent.settings,
settingsTab: tab ?? state.settingsTab,
settingsRequest: state.settingsRequest + (tab == null ? 0 : 1),
workspace: workspace ?? state.workspace,
settingsVisited: true,
resourcesSelected: state.resourcesSelected,
);
}
}
@@ -3,14 +3,19 @@ import 'package:flutter/foundation.dart';
/// Desktop split preferences outlive the desktop shell when a window narrows.
class DesktopWorkspaceController extends ChangeNotifier {
double? _agentWidth;
bool _editorCollapsedByAgent = false;
bool _agentFullscreen = false;
double? get agentWidth => _agentWidth;
bool get editorCollapsedByAgent => _editorCollapsedByAgent;
bool get agentFullscreen => _agentFullscreen;
void setSplit(double? width, {required bool editorCollapsed}) {
void setAgentWidth(double width) {
_agentWidth = width;
_editorCollapsedByAgent = editorCollapsed;
notifyListeners();
}
void setAgentFullscreen(bool value) {
if (_agentFullscreen == value) return;
_agentFullscreen = value;
notifyListeners();
}
}
@@ -23,8 +23,7 @@ final class DesktopWorkspaceGeometry {
required this.editorHidden,
});
static const editorCollapseWidth = 480.0;
static const editorCollapseDragBuffer = editorCollapseWidth / 3;
static const editorMinimumWidth = 480.0;
static const editorRestoreWidth = 560.0;
final double sidebarWidth;
@@ -42,7 +41,7 @@ final class DesktopWorkspaceGeometry {
required bool sidebarCollapsed,
double? sidebarWidth,
double? agentWidth,
bool editorCollapsedByAgent = false,
bool agentFullscreen = false,
}) {
final navigationWidth =
(sidebarWidth ?? WorkspaceLayoutMetrics.sidebarDefaultWidth)
@@ -57,19 +56,17 @@ final class DesktopWorkspaceGeometry {
.clamp(220.0, math.max(220.0, width - navigationSpace - 1))
.toDouble()
: 0.0;
final remaining = width - navigationSpace - requestedAgentWidth - 1;
final hidden =
mode == WorkspaceMode.agent &&
(width - navigationSpace - 1 < 220 + editorCollapseWidth ||
(editorCollapsedByAgent && remaining < editorRestoreWidth) ||
remaining <= editorCollapseWidth - editorCollapseDragBuffer);
(width - navigationSpace - 1 < 220 + editorMinimumWidth ||
agentFullscreen);
return DesktopWorkspaceGeometry(
sidebarWidth: navigationWidth,
agentWidth: hidden
? width - navigationSpace
: mode == WorkspaceMode.agent
? requestedAgentWidth
.clamp(220.0, width - navigationSpace - editorCollapseWidth - 1)
.clamp(220.0, width - navigationSpace - editorMinimumWidth - 1)
.toDouble()
: 0,
editorHidden: hidden,