Skip to content

Commit

Permalink
Merge pull request #9 from qwertyyb/develop
Browse files Browse the repository at this point in the history
fix: some issue
  • Loading branch information
qwertyyb authored Oct 22, 2019
2 parents c1d3326 + 5f4a40c commit dfc2102
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 13 deletions.
16 changes: 16 additions & 0 deletions YPaste.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -51,6 +53,8 @@
4596AE702322B5CB00F63EBF /* MainWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = "<group>"; };
4596AE722323CF5800F63EBF /* SummaryTransformer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryTransformer.swift; sourceTree = "<group>"; };
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 = "<group>"; };
67096212235EC0D7009068B9 /* SearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchField.swift; sourceTree = "<group>"; };
67136E332359E05E00EFB448 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/Preferences.xib; sourceTree = "<group>"; };
67136E372359E66C00EFB448 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Preferences.strings"; sourceTree = "<group>"; };
6790407F235D8C1D00B0C74E /* PasteItemsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasteItemsController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -120,6 +124,7 @@
4596AE46232025A700F63EBF /* YPaste */ = {
isa = PBXGroup;
children = (
67096211235EC0B0009068B9 /* Window */,
4596AE47232025A700F63EBF /* AppDelegate.swift */,
4596AE49232025A700F63EBF /* ViewController.swift */,
4596AE4E232025A800F63EBF /* Assets.xcassets */,
Expand All @@ -134,6 +139,7 @@
67C3262B2359D86300248CDE /* PreferencesWindowController.swift */,
6790407F235D8C1D00B0C74E /* PasteItemsController.swift */,
67C640E1235DE41D00649FD3 /* ScrollView.swift */,
6709620F235EC02E009068B9 /* TableView.swift */,
);
path = YPaste;
sourceTree = "<group>";
Expand All @@ -147,6 +153,14 @@
path = YPasteTests;
sourceTree = "<group>";
};
67096211235EC0B0009068B9 /* Window */ = {
isa = PBXGroup;
children = (
67096212235EC0D7009068B9 /* SearchField.swift */,
);
path = Window;
sourceTree = "<group>";
};
F8B5BBE6526EC7D03DBE8BD7 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -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 */,
Expand Down
6 changes: 3 additions & 3 deletions YPaste/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<searchField wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Hah-LV-MYL">
<searchField wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Hah-LV-MYL" customClass="SearchField" customModule="YPaste" customModuleProvider="target">
<rect key="frame" x="0.0" y="248" width="480" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" refusesFirstResponder="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" id="5lS-pC-S4h">
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" id="5lS-pC-S4h">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -114,7 +114,7 @@
<rect key="frame" x="1" y="1" width="478" height="248"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="IWK-h8-GX2">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="IWK-h8-GX2" customClass="TableView" customModule="YPaste" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="478" height="248"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
Expand Down
2 changes: 1 addition & 1 deletion YPaste/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>Explosion v0.1.8</string>
<key>CFBundleVersion</key>
<string>100356</string>
<string>100436</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
23 changes: 14 additions & 9 deletions YPaste/MainWindow/ScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@
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)

// 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)

}
}



}
56 changes: 56 additions & 0 deletions YPaste/MainWindow/TableView.swift
Original file line number Diff line number Diff line change
@@ -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)
}

}
32 changes: 32 additions & 0 deletions YPaste/Window/SearchField.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit dfc2102

Please sign in to comment.