Skip to content

Commit

Permalink
show web ui for preference config: user can toggle the translation an…
Browse files Browse the repository at this point in the history
…notation.
  • Loading branch information
dongyuwei committed Sep 20, 2017
1 parent 491a757 commit 1dd0415
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 107 deletions.
8 changes: 0 additions & 8 deletions hallelujah.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
0DE74BFE1978EC6A00040F3C /* him.png in Resources */ = {isa = PBXBuildFile; fileRef = 0DE74BFD1978EC6A00040F3C /* him.png */; };
0DE74C001978F18E00040F3C /* him.icns in Resources */ = {isa = PBXBuildFile; fileRef = 0DE74BFF1978F18E00040F3C /* him.icns */; };
389468CB1F56A34A00EF1F5E /* web in Resources */ = {isa = PBXBuildFile; fileRef = 389468CA1F56A34A00EF1F5E /* web */; };
389468CD1F57BC4D00EF1F5E /* preferences.nib in Resources */ = {isa = PBXBuildFile; fileRef = 389468CC1F57BC4D00EF1F5E /* preferences.nib */; };
389468CF1F57BC5B00EF1F5E /* preferences.plist in Resources */ = {isa = PBXBuildFile; fileRef = 389468CE1F57BC5B00EF1F5E /* preferences.plist */; };
389468D61F57C8CE00EF1F5E /* InputApplicationDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 389468D51F57C8CE00EF1F5E /* InputApplicationDelegate.m */; };
38DD401A1F5800A400A276CB /* PreferencesMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 38DD40191F5800A400A276CB /* PreferencesMenu.xib */; };
56DAA2D1B676B02B33021777 /* libPods-hallelujah.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 83B7001F97014A6184CCEDD3 /* libPods-hallelujah.a */; };
Expand Down Expand Up @@ -42,8 +40,6 @@
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
389468CA1F56A34A00EF1F5E /* web */ = {isa = PBXFileReference; lastKnownFileType = folder; path = web; sourceTree = "<group>"; };
389468CC1F57BC4D00EF1F5E /* preferences.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = preferences.nib; sourceTree = "<group>"; };
389468CE1F57BC5B00EF1F5E /* preferences.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = preferences.plist; sourceTree = "<group>"; };
389468D41F57C8CE00EF1F5E /* InputApplicationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = InputApplicationDelegate.h; path = src/InputApplicationDelegate.h; sourceTree = "<group>"; };
389468D51F57C8CE00EF1F5E /* InputApplicationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InputApplicationDelegate.m; path = src/InputApplicationDelegate.m; sourceTree = "<group>"; };
38DD40191F5800A400A276CB /* PreferencesMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PreferencesMenu.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -133,9 +129,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
389468CC1F57BC4D00EF1F5E /* preferences.nib */,
38DD40191F5800A400A276CB /* PreferencesMenu.xib */,
389468CE1F57BC5B00EF1F5E /* preferences.plist */,
389468CA1F56A34A00EF1F5E /* web */,
F102C5A71F48818A0005B03F /* words_with_frequency_and_translation.json */,
F102C5A51F487DE80005B03F /* google_227800_words.bin */,
Expand Down Expand Up @@ -240,9 +234,7 @@
0D2BFD8F194588F400DE18D9 /* Images.xcassets in Resources */,
38DD401A1F5800A400A276CB /* PreferencesMenu.xib in Resources */,
0DE74C001978F18E00040F3C /* him.icns in Resources */,
389468CF1F57BC5B00EF1F5E /* preferences.plist in Resources */,
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
389468CD1F57BC4D00EF1F5E /* preferences.nib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "src/main.mm"
timestampString = "527608760.655638"
timestampString = "527610592.721219"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "82"
endingLineNumber = "82"
startingLineNumber = "80"
endingLineNumber = "80"
landmarkName = "startHttpServer()"
landmarkType = "9">
</BreakpointContent>
Expand Down
67 changes: 0 additions & 67 deletions preferences.nib/designable.nib

This file was deleted.

Binary file removed preferences.nib/keyedobjects.nib
Binary file not shown.
14 changes: 0 additions & 14 deletions preferences.plist

This file was deleted.

7 changes: 3 additions & 4 deletions src/InputApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ -(NSMenu*)menu

-(void)awakeFromNib
{
NSMenuItem* preferences = [_menu itemWithTag:1];
NSMenuItem* preferenceMenu = [_menu itemWithTag:1];

if ( preferences ) {
[preferences setAction:@selector(showPreferences:)];
if ( preferenceMenu ) {
[preferenceMenu setAction:@selector(showPreferences:)];
}

}

@end
22 changes: 11 additions & 11 deletions src/InputController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
extern NSMutableDictionary* wordsWithFrequencyAndTranslation;
extern BOOL defaultEnglishMode;
extern NSDictionary* substitutions;
extern NSMutableDictionary* preference;
extern NSUserDefaults* preference;

typedef NSInteger KeyCode;
static const KeyCode
Expand Down Expand Up @@ -327,14 +327,11 @@ - (void)candidateSelectionChanged:(NSAttributedString*) candidateString {

_insertionIndex = [candidateString length];

bool showTranslations = [[NSUserDefaults standardUserDefaults] boolForKey: @"showTranslations"];

NSArray* pinyinApi = [[NSUserDefaults standardUserDefaults] arrayForKey: @"showTranslations"];

NSLog(@"showTranslations: %@, pinyinApi: %@", showTranslations, pinyinApi);


[self showAnnotation: candidateString];
BOOL showTranslation = [preference boolForKey: @"showTranslation"];
NSLog(@"showTranslation: %hhd", showTranslation);
if (showTranslation) {
[self showAnnotation: candidateString];
}
}

- (void)candidateSelected:(NSAttributedString*)candidateString {
Expand Down Expand Up @@ -363,11 +360,14 @@ - (void)deactivateServer:(id)sender {
[self reset];
}

-(NSMenu*)menu
{
-(NSMenu*)menu {
return [[NSApp delegate] performSelector:NSSelectorFromString(@"menu")];
}

- (void)showPreferences:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: @"http://localhost:62718/index.html"]];
}


-(void)showAnnotation:(NSAttributedString*)candidateString{
NSArray* subList = [self getTranslations: candidateString];
Expand Down

0 comments on commit 1dd0415

Please sign in to comment.