Skip to content

Commit

Permalink
Add copy to post list and images
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-taffe committed Dec 3, 2018
1 parent 4ad409b commit 6380d07
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 14 deletions.
6 changes: 6 additions & 0 deletions BetteReddit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
FA4CA82621A9195F00181389 /* NSImage+Resize.m in Sources */ = {isa = PBXBuildFile; fileRef = FA4CA82521A9195F00181389 /* NSImage+Resize.m */; };
FA4FE6E8219F5264004CC677 /* CommentTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FA4FE6E7219F5264004CC677 /* CommentTableViewCell.m */; };
FA579F7321AF155D006FE4F4 /* NSString+TimeSince.m in Sources */ = {isa = PBXBuildFile; fileRef = FA579F7221AF155D006FE4F4 /* NSString+TimeSince.m */; };
FA67776021B5915B00384FD9 /* CopyableImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = FA67775F21B5915B00384FD9 /* CopyableImageView.m */; };
FA8F394F20BB759C007CAC55 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FA8F394E20BB759C007CAC55 /* AppDelegate.m */; };
FA8F395520BB759C007CAC55 /* BetteReddit.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = FA8F395320BB759C007CAC55 /* BetteReddit.xcdatamodeld */; };
FA8F395720BB759E007CAC55 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA8F395620BB759E007CAC55 /* Assets.xcassets */; };
Expand Down Expand Up @@ -81,6 +82,8 @@
FA4FE6E7219F5264004CC677 /* CommentTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CommentTableViewCell.m; sourceTree = "<group>"; };
FA579F7121AF155D006FE4F4 /* NSString+TimeSince.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+TimeSince.h"; sourceTree = "<group>"; };
FA579F7221AF155D006FE4F4 /* NSString+TimeSince.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+TimeSince.m"; sourceTree = "<group>"; };
FA67775E21B5915B00384FD9 /* CopyableImageView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CopyableImageView.h; sourceTree = "<group>"; };
FA67775F21B5915B00384FD9 /* CopyableImageView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CopyableImageView.m; sourceTree = "<group>"; };
FA8F394A20BB759C007CAC55 /* BetteReddit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BetteReddit.app; sourceTree = BUILT_PRODUCTS_DIR; };
FA8F394D20BB759C007CAC55 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
FA8F394E20BB759C007CAC55 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -193,6 +196,8 @@
FAAC7CDA219CA83300E9219D /* PostTableViewCell.m */,
FA4FE6E6219F5264004CC677 /* CommentTableViewCell.h */,
FA4FE6E7219F5264004CC677 /* CommentTableViewCell.m */,
FA67775E21B5915B00384FD9 /* CopyableImageView.h */,
FA67775F21B5915B00384FD9 /* CopyableImageView.m */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -540,6 +545,7 @@
FAE23916219B239300C9F683 /* BRSubreddit.m in Sources */,
FA4FE6E8219F5264004CC677 /* CommentTableViewCell.m in Sources */,
FA0D1B29219CE75D00050BB0 /* ContentSplitViewController.m in Sources */,
FA67776021B5915B00384FD9 /* CopyableImageView.m in Sources */,
FAE23917219B239300C9F683 /* BRUser.m in Sources */,
FAEB4B9E219C698500E29E78 /* BROAuthHelper.m in Sources */,
FA0D1B2C219CE7CA00050BB0 /* CommentViewController.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion BetteReddit/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@
<rect key="frame" x="1" y="1" width="600" height="498"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="KBY-hK-zkE">
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="KBY-hK-zkE" customClass="CopyableImageView">
<rect key="frame" x="0.0" y="0.0" width="600" height="498"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="600" id="Tmm-vK-3Ub"/>
Expand Down
12 changes: 2 additions & 10 deletions BetteReddit/Controller/ContentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ContentViewController.h"
#import "BRPost.h"
#import "CopyableImageView.h"
@import SDWebImage;

@interface ContentViewController ()
Expand Down Expand Up @@ -49,6 +50,7 @@ -(void)changedPost:(NSNotification *)notification{
self.imageView.hidden = false;
self.imageScrollView.hidden = false;
[self.imageView sd_setImageWithURL:[NSURL URLWithString:self.current.postPreviewLink]];
((CopyableImageView *) self.imageView).post = self.current;
return;
} else if([self.current.postHint isEqualToString:@"link"] ||
[self.current.postHint isEqualToString:@"hosted:video"]){
Expand All @@ -64,15 +66,5 @@ -(void)changedPost:(NSNotification *)notification{
}
[self.imageView setImage:nil];
}
- (IBAction)rightClickImage:(id)sender {

NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@"Contextual Menu"];

[theMenu insertItemWithTitle:@"Beep" action:@selector(beep:) keyEquivalent:@"" atIndex:0];

[theMenu insertItemWithTitle:@"Honk" action:@selector(honk:) keyEquivalent:@"" atIndex:1];

[NSMenu popUpContextMenu:theMenu withEvent:nil forView:self.view];
}

@end
20 changes: 20 additions & 0 deletions BetteReddit/View/CopyableImageView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// CopyableImageView.h
// BetteReddit
//
// Created by Alex Taffe on 12/3/18.
// Copyright © 2018 Alex Taffe. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "BRPost.h"

NS_ASSUME_NONNULL_BEGIN

@interface CopyableImageView : NSImageView

@property (strong, nonatomic) BRPost *post;

@end

NS_ASSUME_NONNULL_END
34 changes: 34 additions & 0 deletions BetteReddit/View/CopyableImageView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// CopyableImageView.m
// BetteReddit
//
// Created by Alex Taffe on 12/3/18.
// Copyright © 2018 Alex Taffe. All rights reserved.
//

#import "CopyableImageView.h"

@implementation CopyableImageView

- (void)rightMouseUp:(NSEvent *)event{
NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@"Contextual Menu"];

[theMenu insertItemWithTitle:@"Copy Link" action:@selector(copyLink) keyEquivalent:@"" atIndex:0];
[theMenu insertItemWithTitle:@"Copy Image" action:@selector(copyImage) keyEquivalent:@"" atIndex:1];


[NSMenu popUpContextMenu:theMenu withEvent:event forView:self];
}

#pragma mark - Right click options
-(void)copyLink{
[[NSPasteboard generalPasteboard] clearContents];
[[NSPasteboard generalPasteboard] setString:self.post.url forType:NSPasteboardTypeString];
}

-(void)copyImage{
[[NSPasteboard generalPasteboard] clearContents];
[[NSPasteboard generalPasteboard] setData:[self.image TIFFRepresentation] forType:NSPasteboardTypeTIFF];
}

@end
10 changes: 7 additions & 3 deletions BetteReddit/View/PostTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ -(void)updateColorScheme{
- (void)rightMouseUp:(NSEvent *)event{
NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@"Contextual Menu"];

// [theMenu insertItemWithTitle:@"Copy Link" action:[NSBlockOperation blockOperationWithBlock:^{
//
// }] keyEquivalent:@"" atIndex:0];
[theMenu insertItemWithTitle:@"Copy Link" action:@selector(copyLink) keyEquivalent:@"" atIndex:0];


[NSMenu popUpContextMenu:theMenu withEvent:event forView:self];
}

#pragma mark - Right click options
-(void)copyLink{
[[NSPasteboard generalPasteboard] clearContents];
[[NSPasteboard generalPasteboard] setString:self.post.url forType:NSPasteboardTypeString];
}
@end

0 comments on commit 6380d07

Please sign in to comment.