Created
November 11, 2014 06:55
-
-
Save frank4565/fab3d6558c29b950116b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a13aeb2446091a9bbd769c164d16b13d7f139ab4 Mon Sep 17 00:00:00 2001 | |
From: Junlu Cheng <[email protected]> | |
Date: Wed, 5 Nov 2014 19:20:34 +0800 | |
Subject: [PATCH] Fixed warnings about [NSApp delegate]. | |
--- | |
SquirrelApplicationDelegate.m | 2 +- | |
SquirrelInputController.m | 28 ++++++++++++++-------------- | |
main.m | 8 ++++---- | |
3 files changed, 19 insertions(+), 19 deletions(-) | |
diff --git a/SquirrelApplicationDelegate.m b/SquirrelApplicationDelegate.m | |
index 0880b68..c8961ef 100644 | |
--- a/SquirrelApplicationDelegate.m | |
+++ b/SquirrelApplicationDelegate.m | |
@@ -95,7 +95,7 @@ static void show_message_notification_center(const char* msg_text, const char* m | |
} | |
static void show_status_message(const char* msg_text, const char* msg_id) { | |
- SquirrelPanel* panel = [[NSApp delegate] panel]; | |
+ SquirrelPanel* panel = [(SquirrelApplicationDelegate *)[NSApp delegate] panel]; | |
if (panel) { | |
[panel updateMessage:NSLocalizedString([NSString stringWithUTF8String:msg_text], nil)]; | |
} | |
diff --git a/SquirrelInputController.m b/SquirrelInputController.m | |
index f9a1e0d..b936aa5 100644 | |
--- a/SquirrelInputController.m | |
+++ b/SquirrelInputController.m | |
@@ -201,7 +201,7 @@ | |
if (_chordTimer && [_chordTimer isValid]) { | |
[_chordTimer invalidate]; | |
} | |
- NSTimeInterval interval = [[NSApp delegate] chordDuration]; | |
+ NSTimeInterval interval = [(SquirrelApplicationDelegate *)[NSApp delegate] chordDuration]; | |
_chordTimer = [NSTimer scheduledTimerWithTimeInterval:interval | |
target:self | |
selector:@selector(onChordTimer:) | |
@@ -231,7 +231,7 @@ | |
-(void)activateServer:(id)sender | |
{ | |
//NSLog(@"activateServer:"); | |
- if ([[NSApp delegate] useUSKeyboardLayout]) { | |
+ if ([(SquirrelApplicationDelegate *)[NSApp delegate] useUSKeyboardLayout]) { | |
[sender overrideKeyboardWithKeyboardNamed:@"com.apple.keylayout.US"]; | |
} | |
_preeditString = @""; | |
@@ -250,7 +250,7 @@ | |
-(void)deactivateServer:(id)sender | |
{ | |
//NSLog(@"deactivateServer:"); | |
- [[[NSApp delegate] panel] hide]; | |
+ [[(SquirrelApplicationDelegate *)[NSApp delegate] panel] hide]; | |
[self commitComposition:sender]; | |
} | |
@@ -283,32 +283,32 @@ | |
// so here we deliver messages to our responsible SquirrelApplicationDelegate | |
-(void)deploy:(id)sender | |
{ | |
- [[NSApp delegate] deploy:sender]; | |
+ [(SquirrelApplicationDelegate *)[NSApp delegate] deploy:sender]; | |
} | |
-(void)syncUserData:(id)sender | |
{ | |
- [[NSApp delegate] syncUserData:sender]; | |
+ [(SquirrelApplicationDelegate *)[NSApp delegate] syncUserData:sender]; | |
} | |
-(void)configure:(id)sender | |
{ | |
- [[NSApp delegate] configure:sender]; | |
+ [(SquirrelApplicationDelegate *)[NSApp delegate] configure:sender]; | |
} | |
-(void)checkForUpdates:(id)sender | |
{ | |
- [[[NSApp delegate] updater] performSelector:@selector(checkForUpdates:) withObject:sender]; | |
+ [[(SquirrelApplicationDelegate *)[NSApp delegate] updater] performSelector:@selector(checkForUpdates:) withObject:sender]; | |
} | |
-(void)openWiki:(id)sender | |
{ | |
- [[NSApp delegate] openWiki:sender]; | |
+ [(SquirrelApplicationDelegate *)[NSApp delegate] openWiki:sender]; | |
} | |
-(NSMenu*)menu | |
{ | |
- return [[NSApp delegate] menu]; | |
+ return [(SquirrelApplicationDelegate *)[NSApp delegate] menu]; | |
} | |
-(NSArray*)candidates:(id)sender | |
@@ -334,7 +334,7 @@ | |
[_preeditString release]; | |
_preeditString = @""; | |
- [[[NSApp delegate] panel] hide]; | |
+ [[(SquirrelApplicationDelegate *)[NSApp delegate] panel] hide]; | |
} | |
-(void)showPreeditString:(NSString*)preedit | |
@@ -387,7 +387,7 @@ | |
_candidates = candidates; | |
NSRect inputPos; | |
[_currentClient attributesForCharacterIndex:0 lineHeightRectangle:&inputPos]; | |
- SquirrelPanel* panel = [[NSApp delegate] panel]; | |
+ SquirrelPanel* panel = [(SquirrelApplicationDelegate *)[NSApp delegate] panel]; | |
[panel updatePosition:inputPos]; | |
[panel updatePreedit:preedit | |
withSelRange:selRange | |
@@ -414,7 +414,7 @@ | |
_schemaId = nil; | |
// optionally, set app specific options | |
- NSDictionary* appOptions = [[NSApp delegate] appOptions]; | |
+ NSDictionary* appOptions = [(SquirrelApplicationDelegate *)[NSApp delegate] appOptions]; | |
NSDictionary* options = [appOptions objectForKey:app]; | |
if (options) { | |
for (NSString* key in options) { | |
@@ -450,7 +450,7 @@ | |
-(void)loadSchemaSpecificSettings:(NSString*)schemaId { | |
RimeConfig config; | |
if (RimeSchemaOpen([schemaId UTF8String], &config)) { | |
- [[NSApp delegate] updateUIStyle:&config initialize:NO]; | |
+ [(SquirrelApplicationDelegate *)[NSApp delegate] updateUIStyle:&config initialize:NO]; | |
RimeConfigClose(&config); | |
} | |
} | |
@@ -468,7 +468,7 @@ | |
_schemaId = [[NSString alloc] initWithUTF8String:status.schema_id]; | |
[self loadSchemaSpecificSettings:_schemaId]; | |
// inline preedit | |
- _inlinePreedit = [[[NSApp delegate] panel] inlinePreedit] && | |
+ _inlinePreedit = [[(SquirrelApplicationDelegate *)[NSApp delegate] panel] inlinePreedit] && | |
!RimeGetOption(_session, "no_inline") && // not disabled in app options | |
![_schemaId isEqualToString:@".default"]; // not in switcher where app options are not accessible | |
// if not inline, embed soft cursor in preedit string | |
diff --git a/main.m b/main.m | |
index 988f621..876fa1c 100644 | |
--- a/main.m | |
+++ b/main.m | |
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) | |
// opencc will be configured with relative dictionary paths | |
[[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] sharedSupportPath]]; | |
- if ([[NSApp delegate] problematicLaunchDetected]) { | |
+ if ([(SquirrelApplicationDelegate *)[NSApp delegate] problematicLaunchDetected]) { | |
NSLog(@"Problematic launch detected!"); | |
NSArray* args = [NSArray arrayWithObjects:@"Problematic launch detected! \ | |
Squirrel may be suffering a crash due to imporper configuration. \ | |
@@ -72,9 +72,9 @@ int main(int argc, char *argv[]) | |
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/say" arguments:args]; | |
} | |
else { | |
- [[NSApp delegate] setupRime]; | |
- [[NSApp delegate] startRimeWithFullCheck:NO]; | |
- [[NSApp delegate] loadSquirrelConfig]; | |
+ [(SquirrelApplicationDelegate *)[NSApp delegate] setupRime]; | |
+ [(SquirrelApplicationDelegate *)[NSApp delegate] startRimeWithFullCheck:NO]; | |
+ [(SquirrelApplicationDelegate *)[NSApp delegate] loadSquirrelConfig]; | |
NSLog(@"Squirrel reporting!"); | |
} | |
-- | |
1.8.4.2 | |
From 613a5917aa439bfb877ce6fdb47722239ee97187 Mon Sep 17 00:00:00 2001 | |
From: Junlu Cheng <[email protected]> | |
Date: Wed, 5 Nov 2014 19:21:08 +0800 | |
Subject: [PATCH] Fixed app_options not working in OS X 10.10 Yosemite. | |
--- | |
SquirrelInputController.m | 5 +---- | |
1 file changed, 1 insertion(+), 4 deletions(-) | |
diff --git a/SquirrelInputController.m b/SquirrelInputController.m | |
index b936aa5..e22cb4f 100644 | |
--- a/SquirrelInputController.m | |
+++ b/SquirrelInputController.m | |
@@ -240,10 +240,7 @@ | |
-(id)initWithServer:(IMKServer*)server delegate:(id)delegate client:(id)inputClient | |
{ | |
//NSLog(@"initWithServer:delegate:client:"); | |
- if (self = [super initWithServer:server delegate:delegate client:inputClient]) { | |
- _currentClient = inputClient; | |
- [self createSession]; | |
- } | |
+ self = [super initWithServer:server delegate:delegate client:inputClient]; | |
return self; | |
} | |
-- | |
1.8.4.2 | |
From 480e58daf7eae00609b2c30ba5f61b04a0f29058 Mon Sep 17 00:00:00 2001 | |
From: Junlu Cheng <[email protected]> | |
Date: Tue, 11 Nov 2014 14:48:03 +0800 | |
Subject: [PATCH] Add _currentApp to store last app for app_options. | |
--- | |
SquirrelInputController.h | 1 + | |
SquirrelInputController.m | 32 ++++++++++++++++++++++++++++---- | |
2 files changed, 29 insertions(+), 4 deletions(-) | |
diff --git a/SquirrelInputController.h b/SquirrelInputController.h | |
index 36ad692..840a4a6 100644 | |
--- a/SquirrelInputController.h | |
+++ b/SquirrelInputController.h | |
@@ -17,6 +17,7 @@ | |
// for chord-typing | |
char _chord[128]; | |
NSTimer *_chordTimer; | |
+ NSString *_currentApp; | |
} | |
-(void)commitString:(NSString*)string; | |
diff --git a/SquirrelInputController.m b/SquirrelInputController.m | |
index e22cb4f..60a7f5e 100644 | |
--- a/SquirrelInputController.m | |
+++ b/SquirrelInputController.m | |
@@ -12,6 +12,7 @@ | |
-(void)destroySession; | |
-(void)rimeConsumeCommittedText; | |
-(void)rimeUpdate; | |
+-(void)updateAppOptions; | |
@end | |
// implementation of the public interface | |
@@ -29,10 +30,10 @@ | |
// system will not deliver a key down event to the application. | |
// Returning NO means the original key down will be passed on to the client. | |
- //NSLog(@"handleEvent:client:"); | |
+// NSLog(@"handleEvent:client:"); | |
_currentClient = sender; | |
- | |
+ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
if (!_session || !RimeFindSession(_session)) { | |
@@ -42,6 +43,15 @@ | |
return NO; | |
} | |
} | |
+ | |
+ NSString *app = [_currentClient bundleIdentifier]; | |
+// NSLog(@"app = %@", app); | |
+// NSLog(@"_currentApp = %@", _currentApp); | |
+ | |
+ if (![_currentApp isEqualToString:app]) { | |
+ _currentApp = [app copy]; | |
+ [self updateAppOptions]; | |
+ } | |
BOOL handled = NO; | |
NSUInteger modifiers = [event modifierFlags]; | |
@@ -240,7 +250,10 @@ | |
-(id)initWithServer:(IMKServer*)server delegate:(id)delegate client:(id)inputClient | |
{ | |
//NSLog(@"initWithServer:delegate:client:"); | |
- self = [super initWithServer:server delegate:delegate client:inputClient]; | |
+ if (self = [super initWithServer:server delegate:delegate client:inputClient]) { | |
+ _currentClient = inputClient; | |
+ [self createSession]; | |
+ } | |
return self; | |
} | |
@@ -319,6 +332,7 @@ | |
[_preeditString release]; | |
[_candidates release]; | |
[_schemaId release]; | |
+ [_currentApp release]; | |
[super dealloc]; | |
} | |
@@ -405,14 +419,24 @@ | |
{ | |
NSString* app = [_currentClient bundleIdentifier]; | |
NSLog(@"createSession: %@", app); | |
+ _currentApp = [app copy]; | |
_session = RimeCreateSession(); | |
[_schemaId release]; | |
_schemaId = nil; | |
+ if (_session) { | |
+ [self updateAppOptions]; | |
+ } | |
+} | |
+ | |
+-(void)updateAppOptions | |
+{ | |
+ if (!_currentApp) return; | |
+ NSLog(@"setAppOptions: %@", _currentApp); | |
// optionally, set app specific options | |
NSDictionary* appOptions = [(SquirrelApplicationDelegate *)[NSApp delegate] appOptions]; | |
- NSDictionary* options = [appOptions objectForKey:app]; | |
+ NSDictionary* options = [appOptions objectForKey:_currentApp]; | |
if (options) { | |
for (NSString* key in options) { | |
NSNumber* value = [options objectForKey:key]; | |
-- | |
1.8.4.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment