Skip to content
This repository

Keep icons current in the UI #1200

Merged
merged 7 commits into from over 1 year ago

3 participants

Rob McBroom Patrick Robertson Etienne Samson
Rob McBroom
Owner

I took the resultIcons branch from #1190 and rebased it to get rid of unused commits and squash some that should have gone together.

The one change in addition to what was on that branch (prior to KVO) is that I've told QSSearchObjectView to only watch for notifications from the selected objects (instead of it having to deal with all of them).

@tiennou - This means the updateIcon: method is back in, if you want to use it in the Keychain plug-in.

added some commits October 30, 2012
Rob McBroom add some styles for definition lists in documentation 14ec29b
Rob McBroom update views when icons finish loading
Instead of the interface controller getting these notifications and trying to figure out where to send them, just let the QSSearchObjectView and QSResultController take care of their own changes. Icons should now appear correctly in the pane, the results list and the child results list (if enabled).
aa47320
Rob McBroom when loading icons, only redraw the row that changed d38ab61
Rob McBroom remove the one-line rowModified method 59f1503
Rob McBroom add a method that takes care of setting an icon and notifying the UI 5409776
Rob McBroom update icon for a proxy object when the object it refers to is updated ad8e4fe
Rob McBroom register for QSObjectIconModified notification only on the selected o…
…bject

This prevents QSSearchObjectView from having to process dozens of irrelevant notifications.
7538401
Patrick Robertson
Owner

@tiennou would you mind chiming in just to make sure you're happy with going back to NSNotifications? :)

Etienne Samson
Owner

No problem for me, if it works better that way. I'll try to remember that there are still some fishy things in there (e.g. I don't like the unused return values and the different meaning they might have).

Patrick Robertson
Owner

Great, merci Etienne :)

btw Rob - there seems to be a tiny merge conflict (I think) with file-uti branch, but nothing to worry about

Rob McBroom
Owner

Yes, there is. The one that has updateIcon: wins. (This one.)

Patrick Robertson pjrobertson merged commit c17f2c1 into from November 11, 2012
Patrick Robertson pjrobertson closed this November 11, 2012
Patrick Robertson pjrobertson referenced this pull request from a commit November 13, 2012
Patrick Robertson Merge branch 'file-uti' of git://github.com/skurfer/Quicksilver into …
…file-uti

Conflicts:
	Quicksilver/Code-QuickStepCore/QSObject_FileHandling.m
	Conflict with pull #1200
34129b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 7 unique commits by 1 author.

Oct 30, 2012
Rob McBroom add some styles for definition lists in documentation 14ec29b
Nov 08, 2012
Rob McBroom update views when icons finish loading
Instead of the interface controller getting these notifications and trying to figure out where to send them, just let the QSSearchObjectView and QSResultController take care of their own changes. Icons should now appear correctly in the pane, the results list and the child results list (if enabled).
aa47320
Rob McBroom when loading icons, only redraw the row that changed d38ab61
Rob McBroom remove the one-line rowModified method 59f1503
Rob McBroom add a method that takes care of setting an icon and notifying the UI 5409776
Rob McBroom update icon for a proxy object when the object it refers to is updated ad8e4fe
Rob McBroom register for QSObjectIconModified notification only on the selected o…
…bject

This prevents QSSearchObjectView from having to process dozens of irrelevant notifications.
7538401
This page is out of date. Refresh to see the latest.
3  Quicksilver/Code-QuickStepCore/QSObject.h
@@ -144,7 +144,8 @@ extern NSSize QSMaxIconSize;
144 144
 - (BOOL)loadIcon;
145 145
 - (BOOL)unloadIcon;
146 146
 - (NSImage *)icon;
147  
-- (void)setIcon:(NSImage *)newIcon ;
  147
+- (void)setIcon:(NSImage *)newIcon;
  148
+- (void)updateIcon:(NSImage *)newIcon;
148 149
 @end
149 150
 
150 151
 @interface QSObject (Hierarchy)
7  Quicksilver/Code-QuickStepCore/QSObject.m
@@ -1000,7 +1000,12 @@ - (void)setIcon:(NSImage *)newIcon {
1000 1000
 		icon = [newIcon retain];
1001 1001
 		[icon setCacheMode:NSImageCacheNever];
1002 1002
 	}
1003  
-    
  1003
+}
  1004
+
  1005
+- (void)updateIcon:(NSImage *)newIcon
  1006
