forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBookmarkModel.h
124 lines (110 loc) · 4.41 KB
/
BookmarkModel.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
** BookmarkModel.h
** iTerm
**
** Created by George Nachman on 8/24/10.
** Project: iTerm
**
** Description: Model for an ordered collection of bookmarks. Bookmarks have
** numerous attributes, but always have a name, set of tags, and a guid.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
*/
#import <Cocoa/Cocoa.h>
#define BMKEY_BOOKMARKS_ARRAY @"Bookmarks Array"
typedef NSDictionary Bookmark;
typedef struct {
SEL selector; // normal action
SEL alternateSelector; // opt+click
SEL openAllSelector; // open all bookmarks
SEL alternateOpenAllSelector; // opt+open all bookmarks
id target; // receiver of selector
} JournalParams;
@interface BookmarkModel : NSObject {
NSMutableArray* bookmarks_;
NSString* defaultBookmarkGuid_;
// The journal is an array of actions since the last change notification was
// posted.
NSMutableArray* journal_;
NSUserDefaults* prefs_;
BOOL postChanges_; // should change notifications be posted?
}
+ (BookmarkModel*)sharedInstance;
+ (BookmarkModel*)sessionsInstance;
+ (NSString*)freshGuid;
+ (void)migratePromptOnCloseInMutableBookmark:(NSMutableDictionary *)dict;
+ (BOOL)migrated;
- (int)numberOfBookmarks;
- (int)numberOfBookmarksWithFilter:(NSString*)filter;
- (NSArray*)bookmarkIndicesMatchingFilter:(NSString*)filter;
- (int)indexOfBookmarkWithGuid:(NSString*)guid;
- (int)indexOfBookmarkWithGuid:(NSString*)guid withFilter:(NSString*)filter;
- (Bookmark*)bookmarkAtIndex:(int)index;
- (Bookmark*)bookmarkAtIndex:(int)index withFilter:(NSString*)filter;
- (void)addBookmark:(Bookmark*)bookmark;
- (void)addBookmark:(Bookmark*)bookmark inSortedOrder:(BOOL)sort;
- (void)removeBookmarkWithGuid:(NSString*)guid;
- (void)removeBookmarksAtIndices:(NSArray*)indices;
- (void)removeBookmarkAtIndex:(int)index;
- (void)removeBookmarkAtIndex:(int)index withFilter:(NSString*)filter;
- (void)setBookmark:(Bookmark*)bookmark atIndex:(int)index;
- (void)setBookmark:(Bookmark*)bookmark withGuid:(NSString*)guid;
- (void)removeAllBookmarks;
- (NSArray*)rawData;
- (void)load:(NSArray*)prefs;
- (Bookmark*)defaultBookmark;
- (Bookmark*)bookmarkWithName:(NSString*)name;
- (Bookmark*)bookmarkWithGuid:(NSString*)guid;
- (int)indexOfBookmarkWithName:(NSString*)name;
- (NSArray*)allTags;
- (BOOL)bookmark:(Bookmark*)bookmark hasTag:(NSString*)tag;
- (Bookmark*)setObject:(id)object forKey:(NSString*)key inBookmark:(Bookmark*)bookmark;
- (void)setDefaultByGuid:(NSString*)guid;
- (void)moveGuid:(NSString*)guid toRow:(int)row;
- (void)rebuildMenus;
// Return the absolute index of a bookmark given its index with the filter applied.
- (int)convertFilteredIndex:(int)theIndex withFilter:(NSString*)filter;
- (void)dump;
- (NSArray*)bookmarks;
- (NSArray*)guids;
- (void)addBookmark:(Bookmark*)b toMenu:(NSMenu*)menu startingAtItem:(int)skip withTags:(NSArray*)tags params:(JournalParams*)params atPos:(int)pos;
// Tell all listeners that the model has changed.
- (void)postChangeNotification;
+ (void)applyJournal:(NSDictionary*)journal
toMenu:(NSMenu*)menu
startingAtItem:(int)skip
params:(JournalParams*)params;
+ (void)applyJournal:(NSDictionary*)journal
toMenu:(NSMenu*)menu
params:(JournalParams*)params;
@end
typedef enum {
JOURNAL_ADD,
JOURNAL_REMOVE,
JOURNAL_REMOVE_ALL,
JOURNAL_SET_DEFAULT
} JournalAction;
@interface BookmarkJournalEntry : NSObject {
@public
JournalAction action;
NSString* guid;
BookmarkModel* model;
// Tags before the action was applied.
NSArray* tags;
int index; // Index of bookmark
}
+ (BookmarkJournalEntry*)journalWithAction:(JournalAction)action
bookmark:(Bookmark*)bookmark
model:(BookmarkModel*)model;
@end