Skip to content

Commit

Permalink
Support Delete history (Clipy#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Econa77 committed Oct 1, 2017
1 parent 923cdfc commit f2500bc
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 69 deletions.
11 changes: 1 addition & 10 deletions Clipy/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,7 @@ class AppDelegate: NSObject {
return
}

let modifierFlags = NSEvent.modifierFlags()

switch modifierFlags {
case [.option]:
AppEnvironment.current.clipService.clear(clip: clip)

default:
AppEnvironment.current.pasteService.copyToPasteboard(with: clip)
AppEnvironment.current.pasteService.paste()
}
AppEnvironment.current.pasteService.paste(with: clip)
}

func selectSnippetMenuItem(_ sender: AnyObject) {
Expand Down
10 changes: 7 additions & 3 deletions Clipy/Sources/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ struct Constants {
}

struct Beta {
static let pastePlainText = "kCPYBetaPastePlainText"
static let pastePlainTextModifier = "kCPYBetaPastePlainTextModifier"
static let observerScreenshot = "kCPYBetaObserveScreenshot"
static let pastePlainText = "kCPYBetaPastePlainText"
static let pastePlainTextModifier = "kCPYBetaPastePlainTextModifier"
static let deleteHistory = "kCPYBetaDeleteHistory"
static let deleteHistoryModifier = "kCPYBetaDeleteHistoryModifier"
static let pasteAndDeleteHistory = "kCPYBetaPasteAndDeleteHistory"
static let pasteAndDeleteHistoryModifier = "kCPYBetapasteAndDeleteHistoryModifier"
static let observerScreenshot = "kCPYBetaObserveScreenshot"
}

struct Update {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1510" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -13,11 +13,11 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="166"/>
<rect key="frame" x="0.0" y="0.0" width="480" height="229"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aNl-8j-KxN" customClass="CPYDesignableButton" customModule="Clipy" customModuleProvider="target">
<rect key="frame" x="59" y="75" width="237" height="18"/>
<rect key="frame" x="59" y="138" width="237" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Paste as PlainText" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="r0C-kF-Q0z">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -27,8 +27,8 @@
<binding destination="zBg-yp-15f" name="value" keyPath="values.kCPYBetaPastePlainText" id="yWk-xb-ghE"/>
</connections>
</button>
<textField verticalHuggingPriority="750" fixedFrame="YES" preferredMaxLayoutWidth="206" translatesAutoresizingMaskIntoConstraints="NO" id="3h0-VG-ZCf">
<rect key="frame" x="59" y="99" width="210" height="17"/>
<textField verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="YES" preferredMaxLayoutWidth="206" translatesAutoresizingMaskIntoConstraints="NO" id="3h0-VG-ZCf">
<rect key="frame" x="59" y="162" width="210" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" allowsUndo="NO" sendsActionOnEndEditing="YES" title="Action" id="6RM-Ow-USQ">
<font key="font" size="13" name=".HiraKakuInterface-W6"/>
Expand All @@ -47,7 +47,7 @@
<binding destination="zBg-yp-15f" name="value" keyPath="values.kCPYBetaObserveScreenshot" id="Wyb-lc-cVJ"/>
</connections>
</button>
<textField verticalHuggingPriority="750" fixedFrame="YES" preferredMaxLayoutWidth="206" translatesAutoresizingMaskIntoConstraints="NO" id="2iQ-ta-6Z6">
<textField verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="YES" preferredMaxLayoutWidth="206" translatesAutoresizingMaskIntoConstraints="NO" id="2iQ-ta-6Z6">
<rect key="frame" x="59" y="42" width="210" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" allowsUndo="NO" sendsActionOnEndEditing="YES" title="Screenshot" id="0f7-ic-bHq">
Expand All @@ -56,8 +56,8 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" preferredMaxLayoutWidth="436" translatesAutoresizingMaskIntoConstraints="NO" id="5vu-ef-NJt">
<rect key="frame" x="20" y="122" width="440" height="27"/>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="YES" preferredMaxLayoutWidth="436" translatesAutoresizingMaskIntoConstraints="NO" id="5vu-ef-NJt">
<rect key="frame" x="20" y="185" width="440" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="center" title="Beta settings might be moved to a different pane in future versions." id="c4z-RD-3UN">
<font key="font" size="13" name=".HiraKakuInterface-W3"/>
Expand All @@ -66,7 +66,7 @@
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cPO-Kb-LG8">
<rect key="frame" x="316" y="70" width="108" height="26"/>
<rect key="frame" x="316" y="133" width="108" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="DPj-O5-TCm">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -85,8 +85,70 @@
<binding destination="zBg-yp-15f" name="selectedIndex" keyPath="values.kCPYBetaPastePlainTextModifier" id="NP9-oI-Jv3"/>
</connections>
</popUpButton>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uSX-Yy-86r" customClass="CPYDesignableButton" customModule="Clipy" customModuleProvider="target">
<rect key="frame" x="59" y="107" width="237" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Delete history" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="sYs-Da-TSj">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="zBg-yp-15f" name="value" keyPath="values.kCPYBetaDeleteHistory" id="47p-q5-Mls"/>
</connections>
</button>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Xih-Sx-WpW">
<rect key="frame" x="316" y="102" width="108" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Command" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="I0s-bs-Y8L">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="AWw-Hg-ORg">
<items>
<menuItem title="Command" state="on" id="HZd-yn-p4o"/>
<menuItem title="Shift" id="oNH-8M-ZSE"/>
<menuItem title="Control" id="z3A-El-En9"/>
<menuItem title="Alt" id="M9s-9f-OKA"/>
</items>
</menu>
</popUpButtonCell>
<connections>
<binding destination="zBg-yp-15f" name="enabled" keyPath="values.kCPYBetaDeleteHistory" id="t9Q-ak-O2E"/>
<binding destination="zBg-yp-15f" name="selectedIndex" keyPath="values.kCPYBetaDeleteHistoryModifier" id="tfx-sF-bDn"/>
</connections>
</popUpButton>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="195-Rx-goW" customClass="CPYDesignableButton" customModule="Clipy" customModuleProvider="target">
<rect key="frame" x="59" y="76" width="237" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Paste and delete history" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="M5n-Mr-02l">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="zBg-yp-15f" name="value" keyPath="values.kCPYBetaPasteAndDeleteHistory" id="dhT-tJ-Eg4"/>
</connections>
</button>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="pwa-Yn-1fY">
<rect key="frame" x="316" y="71" width="108" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Command" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="RLH-Us-QOE">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="etc-Mh-b0d">
<items>
<menuItem title="Command" state="on" id="yZK-TZ-SNb"/>
<menuItem title="Shift" id="NFq-oQ-VKz"/>
<menuItem title="Control" id="kZF-3Q-Tge"/>
<menuItem title="Alt" id="orJ-AB-Oxl"/>
</items>
</menu>
</popUpButtonCell>
<connections>
<binding destination="zBg-yp-15f" name="enabled" keyPath="values.kCPYBetaPasteAndDeleteHistory" id="Fpz-Jl-Qii"/>
<binding destination="zBg-yp-15f" name="selectedIndex" keyPath="values.kCPYBetapasteAndDeleteHistoryModifier" id="2KJ-zu-vKd"/>
</connections>
</popUpButton>
</subviews>
<point key="canvasLocation" x="640" y="480"/>
<point key="canvasLocation" x="445" y="443.5"/>
</customView>
<userDefaultsController id="zPt-b5-lYK"/>
<userDefaultsController representsSharedInstance="YES" id="zBg-yp-15f"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,33 @@

/* Class = "NSMenuItem"; title = "Control"; ObjectID = "vtQ-7v-nLJ"; */
"vtQ-7v-nLJ.title" = "Control";

/* Class = "NSMenuItem"; title = "Command"; ObjectID = "HZd-yn-p4o"; */
"HZd-yn-p4o.title" = "Command";

/* Class = "NSButtonCell"; title = "Paste and delete history"; ObjectID = "M5n-Mr-02l"; */
"M5n-Mr-02l.title" = "Paste and delete history";

/* Class = "NSMenuItem"; title = "Alt"; ObjectID = "M9s-9f-OKA"; */
"M9s-9f-OKA.title" = "Alt";

/* Class = "NSMenuItem"; title = "Shift"; ObjectID = "NFq-oQ-VKz"; */
"NFq-oQ-VKz.title" = "Maiuscolo";

/* Class = "NSMenuItem"; title = "Control"; ObjectID = "kZF-3Q-Tge"; */
"kZF-3Q-Tge.title" = "Control";

/* Class = "NSMenuItem"; title = "Shift"; ObjectID = "oNH-8M-ZSE"; */
"oNH-8M-ZSE.title" = "Maiuscolo";

/* Class = "NSMenuItem"; title = "Alt"; ObjectID = "orJ-AB-Oxl"; */
"orJ-AB-Oxl.title" = "Alt";

/* Class = "NSButtonCell"; title = "Delete history"; ObjectID = "sYs-Da-TSj"; */
"sYs-Da-TSj.title" = "Delete history";

/* Class = "NSMenuItem"; title = "Command"; ObjectID = "yZK-TZ-SNb"; */
"yZK-TZ-SNb.title" = "Command";

/* Class = "NSMenuItem"; title = "Control"; ObjectID = "z3A-El-En9"; */
"z3A-El-En9.title" = "Control";
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,40 @@
"pgE-3j-ZEy.title" = "スクリーンショットを履歴に保存";

/* Class = "NSButtonCell"; title = "Paste as PlainText"; ObjectID = "r0C-kF-Q0z"; */
"r0C-kF-Q0z.title" = "同時選択でPlainTextとしてペースト";
"r0C-kF-Q0z.title" = "PlainTextとしてペースト";

/* Class = "NSMenuItem"; title = "Shift"; ObjectID = "riQ-CH-Kcr"; */
"riQ-CH-Kcr.title" = "Shift";

/* Class = "NSMenuItem"; title = "Control"; ObjectID = "vtQ-7v-nLJ"; */
"vtQ-7v-nLJ.title" = "Control";

/* Class = "NSMenuItem"; title = "Command"; ObjectID = "HZd-yn-p4o"; */
"HZd-yn-p4o.title" = "Command";

/* Class = "NSButtonCell"; title = "Paste and delete history"; ObjectID = "M5n-Mr-02l"; */
"M5n-Mr-02l.title" = "ペーストした後に履歴を削除する";

/* Class = "NSMenuItem"; title = "Alt"; ObjectID = "M9s-9f-OKA"; */
"M9s-9f-OKA.title" = "Alt";

/* Class = "NSMenuItem"; title = "Shift"; ObjectID = "NFq-oQ-VKz"; */
"NFq-oQ-VKz.title" = "Shift";

/* Class = "NSMenuItem"; title = "Control"; ObjectID = "kZF-3Q-Tge"; */
"kZF-3Q-Tge.title" = "Control";

/* Class = "NSMenuItem"; title = "Shift"; ObjectID = "oNH-8M-ZSE"; */
"oNH-8M-ZSE.title" = "Shift";

/* Class = "NSMenuItem"; title = "Alt"; ObjectID = "orJ-AB-Oxl"; */
"orJ-AB-Oxl.title" = "Alt";

/* Class = "NSButtonCell"; title = "Delete history"; ObjectID = "sYs-Da-TSj"; */
"sYs-Da-TSj.title" = "履歴を削除する";

/* Class = "NSMenuItem"; title = "Command"; ObjectID = "yZK-TZ-SNb"; */
"yZK-TZ-SNb.title" = "Command";

/* Class = "NSMenuItem"; title = "Control"; ObjectID = "z3A-El-En9"; */
"z3A-El-En9.title" = "Control";
13 changes: 7 additions & 6 deletions Clipy/Sources/Services/ClipService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class ClipService {
AppEnvironment.current.defaults.rx
.observe([String: NSNumber].self, Constants.UserDefaults.storeTypes)
.filterNil()
.asDriver(onErrorJustReturn: [:])
.asDriver(onErrorDriveWith: .empty())
.drive(onNext: { [weak self] in
self?.storeTypes = $0
})
Expand All @@ -61,20 +61,19 @@ final class ClipService {
AppEnvironment.current.dataCleanService.cleanDatas()
}

func clear(clip: CPYClip) {
func delete(with clip: CPYClip) {
let realm = try! Realm()

// Delete saved images
let path = clip.thumbnailPath
if !path.isEmpty {
PINCache.shared().removeObject(forKey: path)
}

// Delete Realm
realm.transaction { realm.delete(clip) }
}

// Delete writed datas
AppEnvironment.current.dataCleanService.cleanDatas()
func incrementChangeCount() {
cachedChangeCount.value += 1
}

}
Expand Down Expand Up @@ -114,6 +113,8 @@ extension ClipService {
// Copy already copied history
let isCopySameHistory = AppEnvironment.current.defaults.bool(forKey: Constants.UserDefaults.copySameHistory)
if realm.object(ofType: CPYClip.self, forPrimaryKey: "\(data.hash)") != nil, !isCopySameHistory { return }
// Don't save invalidated clip
if let clip = realm.object(ofType: CPYClip.self, forPrimaryKey: "\(data.hash)"), clip.isInvalidated { return }

// Don't save empty string history
if data.isOnlyStringType && data.stringValue.isEmpty { return }
Expand Down
Loading

0 comments on commit f2500bc

Please sign in to comment.