feat: the files panel uses the server's gitignored setting
- OpenChamber keeps filesViewShowGitignored in its profile settings (the web UI's "Display gitignored files"); the client now reads it in refreshChatSettings instead of starting from a local false, so a server that shows ignored files shows them here too - toggling "Show git-ignored files" writes the same key back through PUT /api/config/settings (surface=mobile) and reloads the listing; a failed save restores the previous value and reports the error - while the panel is open, a change to the setting from another client reloads the list with the new filter - version 0.6.3+603; tests cover reading, writing and rollback
This commit is contained in:
1 parent
8ac36b1fb1
commit
ba3c820186
6 files changed
+154
-9
No files matched your search
@@ -80,8 +80,9 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
String? _error;
|
||||
String _query = '';
|
||||
|
||||
/// A project listing hides what git ignores; the menu can show it.
|
||||
bool _showIgnored = false;
|
||||
/// The last gitignore choice seen; the app's server-backed setting can
|
||||
/// change while the panel is open (the switch writes it, a reload reads it).
|
||||
bool _lastShowIgnored = false;
|
||||
|
||||
List<FsEntry> _deepResults = [];
|
||||
bool _deepDone = false;
|
||||
@@ -112,17 +113,29 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_lastShowIgnored = widget.app.showGitignored;
|
||||
widget.app.addListener(_onApp);
|
||||
_path = _root;
|
||||
if (_root.isNotEmpty) _load();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.app.removeListener(_onApp);
|
||||
_editor.dispose();
|
||||
_search.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// The gitignore setting is shared with the web UI; when it changes (here
|
||||
/// or on another client), reload the listing with the new filter.
|
||||
void _onApp() {
|
||||
if (!mounted || widget.app.showGitignored == _lastShowIgnored) return;
|
||||
_lastShowIgnored = widget.app.showGitignored;
|
||||
setState(() {});
|
||||
if (_previewPath == null) _load();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- files
|
||||
|
||||
Future<void> _load([String? path]) async {
|
||||
@@ -138,8 +151,8 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
_deepDone = false;
|
||||
});
|
||||
try {
|
||||
final list = await client
|
||||
.fsList(target, directory: _root, respectGitignore: !_showIgnored)
|
||||
final list = await client.fsList(target,
|
||||
directory: _root, respectGitignore: !widget.app.showGitignored)
|
||||
..removeWhere((e) => e.name == '.git');
|
||||
list.sort((a, b) {
|
||||
if (a.isDirectory != b.isDirectory) return a.isDirectory ? -1 : 1;
|
||||
@@ -626,8 +639,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
tooltip: tr('More'),
|
||||
onSelected: (value) {
|
||||
if (value == 'ignored') {
|
||||
setState(() => _showIgnored = !_showIgnored);
|
||||
_load();
|
||||
widget.app.setShowGitignored(!widget.app.showGitignored);
|
||||
} else if (value == 'refresh') {
|
||||
_load();
|
||||
}
|
||||
@@ -635,7 +647,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
||||
itemBuilder: (_) => [
|
||||
CheckedPopupMenuItem(
|
||||
value: 'ignored',
|
||||
checked: _showIgnored,
|
||||
checked: widget.app.showGitignored,
|
||||
child: const AppText('Show git-ignored files'),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
|
||||
@@ -109,6 +109,11 @@ class AppState extends ChangeNotifier {
|
||||
/// `allowPromptingSubagentSessions`).
|
||||
bool allowPromptingSubagentSessions = false;
|
||||
|
||||
/// Server setting (`filesViewShowGitignored`): the files panel also lists
|
||||
/// files git ignores. Shared with the web UI's profile settings; off when
|
||||
/// the server has never written it.
|
||||
bool showGitignored = false;
|
||||
|
||||
/// OpenChamber's own agent tools — the web client's 通用 page: what the
|
||||
/// agent may do inside a chat, and what it may know about the person and the
|
||||
/// project. Server-backed (`/api/config/settings`), shared with the web UI;
|
||||
@@ -203,6 +208,7 @@ class AppState extends ChangeNotifier {
|
||||
followUpBehavior = normalizeFollowUp(settings['followUpBehavior']);
|
||||
allowPromptingSubagentSessions =
|
||||
settings['allowPromptingSubagentSessions'] == true;
|
||||
showGitignored = settings['filesViewShowGitignored'] == true;
|
||||
_applyToolSettings(settings);
|
||||
notifyListeners();
|
||||
} catch (_) {}
|
||||
@@ -264,6 +270,33 @@ class AppState extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows or hides gitignored files in the files panel and writes the same
|
||||
/// server setting the web UI keeps (`filesViewShowGitignored`). The switch
|
||||
/// moves at once; a failed save puts the previous value back.
|
||||
Future<bool> setShowGitignored(bool value) async {
|
||||
final before = showGitignored;
|
||||
if (value == before) return true;
|
||||
showGitignored = value;
|
||||
notifyListeners();
|
||||
final cl = client;
|
||||
if (cl == null) return true;
|
||||
try {
|
||||
final settings =
|
||||
await cl.saveSettings({'filesViewShowGitignored': value});
|
||||
if (client != cl) return true;
|
||||
showGitignored = settings['filesViewShowGitignored'] as bool? ?? value;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (client == cl) {
|
||||
showGitignored = before;
|
||||
_lastError = trArgs('Couldn\'t save: {0}', [e]);
|
||||
notifyListeners();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
connections = await storage.connections();
|
||||
if (connections.isNotEmpty) {
|
||||
|
||||
Reference in new issue
Block a user