Skip to content

Loading…

Allow 'current context' to work in AppleScript when multiple contexts are enabled #328

Merged
merged 1 commit into from

2 participants

@waisbrot

Created a currentContextAsString method in CPController. This is called by current context in Applescript, and will either return the currentContextPath (the current behavior) or will join the active contexts into a big string.
The method uses the code from updateMenuBarAndContextMenu, and I refactored that method to call the new one.

Fixes #325, fixes #323

@waisbrot waisbrot Allow the 'current context' AppleScript property to work with multipl…
…e-context

Created a new method 'currentContextAsString' to either fetch from
currentContextPath or compute a string by joining activeContexts.
d9e7923
@dustinrue dustinrue merged commit 204c146 into dustinrue:master
@waisbrot waisbrot deleted the waisbrot:applescript-fix branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 24, 2014
  1. @waisbrot

    Allow the 'current context' AppleScript property to work with multipl…

    waisbrot committed
    …e-context
    
    Created a new method 'currentContextAsString' to either fetch from
    currentContextPath or compute a string by joining activeContexts.
Showing with 16 additions and 4 deletions.
  1. +1 −1 Source/AppleScript.m
  2. +2 −0 Source/CPController.h
  3. +13 −3 Source/CPController.m
View
2 Source/AppleScript.m
@@ -14,7 +14,7 @@ @implementation NSApplication (AppleScript)
// current context property
- (NSString *) currentContext {
- return [[NSApp delegate] currentContextPath];
+ return [[NSApp delegate] currentContextAsString];
}
- (void) setCurrentContext: (NSString*) newContext {
View
2 Source/CPController.h
@@ -41,6 +41,8 @@
- (void)resumeRegularUpdates;
- (void)resumeRegularUpdatesWithDelay:(int64_t)nanoseconds;
- (void)forceUpdate;
+
+- (NSString*)currentContextAsString;
+ (NSSet *) sharedActiveContexts;
@end
View
16 Source/CPController.m
@@ -773,9 +773,7 @@ - (void)updateMenuBarAndContextMenu {
[_joinedContextPaths appendString:context.name]; //[contextsDataSource pathFromRootTo:context.uuid]];
}
self.currentContextPath=_joinedContextPaths;*/
- NSSortDescriptor *sortKey=[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:TRUE];
- NSArray *keyArray=[NSArray arrayWithObject:sortKey];
- self.currentContextPath=[[self.activeContexts sortedArrayUsingDescriptors:keyArray] componentsJoinedByString:@" + "]; // sans context-paths, to conserve space. perhaps we'll add a pref to switch it on (above).
+ self.currentContextPath=[self currentContextAsString];
}
[self setStatusTitle:[self currentContextPath]];
}
@@ -1968,4 +1966,16 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
break;
}
}
+
+- (NSString*) currentContextAsString {
+ if ([self useMultipleActiveContexts]) {
+ NSSortDescriptor *sortKey=[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:TRUE];
+ NSArray *keyArray=[NSArray arrayWithObject:sortKey];
+ NSArray* aca = [self.activeContexts sortedArrayUsingDescriptors:keyArray];
+ NSString* acas = [aca componentsJoinedByString:@" + "];
+ return acas;
+ } else {
+ return self.currentContextPath;
+ }
+}
@end
Something went wrong with that request. Please try again.