Skip to content

Commit 193073d

Browse files
committed
תיקון issue #2543 — היקף חיפוש "ספרים פתוחים"
בתפריט היקף החיפוש בספרייה לא הייתה דרך לחפש רק בספרים שפתוחים בכרטיסיות. זו לא רגרסיה: האפשרות לא הייתה קיימת מעולם (git log -S "ספרים פתוחים" / "openBooks" ב-lib/search לא מוצא מימוש קודם). - openSearchableBooks אוסף מה-TabsBloc של החלון הנוכחי את הספרים בכל חלונית (leafPanes, כולל טאב מפוצל), רק ספרים שנכנסים לאינדקס: PDF רק כשאינדוקס PDF פעיל, ספר אישי רק כשספרים אישיים באינדקס. - הזהות היא זו של האינדקס (BookIdentity.indexedFilePath): PDF מקומי עשוי לשאול את ה-id של ספר הטקסט המקביל, ובאינדקס הוא מסמך נפרד. כך טקסט ו-PDF שפתוחים יחד נבחרים שניהם, וטקסט פתוח לבדו אינו בוחר את ה-PDF. - בתפריט, אחרי "ספרי יסוד", שורה "ספרים פתוחים" שבוחרת את ה-facets של הספרים האלה מהעץ הגלוי ושומרת את הממדים (תקופה/מחבר). הבחירה היא תמונת מצב ברגע הלחיצה, ואפשר לשמור אותה כהיקף שמור. - השורה בלי כותרת משנה, עם צבע הסמל של "כל הספרים"/"ספרי יסוד" (הערת Nathaniel-260); ההסבר על תמונת המצב ב-tooltip. - בלי ספרים פתוחים השורה מושבתת עם tooltip "אין ספרים פתוחים". כשאף ספר פתוח אינו בעץ הנחיפש הבחירה לא משתנה (בחירה ריקה הייתה חיפוש בכל הספרייה) ומוצגת הודעה. - הרשימה עוברת לתפריט כפונקציה ונקראת רק כשהתפריט פתוח, כך שדיאלוג החיפוש אינו קורא את TabsBloc בכל בנייה. - החיפוש החכם אינו מעביר openBooks ולכן השורה לא מוצגת בו.
1 parent a6a9651 commit 193073d

6 files changed

Lines changed: 134 additions & 13 deletions

File tree

