Skip to content

Commit

Permalink
added bookmarks support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sivan22 committed Mar 25, 2024
1 parent 6ffd717 commit 69130d0
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 15 deletions.
70 changes: 70 additions & 0 deletions lib/bookmark_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import 'package:flutter/material.dart';
import 'tab_window.dart';

class BookmarkView extends StatefulWidget {
final List<Bookmark> bookmarks;
final void Function(TabWindow) addTabCallBack;
const BookmarkView(
{Key? key, required this.bookmarks, required this.addTabCallBack})
: super(key: key);

@override
State<BookmarkView> createState() => _BookmarkViewState();
}

class _BookmarkViewState extends State<BookmarkView> {
@override
Widget build(BuildContext context) {
return Column(
children: [
Expanded(
child: ListView.builder(
itemCount: widget.bookmarks.length,
itemBuilder: (context, index) => ListTile(
title: Text(widget.bookmarks[index].ref),
onTap: () {
widget.addTabCallBack(BookTabWindow(
widget.bookmarks[index].path,
widget.bookmarks[index].index));
},
trailing: IconButton(
icon: const Icon(Icons.delete_forever),
onPressed: () {
widget.bookmarks.removeAt(index);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('הסימניה נמחקה'),
),
);
setState(() {});
},
)),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () {
widget.bookmarks.clear();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('כל הסימניות נמחקו'),
),
);
setState(() {});
},
child: const Text('מחק את כל הסימניות'),
),
),
],
);
}
}

class Bookmark {
final String ref;
final String path;
final int index;

Bookmark({required this.ref, required this.path, required this.index});
}
39 changes: 38 additions & 1 deletion lib/main_window_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/services.dart';
import 'package:otzaria/bookmark_view.dart';
import 'package:otzaria/settings_screen.dart';
import 'dart:io';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -38,9 +39,12 @@ class MainWindowViewState extends State<MainWindowView>
length: tabs.length, vsync: this, initialIndex: max(0, tabs.length - 1));
final showBooksBrowser = ValueNotifier<bool>(false);
final showBookSearch = ValueNotifier<bool>(false);
final showBookmarksView = ValueNotifier<bool>(false);
final bookSearchfocusNode = FocusNode();
final FocusScopeNode mainFocusScopeNode = FocusScopeNode();
late Future<String?> libraryRootPath;
final List<Bookmark> bookmarks = [];

final Map<String, LogicalKeySet> shortcuts = {
'ctrl+a':
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyA),
Expand Down Expand Up @@ -248,6 +252,7 @@ class MainWindowViewState extends State<MainWindowView>
buildNavigationSideBar(),
buildBooksBrowser(),
buildBookSearchScreen(),
buildBookmarksView(),
buildTabBarAndTabView()
]),
));
Expand Down Expand Up @@ -291,6 +296,7 @@ class MainWindowViewState extends State<MainWindowView>
tab: tab,
openBookCallback: addTab,
data: tab.data,
bookmarks: bookmarks,
);
}
}
Expand Down Expand Up @@ -388,6 +394,23 @@ class MainWindowViewState extends State<MainWindowView>
);
}

AnimatedSize buildBookmarksView() {
return AnimatedSize(
duration: const Duration(milliseconds: 300),
child: ValueListenableBuilder(
valueListenable: showBookmarksView,
builder: (context, showBookmarksView, child) => SizedBox(
width: showBookmarksView ? 300 : 0,
height: showBookmarksView ? null : 0,
child: child!,
),
child: BookmarkView(
addTabCallBack: addTab,
bookmarks: bookmarks,
)),
);
}

