Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions SquirrelApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ -(void)rimeNeedsSync:(NSNotification *)aNotification
[self syncUserData:nil];
}

-(void)rimeChangeToAsciiMode:(NSNotification *)aNotification
{
[_panel changeToAscii];
}

-(void)rimeChangeToAsciiModePrev:(NSNotification *)aNotification
{
[_panel changeToAsciiPrev];
}

-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
NSLog(@"Squirrel is quitting.");
Expand Down Expand Up @@ -242,6 +252,14 @@ -(void)awakeFromNib
selector:@selector(rimeNeedsSync:)
name:@"SquirrelSyncNotification"
object:nil];
[notifCenter addObserver:self
selector:@selector(rimeChangeToAsciiMode:)
name:@"SquirrelChangeToAsciiModeNotification"
object:nil];
[notifCenter addObserver:self
selector:@selector(rimeChangeToAsciiModePrev:)
name:@"SquirrelChangeToAsciiModePrevNotification"
object:nil];

}

Expand Down
3 changes: 3 additions & 0 deletions SquirrelInputController.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
@interface SquirrelInputController : IMKInputController
- (BOOL)selectCandidate:(NSInteger)index;
- (BOOL)pageUp:(BOOL)up;
-(void)changeToAscii;
-(void)changeToAsciiPrev;

@end
12 changes: 12 additions & 0 deletions SquirrelInputController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ @implementation SquirrelInputController {
NSTimer *_chordTimer;
NSTimeInterval _chordDuration;
NSString *_currentApp;
NSNumber *_prev;
}

/*!
Expand Down Expand Up @@ -164,6 +165,17 @@ - (BOOL)handleEvent:(NSEvent*)event client:(id)sender

return handled;
}
-(void)changeToAscii {
_prev = [NSNumber numberWithBool:rime_get_api()->get_option(_session, "ascii_mode")];
rime_get_api()->set_option(_session, "ascii_mode", True);
}

-(void)changeToAsciiPrev {
if (_prev) {
rime_get_api()->set_option(_session, "ascii_mode", [_prev boolValue]);
_prev = nil;
}
}

-(BOOL)processKey:(int)rime_keycode modifiers:(int)rime_modifiers
{
Expand Down
3 changes: 3 additions & 0 deletions SquirrelPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@
-(void)loadConfig:(SquirrelConfig*)config
forDarkMode:(BOOL)isDark;

-(void)changeToAscii;
-(void)changeToAsciiPrev;

@end
7 changes: 7 additions & 0 deletions SquirrelPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,13 @@ - (instancetype)init {
}
return self;
}
-(void)changeToAscii {
[self.inputController changeToAscii];
}

-(void)changeToAsciiPrev {
[self.inputController changeToAsciiPrev];
}

- (NSPoint)mousePosition {
NSPoint point = NSEvent.mouseLocation;
Expand Down
25 changes: 20 additions & 5 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ int main(int argc, char *argv[]) {
return 0;
}

if (argc > 1 && !strcmp("--ascii_mode", argv[1])) {
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:@"SquirrelChangeToAsciiModeNotification"
object: nil];
return 0;
}

if (argc > 1 && !strcmp("--ascii_mode_prev", argv[1])) {
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:@"SquirrelChangeToAsciiModePrevNotification"
object: nil];
return 0;
}


@autoreleasepool {
// find the bundle identifier and then initialize the input method server
NSBundle *main = [NSBundle mainBundle];
Expand All @@ -70,19 +85,19 @@ int main(int argc, char *argv[]) {

// load the bundle explicitly because in this case the input method is a
// background only application
[main loadNibNamed:@"MainMenu" owner:[NSApplication sharedApplication] topLevelObjects:NULL];
[main loadNibNamed:@"MainMenu"
owner:[NSApplication sharedApplication]
topLevelObjects:NULL];

// opencc will be configured with relative dictionary paths
[[NSFileManager defaultManager]
changeCurrentDirectoryPath:main.sharedSupportPath];

if (NSApp.squirrelAppDelegate.problematicLaunchDetected) {
NSLog(@"Problematic launch detected!");
NSArray *args = @[
@"Problematic launch detected! \
NSArray *args = @[ @"Problematic launch detected! \
Squirrel may be suffering a crash due to imporper configuration. \
Revert previous modifications to see if the problem recurs."
];
Revert previous modifications to see if the problem recurs." ];
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/say" arguments:args];
} else {
[NSApp.squirrelAppDelegate setupRime];
Expand Down