diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index d8ba0e15..b5a1e252 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -34,6 +34,7 @@ #import "AppDelegate.h" #import "UpdateNotificationController.h" +#import "PreferencesWindowController.h" void LTLoadLanguageModel(); @@ -58,6 +59,11 @@ static const NSTimeInterval kNextCheckInterval = 86400.0; LTLoadLanguageModel(); [self checkForUpdate]; + + if (0) { + PreferencesWindowController *controller = [[PreferencesWindowController alloc] initWithWindowNibName:@"preferences"]; + [[controller window] orderFront:nil]; + } } - (void)checkForUpdate diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 95fb4bf6..49a1ca88 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -50,7 +50,7 @@ using namespace Formosa::Gramambular; using namespace OpenVanilla; // default, min and max candidate list text size -static const NSInteger kDefaultCandidateListTextSize = 14; +static const NSInteger kDefaultCandidateListTextSize = 16; static const NSInteger kMinKeyLabelSize = 10; static const NSInteger kMinCandidateListTextSize = 12; static const NSInteger kMaxCandidateListTextSize = 128; @@ -67,6 +67,7 @@ static const NSInteger kMaxComposingBufferSize = 20; // user defaults (app perferences) key names; in this project we use // NSUserDefaults throughout and do not wrap them in another config object static NSString *const kKeyboardLayoutPreferenceKey = @"KeyboardLayout"; +static NSString *const kBasisKeyboardLayoutPreferenceKey = @"BasisKeyboardLayout"; // alphanumeric ("ASCII") input basis static NSString *const kCandidateListTextSizeKey = @"CandidateListTextSize"; static NSString *const kSelectPhraseAfterCursorAsCandidatePreferenceKey = @"SelectPhraseAfterCursorAsCandidate"; static NSString *const kUseHorizontalCandidateListPreferenceKey = @"UseHorizontalCandidateList"; @@ -313,7 +314,12 @@ public: _inputMode = kBopomofoModeIdentifier; } - [sender overrideKeyboardWithKeyboardNamed:@"com.apple.keylayout.US"]; + NSString *basisKeyboardLayoutID = [[NSUserDefaults standardUserDefaults] stringForKey:kBasisKeyboardLayoutPreferenceKey]; + if (!basisKeyboardLayoutID) { + basisKeyboardLayoutID = @"com.apple.keylayout.US"; + } + + [sender overrideKeyboardWithKeyboardNamed:basisKeyboardLayoutID]; if (!_bpmfReadingBuffer->isEmpty()) { _bpmfReadingBuffer->clear(); diff --git a/Source/PreferencesWindowController.h b/Source/PreferencesWindowController.h index 98b6c42e..7ca3afd7 100644 --- a/Source/PreferencesWindowController.h +++ b/Source/PreferencesWindowController.h @@ -36,8 +36,10 @@ @interface PreferencesWindowController : NSWindowController { @private - IBOutlet NSPopUpButton *_fontSizePopUpButton; + NSPopUpButton *_fontSizePopUpButton; + NSPopUpButton *_basisKeyboardLayoutButton; } - +- (IBAction)updateBasisKeyboardLayoutAction:(id)sender; @property (assign, nonatomic) IBOutlet NSPopUpButton *fontSizePopUpButton; +@property (assign, nonatomic) IBOutlet NSPopUpButton *basisKeyboardLayoutButton; @end diff --git a/Source/PreferencesWindowController.m b/Source/PreferencesWindowController.m index a2ac5b17..8fc7a134 100644 --- a/Source/PreferencesWindowController.m +++ b/Source/PreferencesWindowController.m @@ -32,26 +32,70 @@ // OTHER DEALINGS IN THE SOFTWARE. // #import "PreferencesWindowController.h" +#import + +static NSString *const kBasisKeyboardLayoutPreferenceKey = @"BasisKeyboardLayout"; // alphanumeric ("ASCII") input basis @implementation PreferencesWindowController @synthesize fontSizePopUpButton = _fontSizePopUpButton; +@synthesize basisKeyboardLayoutButton = _basisKeyboardLayoutButton; - (void)awakeFromNib { - // this is a way to find if we're on OS X 10.7 -// if (![[NSApplication sharedApplication] respondsToSelector:@selector(disableRelaunchOnLogin)]) { -// return; -// } + CFArrayRef list = TISCreateInputSourceList(NULL, true); + NSMenuItem *usKeyboardLayoutItem = nil; + NSMenuItem *chosenItem = nil; -// NSMenu *menu = [_fontSizePopUpButton menu]; -// NSArray *menuItems = [menu itemArray]; -// -// for (NSMenuItem *item in menuItems) { -// NSUInteger tag = [item tag]; -// -// if (tag != 14 && tag != 24) { -// [menu removeItem:item]; -// } -// } + [[self.basisKeyboardLayoutButton menu] removeAllItems]; + + NSString *basisKeyboardLayoutID = [[NSUserDefaults standardUserDefaults] stringForKey:kBasisKeyboardLayoutPreferenceKey]; + + for (int i = 0; i < CFArrayGetCount(list); i++) { + TISInputSourceRef source = (TISInputSourceRef)CFArrayGetValueAtIndex(list, i); + + CFStringRef category = TISGetInputSourceProperty(source, kTISPropertyInputSourceCategory); + if (CFStringCompare(category, kTISCategoryKeyboardInputSource, 0) != kCFCompareEqualTo) { + continue; + } + + CFBooleanRef asciiCapable = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsASCIICapable); + if (!CFBooleanGetValue(asciiCapable)) { + continue; + } + + CFStringRef sourceType = TISGetInputSourceProperty(source, kTISPropertyInputSourceType); + if (CFStringCompare(sourceType, kTISTypeKeyboardLayout, 0) != kCFCompareEqualTo) { + continue; + } + + NSString *sourceID = (NSString *)TISGetInputSourceProperty(source, kTISPropertyInputSourceID); + NSString *localizedName = (NSString *)TISGetInputSourceProperty(source, kTISPropertyLocalizedName); + + NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; + [item setTitle:localizedName]; + [item setRepresentedObject:sourceID]; + + if ([sourceID isEqualToString:@"com.apple.keylayout.US"]) { + usKeyboardLayoutItem = item; + } + + // false if nil + if ([basisKeyboardLayoutID isEqualToString:sourceID]) { + chosenItem = item; + } + + [[self.basisKeyboardLayoutButton menu] addItem:item]; + } + + [self.basisKeyboardLayoutButton selectItem:(chosenItem ? chosenItem : usKeyboardLayoutItem)]; + CFRelease(list); +} + +- (IBAction)updateBasisKeyboardLayoutAction:(id)sender +{ + NSString *sourceID = [[self.basisKeyboardLayoutButton selectedItem] representedObject]; + if (sourceID) { + [[NSUserDefaults standardUserDefaults] setObject:sourceID forKey:kBasisKeyboardLayoutPreferenceKey]; + } } @end diff --git a/Source/en.lproj/preferences.xib b/Source/en.lproj/preferences.xib index b893d4f6..c6bbf233 100644 --- a/Source/en.lproj/preferences.xib +++ b/Source/en.lproj/preferences.xib @@ -2,40 +2,37 @@ 1070 - 11B26 - 1617 - 1138 - 566.00 + 11E53 + 2549 + 1138.47 + 569.00 com.apple.InterfaceBuilder.CocoaPlugin - 1617 + 2549 YES - NSUserDefaultsController - NSPopUpButton - NSMenuItem - NSMenu - NSTextFieldCell - NSButtonCell NSButton - NSMatrix + NSButtonCell NSCustomObject + NSMatrix + NSMenu + NSMenuItem + NSPopUpButton + NSPopUpButtonCell + NSTextField + NSTextFieldCell + NSUserDefaultsController NSView NSWindowTemplate - NSTextField - NSPopUpButtonCell YES com.apple.InterfaceBuilder.CocoaPlugin - YES - - YES - - + PluginDependencyRecalculationVersion + YES @@ -51,7 +48,7 @@ 7 2 - {{809, 539}, {435, 227}} + {{809, 539}, {460, 266}} 544735232 Bopomofo Preferences NSWindow @@ -65,10 +62,10 @@ 268 - {{174, 183}, {151, 26}} + {{224, 222}, {119, 26}} - + YES -2076049856 @@ -160,7 +157,6 @@ - -1 1 YES YES @@ -170,7 +166,7 @@ 268 - {{58, 189}, {114, 17}} + {{39, 228}, {183, 17}} @@ -178,7 +174,7 @@ 68288064 71304192 - Keyboard Layout: + Bopomofo Keyboard Layout: @@ -201,10 +197,63 @@ + + + 268 + {{224, 182}, {156, 26}} + + + + YES + + -2076049856 + 2048 + + + 109199615 + 129 + + + 400 + 75 + + YES + + OtherViews + + YES + + + + -1 + 1 + YES + YES + 2 + + + + + 268 + {{17, 186}, {205, 17}} + + + + YES + + 68288064 + 71304192 + Alphanumeric Keyboard Layout: + + + + + + 268 - {{17, 149}, {155, 17}} + {{67, 149}, {155, 17}} @@ -222,7 +271,7 @@ 268 - {{34, 103}, {138, 17}} + {{84, 103}, {138, 17}} @@ -240,7 +289,7 @@ 268 - {{38, 56}, {134, 17}} + {{88, 56}, {134, 17}} @@ -258,7 +307,7 @@ 268 - {{177, 128}, {213, 38}} + {{227, 128}, {213, 38}} @@ -461,7 +510,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 - {{177, 82}, {207, 38}} + {{227, 82}, {207, 38}} @@ -655,7 +704,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 - {{174, 50}, {86, 26}} + {{224, 50}, {86, 26}} @@ -787,16 +836,15 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 - {{175, 18}, {242, 18}} + {{225, 18}, {217, 18}} - _NS:239 YES -2080244224 0 - Use space key to choose candidates + Space key chooses candidate _NS:239 @@ -816,12 +864,12 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - {435, 227} + {460, 266} - {{0, 0}, {1680, 1028}} + {{0, 0}, {1440, 878}} {10000000000000, 10000000000000} YES @@ -840,6 +888,30 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 30 + + + fontSizePopUpButton + + + + 108 + + + + basisKeyboardLayoutButton + + + + 135 + + + + updateBasisKeyboardLayoutAction: + + + + 136 + selectedTag: values.KeyboardLayout @@ -904,14 +976,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 107 - - - fontSizePopUpButton - - - - 108 - value: values.ChooseCandidateUsingSpaceKey @@ -934,7 +998,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES 0 - + + YES + @@ -973,11 +1039,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES - - - + + + + + @@ -1240,6 +1308,46 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + + 124 + + + YES + + + + + + 125 + + + YES + + + + + + 126 + + + + + 127 + + + YES + + + + + + 128 + + + YES + + + @@ -1261,6 +1369,11 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 11.IBPluginDependency 110.IBPluginDependency 12.IBPluginDependency + 124.IBPluginDependency + 125.IBPluginDependency + 126.IBPluginDependency + 127.IBPluginDependency + 128.IBPluginDependency 13.IBPluginDependency 14.IBPluginDependency 15.IBPluginDependency @@ -1294,7 +1407,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 98.IBPluginDependency 99.IBPluginDependency - + YES com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1343,6 +1456,11 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -1357,7 +1475,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - 112 + 136 @@ -1365,14 +1483,25 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA PreferencesWindowController NSWindowController + + updateBasisKeyboardLayoutAction: + id + + + updateBasisKeyboardLayoutAction: + + updateBasisKeyboardLayoutAction: + id + + YES YES - _fontSizePopUpButton + basisKeyboardLayoutButton fontSizePopUpButton - + YES NSPopUpButton NSPopUpButton @@ -1382,13 +1511,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES YES - _fontSizePopUpButton + basisKeyboardLayoutButton fontSizePopUpButton - + YES - _fontSizePopUpButton + basisKeyboardLayoutButton NSPopUpButton @@ -1420,10 +1549,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA NSMenuMixedState NSSwitch - + YES - {9, 8} - {7, 2} + {11, 11} + {10, 3} {15, 15} diff --git a/Source/zh-Hant.lproj/preferences.xib b/Source/zh-Hant.lproj/preferences.xib index 5590cf7f..b4b7e202 100644 --- a/Source/zh-Hant.lproj/preferences.xib +++ b/Source/zh-Hant.lproj/preferences.xib @@ -2,40 +2,37 @@ 1070 - 11B26 - 1617 - 1138 - 566.00 + 11E53 + 2549 + 1138.47 + 569.00 com.apple.InterfaceBuilder.CocoaPlugin - 1617 + 2549 YES - NSUserDefaultsController - NSPopUpButton - NSMenuItem - NSMenu - NSTextFieldCell - NSButtonCell NSButton - NSMatrix + NSButtonCell NSCustomObject + NSMatrix + NSMenu + NSMenuItem + NSPopUpButton + NSPopUpButtonCell + NSTextField + NSTextFieldCell + NSUserDefaultsController NSView NSWindowTemplate - NSTextField - NSPopUpButtonCell YES com.apple.InterfaceBuilder.CocoaPlugin - YES - - YES - - + PluginDependencyRecalculationVersion + YES @@ -51,7 +48,7 @@ 7 2 - {{809, 539}, {409, 227}} + {{809, 539}, {386, 265}} 544735232 注音偏好設定 NSWindow @@ -65,10 +62,10 @@ 268 - {{179, 183}, {125, 26}} + {{179, 222}, {125, 26}} - + YES -2076049856 @@ -150,7 +147,6 @@ 1048576 2147483647 - 1 _popUpItemAction: @@ -160,7 +156,6 @@ - 4 1 YES YES @@ -170,7 +165,7 @@ 268 - {{82, 189}, {95, 17}} + {{82, 228}, {95, 17}} @@ -179,11 +174,7 @@ 68288064 71304192 注音鍵盤配置: - - STHeitiTC-Light - 13 - 16 - + 6 @@ -205,6 +196,59 @@ + + + 268 + {{179, 182}, {149, 26}} + + + + YES + + -2076049856 + 2048 + + + 109199615 + 129 + + + 400 + 75 + + YES + + OtherViews + + YES + + + + -1 + 1 + YES + YES + 2 + + + + + 268 + {{69, 188}, {108, 17}} + + + + YES + + 68288064 + 71304192 + 英數字鍵盤配置: + + + + + + 268 @@ -217,7 +261,7 @@ 68288064 71304192 選字時,候選詞起算點在: - + @@ -235,7 +279,7 @@ 68288064 71304192 候選詞呈現方式: - + @@ -253,7 +297,7 @@ 68288064 71304192 選字窗文字大小: - + @@ -801,11 +845,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA -2080244224 0 使用空白鍵選字 - - LiHeiPro - 13 - 16 - + _NS:239 1211912703 @@ -824,12 +864,12 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - {409, 227} + {386, 265} - {{0, 0}, {1680, 1028}} + {{0, 0}, {1440, 878}} {10000000000000, 10000000000000} YES @@ -848,6 +888,30 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 30 + + + fontSizePopUpButton + + + + 108 + + + + basisKeyboardLayoutButton + + + + 123 + + + + updateBasisKeyboardLayoutAction: + + + + 124 + selectedTag: values.KeyboardLayout @@ -912,14 +976,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 107 - - - fontSizePopUpButton - - - - 108 - value: values.ChooseCandidateUsingSpaceKey @@ -942,7 +998,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES 0 - + + YES + @@ -979,15 +1037,17 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES - + + + - - + - + + @@ -1248,6 +1308,46 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + + 112 + + + YES + + + + + + 113 + + + YES + + + + + + 114 + + + + + 115 + + + YES + + + + + + 116 + + + YES + + + @@ -1268,6 +1368,11 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 109.IBPluginDependency 11.IBPluginDependency 110.IBPluginDependency + 112.IBPluginDependency + 113.IBPluginDependency + 114.IBPluginDependency + 115.IBPluginDependency + 116.IBPluginDependency 12.IBPluginDependency 13.IBPluginDependency 14.IBPluginDependency @@ -1302,7 +1407,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 98.IBPluginDependency 99.IBPluginDependency - + YES com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1351,6 +1456,11 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -1365,7 +1475,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - 111 + 124 @@ -1373,14 +1483,25 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA PreferencesWindowController NSWindowController + + updateBasisKeyboardLayoutAction: + id + + + updateBasisKeyboardLayoutAction: + + updateBasisKeyboardLayoutAction: + id + + YES YES - _fontSizePopUpButton + basisKeyboardLayoutButton fontSizePopUpButton - + YES NSPopUpButton NSPopUpButton @@ -1390,13 +1511,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES YES - _fontSizePopUpButton + basisKeyboardLayoutButton fontSizePopUpButton - + YES - _fontSizePopUpButton + basisKeyboardLayoutButton NSPopUpButton @@ -1428,10 +1549,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA NSMenuMixedState NSSwitch - + YES - {9, 8} - {7, 2} + {11, 11} + {10, 3} {15, 15}