‎lib/core/messages/library_messages.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ abstract class LibraryMessages {
4040
// ===== חיפוש =====
4141
static String savedScopeDeleted(String name) => 'ההיקף "$name" נמחק';
4242

43+
static const String openBooksNotSearchable =
44+
'אף אחד מהספרים הפתוחים אינו בספרייה שבה מחפשים';
45+
4346
static String distanceSetAsDefault(int distance) =>
4447
'מרווח $distance נקבע כברירת מחדל לחיפוש רגיל';
4548

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:otzaria/data/book_identity.dart';
2+
import 'package:otzaria/indexing/repository/indexing_repository.dart';
3+
import 'package:otzaria/models/books.dart';
4+
import 'package:otzaria/tabs/models/combined_tab.dart';
5+
import 'package:otzaria/tabs/models/pdf_tab.dart';
6+
import 'package:otzaria/tabs/models/tab.dart';
7+
import 'package:otzaria/tabs/models/text_tab.dart';
8+
9+
/// הספרים הפתוחים ב-[tabs] (כל חלונית, גם בטאב מפוצל) שנכנסים לאינדקס
10+
/// החיפוש, בסדר הכרטיסיות ובלי כפילויות לפי זהות מסמך החיפוש — PDF
11+
/// ששואל את ה-id של ספר הטקסט הוא מסמך נפרד ונשמר לצדו.
12+
List<Book> openSearchableBooks(
13+
Iterable<OpenedTab> tabs, {
14+
required bool includePdfBooks,
15+
required bool includeUserBooks,
16+
}) {
17+
final seen = <String>{};
18+
final books = <Book>[];
19+
for (final pane in tabs.expand(leafPanes)) {
20+
final Book book;
21+
if (pane is TextBookTab) {
22+
book = pane.book;
23+
} else if (pane is PdfBookTab && includePdfBooks) {
24+
book = pane.book;
25+
} else {
26+
continue;
27+
}
28+
if (!IndexingRepository.isIndexableBook(book)) continue;
29+
if (!includeUserBooks && book.source.isUser) continue;
30+
if (seen.add(BookIdentity.indexedFilePath(book))) books.add(book);
31+
}
32+
return books;
33+
}

‎lib/search/view/search_dialog.dart‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'package:otzaria/history/bloc/history_event.dart';
2323
import 'package:otzaria/history/bloc/history_state.dart';
2424
import 'package:otzaria/search/search_scope_preferences.dart';
2525
import 'package:otzaria/search/view/search_history_menu.dart';
26+
import 'package:otzaria/search/utils/open_search_books.dart';
2627
import 'package:otzaria/search/view/search_scope_menu.dart';
2728
import 'package:otzaria/indexing/bloc/indexing_bloc.dart';
2829
import 'package:otzaria/indexing/bloc/indexing_event.dart';
@@ -48,6 +49,7 @@ import 'package:otzaria/library/models/library.dart';
4849
import 'package:otzaria/search/view/enhanced_search_field.dart';
4950
import 'package:otzaria/search/view/advanced_search_controls.dart';
5051
import 'package:otzaria/indexing/models/index_update_mode.dart';
52+
import 'package:otzaria/indexing/models/pdf_index_setting.dart';
5153
import 'package:otzaria/search/view/full_text_settings_widgets.dart';
5254
import 'package:otzaria/settings/l10n/settings_l10n_exports.dart';
5355
import 'package:otzaria/tabs/bloc/tabs_bloc.dart';
@@ -1789,14 +1791,7 @@ class _SearchDialogState extends State<SearchDialog> {
17891791
);
17901792

17911793
// תפריט הסינון המאוחד רלוונטי רק לחיפוש בספרייה (לא בחיפוש בתוך ספר).
1792-
final scopeButton = widget.bookTitle == null
1793-
? SearchScopeMenuButton(
1794-
selected: _scopeSelection,
1795-
onChanged: _onScopeChanged,
1796-
excludeUserBooks:
1797-
!IndexUpdateMode.readStored().indexesPersonalBooks,
1798-
)
1799-
: null;
1794+
final scopeButton = widget.bookTitle == null ? _buildScopeButton() : null;
18001795

18011796
return Column(
18021797
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -1816,6 +1811,20 @@ class _SearchDialogState extends State<SearchDialog> {
18161811
);
18171812
}
18181813

1814+
Widget _buildScopeButton() {
1815+
final includeUserBooks = IndexUpdateMode.readStored().indexesPersonalBooks;
1816+
return SearchScopeMenuButton(
1817+
selected: _scopeSelection,
1818+
onChanged: _onScopeChanged,
1819+
excludeUserBooks: !includeUserBooks,
1820+
openBooks: () => openSearchableBooks(
1821+
context.read<TabsBloc?>()?.state.tabs ?? const [],
1822+
includePdfBooks: readIndexPdfBooksSetting(),
1823+
includeUserBooks: includeUserBooks,
1824+
),
1825+
);
1826+
}
1827+
18191828
/// שדה "ללא" — סינון תוצאות שמכילות מילים מסוימות (מצב מתקדם בלבד).
18201829
Widget _buildNegativeSection() {
18211830
return Column(

‎lib/search/view/search_scope_menu.dart‎

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:fluentui_system_icons/fluentui_system_icons.dart';
1212
import 'package:otzaria_icons/otzaria_icons.dart';
1313
import 'package:flutter_bloc/flutter_bloc.dart';
1414
import 'package:otzaria/widgets/text/otzaria_search_field.dart';
15+
import 'package:otzaria/data/book_identity.dart';
1516
import 'package:otzaria/data/cache/acronyms_cache.dart';
1617
import 'package:otzaria/data/data_providers/sqlite_data_provider.dart';
1718
import 'package:otzaria/indexing/utils/book_facet_metadata_cache.dart';
@@ -56,13 +57,18 @@ class SearchScopeMenuButton extends StatefulWidget {
5657
/// מסתיר ספרים אישיים כשאינם באינדקס ("בלי ספרים אישיים").
5758
final bool excludeUserBooks;
5859

60+
/// הספרים הפתוחים בחלון, להיקף "ספרים פתוחים"; null — בלי ההיקף.
61+
/// נקרא רק כשהתפריט פתוח, כדי שהבחירה תשקף את הכרטיסיות של אותו רגע.
62+
final List<Book> Function()? openBooks;
63+
5964
const SearchScopeMenuButton({
6065
super.key,
6166
required this.selected,
6267
required this.onChanged,
6368
this.officialBooksOnly = false,
6469
this.coveredFilePaths,
6570
this.excludeUserBooks = false,
71+
this.openBooks,
6672
});
6773

6874
@override
@@ -275,6 +281,30 @@ class _SearchScopeMenuButtonState extends State<SearchScopeMenuButton> {
275281
);
276282
}
277283

284+
/// בחירת הספרים הפתוחים כעת שבעץ הגלוי (רק הם ברי חיפוש). בחירה ריקה
285+
/// הייתה חיפוש בכל הספרייה, ולכן אז הבחירה אינה משתנה.
286+
Future<void> _selectOpenBooks() async {
287+
final tree = await _ensureTree();
288+
if (tree == null || !mounted) return;
289+
final keys = {
290+
for (final book in widget.openBooks?.call() ?? const <Book>[])
291+
BookIdentity.indexedFilePath(book),
292+
};
293+
final facets = {
294+
for (final node in tree.allBookNodes())
295+
if (keys.contains(BookIdentity.indexedFilePath(node.book))) node.facet,
296+
};
297+
if (facets.isEmpty) {
298+
UiSnack.show(LibraryMessages.openBooksNotSearchable);
299+
return;
300+
}
301+
widget.onChanged({
302+
...facets,
303+
...FacetHelper.dimensionFacetsOf(widget.selected),
304+
});
305+
_fieldFocus.requestFocus();
306+
}
307+
278308
Future<void> _loadBaseBookIds() async {
279309
// מהמטמון שנקרא ב-isolate: סריקת טבלת book על חיבור ה-UI חוסמת בדיסק איטי.
280310
final cache = BookFacetMetadataCache.instance;
@@ -570,6 +600,8 @@ class _SearchScopeMenuButtonState extends State<SearchScopeMenuButton> {
570600
onSaveCurrent: () => unawaited(_saveCurrentScope()),
571601
onUpdateSaved: (name) => unawaited(_updateSavedScope(name)),
572602
onDeleteSaved: (name) => unawaited(_deleteSavedScope(name)),
603+
openBooksCount: widget.openBooks?.call().length,
604+
onSelectOpenBooks: () => unawaited(_selectOpenBooks()),
573605
),
574606
),
575607
),
@@ -656,6 +688,12 @@ class _MenuItem {
656688
final VoidCallback? onDelete;
657689
final bool isHeader;
658690

691+
/// הסבר בריחוף; בשורה מושבתת — הסיבה.
692+
final String? tooltip;
693+
694+
/// שורה מושבתת אינה מגיבה ללחיצה.
695+
final bool enabled;
696+
659697
bool get isDrill => onDrill != null;
660698

661699
const _MenuItem({
@@ -670,6 +708,8 @@ class _MenuItem {
670708
this.onOnly,
671709
this.onUpdate,
672710
this.onDelete,
711+
this.tooltip,
712+
this.enabled = true,
673713
}) : isHeader = false;
674714

675715
const _MenuItem.header(this.label)
@@ -683,6 +723,8 @@ class _MenuItem {
683723
onOnly = null,
684724
onUpdate = null,
685725
onDelete = null,
726+
tooltip = null,
727+
enabled = true,
686728
isHeader = true;
687729
}
688730

@@ -700,6 +742,10 @@ class _ScopeMenuPanel extends StatefulWidget {
700742
final ValueChanged<String> onUpdateSaved;
701743
final ValueChanged<String> onDeleteSaved;
702744

745+
/// null — אין בתפריט היקף "ספרים פתוחים"; 0 — השורה מושבתת.
746+
final int? openBooksCount;
747+
final VoidCallback onSelectOpenBooks;
748+
703749
const _ScopeMenuPanel({
704750
super.key,
705751
required this.tree,
@@ -714,6 +760,8 @@ class _ScopeMenuPanel extends StatefulWidget {
714760
required this.onSaveCurrent,
715761
required this.onUpdateSaved,
716762
required this.onDeleteSaved,
763+
required this.openBooksCount,
764+
required this.onSelectOpenBooks,
717765
});
718766

719767
@override
@@ -1115,6 +1163,8 @@ class _ScopeMenuPanelState extends State<_ScopeMenuPanel> {
11151163
final hasAllCategories = categoryPart.contains('/');
11161164
final hasPartialCategories = categoryPart.isNotEmpty && !hasAllCategories;
11171165
final baseSelected = _selection.contains(FacetHelper.baseDimensionFacet);
1166+
final openBooksCount = widget.openBooksCount;
1167+
final hasOpenBooks = (openBooksCount ?? 0) > 0;
11181168

11191169
return [
11201170
if (!isEverything)
@@ -1139,6 +1189,19 @@ class _ScopeMenuPanelState extends State<_ScopeMenuPanel> {
11391189
onToggle: (v) => _toggleDimension(FacetHelper.baseDimensionFacet, v),
11401190
onDrill: () => _enterView(_View.base),
11411191
),
1192+
if (openBooksCount != null)
1193+
_MenuItem(
1194+
label: context.settingsText('ספרים פתוחים'),
1195+
icon: OtzariaIcons.book_open_medium_24_regular,
1196+
check: null,
1197+
onTap: widget.onSelectOpenBooks,
1198+
enabled: hasOpenBooks,
1199+
tooltip: context.settingsText(
1200+
hasOpenBooks
1201+
? 'הבחירה נלקחת מהספרים הפתוחים ברגע הלחיצה'
1202+
: 'אין ספרים פתוחים',
1203+
),
1204+
),
11421205
const _MenuItem.header('תקופה'),
11431206
for (final era in _eraNames)
11441207
_MenuItem(
@@ -1375,8 +1438,13 @@ class _ScopeMenuPanelState extends State<_ScopeMenuPanel> {
13751438
final isFolder =
13761439
item.icon == FluentIcons.folder_24_regular ||
13771440
item.icon == FluentIcons.library_24_regular ||
1378-
item.icon == OtzariaIcons.book_star_24_regular;
1379-
final iconColor = isFolder
1441+
item.icon == OtzariaIcons.book_star_24_regular ||
1442+
item.icon == OtzariaIcons.book_open_medium_24_regular;
1443+
final disabled = !item.enabled;
1444+
final disabledColor = Theme.of(context).disabledColor;
1445+
final iconColor = disabled
1446+
? disabledColor
1447+
: isFolder
13801448
? colorScheme.primary
13811449
: colorScheme.onSurfaceVariant;
13821450

@@ -1392,9 +1460,9 @@ class _ScopeMenuPanelState extends State<_ScopeMenuPanel> {
13921460

13931461
// במגע אין hover — "רק" מוצג תמיד; בעכבר הוא נחשף בריחוף או בניווט מקלדת.
13941462

1395-
return InkWell(
1463+
final row = InkWell(
13961464
canRequestFocus: false,
1397-
onTap: onRowTap,
1465+
onTap: disabled ? null : onRowTap,
13981466
onHover: (hovering) {
13991467
if (hovering) {
14001468
_hoveredRow.value = index;
@@ -1450,7 +1518,7 @@ class _ScopeMenuPanelState extends State<_ScopeMenuPanel> {
14501518
item.label,
14511519
style: TextStyle(
14521520
fontSize: 14,
1453-
color: colorScheme.onSurface,
1521+
color: disabled ? disabledColor : colorScheme.onSurface,
14541522
),
14551523
maxLines: 1,
14561524
overflow: TextOverflow.ellipsis,
@@ -1524,5 +1592,7 @@ class _ScopeMenuPanelState extends State<_ScopeMenuPanel> {
15241592
),
15251593
),
15261594
);
1595+
final tooltip = item.tooltip;
1596+
return tooltip == null ? row : Tooltip(message: tooltip, child: row);
15271597
}
15281598
}

‎lib/settings/l10n/settings_catalogs.g.dart‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/settings/l10n/settings_en.arb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,9 @@
11811181
"סינון לפי ספר או מחבר": "Filter by book or author",
11821182
"היקפים שמורים": "Saved scopes",
11831183
"שמור את הבחירה הנוכחית…": "Save current selection…",
1184+
"ספרים פתוחים": "Open books",
1185+
"הבחירה נלקחת מהספרים הפתוחים ברגע הלחיצה": "The selection is taken from the open books at the moment you click",
1186+
"אין ספרים פתוחים": "No open books",
11841187
"שמירת היקף החיפוש": "Save search scope",
11851188
"הבחירה הנוכחית תישמר ותוכל לחזור אליה בלחיצה אחת": "The current selection is saved so you can return to it in one click",
11861189
"שם ההיקף": "Scope name",

0 commit comments

Comments
 (0)