diff --git a/YPaste.xcodeproj/project.pbxproj b/YPaste.xcodeproj/project.pbxproj index 69637d7..ee10a80 100644 --- a/YPaste.xcodeproj/project.pbxproj +++ b/YPaste.xcodeproj/project.pbxproj @@ -16,6 +16,8 @@ 4596AE6923216E6C00F63EBF /* YPasteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE6823216E6C00F63EBF /* YPasteTests.swift */; }; 4596AE712322B5CB00F63EBF /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE702322B5CB00F63EBF /* MainWindowController.swift */; }; 4596AE732323CF5800F63EBF /* SummaryTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE722323CF5800F63EBF /* SummaryTransformer.swift */; }; + 67096210235EC02E009068B9 /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6709620F235EC02E009068B9 /* TableView.swift */; }; + 67096213235EC0D7009068B9 /* SearchField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67096212235EC0D7009068B9 /* SearchField.swift */; }; 67136E302359E04F00EFB448 /* Preferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = 67136E322359E04F00EFB448 /* Preferences.xib */; }; 67904080235D8C1D00B0C74E /* PasteItemsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6790407F235D8C1D00B0C74E /* PasteItemsController.swift */; }; 67C3262C2359D86300248CDE /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67C3262B2359D86300248CDE /* PreferencesWindowController.swift */; }; @@ -51,6 +53,8 @@ 4596AE702322B5CB00F63EBF /* MainWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = ""; }; 4596AE722323CF5800F63EBF /* SummaryTransformer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryTransformer.swift; sourceTree = ""; }; 5798607827522D99BA309E4B /* libPods-YPaste.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-YPaste.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 6709620F235EC02E009068B9 /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TableView.swift; path = MainWindow/TableView.swift; sourceTree = ""; }; + 67096212235EC0D7009068B9 /* SearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchField.swift; sourceTree = ""; }; 67136E332359E05E00EFB448 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/Preferences.xib; sourceTree = ""; }; 67136E372359E66C00EFB448 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Preferences.strings"; sourceTree = ""; }; 6790407F235D8C1D00B0C74E /* PasteItemsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasteItemsController.swift; sourceTree = ""; }; @@ -120,6 +124,7 @@ 4596AE46232025A700F63EBF /* YPaste */ = { isa = PBXGroup; children = ( + 67096211235EC0B0009068B9 /* Window */, 4596AE47232025A700F63EBF /* AppDelegate.swift */, 4596AE49232025A700F63EBF /* ViewController.swift */, 4596AE4E232025A800F63EBF /* Assets.xcassets */, @@ -134,6 +139,7 @@ 67C3262B2359D86300248CDE /* PreferencesWindowController.swift */, 6790407F235D8C1D00B0C74E /* PasteItemsController.swift */, 67C640E1235DE41D00649FD3 /* ScrollView.swift */, + 6709620F235EC02E009068B9 /* TableView.swift */, ); path = YPaste; sourceTree = ""; @@ -147,6 +153,14 @@ path = YPasteTests; sourceTree = ""; }; + 67096211235EC0B0009068B9 /* Window */ = { + isa = PBXGroup; + children = ( + 67096212235EC0D7009068B9 /* SearchField.swift */, + ); + path = Window; + sourceTree = ""; + }; F8B5BBE6526EC7D03DBE8BD7 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -352,8 +366,10 @@ buildActionMask = 2147483647; files = ( 67904080235D8C1D00B0C74E /* PasteItemsController.swift in Sources */, + 67096210235EC02E009068B9 /* TableView.swift in Sources */, 4596AE4D232025A700F63EBF /* YPaste.xcdatamodeld in Sources */, 4596AE6123216A8500F63EBF /* YPaste.swift in Sources */, + 67096213235EC0D7009068B9 /* SearchField.swift in Sources */, 4596AE732323CF5800F63EBF /* SummaryTransformer.swift in Sources */, 4596AE4A232025A700F63EBF /* ViewController.swift in Sources */, 4596AE48232025A700F63EBF /* AppDelegate.swift in Sources */, diff --git a/YPaste/Base.lproj/Main.storyboard b/YPaste/Base.lproj/Main.storyboard index e47a333..b4fc5e3 100644 --- a/YPaste/Base.lproj/Main.storyboard +++ b/YPaste/Base.lproj/Main.storyboard @@ -89,10 +89,10 @@ - + - + @@ -114,7 +114,7 @@ - + diff --git a/YPaste/Info.plist b/YPaste/Info.plist index 9c49ec6..e235f90 100644 --- a/YPaste/Info.plist +++ b/YPaste/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString Explosion v0.1.8 CFBundleVersion - 100356 + 100436 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/YPaste/MainWindow/ScrollView.swift b/YPaste/MainWindow/ScrollView.swift index a5ea295..258150e 100644 --- a/YPaste/MainWindow/ScrollView.swift +++ b/YPaste/MainWindow/ScrollView.swift @@ -9,6 +9,12 @@ import Cocoa class ScrollView: NSScrollView { + + required init?(coder: NSCoder) { + super.init(coder: coder) + contentView.postsBoundsChangedNotifications = true + NotificationCenter.default.addObserver(self, selector: #selector(contentViewDidChangeBounds), name: NSView.boundsDidChangeNotification, object: nil) + } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) @@ -16,18 +22,17 @@ class ScrollView: NSScrollView { // Drawing code here. } - override func scrollWheel(with event: NSEvent) { - super.scrollWheel(with: event) - guard let documentView = self.documentView, let scroller = self.verticalScroller, - event.scrollingDeltaY < 0 - else { return } - let scrollDistance = CGFloat(scroller.doubleValue) * documentView.frame.height - if (documentView.frame.height - scrollDistance < 100) { + @objc private func contentViewDidChangeBounds(_ notification: Notification) { + guard let documentView = self.documentView else { return } + + let clipView = self.contentView + if clipView.bounds.origin.y == 0 { + print("top") + } else if clipView.bounds.origin.y + clipView.bounds.height == documentView.bounds.height { let notification = Notification(name: Notification.Name(rawValue: "scrollerview-ToReachBottom"), object: nil) NotificationCenter.default.post(notification) + } } - - } diff --git a/YPaste/MainWindow/TableView.swift b/YPaste/MainWindow/TableView.swift new file mode 100644 index 0000000..aea8803 --- /dev/null +++ b/YPaste/MainWindow/TableView.swift @@ -0,0 +1,56 @@ +// +// TableView.swift +// YPaste +// +// Created by marchyang on 2019/10/22. +// Copyright © 2019 qwertyyb. All rights reserved. +// + +import Cocoa +import HotKey + + +class TableView: NSTableView { + + required init?(coder: NSCoder) { + super.init(coder: coder) + NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "SearchField-KeyUp"), object: nil, queue: nil) { (notification) in + if notification.userInfo!["keyCode"] as! UInt16 == Key.downArrow.carbonKeyCode { + self.window?.makeFirstResponder(self) + } + } + NSEvent.addLocalMonitorForEvents(matching: NSEvent.EventTypeMask.mouseMoved) { (event) -> NSEvent? in + var location = event.locationInWindow + var visibleRect = self.visibleRect + let originY = visibleRect.origin.y + visibleRect.origin.y = 0 + guard visibleRect.contains(location) else { return event } + location.y = self.frame.height - (visibleRect.height - location.y) - originY + let row = self.row(at: location) + if row == -1 { + return event + } + self.window?.makeFirstResponder(self) + self.selectRowIndexes(IndexSet.init(arrayLiteral: self.numberOfRows - row - 1), byExtendingSelection: false) + return event + } + } + + override func draw(_ dirtyRect: NSRect) { + super.draw(dirtyRect) + + // Drawing code here. + } + + override func keyDown(with event: NSEvent) { + if self.selectedRow == 0 && event.keyCode == Key.upArrow.carbonKeyCode { + NotificationCenter.default.post(name: NSNotification.Name(rawValue: "TableView-ReachTop"), object: nil, userInfo: nil) + } + super.keyDown(with: event) + } + + @objc override func mouseDown(with event: NSEvent) { + super.mouseDown(with: event) + } + +} diff --git a/YPaste/Window/SearchField.swift b/YPaste/Window/SearchField.swift new file mode 100644 index 0000000..34954b8 --- /dev/null +++ b/YPaste/Window/SearchField.swift @@ -0,0 +1,32 @@ +// +// SearchField.swift +// YPaste +// +// Created by marchyang on 2019/10/22. +// Copyright © 2019 qwertyyb. All rights reserved. +// + +import Cocoa +import HotKey + +class SearchField: NSSearchField { + + required init?(coder: NSCoder) { + super.init(coder: coder) + + NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "TableView-ReachTop"), object: nil, queue: nil) { (notification) in + self.window?.makeFirstResponder(self) + } + } + + override func draw(_ dirtyRect: NSRect) { + super.draw(dirtyRect) + + // Drawing code here. + } + + override func keyUp(with event: NSEvent) { + NotificationCenter.default.post(name: NSNotification.Name(rawValue: "SearchField-KeyUp"), object: nil, userInfo: ["keyCode": event.keyCode]) + super.keyDown(with: event) + } +}