|
5 | 5 | @interface SSYReplacePredicateCheckbox ()
|
6 | 6 |
|
7 | 7 | @property (assign) CGFloat lastSuperWidth ;
|
| 8 | +@property (copy) NSString* attributeKey ; |
8 | 9 |
|
9 | 10 | @end
|
10 | 11 |
|
@@ -67,18 +68,49 @@ - (void)trackSuperview {
|
67 | 68 | }
|
68 | 69 | #endif
|
69 | 70 |
|
| 71 | +/*! |
| 72 | + @details This method is a kludge. I tried to do it the proper way, which is |
| 73 | + to look at the -representedObject of the menu items. Unfortunately, that is |
| 74 | + an undocumented NSDictionary. Then I tried to add tags of value equal to the |
| 75 | + to NSPredicateOperatorType value, in -[StarkPredicateEditor templates]. That |
| 76 | + didn't work because the popup menu in the view is a |
| 77 | + NSRuleEditorPopupButton which is apparently copied by Cocoa from the |
| 78 | + NSPopUpButton seen in the -templates method, but when Cocoa copies it, it |
| 79 | + apparently does not copy the tag because the tags in these copies are all 0. |
| 80 | + So, finally I settled on this kludge which is to compare the, eek, menu titles. |
| 81 | + It is reliable because I defined localizedRegexMenuItemTitle and use it to both |
| 82 | + make the menu and, then in here, to do the comparison and, or course, it would |
| 83 | + be a programming error if two menu items had the same title :) But it's still |
| 84 | + a code-smelly way to identify a menu item. */ |
| 85 | +- (BOOL)isRegex { |
| 86 | + NSPopUpButton* operatorPopup = nil ; |
| 87 | + for (NSView* sibling in self.superview.subviews) { |
| 88 | + if ([sibling isKindOfClass:[NSPopUpButton class]]) { |
| 89 | + if (sibling.frame.origin.x >= operatorPopup.frame.origin.x) { |
| 90 | + operatorPopup = (NSPopUpButton*)sibling ; |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + NSString* selectedTitle = operatorPopup.selectedItem.title ; |
| 96 | + BOOL isRegex = ([selectedTitle isEqualToString:[SSYReplacePredicateEditorRowTemplate localizedRegexMenuItemTitle]]) ; |
| 97 | + |
| 98 | + return isRegex ; |
| 99 | +} |
| 100 | + |
| 101 | + |
70 | 102 | @end
|
71 | 103 |
|
72 | 104 | @implementation SSYReplacePredicateEditorRowTemplate
|
73 | 105 |
|
74 | 106 | /* Superclass NSPredicateEditorRowTemplate must conform to NSCopying because,
|
75 |
| - as the name implies, this is a *template*. Cocoa makes a copy whenever |
76 |
| - it needs another one. */ |
| 107 | + as the name implies, this is a *template*. For some reason, Cocoa makes a copy |
| 108 | + whenever it needs another one, and then of course, I guess, it makes a view |
| 109 | + (NSView) from that. */ |
77 | 110 | - (SSYReplacePredicateEditorRowTemplate*)copyWithZone:(NSZone*)zone {
|
78 | 111 | SSYReplacePredicateEditorRowTemplate* copy = [super copyWithZone:zone] ;
|
79 | 112 | copy.replacer = self.replacer ;
|
80 | 113 | copy.attributeKey = self.attributeKey ;
|
81 |
| - /*SSYDBL*/ NSLog(@"Made copy: %@ with ak=%@", copy, copy.attributeKey ) ; |
82 | 114 | return copy ;
|
83 | 115 | }
|
84 | 116 |
|
@@ -138,4 +170,8 @@ + (NSString*)anyEditableStringValueInView:(NSView*)view {
|
138 | 170 | return answer ;
|
139 | 171 | }
|
140 | 172 |
|
| 173 | ++ (NSString*)localizedRegexMenuItemTitle { |
| 174 | + return NSLocalizedString(@"Regular Expression (grep)", nil) ; |
| 175 | +} |
| 176 | + |
141 | 177 | @end
|
0 commit comments