+{
  1007
+    [self setIcon:newIcon];
  1008
+    [[NSNotificationCenter defaultCenter] postNotificationName:QSObjectIconModified object:self];
1004 1009
 }
1005 1010
 @end
1006 1011
 
3  Quicksilver/Code-QuickStepCore/QSObject_FileHandling.m
@@ -317,8 +317,7 @@ -(void)previewIcon:(id)object {
317 317
 	
318 318
 	theImage = [self prepareImageforIcon:theImage];
319 319
 	
320  
-	[object setIcon:theImage];
321  
-	[[NSNotificationCenter defaultCenter] postNotificationName:QSObjectIconModified object:object];
  320
+	[object updateIcon:theImage];
322 321
 }
323 322
 
324 323
 -(NSImage *)prepareImageforIcon:(NSImage *)theImage {
4  Quicksilver/Code-QuickStepCore/QSObject_URLHandling.m
@@ -99,9 +99,7 @@ - (void)buildWebSearchIconForObject:(QSObject *)object {
99 99
     
100 100
     [webSearchImage setName:@"Web Search Icon"];
101 101
 
102  
-    [object setIcon:webSearchImage];
103  
-    [[NSNotificationCenter defaultCenter] postNotificationName:QSObjectIconModified object:object];
104  
-
  102
+    [object updateIcon:webSearchImage];
105 103
 }
106 104
 
107 105
 #pragma mark image handling
2  Quicksilver/Code-QuickStepCore/QSProxyObject.h
@@ -39,7 +39,7 @@
39 39
 - (BOOL)bypassValidation;
40 40
 - (NSArray *)proxyTypes;
41 41
 //- (id)proxyObjectWithProviderClass:(NSString *)providerClass;
42  
-
  42
+- (void)objectIconModified:(NSNotification *)notif;
43 43
 @end
44 44
 
45 45
 
11  Quicksilver/Code-QuickStepCore/QSProxyObject.m
@@ -68,8 +68,10 @@ - (QSObject*)proxyObject {
68 68
     if ([self isEqual:proxy]) return nil;
69 69
     
70 70
     //NSLog(@"Proxy: %@", proxy);
71  
-    if (proxy)
  71
+    if (proxy) {
72 72
         [self setObject:proxy forCache:QSProxyTargetCache];
  73
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectIconModified:) name:QSObjectIconModified object:proxy];
  74
+    }
73 75
     
74 76
     NSTimeInterval interval = 3.0f;
75 77
     
