-
Notifications
You must be signed in to change notification settings - Fork 9
Implemented drag-n-drop task reordering #8
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
Open
jkoutavas
wants to merge
7
commits into
ReSwift:master
Choose a base branch
from
jkoutavas:jay/reorder-tasks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3699f3d
Updated project to Xcode 11.3.1
jkoutavas 31db7cd
Separated-out ToDoSerializer from ToDoListSerializer
jkoutavas 4d6906b
Implemented drag-n-drop task reordering
jkoutavas 3b6f316
Updated ToDoTableDataSourceType unit test
jkoutavas 2a11bd8
Implemented inverse for MoveTaskAction
jkoutavas b8e6e0c
Removed unused reference
jkoutavas 6f28677
Renamed "ArrayUtil.swift" to "Array+ReSwiftTodo.swift" in keeping wit…
jkoutavas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
ReSwift-Todo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// ArrayUtil.swift | ||
// ReSwift-Todo | ||
// | ||
// Created by Jay Koutavas on 2/26/20. | ||
// Copyright © 2020 ReSwift. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Array { | ||
// These functions from sooop on GitHub | ||
// https://gist.github.com/sooop/3c964900d429516ba48bd75050d0de0a | ||
mutating func move(from start: Index, to end: Index) { | ||
guard (0..<count) ~= start, (0...count) ~= end else { return } | ||
if start == end { return } | ||
let targetIndex = start < end ? end - 1 : end | ||
insert(remove(at: start), at: targetIndex) | ||
} | ||
|
||
mutating func move(from indexes: IndexSet, to toIndex: Index) { | ||
let movingData = indexes.map{ self[$0] } | ||
let targetIndex = toIndex - indexes.filter{ $0 < toIndex }.count | ||
for (i, e) in indexes.enumerated() { | ||
remove(at: e - i) | ||
} | ||
insert(contentsOf: movingData, at: targetIndex) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// ToDoPasteboardWriter.swift | ||
// ReSwift-TodoTests | ||
// | ||
// Created by Jay Koutavas on 2/26/20. | ||
// Copyright © 2020 ReSwift. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
class ToDoPasteboardWriter: NSObject, NSPasteboardWriting { | ||
var todoViewModel: ToDoViewModel | ||
var index: Int | ||
lazy var toDoSerializer = ToDoSerializer() | ||
|
||
init(todoViewModel: ToDoViewModel, at index: Int) { | ||
self.todoViewModel = todoViewModel | ||
self.index = index | ||
} | ||
|
||
func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] { | ||
return [.todo, .tableViewIndex] | ||
} | ||
|
||
func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? { | ||
switch type { | ||
case .todo: | ||
return todoViewModel.title | ||
case .tableViewIndex: | ||
return index | ||
default: | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
extension NSPasteboard.PasteboardType { | ||
static let todo = NSPasteboard.PasteboardType("com.heynow.todo") | ||
static let tableViewIndex = NSPasteboard.PasteboardType("com.heynow.tableViewIndex") | ||
} | ||
|
||
extension NSPasteboardItem { | ||
open func integer(forType type: NSPasteboard.PasteboardType) -> Int? { | ||
guard let data = data(forType: type) else { return nil } | ||
let plist = try? PropertyListSerialization.propertyList( | ||
from: data, | ||
options: .mutableContainers, | ||
format: nil) | ||
return plist as? Int | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// ToDoSerializer.swift | ||
// ReSwift-Todo | ||
// | ||
// Created by Jay Koutavas on 2/26/20. | ||
// Copyright © 2020 ReSwift. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class ToDoSerializer { | ||
|
||
init() { } | ||
|
||
lazy var dateConverter: DateConverter = DateConverter() | ||
|
||
func itemRepresentation(_ item: ToDo) -> String { | ||
|
||
let body = "- \(item.title)" | ||
let tags = item.tags.sorted().map { "@\($0)" } | ||
let done: String? = { | ||
switch item.completion { | ||
case .unfinished: return nil | ||
case .finished(when: let date): | ||
guard let date = date else { return "@done" } | ||
|
||
let dateString = dateConverter.string(date: date) | ||
return "@done(\(dateString))" | ||
} | ||
}() | ||
|
||
return [body] | ||
.appendedContentsOf(tags) | ||
.appendedContentsOf([done].compactMap(identity)) // remove nil | ||
.joined(separator: " ") | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.