Skip to content
Browse files

slow down jobs timer when not key window. optimize jobs timer if no c…

…hanges. fix cursor after reloading a table view in toolbelt.
  • Loading branch information...
1 parent a906350 commit 72404b8b80a8051ae0e207da2cc7fe998b315499 @gnachman gnachman committed Sep 7, 2011
Showing with 58 additions and 2 deletions.
  1. +47 −2 ToolJobs.m
  2. +11 −0 ToolPasteHistory.m
View
49 ToolJobs.m
@@ -106,17 +106,49 @@ - (id)initWithFrame:(NSRect)frame {
[tableView_ sizeToFit];
[tableView_ setColumnAutoresizingStyle:NSTableViewSequentialColumnAutoresizingStyle];
-
+
timer_ = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateTimer:)
userInfo:nil
- repeats:YES];
+ repeats:YES];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(setSlowTimer)
+ name:NSWindowDidResignMainNotification
+ object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(setFastTimer)
+ name:NSWindowDidBecomeKeyNotification
+ object:nil];
+
[self updateTimer:nil];
}
return self;
}
+// When not key, check much less often to avoid burning the battery.
+- (void)setSlowTimer
+{
+ [timer_ invalidate];
+ timer_ = [NSTimer scheduledTimerWithTimeInterval:10
+ target:self
+ selector:@selector(updateTimer:)
+ userInfo:nil
+ repeats:YES];
+}
+
+- (void)setFastTimer
+{
+ [self updateTimer:nil];
+ [timer_ invalidate];
+ timer_ = [NSTimer scheduledTimerWithTimeInterval:1
+ target:self
+ selector:@selector(updateTimer:)
+ userInfo:nil
+ repeats:YES];
+}
+
- (void)dealloc
{
[signal_ release];
@@ -140,6 +172,10 @@ - (void)updateTimer:(id)sender
ToolWrapper *wrapper = (ToolWrapper *)[[self superview] superview];
pid_t rootPid = [[[wrapper.term currentSession] SHELL] pid];
NSSet *pids = [[ProcessCache sharedInstance] childrenOfPid:rootPid levelsToSkip:0];
+ if ([pids isEqualToSet:[NSSet setWithArray:pids_]]) {
+ // Nothing to do, skip the expensive step of getting names.
+ return;
+ }
[pids_ release];
pids_ = [[[pids allObjects] sortedArrayUsingSelector:@selector(compare:)] retain];
[names_ removeAllObjects];
@@ -153,6 +189,15 @@ - (void)updateTimer:(id)sender
}
}
[tableView_ reloadData];
+
+ // Updating the table data causes the cursor to change into an arrow!
+ [self performSelector:@selector(fixCursor) withObject:nil afterDelay:0];
+}
+
+- (void)fixCursor
+{
+ ToolWrapper *wrapper = (ToolWrapper *)[[self superview] superview];
+ [[[wrapper.term currentSession] TEXTVIEW] updateCursor:[[NSApplication sharedApplication] currentEvent]];
}
- (BOOL)isFlipped
View
11 ToolPasteHistory.m
@@ -9,6 +9,7 @@
#import "ToolPasteHistory.h"
#import "NSDateFormatterExtras.h"
#import "iTermController.h"
+#import "ToolWrapper.h"
@implementation ToolPasteHistory
@@ -114,6 +115,14 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu
- (void)pasteboardHistoryDidChange:(id)sender
{
[tableView_ reloadData];
+ // Updating the table data causes the cursor to change into an arrow!
+ [self performSelector:@selector(fixCursor) withObject:nil afterDelay:0];
+}
+
+- (void)fixCursor
+{
+ ToolWrapper *wrapper = (ToolWrapper *)[[self superview] superview];
+ [[[wrapper.term currentSession] TEXTVIEW] updateCursor:[[NSApplication sharedApplication] currentEvent]];
}
- (void)doubleClickOnTableView:(id)sender
@@ -134,6 +143,8 @@ - (void)clear:(id)sender
[pasteHistory_ eraseHistory];
[pasteHistory_ clear];
[tableView_ reloadData];
+ // Updating the table data causes the cursor to change into an arrow!
+ [self performSelector:@selector(fixCursor) withObject:nil afterDelay:0];
}
@end

0 comments on commit 72404b8

Please sign in to comment.
Something went wrong with that request. Please try again.