Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing between highlight and underline annotations #1050

Merged
merged 3 commits into from
Jan 23, 2025
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
4 changes: 4 additions & 0 deletions Zotero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@
B3A17D1927FC33B800322CAD /* LowPowerModeController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A17D1827FC33B800322CAD /* LowPowerModeController.swift */; };
B3A27ACD25BEE91A00DE0BB2 /* TranslationWebViewHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A27ACC25BEE91A00DE0BB2 /* TranslationWebViewHandler.swift */; };
B3A27AD125BEE93400DE0BB2 /* FilenameFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A27AD025BEE93400DE0BB2 /* FilenameFormatter.swift */; };
B3A297B72D366B23008AD19D /* SegmentedControlCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A297B62D366B23008AD19D /* SegmentedControlCell.swift */; };
B3A2AECC26552248004BF3A4 /* SettingsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A2AECB26552248004BF3A4 /* SettingsCoordinator.swift */; };
B3A2AECE26553DD8004BF3A4 /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A2AECD26553DD8004BF3A4 /* NavigationViewController.swift */; };
B3A2AEDC2656511D004BF3A4 /* StylesRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A2AEDB2656511D004BF3A4 /* StylesRequest.swift */; };
Expand Down Expand Up @@ -1913,6 +1914,7 @@
B3A17D1827FC33B800322CAD /* LowPowerModeController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LowPowerModeController.swift; sourceTree = "<group>"; };
B3A27ACC25BEE91A00DE0BB2 /* TranslationWebViewHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranslationWebViewHandler.swift; sourceTree = "<group>"; };
B3A27AD025BEE93400DE0BB2 /* FilenameFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilenameFormatter.swift; sourceTree = "<group>"; };
B3A297B62D366B23008AD19D /* SegmentedControlCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedControlCell.swift; sourceTree = "<group>"; };
B3A2AECB26552248004BF3A4 /* SettingsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsCoordinator.swift; sourceTree = "<group>"; };
B3A2AECD26553DD8004BF3A4 /* NavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationViewController.swift; sourceTree = "<group>"; };
B3A2AEDB2656511D004BF3A4 /* StylesRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StylesRequest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3137,6 +3139,7 @@
B398D6BF2A77F9C60049A296 /* FontSizeView.swift */,
B34A4B7126E65FC200B3E993 /* LineWidthCell.swift */,
B34A4B6F26E63C9900B3E993 /* LineWidthView.swift */,
B3A297B62D366B23008AD19D /* SegmentedControlCell.swift */,
B34DF1BB2576956F0019CCD1 /* SwitchCell.swift */,
B34DF1BC2576956F0019CCD1 /* SwitchCell.xib */,
B398142C257A649D002C755C /* TextContentEditCell.swift */,
Expand Down Expand Up @@ -4972,6 +4975,7 @@
B30566AF23FC051F003304F2 /* LibraryResponse.swift in Sources */,
B33F47732CA1656E00278240 /* BaseItemsActionHandler.swift in Sources */,
B3868537270D90640068A022 /* RawDataEncoding.swift in Sources */,
B3A297B72D366B23008AD19D /* SegmentedControlCell.swift in Sources */,
B37C5B6D26453C58009A37E5 /* NoteEditorAction.swift in Sources */,
B30566C223FC051F003304F2 /* LibraryData.swift in Sources */,
B391480726D9093E0016B7B2 /* UIPasteboard+Extensions.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extension AnnotationPopoverCoordinator: AnnotationPopoverAnnotationCoordinatorDe
func createShareAnnotationMenu(sender: UIButton) -> UIMenu? {
return (parentCoordinator as? PDFCoordinator)?.createShareAnnotationMenuForSelectedAnnotation(sender: sender)
}

func showEdit(state: AnnotationPopoverState, saveAction: @escaping AnnotationEditSaveAction, deleteAction: @escaping AnnotationEditDeleteAction) {
let data = AnnotationEditState.Data(
type: state.type,
Expand All @@ -89,7 +89,12 @@ extension AnnotationPopoverCoordinator: AnnotationPopoverAnnotationCoordinatorDe
let state = AnnotationEditState(data: data)
let handler = AnnotationEditActionHandler()
let viewModel = ViewModel(initialState: state, handler: handler)
let controller = AnnotationEditViewController(viewModel: viewModel, includeColorPicker: false, includeFontPicker: false, saveAction: saveAction, deleteAction: deleteAction)
let controller = AnnotationEditViewController(
viewModel: viewModel,
properties: AnnotationEditViewController.PropertyRow.from(type: state.type, isAdditionalSettings: true),
saveAction: saveAction,
deleteAction: deleteAction
)
controller.coordinatorDelegate = self
self.navigationController?.pushViewController(controller, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ enum AnnotationEditAction {
case setPageLabel(String, Bool)
case setHighlight(NSAttributedString)
case setFontSize(CGFloat)
case setAnnotationType(AnnotationType)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ struct AnnotationEditState: ViewModelState {

static let color = Changes(rawValue: 1 << 0)
static let pageLabel = Changes(rawValue: 1 << 1)
static let type = Changes(rawValue: 1 << 2)
}

let type: AnnotationType
let isEditable: Bool

var type: AnnotationType
var color: String
var lineWidth: CGFloat
var pageLabel: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ enum AnnotationPopoverAction {
case setTags([Tag])
case setComment(NSAttributedString)
case delete
case setProperties(pageLabel: String, updateSubsequentLabels: Bool, highlightText: NSAttributedString)
case setProperties(type: AnnotationType, pageLabel: String, updateSubsequentLabels: Bool, highlightText: NSAttributedString)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ struct AnnotationPopoverState: ViewModelState {
static let highlight = Changes(rawValue: 1 << 4)
static let tags = Changes(rawValue: 1 << 5)
static let deletion = Changes(rawValue: 1 << 6)
static let type = Changes(rawValue: 1 << 7)
}

let libraryId: LibraryIdentifier
let type: AnnotationType
let isEditable: Bool
let author: String
let showsDeleteButton: Bool

var type: AnnotationType
var comment: NSAttributedString
var color: String
var lineWidth: CGFloat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,38 @@ struct AnnotationEditActionHandler: ViewModelActionHandler {
func process(action: AnnotationEditAction, in viewModel: ViewModel<AnnotationEditActionHandler>) {
switch action {
case .setColor(let hexString):
self.update(viewModel: viewModel) { state in
update(viewModel: viewModel) { state in
state.color = hexString
state.changes = .color
}

case .setLineWidth(let width):
self.update(viewModel: viewModel) { state in
update(viewModel: viewModel) { state in
state.lineWidth = width
}

case .setPageLabel(let label, let updateSubsequentPages):
self.update(viewModel: viewModel) { state in
update(viewModel: viewModel) { state in
state.pageLabel = label
state.updateSubsequentLabels = updateSubsequentPages
state.changes = .pageLabel
}

case .setHighlight(let text):
self.update(viewModel: viewModel) { state in
update(viewModel: viewModel) { state in
state.highlightText = text
}

case .setFontSize(let size):
self.update(viewModel: viewModel) { state in
update(viewModel: viewModel) { state in
state.fontSize = size
}

case .setAnnotationType(let type):
update(viewModel: viewModel) { state in
state.type = type
state.changes = .type
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ struct AnnotationPopoverActionHandler: ViewModelActionHandler {
state.changes = .deletion
}

case .setProperties(pageLabel: let pageLabel, updateSubsequentLabels: let updateSubsequentLabels, highlightText: let highlightText):
case .setProperties(let type, let pageLabel, let updateSubsequentLabels, let highlightText):
update(viewModel: viewModel) { state in
if state.type != type {
state.type = type
state.changes.insert(.type)
}

if state.pageLabel != pageLabel {
state.pageLabel = pageLabel
state.updateSubsequentLabels = updateSubsequentLabels
state.changes = .pageLabel
state.changes.insert(.pageLabel)
}

if state.highlightText != highlightText {
Expand Down
Loading
Loading