From 5f4a40cf1a2d1131e11f586e6c06ee460b0772fa Mon Sep 17 00:00:00 2001 From: qwertyyb Date: Tue, 22 Oct 2019 14:47:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=94=AE=E7=9B=98=E7=A7=BB=E5=8A=A8=E5=88=B0=E6=9C=80=E4=B8=8B?= =?UTF-8?q?=E6=96=B9=E4=B8=8D=E4=BC=9A=E5=8A=A0=E8=BD=BD=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E9=97=AE=E9=A2=98=20fix:=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=9C=A8=E6=90=9C=E7=B4=A2=E6=A0=8F=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=97=B6=E6=8C=89=E5=90=91=E4=B8=8B=E9=94=AE?= =?UTF-8?q?=EF=BC=8C=E7=84=A6=E7=82=B9=E4=B8=8D=E4=BC=9A=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=E5=88=97=E8=A1=A8=E4=B8=8A=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E6=9C=80=E4=B8=8A=E9=9D=A2=E4=B8=80=E6=9D=A1?= =?UTF-8?q?=EF=BC=8C=E6=8C=89=E4=B8=8B=E5=90=91=E4=B8=8A=E9=94=AE=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E8=87=AA=E5=8A=A8=E8=B7=B3=E8=BD=AC=E5=88=B0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86=E7=9A=84=E9=97=AE=E9=A2=98=20fix:=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=BC=A0=E6=A0=87=E5=9C=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E4=B8=AD=E7=A7=BB=E5=8A=A8=E6=97=B6=E4=B8=8D=E4=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=80=89=E4=B8=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YPaste.xcodeproj/project.pbxproj | 16 +++++++++ YPaste/Base.lproj/Main.storyboard | 6 ++-- YPaste/Info.plist | 2 +- YPaste/MainWindow/ScrollView.swift | 23 +++++++----- YPaste/MainWindow/TableView.swift | 56 ++++++++++++++++++++++++++++++ YPaste/Window/SearchField.swift | 32 +++++++++++++++++ 6 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 YPaste/MainWindow/TableView.swift create mode 100644 YPaste/Window/SearchField.swift 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) + } +}