Skip to content

Commit

Permalink
Bookmarks view #59: Select/deselect all bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
filimo committed Dec 9, 2019
1 parent d7a6c1b commit db2ce7d
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 42 deletions.
16 changes: 15 additions & 1 deletion ReaderTranslator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@
F0EDE34B236418E000E0B81C /* DOMEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EE0A0F23478C86004A5EAD /* DOMEvent.swift */; };
F0EDE34D23641B1300E0B81C /* Stack.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EDE34C23641B1300E0B81C /* Stack.swift */; };
F0EDE34E23641B1300E0B81C /* Stack.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EDE34C23641B1300E0B81C /* Stack.swift */; };
F0EDFB1F239E2F210048CFD1 /* BookmarksView_Controls_ActionMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EDFB1E239E2F210048CFD1 /* BookmarksView_Controls_ActionMenu.swift */; };
F0EDFB20239E2F210048CFD1 /* BookmarksView_Controls_ActionMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EDFB1E239E2F210048CFD1 /* BookmarksView_Controls_ActionMenu.swift */; };
F0EE0A1023478C86004A5EAD /* DOMEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EE0A0F23478C86004A5EAD /* DOMEvent.swift */; };
F0EE0A162347BF09004A5EAD /* WKPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EE0A152347BF09004A5EAD /* WKPageView.swift */; };
F0EE0A172347BF09004A5EAD /* WKPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0EE0A152347BF09004A5EAD /* WKPageView.swift */; };
Expand Down Expand Up @@ -369,6 +371,7 @@
F0D2E333234BA49000D95994 /* Safari.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Safari.swift; sourceTree = "<group>"; };
F0D31C5023491C23003CF86B /* GTranslatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GTranslatorView.swift; sourceTree = "<group>"; };
F0EDE34C23641B1300E0B81C /* Stack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stack.swift; sourceTree = "<group>"; };
F0EDFB1E239E2F210048CFD1 /* BookmarksView_Controls_ActionMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksView_Controls_ActionMenu.swift; sourceTree = "<group>"; };
F0EE0A0F23478C86004A5EAD /* DOMEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DOMEvent.swift; sourceTree = "<group>"; };
F0EE0A152347BF09004A5EAD /* WKPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKPageView.swift; sourceTree = "<group>"; };
F0EE0A18234897CC004A5EAD /* StatusBarView_Safari.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarView_Safari.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -487,7 +490,7 @@
isa = PBXGroup;
children = (
F058C7FF23992F92002C84F0 /* BookmarksView.swift */,
F0C706CF239ACDBD0061F790 /* BookmarksView_Controls.swift */,
F0EDFB1D239E2EFE0048CFD1 /* BookmarksView_Controls */,
F08D9406239C2BA000147ECE /* BookmarksView_List */,
);
path = Bookmarks;
Expand Down Expand Up @@ -787,6 +790,15 @@
path = ReaderView_Pdf;
sourceTree = "<group>";
};
F0EDFB1D239E2EFE0048CFD1 /* BookmarksView_Controls */ = {
isa = PBXGroup;
children = (
F0C706CF239ACDBD0061F790 /* BookmarksView_Controls.swift */,
F0EDFB1E239E2F210048CFD1 /* BookmarksView_Controls_ActionMenu.swift */,
);
path = BookmarksView_Controls;
sourceTree = "<group>";
};
F0EE0A142347BEDB004A5EAD /* WebKit */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1134,6 +1146,7 @@
F08EBB02239541FB009025D3 /* PeerConnection.swift in Sources */,
F06DB10B234504FD00C2DE90 /* EditorNSTextRepresentable.swift in Sources */,
F0AD8B1C236413F60017C22F /* AvailableView.swift in Sources */,
F0EDFB20239E2F210048CFD1 /* BookmarksView_Controls_ActionMenu.swift in Sources */,
F06DB10E23450B6000C2DE90 /* View.swift in Sources */,
F04C830D23617653003A25B4 /* StatusBarView_ViewsEnabler.swift in Sources */,
F0D31C5223491C23003CF86B /* GTranslatorView.swift in Sources */,
Expand Down Expand Up @@ -1248,6 +1261,7 @@
F08EBAF023952AD6009025D3 /* WebViewContainer.swift in Sources */,
F0AB12B6233F59B4005B9F2A /* StatusBarView_Voice_Volume.swift in Sources */,
F0AA69D4232E9762007CC07B /* ReaderView.swift in Sources */,
F0EDFB1F239E2F210048CFD1 /* BookmarksView_Controls_ActionMenu.swift in Sources */,
F0AB12B0233F5968005B9F2A /* StatusBarView_Voice.swift in Sources */,
F0AB12B2233F597B005B9F2A /* StatusBarView_Voice_Select.swift in Sources */,
F0EE0A162347BF09004A5EAD /* WKPageView.swift in Sources */,
Expand Down
9 changes: 9 additions & 0 deletions ReaderTranslator/Stores/Bookmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ struct Bookmark: Codable, Hashable {

typealias Bookmarks = [Bookmark]

extension Bookmarks {
func selectedAll() {
for var bookmark in self { bookmark.checked = true }
}
func clearSelectedAll() {
for var bookmark in self { bookmark.checked = false }
}
}

extension Array where Element == Bookmark {
func contains(text: String) -> Bool {
self.first { $0.text == text } != nil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// BookmarksView_List.swift
// ReaderTranslator
//
// Created by Viktor Kushnerov on 6/12/19.
// Copyright © 2019 Viktor Kushnerov. All rights reserved.
//

import SwiftUI

struct BookmarksView_Controls: View {
@ObservedObject var store = Store.shared

private var audioRateString: String {
String(format: "%.1f", arguments: [self.store.longmanAudioRate])
}

var body: some View {
VStack {
HStack {
Text("\(store.bookmarks.checked.count)/\(store.bookmarks.count)")
BookmarksView_Controls_ActionMenu()
}
audioRateButtonsView
}
}

private var audioRateButtonsView: some View {
HStack {
Button(action: { self.store.longmanAudioRate = 0.2 }, label: { Text(".2") })
Button(action: { self.store.longmanAudioRate = 0.5 }, label: { Text(".5") })
Button(action: { self.store.longmanAudioRate -= 0.1 }, label: { Text("-") })
Text(audioRateString)
Button(action: { self.store.longmanAudioRate += 0.1 }, label: { Text("+") })
Button(action: { self.store.longmanAudioRate = 1 }, label: { Text("1") })
}
}
}

struct BookmarksView_Controls_Previews: PreviewProvider {
static var previews: some View {
BookmarksView_Controls()
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
//
// BookmarksView_List.swift
// BookmarksView_Controls_ActionMenu.swift
// ReaderTranslator
//
// Created by Viktor Kushnerov on 6/12/19.
// Created by Viktor Kushnerov on 9/12/19.
// Copyright © 2019 Viktor Kushnerov. All rights reserved.
//

import SwiftUI

struct BookmarksView_Controls: View {
struct BookmarksView_Controls_ActionMenu: View {
@ObservedObject var store = Store.shared

@State var showConfirm = false

private var audioRateString: String {
String(format: "%.1f", arguments: [self.store.longmanAudioRate])
}

var body: some View {
VStack {
HStack {
Text("\(store.bookmarks.checked.count)/\(store.bookmarks.count)")
actionMenuView
}
audioRateButtonsView
}
.alert(isPresented: $showConfirm) {
Alert(
title: Text("Are you sure?"),
message: Text("Remove all bookmarks?"),
primaryButton: .cancel(),
secondaryButton: .default(Text("Ok")) { self.store.bookmarks.removeAll() })
}
}

private var audioRateButtonsView: some View {
HStack {
Button(action: { self.store.longmanAudioRate = 0.2 }, label: { Text(".2") })
Button(action: { self.store.longmanAudioRate = 0.5 }, label: { Text(".5") })
Button(action: { self.store.longmanAudioRate -= 0.1 }, label: { Text("-") })
Text(audioRateString)
Button(action: { self.store.longmanAudioRate += 0.1 }, label: { Text("+") })
Button(action: { self.store.longmanAudioRate = 1 }, label: { Text("1") })
}
}

private var actionMenuView: some View {
MenuButton("Actions") {
Button(action: {
self.store.bookmarks.selectedAll()
}, label: { Text("Select all bookmarks") })
Button(action: {
self.store.bookmarks.clearSelectedAll()
}, label: { Text("Deselect all bookmarks") })
Button(action: {
Clipboard.copy(self.store.bookmarks.joined(separator: "\n"))
}, label: { Text("Copy bookmarks to Clipboard") })
Expand All @@ -62,12 +35,18 @@ struct BookmarksView_Controls: View {
.menuButtonStyle(BorderlessButtonMenuButtonStyle())
.padding([.leading, .trailing], 5)
.background(RoundedRectangle(cornerRadius: 3).foregroundColor(Color(NSColor.controlColor)))

.alert(isPresented: $showConfirm) {
Alert(
title: Text("Are you sure?"),
message: Text("Remove all bookmarks?"),
primaryButton: .cancel(),
secondaryButton: .default(Text("Ok")) { self.store.bookmarks.removeAll() })
}
}
}

struct BookmarksView_Controls_Previews: PreviewProvider {
struct BookmarksView_Controls_ActionMenu_Previews: PreviewProvider {
static var previews: some View {
BookmarksView_Controls()
BookmarksView_Controls_ActionMenu()
}
}
2 changes: 1 addition & 1 deletion ReaderTranslatorMac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>762</string>
<string>764</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.education</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion ReaderTranslatorSafari/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1169</string>
<string>1177</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSAppleEventsUsageDescription</key>
Expand Down

0 comments on commit db2ce7d

Please sign in to comment.