File: SelectionManager.m

package info (click to toggle)
agenda.app 0.47-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,008 kB
  • sloc: objc: 8,103; makefile: 16; sh: 5
file content (100 lines) | stat: -rw-r--r-- 1,512 bytes parent folder | download | duplicates (5)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import "SelectionManager.h"

static SelectionManager *singleton;

@implementation SelectionManager(Private)
- (id)init
{
  self = [super init];
  if (self) {
    _objects = [NSMutableArray new];
    _copyarea = [NSMutableArray new];
  }
  return self;
}
@end

@implementation SelectionManager
+ (void)initialize
{
  if ([SelectionManager class] == self)
    singleton = [[SelectionManager alloc] init];
}

+ (SelectionManager *)globalManager
{
  return singleton;
}

- (void)dealloc
{
  [_objects release];
  [_copyarea release];
  [super dealloc];
}

- (int)count
{
  return [_objects count];
}

- (int)copiedCount
{
  return [_copyarea count];
}

- (void)select:(id)object
{
  if (!([[NSApp currentEvent] modifierFlags] & NSControlKeyMask))
    [_objects removeAllObjects];
  if (![_objects containsObject:object])
    [_objects addObject:object];
}

- (void)clear
{
  [_objects removeAllObjects];
}

- (id)lastObject
{
  return [_objects lastObject];
}

- (void)copySelection
{
  [_copyarea setArray:_objects];
  _operation = SMCopy;
}

- (void)cutSelection
{
  [_copyarea setArray:_objects];
  _operation = SMCut;
}

- (NSArray *)paste
{
  NSArray *ret = [NSArray arrayWithArray:_copyarea];
  if (_operation == SMCut)
    [_copyarea removeAllObjects];
  return ret;
}

- (NSArray *)selection
{
  return _objects;
}

- (NSEnumerator *)enumerator
{
  return [_objects objectEnumerator];
}

- (SMOperation)lastOperation
{
  return _operation;
}
@end