-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tweak.xm
71 lines (47 loc) · 1.88 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@interface NoteObject : NSObject
-(BOOL)isPlainText;
-(NSString *)contentAsPlainText;
-(NSString *)content;
-(NSString *)contentAsPlainTextPreservingNewlines;
@end
@interface NotesListController : UIViewController
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
-(NoteObject *)noteAtIndex:(unsigned int)index;
-(UITableView *)table;
@end
unsigned int selectedIndex = 0;
%hook NotesListController
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = %orig;
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(longPressedCell:)];
[cell addGestureRecognizer:longPress];
//[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
%new
-(void)longPressedCell:(UILongPressGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
UITableViewCell *pressedCell = (UITableViewCell *)[gestureRecognizer view];
selectedIndex = [[self table] indexPathForCell:pressedCell].row;
[[UIMenuController sharedMenuController]
setTargetRect:CGRectMake(pressedCell.center.x,pressedCell.center.y,0,0) inView:[self table]];
UIMenuItem *copyItem = [[UIMenuItem alloc] initWithTitle:@"Copy Note" action:@selector(copySelectedNote:)];
[[UIMenuController sharedMenuController] setMenuItems:@[copyItem]];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}
}
%new
-(void)copySelectedNote:(id)sender {
NoteObject *selectedNote = [self noteAtIndex:selectedIndex];
[[UIPasteboard generalPasteboard] setString:[selectedNote contentAsPlainTextPreservingNewlines]];
}
%new
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{
return (action == @selector(copySelectedNote:));
}
%new
-(BOOL)canBecomeFirstResponder {
return TRUE;
}
%end