Skip to content

Commit

Permalink
Incorporate @dive's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Mennella committed May 10, 2020
1 parent c6a50bc commit bc8849d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 57 deletions.
87 changes: 38 additions & 49 deletions Classes/Capture/AddNoteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,47 +56,45 @@ final class AddNoteViewController: UIViewController {

private lazy var toolsBar: UIToolbar = {
let bar = UIToolbar()
let button1 = UIButton( type: .custom )
button1.setImage( UIImage( named: "linkkey.png" ), for: .normal )
button1.addTarget(self, action: #selector(addLinkMarkup), for: .touchUpInside)
button1.frame = CGRect( x: 0, y: 0, width: 53, height: 51 )
button1.bounds = CGRect( x: 0, y: 0, width: 53, height: 51 )
let urlButton = UIBarButtonItem( customView: button1 )
let button2 = UIButton( type: .custom )
button2.setImage( UIImage( named: "datepick.png" ), for: .normal )
button2.addTarget(self, action: #selector(setDatePickerView), for: .touchUpInside)
button2.frame = CGRect( x: 0, y: 0, width: 53, height: 51 )
button2.bounds = CGRect( x: 0, y: 0, width: 53, height: 51 )
let dateButton = UIBarButtonItem( customView: button2 )
let spacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
bar.items = [urlButton, dateButton, spacer ]
bar.items = [
UIBarButtonItem(title: "🔗", style: .plain, target: self, action: #selector(addLinkMarkup)),
UIBarButtonItem(title: "📅", style: .plain, target: self, action: #selector(setDatePickerView)),
UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
]
bar.sizeToFit()
return bar
}()

@objc func addLinkMarkup() {
guard self.textView.text != nil else { return } // If no selected text, ignore. Consider popup?
if let range = self.textView.selectedTextRange, !range.isEmpty {
let selectedText = self.textView.text( in: range )
self.textView.replace( range, withText: "[[\(selectedText!)][]]" )
let newCursor = self.textView.position(from: range.end, offset: 4)!
self.textView.selectedTextRange = self.textView.textRange( from: newCursor, to: newCursor)
guard let selectedText = self.textView.text( in: range ) else { return }
self.textView.replace( range, withText: "[[\(selectedText)][]]" )
if let newCursor = self.textView.position(from: range.end, offset: 4) {
self.textView.selectedTextRange = self.textView.textRange( from: newCursor, to: newCursor)
}
}
}

let datePicker: UIDatePicker = {
let picker = UIDatePicker(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 216))
let picker = UIDatePicker()
picker.datePickerMode = .dateAndTime
return picker
}()

enum DateType: String {
case schedule = "Schd"
case deadline = "Dead"
case agenda = "Agenda"
case plain = "Plain"
}

private lazy var datePickBar: UIToolbar = {
let bar = UIToolbar()
let cancelButton = UIBarButtonItem( title: "Cancel", style: .plain, target: self, action: #selector(setDefaultInputView) )
let scheduleButton = UIBarButtonItem( title: "Schd", style: .plain, target: self, action: #selector(insertDateSchedule) )
let deadlineButton = UIBarButtonItem( title: "Dead", style: .plain, target: self, action: #selector(insertDateDeadline) )
let agendaButton = UIBarButtonItem( title: "Agenda", style: .plain, target: self, action: #selector(insertDateAgenda) )
let plainButton = UIBarButtonItem( title: "Plain", style: .plain, target: self, action: #selector(insertDatePlain) )
let scheduleButton = UIBarButtonItem( title: DateType.schedule.rawValue, style: .plain, target: self, action: #selector(insertDate(_:)) )
let deadlineButton = UIBarButtonItem( title: DateType.deadline.rawValue, style: .plain, target: self, action: #selector(insertDate(_:)) )
let agendaButton = UIBarButtonItem( title: DateType.agenda.rawValue, style: .plain, target: self, action: #selector(insertDate(_:)) )
let plainButton = UIBarButtonItem( title: DateType.plain.rawValue, style: .plain, target: self, action: #selector(insertDate(_:)) )
let spacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
bar.items = [ scheduleButton, deadlineButton, agendaButton, plainButton, spacer, cancelButton ]
bar.sizeToFit()
Expand All @@ -111,35 +109,26 @@ final class AddNoteViewController: UIViewController {
}

private func replaceSelected( with newString: String ) {
print( "replaceSelected" )
if self.textView.text != nil {
if let range = self.textView.selectedTextRange {
self.textView.replace( range, withText: newString )
}
if let range = self.textView.selectedTextRange {
self.textView.replace( range, withText: newString )
}
}

@objc func insertDateSchedule() {
let date = datePicked()
replaceSelected( with: "SCHEDULED: <\(date)>" )
self.setDefaultInputView()
}

@objc func insertDateDeadline() {
@objc private func insertDate(_ sender: UIBarButtonItem) {
guard let title = sender.title else { return }
let date = datePicked()
replaceSelected( with: "DEADLINE: <\(date)>" )
self.setDefaultInputView()
}

@objc func insertDateAgenda() {
let date = datePicked()
replaceSelected( with: "<\(date)>" )
self.setDefaultInputView()
}

@objc func insertDatePlain() {
let date = datePicked()
replaceSelected( with: "[\(date)]" )
switch DateType(rawValue: title) {
case .agenda:
replaceSelected( with: "<\(date)>" )
case .deadline:
replaceSelected( with: "DEADLINE: <\(date)>" )
case .plain:
replaceSelected( with: "[\(date)]" )
case .schedule:
replaceSelected( with: "SCHEDULED: <\(date)>" )
case .none:
break
}
self.setDefaultInputView()
}

Expand Down
8 changes: 0 additions & 8 deletions MobileOrg.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@
83B1312C234AD16D0043D955 /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83B1312B234AD16D0043D955 /* CloudKit.framework */; };
CE67A65B23A5CDD900B2B0BD /* SwiftyDropbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE67A65923A5CB6500B2B0BD /* SwiftyDropbox.framework */; };
CE67A65F23A5CE1800B2B0BD /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE67A65E23A5CE1800B2B0BD /* Alamofire.framework */; };
F02A539B245F8B1E005A1948 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = F02A5399245F8B1E005A1948 /* [email protected] */; };
F02A539C245F8B1E005A1948 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = F02A539A245F8B1E005A1948 /* [email protected] */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -306,8 +304,6 @@
CECD59F923B8D6C200348D89 /* MobileOrg-Shared.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "MobileOrg-Shared.xcconfig"; path = "Configuration/MobileOrg-Shared.xcconfig"; sourceTree = "<group>"; };
CECD59FA23B8D6C200348D89 /* MobileOrg-Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "MobileOrg-Debug.xcconfig"; path = "Configuration/MobileOrg-Debug.xcconfig"; sourceTree = "<group>"; };
CECD59FB23B8D6C200348D89 /* MobileOrg-AppStore.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "MobileOrg-AppStore.xcconfig"; path = "Configuration/MobileOrg-AppStore.xcconfig"; sourceTree = "<group>"; };
F02A5399245F8B1E005A1948 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
F02A539A245F8B1E005A1948 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -686,8 +682,6 @@
79BA55681073A7DF00D67917 /* Images */ = {
isa = PBXGroup;
children = (
F02A539A245F8B1E005A1948 /* [email protected] */,
F02A5399245F8B1E005A1948 /* [email protected] */,
79F87A9810854FEA00A54CA9 /* cant-sync-offline.png */,
8322ED6B176AE93C008B37C7 /* [email protected] */,
79F87A9910854FEA00A54CA9 /* please-configure.png */,
Expand Down Expand Up @@ -854,7 +848,6 @@
buildActionMask = 2147483647;
files = (
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
F02A539B245F8B1E005A1948 /* [email protected] in Resources */,
7998AE2410794DBF0000ED49 /* AlertTextField.png in Resources */,
7998B06B1079847C0000ED49 /* back.png in Resources */,
7998B06C1079847C0000ED49 /* capture.png in Resources */,
Expand All @@ -866,7 +859,6 @@
7998B0711079847C0000ED49 /* forward.png in Resources */,
7998B0721079847C0000ED49 /* home.png in Resources */,
7998B0731079847C0000ED49 /* inbox.png in Resources */,
F02A539C245F8B1E005A1948 /* [email protected] in Resources */,
7998B0741079847C0000ED49 /* noflag.png in Resources */,
7998B0751079847C0000ED49 /* note_entry.png in Resources */,
743C12F41DFED37F0051EC6F /* Images.xcassets in Resources */,
Expand Down
Binary file removed Resources/Images/[email protected]
Binary file not shown.
Binary file removed Resources/Images/[email protected]
Binary file not shown.

0 comments on commit bc8849d

Please sign in to comment.