@@ -83,6 +85,7 @@ - (QSObject*)proxyObject {
83 85
 
84 86
 - (void)releaseProxy {
85 87
 	//NSLog(@"release proxy");
  88
+    [[NSNotificationCenter defaultCenter] removeObserver:self name:QSObjectIconModified object:[cache objectForKey:QSProxyTargetCache]];
86 89
 	[cache removeObjectForKey:QSProxyTargetCache];
87 90
 }
88 91
 
@@ -134,4 +137,8 @@ - (NSMethodSignature*)methodSignatureForSelector:(SEL)sel {
134 137
 	return [[self resolvedObject] methodSignatureForSelector:sel];
135 138
 }
136 139
 
137  
-@end
  140
+- (void)objectIconModified:(NSNotification *)notif
  141
+{
  142
+    [self updateIcon:[[self proxyObject] icon]];
  143
+}
  144
+@end
1  Quicksilver/Code-QuickStepInterface/QSInterfaceController.h
@@ -77,7 +77,6 @@
77 77
 - (void)executePartialCommand:(NSArray *)array;
78 78
 
79 79
 - (void)objectModified:(NSNotification *)notif;
80  
-- (void)objectIconModified:(NSNotification *)notif;
81 80
 
82 81
 - (void)searchObjectChanged:(NSNotification*)notif;
83 82
 
14  Quicksilver/Code-QuickStepInterface/QSInterfaceController.m
@@ -72,7 +72,6 @@ - (id)initWithWindow:(NSWindow *)window {
72 72
 	[nc addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:self];
73 73
 	[nc addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:self];
74 74
 	[nc addObserver:self selector:@selector(objectModified:) name:QSObjectModified object:nil];
75  
-	[nc addObserver:self selector:@selector(objectIconModified:) name:QSObjectIconModified object:nil];
76 75
 	[nc addObserver:self selector:@selector(searchObjectChanged:) name:@"SearchObjectChanged" object:nil];
77 76
 	[nc addObserver:self selector:@selector(sourceArrayCreated:) name:@"QSSourceArrayCreated" object:nil];
78 77
 	[nc addObserver:self selector:@selector(sourceArrayChanged:) name:@"QSSourceArrayUpdated" object:nil];
@@ -430,19 +429,6 @@ - (void)objectModified:(NSNotification*)notif {
430 429
 	}
431 430
 }
432 431
 
433  
-- (void)objectIconModified:(NSNotification *)notif {
434  
-	QSObject *object = [notif object];
435  
-	if ([[dSelector objectValue] isEqual:object]) {
436  
-		// redraw dObject icon
437  
-		[dSelector updateObject:object];
438  
-	}
439  
-	if ([[iSelector objectValue] isEqual:object]) {
440  
-		// redraw iObject icon
441  
-		[iSelector updateObject:object];
442  
-	}
443  
-	
444  
-}
445  
-
446 432
 - (void)searchObjectChanged:(NSNotification*)notif {
447 433
 	[[self window] disableFlushWindow];
448 434
 	if ([notif object] == dSelector) {
3  Quicksilver/Code-QuickStepInterface/QSResultController.h
@@ -107,8 +107,7 @@
107 107
 
108 108
 - (QSIconLoader *)resultChildIconLoader;
109 109
 - (void)setResultChildIconLoader:(QSIconLoader *)aResultChildIconLoader;
110  
-
111  
--(void)rowModified:(NSInteger)index;
  110
+- (void)objectIconModified:(NSNotification *)notif;
112 111
 /*!
113 112
  sortByName
114 113
  @abstract   Sets the results view to show the 'Sort by Name' search mode is activated
37  Quicksilver/Code-QuickStepInterface/QSResultController.m
@@ -80,6 +80,7 @@ - (id)init {
80 80
 		selectedItem = nil;
81 81
 		loadingRange = NSMakeRange(0, 0);
82 82
 		scrollViewTrackingRect = 0;
  83
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectIconModified:) name:QSObjectIconModified object:nil];
83 84
 	}
84 85
 	return self;
85 86
 }
@@ -251,10 +252,6 @@ - (void)loadChildren {
251 252
 	[resultChildTable reloadData];
252 253
 }
253 254
 
254  
--(void)rowModified:(NSInteger)index {
255  
-	[resultTable setNeedsDisplayInRect:[resultTable rectOfRow:index]];
256  
-}
257  
-
258 255
 /*- (void)setSplitLocation {
259 256
 	NSNumber *resultWidth = [[NSUserDefaults standardUserDefaults] objectForKey:kResultTableSplit];
260 257
     
@@ -281,18 +278,11 @@ -(void)rowModified:(NSInteger)index {
281 278
 #pragma mark Icon Loading
282 279
 
283 280
 - (void)iconLoader:(QSIconLoader *)loader loadedIndex:(NSInteger)m inArray:(NSArray *)array {
284  
-	//	NSLog(@"loaded");
285  
-	NSTableView *table = nil;
286 281
 	if (loader == resultIconLoader) {
287  
-		table = resultTable;
288  
-		if (m == [resultTable selectedRow])
289  
-            [focus setNeedsDisplay:YES];
  282
+        [resultTable setNeedsDisplayInRect:[resultTable rectOfRow:m]];
290 283
 	} else if (loader == resultChildIconLoader) {
291  
-		table = resultChildTable;
292  
-	} else {
293  
-		//NSLog(@"RogueLoader %d", m);
  284
+        [resultChildTable setNeedsDisplayInRect:[resultChildTable rectOfRow:m]];
294 285
 	}
295  
-	[table setNeedsDisplay:YES];
296 286
 }
297 287
 
298 288
 - (BOOL)iconsAreLoading {
@@ -332,6 +322,27 @@ - (void)setResultChildIconLoader:(QSIconLoader *)aResultChildIconLoader {
332 322
 		resultChildIconLoader = [aResultChildIconLoader retain];
333 323
 	}
334 324
 }
  325
+
  326
+- (void)objectIconModified:(NSNotification *)notif
  327
+{
  328
+    // if results are showing, check for icons that need updating
  329
+    if ([[self window] isVisible]) {
  330
+        QSObject *object = [notif object];
  331
+        // if updated object is is in the results, update it in the list
  332
+        NSUInteger ind = [currentResults indexOfObject:object];
  333
+        if (ind != NSNotFound) {
  334
+            [resultTable setNeedsDisplayInRect:[resultTable rectOfRow:ind]];
  335
+        }
  336
+        // if updated object is is in the child results, update it in the list
  337
+        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QSResultsShowChildren"]) {
  338
+            ind = [[[self selectedItem] children] indexOfObject:object];
  339
+            if (ind != NSNotFound) {
  340
+                [resultChildTable setNeedsDisplayInRect:[resultChildTable rectOfRow:ind]];
  341
+            }
  342
+        }
  343
+    }
  344
+}
  345
+
335 346
 #pragma mark -
336 347
 #pragma mark Actions
337 348
 - (IBAction)defineMnemonic:(id)sender {
3  Quicksilver/Code-QuickStepInterface/QSSearchObjectView.h
@@ -121,6 +121,7 @@ typedef enum QSSearchMode {
121 121
 - (IBAction)toggleResultView:sender;
122 122
 - (void)selectIndex:(NSInteger)index;
123 123
 - (void)selectObject:(QSBasicObject *)obj;
  124
+- (void)objectIconModified:(NSNotification *)notif;
124 125
 - (void)resetString;
125 126
 - (IBAction)defineMnemonic:(id)sender;
126 127
 - (void)saveMnemonic;
@@ -202,8 +203,6 @@ typedef enum QSSearchMode {
202 203
 - (BOOL)handleSlashEvent:(NSEvent *)theEvent;
203 204
 - (BOOL)handleTildeEvent:(NSEvent *)theEvent;
204 205
 - (BOOL)handleRepeaterEvent:(NSEvent *)theEvent;
205  
-
206  
-- (void)updateObject:(QSObject *)object;
207 206
 @end
208 207
 
209 208
 
29  Quicksilver/Code-QuickStepInterface/QSSearchObjectView.m
@@ -570,8 +570,10 @@ - (void)selectObjectValue:(QSObject *)newObject {
570 570
     }
571 571
     // if the two objects are not the same, send an 'object chagned' notif
572 572
 	if (newObject != currentObject) {
  573
+        [[NSNotificationCenter defaultCenter] removeObserver:self name:QSObjectIconModified object:currentObject];
  574
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectIconModified:) name:QSObjectIconModified object:newObject];
573 575
 		[super setObjectValue:newObject];
574  
-            [[NSNotificationCenter defaultCenter] postNotificationName:@"SearchObjectChanged" object:self];
  576
+        [[NSNotificationCenter defaultCenter] postNotificationName:@"SearchObjectChanged" object:self];
575 577
 	}
576 578
 }
577 579
 
@@ -645,6 +647,11 @@ - (void)selectObject:(QSBasicObject *)obj {
645 647
 	[self selectIndex:index];
646 648
 }
647 649
 
  650
+- (void)objectIconModified:(NSNotification *)notif {
  651
+    // icon changed - update it in the pane
  652
+    [self setNeedsDisplay:YES];
  653
+}
  654
+
648 655
 #pragma mark -
649 656
 #pragma mark Utilities
650 657
 - (id)externalSelection {
@@ -1560,26 +1567,6 @@ - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { return 0; }
1560 1567
 - (NSArray *)validAttributesForMarkedText {
1561 1568
 	return [NSArray array];
1562 1569
 }
1563  
-
1564  
-- (void)updateObject:(QSObject *)object {
1565  
-	// find index of object in the resultlist
1566  
-	NSUInteger ind = [resultArray indexOfObject:object];
1567  
-	NSUInteger count = [resultArray count];
1568  
-	// for cases where there's only 1 object in the results, it's not always selected
1569  
-	if (ind == NSNotFound && count != 1) {
1570  
-		return;
1571  
-	}
1572  
-	
1573  
-	// if object is the currently active object, update it in the pane
1574  
-	if ((ind == selection) || (count == 1)) {
1575  
-		[self setNeedsDisplay:YES];
1576  
-	}
1577  
-	
1578  
-	// update it in the resultlist
1579  
-	if ([[resultController window] isVisible]) {
1580  
-		[resultController rowModified:ind];
1581  
-	}
1582  
-}
1583 1570
 @end
1584 1571
 
1585 1572
 @implementation QSSearchObjectView (History)
12  Quicksilver/Resources/QSStyle.css
@@ -34,3 +34,15 @@ td, th {
34 34
   padding: 0.25em 0.5em;
35 35
   border: 1px solid #EDEDED;
36 36
 }
  37
+dd {
  38
+  margin: 0.25em 0 1em 2em;
  39
+}
  40
+dt {
  41
+  font-weight: bold;
  42
+}
  43
+dd p {
  44
+  margin-top: 0px;
  45
+}
  46
+dd pre {
  47
+  margin: 1em 0px;
  48
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.