SizedBox buildNavigationSideBar() {
return SizedBox.fromSize(
size: const Size.fromWidth(80),
Expand All @@ -402,6 +425,10 @@ class MainWindowViewState extends State<MainWindowView>
icon: Icon(Icons.library_books),
label: Text('איתור ספר'),
),
NavigationRailDestination(
icon: Icon(Icons.bookmark),
label: Text('סימניות'),
),
NavigationRailDestination(
icon: Icon(Icons.search),
label: Text('חיפוש'),
Expand All @@ -418,16 +445,22 @@ class MainWindowViewState extends State<MainWindowView>
switch (index) {
case 0:
showBookSearch.value = false;
showBookmarksView.value = false;
showBooksBrowser.value = !showBooksBrowser.value;
case 1:
showBooksBrowser.value = false;
showBookmarksView.value = false;
showBookSearch.value = !showBookSearch.value;
bookSearchfocusNode.requestFocus();
case 2:
showBookSearch.value = false;
showBooksBrowser.value = false;
_openSearchScreen();
_openBookmarksScreen();
case 3:
showBookSearch.value = false;
showBooksBrowser.value = false;
_openSearchScreen();
case 4:
_openSettingsScreen();
}
});
Expand Down Expand Up @@ -490,6 +523,10 @@ class MainWindowViewState extends State<MainWindowView>
addTab(SearchingTabWindow('חיפוש'));
}

void _openBookmarksScreen() {
showBookmarksView.value = !showBookmarksView.value;
}

void closeLeftPanel() {
showBooksBrowser.value = false;
showBookSearch.value = false;
Expand Down
50 changes: 36 additions & 14 deletions lib/text_book_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_settings_screen_ex/flutter_settings_screen_ex.dart';
import 'package:otzaria/bookmark_view.dart';
import 'package:otzaria/combined_book_commentary_view.dart';
import 'tab_window.dart';
import 'package:otzaria/text_book_search_view.dart';
Expand All @@ -15,12 +16,14 @@ class TextBookViewer extends StatefulWidget {
final BookTabWindow tab;
final Function(TabWindow) openBookCallback;
final Future<String> data;
final List<Bookmark> bookmarks;

const TextBookViewer({
Key? key,
required this.path,
required this.tab,
required this.openBookCallback,
required this.bookmarks,
required this.data,
}) : super(key: key);

Expand Down Expand Up @@ -210,10 +213,13 @@ class _TextBookViewerState extends State<TextBookViewer>
listenable: widget.tab.positionsListener.itemPositions,
builder: (context, _) {
return FutureBuilder(
future: refFromIndex(
widget.tab.positionsListener.itemPositions.value.first.index),
builder: (context, snapshot) =>
snapshot.hasData ? Text(snapshot.data!) : Text("אין כותרת"),
future: refFromIndex(widget
.tab.positionsListener.itemPositions.value.isNotEmpty
? widget.tab.positionsListener.itemPositions.value.first.index
: 0),
builder: (context, snapshot) => snapshot.hasData
? Text(snapshot.data!)
: const SizedBox.shrink(),
);
}),
leading: IconButton(
Expand All @@ -223,15 +229,31 @@ class _TextBookViewerState extends State<TextBookViewer>
showLeftPane.value = !showLeftPane.value;
}),
actions: [
//button to collapse all tiles
// IconButton(
// icon: const Icon(Icons.expand_rounded),
// tooltip: 'הצג/הסתר פרשנות',
// onPressed: () => setState(() {
// allTilesCollapsed.value = !allTilesCollapsed.value;
// })),
//button to add a bookmark
IconButton(
onPressed: () async {
int index =
widget.tab.positionsListener.itemPositions.value.first.index;
widget.bookmarks.add(Bookmark(
ref: widget.tab.title + await refFromIndex(index),
path: widget.path,
index: index,
));
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('הסימניה נוספה בהצלחה'),
),
);
}
},
icon: const Icon(
Icons.bookmark_add,
),
tooltip: 'הוספת סימניה',
),

// button to open the search field
// button to search
IconButton(
onPressed: () {
showLeftPane.value = true;
Expand All @@ -249,15 +271,15 @@ class _TextBookViewerState extends State<TextBookViewer>
icon: const Icon(
Icons.zoom_in,
),
tooltip: 'הגדל טקסט',
tooltip: 'הגדלת טקסט',
onPressed: () => setState(() {
textFontSize = min(50.0, textFontSize + 3);
})),
IconButton(
icon: const Icon(
Icons.zoom_out,
),
tooltip: 'הקטן טקסט',
tooltip: 'הקטנת טקסט',
onPressed: () => setState(() {
textFontSize = max(15.0, textFontSize - 3);
}),
Expand Down

0 comments on commit 69130d0

Please sign in to comment.