Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/settings/l10n/settings_catalogs.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/settings/l10n/settings_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@
"הוספת הערה": "Add a Note",
"דווח על טעות בספר": "Report an Error in the Book",
"פועל כשיש טקסט מסומן או קטע נבחר": "Works when text is selected or a section is chosen",
"רענון ספר אישי": "Refresh Personal Book",
"טוען מחדש ספר אישי פתוח אחרי שינוי בקובץ שלו": "Reloads an open personal book after its file was changed",
"סגור ספר נוכחי": "Close the Current Tab",
"סגור כל הספרים": "Close all Tabs",
"פתח כרטיסייה אחרונה שנסגרה": "Reopen the Last Closed Tab",
Expand Down
25 changes: 23 additions & 2 deletions lib/settings/services/custom_folders/bloc/custom_folders_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:async';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart' show debugPrint;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:path/path.dart' as p;
import 'package:otzaria/settings/engine/app_settings_store.dart';
import 'package:otzaria/core/messages/settings_messages.dart';
import 'package:otzaria/data/cache/generation_cache.dart';
Expand Down Expand Up @@ -331,6 +332,9 @@ class CustomFoldersBloc extends Bloc<CustomFoldersEvent, CustomFoldersState> {
Emitter<CustomFoldersState> emit,
) async {
final currentFolders = _loadFolders();
final onlyFolderPath =
event.onlyFolderPath ??
_folderContaining(currentFolders, event.folderOfFile);
emit(
state.copyWith(
folders: currentFolders,
Expand All @@ -347,7 +351,7 @@ class CustomFoldersBloc extends Bloc<CustomFoldersEvent, CustomFoldersState> {
? const FileSyncResult()
: await _syncCustomFolders(
currentFolders,
onlyFolderPath: event.onlyFolderPath,
onlyFolderPath: onlyFolderPath,
);
final hasChanges = result.addedBooks > 0 || result.updatedBooks > 0;
final hasErrors = result.errors.isNotEmpty;
Expand All @@ -367,7 +371,7 @@ class CustomFoldersBloc extends Bloc<CustomFoldersEvent, CustomFoldersState> {
},
// כשל חלקי לא מסומן כהשלמה — סנכרון הרקע יקבל הזדמנות לנסות שוב.
coversAllFolders:
!skipSync && event.onlyFolderPath == null && result.errors.isEmpty,
!skipSync && onlyFolderPath == null && result.errors.isEmpty,
requestIds: event.requestId == null ? const {} : {event.requestId!},
);
emit(
Expand Down Expand Up @@ -603,6 +607,23 @@ class CustomFoldersBloc extends Bloc<CustomFoldersEvent, CustomFoldersState> {
return 'שגיאות בייבוא הקבצים:\n${SettingsMessages.errorLines(imp.errors)}';
}

static String? _folderContaining(List<CustomFolder> folders, String? file) {
if (file == null) return null;
final normalizedFile = CustomFolderSource.normalizePath(file);
final matches = folders
.map((folder) => folder.path)
.where(
(folder) => p.isWithin(
CustomFolderSource.normalizePath(folder),
normalizedFile,
),
)
.take(2)
.toList();
// תיקיות מקוננות יכולות לייצר רשומות שונות לאותו קובץ.
return matches.length == 1 ? matches.single : null;
}

List<CustomFolder> _loadFolders() {
final override = _loadFoldersOverride;
if (override != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class RescanCustomFolders extends CustomFoldersEvent {
const RescanCustomFolders({
this.showNoChangesMessage = true,
this.onlyFolderPath,
this.folderOfFile,
this.requestId,
});
final bool showNoChangesMessage;
Expand All @@ -71,14 +72,23 @@ class RescanCustomFolders extends CustomFoldersEvent {
/// ממילא לא השתנו.
final String? onlyFolderPath;

/// כמו [onlyFolderPath], לתיקייה שמכילה את הקובץ (רענון ספר פתוח).
/// אם אין תיקייה יחידה שמכילה את הקובץ, נסרקות כל התיקיות.
final String? folderOfFile;

/// מזהה בקשה שידווח ב-[CustomFoldersState.completedScan] בסיום הסריקה,
/// בהצלחה או בכישלון. קיים כדי שקורא שאינו UI (כרגע
/// `library.refreshUserBooks` של תוסף) יוכל לחכות לתוצאה של הסריקה שהוא
/// עצמו ביקש. `null` = סריקה מהממשק, שתוצאתה מוצגת ב-message/error בלבד.
final int? requestId;

@override
List<Object?> get props => [showNoChangesMessage, onlyFolderPath, requestId];
List<Object?> get props => [
showNoChangesMessage,
onlyFolderPath,
folderOfFile,
requestId,
];
}

/// ייבוא ידני של קבצי דורות/קישורים שהמשתמש בחר (לצמיתות, בדריסה מצטברת).
Expand Down
9 changes: 9 additions & 0 deletions lib/settings/tabs/shortcuts_settings_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,15 @@ class _ShortcutsSettingsTabState extends State<ShortcutsSettingsTab> {
icon: FluentIcons.error_circle_24_regular,
allShortcuts: _shortcutsList,
),
_ShortcutTile(
settingKey: ShortcutValidator.refreshBookKey,
label: context.settingsText('רענון ספר אישי'),
subtitle: context.settingsText(
'טוען מחדש ספר אישי פתוח אחרי שינוי בקובץ שלו',
),
icon: FluentIcons.arrow_sync_24_regular,
allShortcuts: _shortcutsList,
),
_ShortcutTile(
settingKey: 'key-shortcut-close-tab',
label: context.settingsText('סגור ספר נוכחי'),
Expand Down
12 changes: 12 additions & 0 deletions lib/shortcuts/shortcut_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class ShortcutValidator {
/// דיווח על טעות בספר — פועל רק כשיש בחירה בטקסט או קטע נבחר.
static const String reportErrorKey = 'key-shortcut-report-error';

/// רענון ספר אישי פתוח — סורק מחדש את תיקיית הקובץ שלו.
static const String refreshBookKey = 'key-shortcut-refresh-book';

/// דפדוף בין עמודי תיקון קוראים.
static const String tikkunPrevPageKey = 'key-shortcut-tikkun-prev-page';
static const String tikkunNextPageKey = 'key-shortcut-tikkun-next-page';
Expand Down Expand Up @@ -263,6 +266,7 @@ class ShortcutValidator {
'key-shortcut-next-toc',
...readerShortcutKeys,
reportErrorKey,
refreshBookKey,
// פתיחת כלים — אופציונלי, ללא ברירת מחדל (ראה openToolShortcutKeys).
'key-shortcut-open-tool-calendar',
'key-shortcut-open-tool-shamor-zachor',
Expand Down Expand Up @@ -347,6 +351,7 @@ class ShortcutValidator {
nextTocReaderKey: 'ctrl+arrowleft',
prevTocReaderKey: 'ctrl+arrowright',
reportErrorKey: 'ctrl+shift+r',
refreshBookKey: 'f5',
'key-shortcut-open-tool-calendar': '',
'key-shortcut-open-tool-shamor-zachor': '',
'key-shortcut-open-tool-measurements': '',
Expand Down Expand Up @@ -421,6 +426,7 @@ class ShortcutValidator {
nextTocReaderKey: 'הדף/פרק הבא (באזור הקריאה)',
prevTocReaderKey: 'הדף/פרק הקודם (באזור הקריאה)',
reportErrorKey: 'דווח על טעות בספר',
refreshBookKey: 'רענון ספר אישי',
'key-shortcut-open-tool-calendar': 'פתיחת לוח שנה',
'key-shortcut-open-tool-shamor-zachor': 'פתיחת שמור וזכור',
'key-shortcut-open-tool-measurements': 'פתיחת מדות ושיעורים',
Expand Down Expand Up @@ -524,6 +530,12 @@ class ShortcutValidator {
if (normalizedDefaultKey.isEmpty) return false;
for (final key in shortcutKeys) {
if (key == settingKey) continue;
// ברירת המחדל החדשה של הרענון מפנה מקום ל-F5 של תוסף קיים.
if (key == refreshBookKey &&
normalizedDefaultKey == _defaultShortcuts[refreshBookKey] &&
!Settings.containsKey(refreshBookKey)) {
continue;
}
if (_pluginShortcuts.containsKey(key)) {
final userValue = Settings.getValue<String>(key);
if (userValue != null &&
Expand Down
54 changes: 54 additions & 0 deletions lib/text_book/view/text_book_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ import 'package:otzaria/text_book/view/selection/plugin_selection_payload.dart';
import 'package:otzaria/core/messages/plugin_messages.dart';
import 'package:otzaria/tools/shamor_zachor/providers/shamor_zachor_data_provider.dart';
import 'package:otzaria/tools/shamor_zachor/providers/shamor_zachor_progress_provider.dart';
import 'package:otzaria/core/messages/settings_messages.dart';
import 'package:otzaria/settings/services/custom_folders/bloc/custom_folders_bloc.dart';
import 'package:otzaria/settings/services/per_book_settings_service.dart';
import 'package:otzaria/widgets/misc/app_menu_exports.dart';
import 'package:otzaria/widgets/misc/app_selection_area.dart';
Expand Down Expand Up @@ -2685,6 +2687,39 @@ Future<void> _setFontSize(
return savePerBookDisplaySettings(context, state, fontSize: size);
}

int _nextRescanRequestId = 0;

/// מחכה לסריקה של ההקשה הזו: סריקה אחרת שרצה במקביל מסתיימת בנפרד.
Future<void> _rescanPersonalBook(
CustomFoldersBloc bloc,
TextBook book,
AppWindowKeys window,
) async {
// שלילי: המזהים החיוביים של תוספים ושל בקשות האינדוקס מגיעים גם הם
// ל-RefreshLibrary.requestIds.
final requestId = --_nextRescanRequestId;
final done = bloc.stream.cast<CustomFoldersState?>().firstWhere(
(state) => state?.completedScan?.requestId == requestId,
orElse: () => null,
);
bloc.add(
RescanCustomFolders(folderOfFile: book.filePath, requestId: requestId),
);
final result = await done;
if (result == null || bloc.isClosed) return;
final scan = result.completedScan!;
if (!scan.isSuccess) {
UiSnack.showError(SettingsMessages.customFolderSyncFailed, window: window);
} else if (scan.errors.isNotEmpty) {
UiSnack.showError(
SettingsMessages.customFolderScanErrors(scan.errors),
window: window,
);
} else if (result.message != null) {
UiSnack.show(result.message!, window: window);
}
}

bool _handleGlobalKeyEvent(
KeyEvent event,
BuildContext context,
Expand Down Expand Up @@ -2726,6 +2761,9 @@ bool _handleGlobalKeyEvent(
final togglePdfShortcut =
ShortcutValidator.getShortcutValue(ShortcutValidator.togglePdfViewKey) ??
'';
final refreshBookShortcut =
ShortcutValidator.getShortcutValue(ShortcutValidator.refreshBookKey) ??
'';
final copyBookLinkShortcut =
ShortcutValidator.getShortcutValue(ShortcutValidator.copyBookLinkKey) ??
'';
Expand Down Expand Up @@ -2810,6 +2848,22 @@ bool _handleGlobalKeyEvent(
return true;
}

// רענון ספר אישי: הסריקה מעדכנת אותו, ו-_libraryReloadSub טוען את הטאב מחדש.
// משתמש שכבר הקצה F5 לפעולה אחרת שומר על הקיצור הקיים שלו.
if (refreshBookShortcut.isNotEmpty &&
state.book.isUserBook &&
ShortcutHelper.matchesShortcut(event, refreshBookShortcut) &&
!ShortcutValidator.hasConflict(ShortcutValidator.refreshBookKey)) {
unawaited(
_rescanPersonalBook(
context.read<CustomFoldersBloc>(),
state.book,
AppWindowKeys.of(context),
),
);
return true;
}

// מעבר ל-PDF
if (ShortcutHelper.matchesShortcut(event, togglePdfShortcut)) {
_togglePdfView(context, state, tab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:otzaria/core/messages/settings_messages.dart';
import 'package:otzaria/settings/engine/settings_repository.dart';
import 'package:otzaria/settings/services/custom_folders/bloc/custom_folders_bloc.dart';
import 'package:otzaria/settings/services/custom_folders/custom_folder.dart';
import 'package:path/path.dart' as p;

import '../../../test_helpers/memory_cache_provider.dart';

Expand Down Expand Up @@ -113,6 +114,37 @@ void main() {
},
);

test(
'RescanCustomFolders סורק את שני המקורות של ספר בתיקייה מקוננת',
() async {
final parent = _folder('parent');
final child = _folder(p.join(parent.path, 'child'));
final scopedPaths = <String?>[];
final bloc = CustomFoldersBloc(
addLibraryEvent: (_) {},
loadFolders: () => [parent, child],
syncFolders: (folders, {String? onlyFolderPath}) async {
scopedPaths.add(onlyFolderPath);
return const FileSyncResult();
},
);
addTearDown(bloc.close);

final done = bloc.stream.firstWhere(
(state) => state.completedScan != null,
);
bloc.add(
RescanCustomFolders(
folderOfFile: p.join(child.path, 'book.txt'),
requestId: 1,
),
);
await done;

expect(scopedPaths, [null]);
},
);

test('RescanCustomFolders מדווח שגיאות סנכרון בממשק', () async {
await _saveFolders([_folder('C:/private-books')]);
final bloc = CustomFoldersBloc(
Expand Down
26 changes: 26 additions & 0 deletions test/shortcuts/shortcut_validator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,32 @@ void main() {
},
);

test('קיצור F5 של תוסף קודם לברירת המחדל של הרענון', () async {
const withF5 = (
pluginId: pluginId,
shortcutId: 'refresh',
label: 'רענון מהתוסף',
defaultKey: 'f5',
command: 'refresh',
contextMenuItemId: null,
);
final pluginKey = ShortcutValidator.pluginShortcutKey(
pluginId,
'refresh',
);
const refreshKey = ShortcutValidator.refreshBookKey;
ShortcutValidator.registerPluginShortcuts({pluginKey: withF5});

expect(ShortcutValidator.getShortcutValue(pluginKey), 'f5');
expect(ShortcutValidator.hasConflict(refreshKey), isTrue);

await Settings.setValue<String>(refreshKey, 'f5');

expect(ShortcutValidator.getShortcutValue(pluginKey), isNull);
expect(ShortcutValidator.getShortcutValue(refreshKey), 'f5');
expect(ShortcutValidator.hasConflict(refreshKey), isFalse);
});

test('ברירת מחדל באותיות גדולות מתנגשת עם קיצור מובנה', () {
const conflicting = (
pluginId: pluginId,
Expand Down
Loading
Loading