Skip to content

Commit

Permalink
Merge pull request #13 from qwertyyb/develop
Browse files Browse the repository at this point in the history
fix: 移除无用的类型字段(暂时不考虑除文字之外的类型支持), 改为时间显示
  • Loading branch information
qwertyyb authored Oct 27, 2019
2 parents 76c4074 + 421d16c commit c544eea
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 39 deletions.
8 changes: 4 additions & 4 deletions YPaste.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
4596AE6123216A8500F63EBF /* YPaste.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE6023216A8500F63EBF /* YPaste.swift */; };
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 */; };
4596AE732323CF5800F63EBF /* Transformers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4596AE722323CF5800F63EBF /* Transformers.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 */; };
Expand Down Expand Up @@ -53,7 +53,7 @@
4596AE6823216E6C00F63EBF /* YPasteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YPasteTests.swift; sourceTree = "<group>"; };
4596AE6A23216E6C00F63EBF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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>"; };
4596AE722323CF5800F63EBF /* Transformers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Transformers.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; path = TableView.swift; sourceTree = "<group>"; };
67096212235EC0D7009068B9 /* SearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchField.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -136,7 +136,6 @@
4596AE53232025A800F63EBF /* Info.plist */,
4596AE54232025A800F63EBF /* YPaste.entitlements */,
4596AE4B232025A700F63EBF /* YPaste.xcdatamodeld */,
4596AE722323CF5800F63EBF /* SummaryTransformer.swift */,
67136E322359E04F00EFB448 /* Preferences.xib */,
67C3262B2359D86300248CDE /* PreferencesWindowController.swift */,
67784475235F376800970786 /* PasteboardHandler.swift */,
Expand All @@ -163,6 +162,7 @@
4596AE49232025A700F63EBF /* ViewController.swift */,
6790407F235D8C1D00B0C74E /* PasteItemsController.swift */,
4596AE702322B5CB00F63EBF /* MainWindowController.swift */,
4596AE722323CF5800F63EBF /* Transformers.swift */,
);
path = Window;
sourceTree = "<group>";
Expand Down Expand Up @@ -377,7 +377,7 @@
4596AE4D232025A700F63EBF /* YPaste.xcdatamodeld in Sources */,
4596AE6123216A8500F63EBF /* YPaste.swift in Sources */,
67096213235EC0D7009068B9 /* SearchField.swift in Sources */,
4596AE732323CF5800F63EBF /* SummaryTransformer.swift in Sources */,
4596AE732323CF5800F63EBF /* Transformers.swift in Sources */,
67446E7A235F3EAE0050AB96 /* HotkeyHandler.swift in Sources */,
4596AE4A232025A700F63EBF /* ViewController.swift in Sources */,
4596AE48232025A700F63EBF /* AppDelegate.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions YPaste/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusItem?.button!.image = NSImage(named: "statusImage")
statusItem?.menu = menu

ValueTransformer.setValueTransformer(SummaryTransformer(), forName: .summaryTransformerName)
ValueTransformer.setValueTransformer(TimeTransformer(), forName: .timeTransformerName)

// check permission
let _ = PasteboardHandler.shared.checkAccess(prompt: true)

Expand Down
24 changes: 14 additions & 10 deletions YPaste/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15400"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14868"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -114,8 +114,8 @@
<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" customClass="TableView" customModule="YPaste" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="478" height="248"/>
<tableView verticalHuggingPriority="750" ambiguous="YES" 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="479" height="248"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -168,7 +168,7 @@
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn width="85" minWidth="40" maxWidth="1000" id="yX1-kQ-pUb">
<tableColumn width="86" minWidth="40" maxWidth="1000" id="yX1-kQ-pUb">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -182,17 +182,21 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="vFT-GW-ujY">
<rect key="frame" x="391" y="1" width="85" height="17"/>
<rect key="frame" x="391" y="1" width="86" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Ew2-hw-lNE">
<rect key="frame" x="0.0" y="1" width="85" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" baseWritingDirection="rightToLeft" title="type" id="dSS-b1-vUc">
<rect key="frame" x="0.0" y="1" width="86" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" baseWritingDirection="rightToLeft" title="Time" id="dSS-b1-vUc">
<font key="font" metaFont="system"/>
<color key="textColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
<connections>
<binding destination="vFT-GW-ujY" name="value" keyPath="objectValue.type" id="Nnj-fO-rQI"/>
<binding destination="vFT-GW-ujY" name="value" keyPath="objectValue.updated_at" id="rMS-Qg-xZy">
<dictionary key="options">
<string key="NSValueTransformerName">TimeTransformer</string>
</dictionary>
</binding>
</connections>
</textFieldCell>
</textField>
Expand All @@ -219,7 +223,7 @@
</subviews>
<nil key="backgroundColor"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="GXx-bY-2zG">
<scroller key="horizontalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="GXx-bY-2zG">
<rect key="frame" x="1" y="233" width="478" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
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>100613</string>
<string>100646</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
23 changes: 0 additions & 23 deletions YPaste/SummaryTransformer.swift

This file was deleted.

53 changes: 53 additions & 0 deletions YPaste/Window/Transformers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// SummaryTransformer.swift
// YPaste
//
// Created by 虚幻 on 2019/9/7.
// Copyright © 2019 qwertyyb. All rights reserved.
//

import Cocoa

class SummaryTransformer: ValueTransformer {
override func transformedValue(_ value: Any?) -> Any? {
if (value == nil) { return value }
let str = value as! String
let trimmedTitle = str.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
return trimmedTitle
}
}

class TimeTransformer: ValueTransformer {
override func transformedValue(_ value: Any?) -> Any? {
if value == nil { return value }
let date = value as! Date
let ts = lround(-date.timeIntervalSinceNow)
let s = ts % 60
let m = Int(ts / 60) % 60
let h = Int(ts / 3600) % 24
let d = Int(ts / 3600 / 24)
var output = ""
if d > 0 { output += "\(d)" }
if d > 2 {
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm MM-dd"
return formatter.string(from: date)
}
if h > 0 { output += "\(h)小时" }
if d > 0 {
return output + ""
}
if m > 0 { output += "\(m)" }
if h > 0 {
return output + ""
}
if s > 0 { output += "\(s)" }
return output + ""
}
}

extension NSValueTransformerName {
static let summaryTransformerName = NSValueTransformerName(rawValue: "SummaryTransformer")
static let timeTransformerName = NSValueTransformerName(rawValue: "TimeTransformer")
}

1 change: 0 additions & 1 deletion YPaste/Window/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ViewController: NSViewController {
required init?(coder: NSCoder) {
self.managedObjectContext = (NSApp.delegate as! AppDelegate).persistentContainer.viewContext
super.init(coder: coder)
ValueTransformer.setValueTransformer(SummaryTransformer(), forName: .summaryTransformerName)
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "fetchPredicateChanged"), object: nil, queue: nil) { (notification) in
self.tableView.scrollRowToVisible(0)
}
Expand Down

0 comments on commit c544eea

Please sign in to comment.