Permalink
Browse files

made pasteboard restore try to save all pasteboard types, not just st…

…rings.
  • Loading branch information...
1 parent 1cec0c6 commit 2282ba39d0d46b83c1d143e8414fd73d75b728bb @jessegrosjean jessegrosjean committed Nov 8, 2011
View
@@ -0,0 +1,16 @@
+//
+// NSPasteboard_Extensions.h
+// QuickCursor
+//
+// Created by Jesse Grosjean on 11/8/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <AppKit/AppKit.h>
+
+@interface NSPasteboard (Extensions)
+
+- (NSDictionary *)savePasteboardContents;
+- (void)restorePasteboardContents:(NSDictionary *)dict;
+
+@end
View
@@ -0,0 +1,32 @@
+//
+// NSPasteboard_Extensions.m
+// QuickCursor
+//
+// Created by Jesse Grosjean on 11/8/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSPasteboard_Extensions.h"
+
+@implementation NSPasteboard (Extensions)
+
+- (NSDictionary *)savePasteboardContents {
+ NSMutableDictionary *result = [NSMutableDictionary dictionary];
+ for (NSString *each in [self types]) {
+ NSData *data = [self dataForType:each];
+ if (data) {
+ [result setObject:data forKey:each];
+ }
+ }
+
+ return result;
+}
+
+- (void)restorePasteboardContents:(NSDictionary *)dict {
+ [self clearContents];
+ for (NSString *each in [dict keyEnumerator]) {
+ [self setData:[dict objectForKey:each] forType:each];
+ }
+}
+
+@end
View
@@ -7,7 +7,7 @@
//
#import "QCUIElement.h"
-
+#import "NSPasteboard_Extensions.h"
@implementation QCUIElement
@@ -345,10 +345,13 @@ - (NSString *)readString {
}
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- NSString *savedContents = [pboard stringForType:NSPasteboardTypeString];
+ NSDictionary *savedContents = [pboard savePasteboardContents];
+
+ //NSString *savedContents = [pboard stringForType:NSPasteboardTypeString];
NSString *copiedContents = [self performCopee:YES];
- [pboard clearContents];
- [pboard setString:savedContents forType:NSPasteboardTypeString]; // trying to restore original clip board contents... doesn't seem to work, not sure if good idaea anyway.
+ [pboard restorePasteboardContents:savedContents];
+ //[pboard clearContents];
+ //[pboard setString:savedContents forType:NSPasteboardTypeString]; // trying to restore original clip board contents... doesn't seem to work, not sure if good idaea anyway.
return copiedContents;
}
@@ -358,7 +361,9 @@ - (NSString *)readString {
- (BOOL)writeString:(NSString *)pasteString {
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
- NSString *savedContents = [pboard stringForType:NSPasteboardTypeString];
+ //NSString *savedContents = [pboard stringForType:NSPasteboardTypeString];
+ NSDictionary *savedContents = [pboard savePasteboardContents];
+
[pboard clearContents];
[pboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
[pboard setString:pasteString forType:NSPasteboardTypeString];
@@ -372,8 +377,9 @@ - (BOOL)writeString:(NSString *)pasteString {
if ([pasteMenuItem enabled]) {
if (AXUIElementPerformAction(pasteMenuItem->uiElementRef, kAXPressAction) == kAXErrorSuccess) {
usleep(100000); // hack... might not work with long documents?
- [pboard clearContents];
- [pboard setString:savedContents forType:NSPasteboardTypeString];
+ [pboard restorePasteboardContents:savedContents];
+ //[pboard clearContents];
+ //[pboard setString:savedContents forType:NSPasteboardTypeString];
return YES;
}
}
@@ -31,6 +31,7 @@
884E34CF128C7E4700B60730 /* ShortcutRecorder.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 884E34C3128C7E4100B60730 /* ShortcutRecorder.framework */; };
88564D8A12DF407E00070CD3 /* StatusItemIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 88564D8912DF407E00070CD3 /* StatusItemIcon.png */; };
8858B82912F9AC6600696670 /* receipt in Resources */ = {isa = PBXBuildFile; fileRef = 8858B82812F9AC6600696670 /* receipt */; };
+ 88C3174D1469D7E0003E71E0 /* NSPasteboard_Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 88C3174C1469D7E0003E71E0 /* NSPasteboard_Extensions.m */; };
88D3FC48133D0F8B00C2E651 /* ReceiptVerification.m in Sources */ = {isa = PBXBuildFile; fileRef = 88D3FC47133D0F8B00C2E651 /* ReceiptVerification.m */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
@@ -94,6 +95,8 @@
884E34C3128C7E4100B60730 /* ShortcutRecorder.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ShortcutRecorder.framework; sourceTree = "<group>"; };
88564D8912DF407E00070CD3 /* StatusItemIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = StatusItemIcon.png; sourceTree = "<group>"; };
8858B82812F9AC6600696670 /* receipt */ = {isa = PBXFileReference; lastKnownFileType = file; path = receipt; sourceTree = "<group>"; };
+ 88C3174B1469D7E0003E71E0 /* NSPasteboard_Extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSPasteboard_Extensions.h; sourceTree = "<group>"; };
+ 88C3174C1469D7E0003E71E0 /* NSPasteboard_Extensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSPasteboard_Extensions.m; sourceTree = "<group>"; };
88D3FC46133D0F8B00C2E651 /* ReceiptVerification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReceiptVerification.h; sourceTree = "<group>"; };
88D3FC47133D0F8B00C2E651 /* ReceiptVerification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReceiptVerification.m; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* QuickCursor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = QuickCursor.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -125,6 +128,8 @@
882A8BAB128C33BC00D05C94 /* QCAppDelegate.m */,
882A8BAC128C33BC00D05C94 /* QCUIElement.h */,
882A8BAD128C33BC00D05C94 /* QCUIElement.m */,
+ 88C3174B1469D7E0003E71E0 /* NSPasteboard_Extensions.h */,
+ 88C3174C1469D7E0003E71E0 /* NSPasteboard_Extensions.m */,
882A8C26128C368400D05C94 /* ODB Editor */,
882A8C27128C369100D05C94 /* Hot Key */,
);
@@ -325,6 +330,7 @@
882A8BDC128C349F00D05C94 /* ODBEditor.m in Sources */,
882A8BDD128C349F00D05C94 /* NSAppleEventDescriptor-Extensions.m in Sources */,
88D3FC48133D0F8B00C2E651 /* ReceiptVerification.m in Sources */,
+ 88C3174D1469D7E0003E71E0 /* NSPasteboard_Extensions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 2282ba3

Please sign in to comment.