forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Popup.h
156 lines (124 loc) · 4.36 KB
/
Popup.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// Popup.h
// iTerm
//
// Created by George Nachman on 11/4/10.
// Copyright 2010 George Nachman. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "PTYSession.h"
@interface PopupWindow : NSWindow {
NSWindow* parentWindow_;
BOOL shutdown_;
}
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)aStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)flag;
- (void)setParentWindow:(NSWindow*)parentWindow;
- (BOOL)canBecomeKeyWindow;
- (void)keyDown:(NSEvent *)event;
- (void)shutdown;
@end
@interface PopupEntry : NSObject
{
NSString* s_;
NSString* prefix_;
double score_;
double hitMultiplier_;
}
+ (PopupEntry*)entryWithString:(NSString*)s score:(double)score;
- (void)setMainValue:(NSString*)s;
- (void)setScore:(double)score;
- (void)setPrefix:(NSString*)prefix;
- (NSString*)prefix;
- (NSString*)mainValue;
- (double)score;
- (BOOL)isEqual:(id)o;
- (NSComparisonResult)compare:(id)otherObject;
// Update the hit multiplier for a new hit and return its new value
- (double)advanceHitMult;
@end
@interface PopupModel : NSObject
{
@private
NSMutableArray* values_;
int maxEntries_;
}
- (id)init;
- (id)initWithMaxEntries:(int)maxEntries;
- (void)dealloc;
- (NSUInteger)count;
- (void)removeAllObjects;
- (void)addObject:(id)object;
- (void)addHit:(PopupEntry*)object;
- (id)objectAtIndex:(NSUInteger)index;
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
- (NSUInteger)indexOfObject:(id)o;
- (void)sortByScore;
- (int)indexOfObjectWithMainValue:(NSString*)value;
@end
@interface Popup : NSWindowController {
@private
// Backing session.
PTYSession* session_;
// Subclass-owned tableview.
NSTableView* tableView_;
// Results currently being displayed.
PopupModel* model_;
// All candidate results, including those not matching filter. Subclass-owend.
PopupModel* unfilteredModel_;
// Timer to set clearFilterOnNextKeyDown_.
NSTimer* timer_;
// If set, then next time a key is pressed erase substring_ before appending.
BOOL clearFilterOnNextKeyDown_;
// What the user has typed so far to filter result set.
NSMutableString* substring_;
// If true then window is above cursor.
BOOL onTop_;
// Set to true when the user changes the selected row.
BOOL haveChangedSelection_;
// String that the user has selected.
NSMutableString* selectionMainValue_;
// True while reloading data.
BOOL reloading_;
}
- (id)initWithWindowNibName:(NSString*)nibName tablePtr:(NSTableView**)table model:(PopupModel*)model;
- (void)dealloc;
// Turn off focus follows mouse while this window is key.
- (BOOL)disableFocusFollowsMouse;
// Called by clients to open window.
- (void)popInSession:(PTYSession*)session;
// Safely shut down the popup when the parent is about to be dealloced. Clients must call this from
// dealloc. It removes possible pending timers.
- (void)shutdown;
// Subclasses may override these methods.
// Begin populating the unfiltered model.
- (void)refresh;
// Notify that a row was selected. Call this method when subclass has accepted
// the selection.
- (void)rowSelected:(id)sender;
// Handle key presses.
- (void)keyDown:(NSEvent*)event;
// Window is closing. Call this method when subclass is done.
- (void)onClose;
// Window is opening. -[refresh] will be called immediately after this returns.
- (void)onOpen;
// Get a value for a table cell. Always returns a value from the model.
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex;
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification;
- (void)setSession:(PTYSession*)session;
- (void)setOnTop:(BOOL)onTop;
- (PTYSession*)session;
- (PopupModel*)unfilteredModel;
- (PopupModel*)model;
- (void)setPosition:(BOOL)canChangeSide;
- (void)reloadData:(BOOL)canChangeSide;
- (void)_setClearFilterOnNextKeyDownFlag:(id)sender;
- (int)convertIndex:(int)i;
- (NSAttributedString*)attributedStringForEntry:(PopupEntry*)entry isSelected:(BOOL)isSelected;
- (void)windowDidResignKey:(NSNotification *)aNotification;
- (void)windowDidBecomeKey:(NSNotification *)aNotification;
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView;
- (BOOL)_word:(NSString*)temp matchesFilter:(NSString*)filter;
@end