Skip to content

Commit

Permalink
expandable tabular
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Feb 26, 2024
1 parent 70e5893 commit 55bbde2
Show file tree
Hide file tree
Showing 17 changed files with 1,480 additions and 620 deletions.
15 changes: 15 additions & 0 deletions Assets.xcassets/Symbols/chevron.down.symbolset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.down.svg",
"idiom" : "universal"
}
]
}
160 changes: 160 additions & 0 deletions Assets.xcassets/Symbols/chevron.down.symbolset/chevron.down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Assets.xcassets/Symbols/chevron.up.symbolset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.up.svg",
"idiom" : "universal"
}
]
}
160 changes: 160 additions & 0 deletions Assets.xcassets/Symbols/chevron.up.symbolset/chevron.up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Assets.xcassets/Symbols/lock.fill.symbolset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"symbols" : [
{
"filename" : "lock.fill.svg",
"idiom" : "universal"
}
]
}
160 changes: 160 additions & 0 deletions Assets.xcassets/Symbols/lock.fill.symbolset/lock.fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 9 additions & 12 deletions SquirrelApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,21 @@ - (void)shutdownRime {
}

NSArray<NSString *> *getScriptOptionsForSchema(SquirrelConfig *schema) {
NSUInteger numSwitches = [schema getListSize:@"switches"];
NSUInteger numSwitches = [schema getListSizeForOption:@"switches"];
if (numSwitches == 0) {
return nil;
}
for (NSUInteger i = 0; i < numSwitches; ++i) {
NSString *name = [schema getString:[NSString stringWithFormat:
@"switches/@%lu/name", i]];
NSString *name = [schema getStringForOption:[NSString stringWithFormat:
@"switches/@%lu/name", i]];
if (name) {
if ([name isEqualToString:@"simplification"] ||
[name isEqualToString:@"traditional"]) {
return @[name];
}
} else {
NSArray *options = [schema getList:[NSString stringWithFormat:
@"switches/@%lu/options", i]];
NSArray *options = [schema getListForOption:[NSString stringWithFormat:
@"switches/@%lu/options", i]];
if ([options containsObject:@"simplification"] ||
[options containsObject:@"traditional"]) {
return options;
Expand Down Expand Up @@ -228,16 +228,15 @@ - (void)loadSettings {
return;
}

NSString *showNotificationsWhen = [_config getString:@"show_notifications_when"];
NSString *showNotificationsWhen = [_config getStringForOption:@"show_notifications_when"];
if ([showNotificationsWhen isEqualToString:@"never"]) {
_showNotifications = kShowNotificationsNever;
} else if ([showNotificationsWhen isEqualToString:@"appropriate"]) {
_showNotifications = kShowNotificationsWhenAppropriate;
} else {
_showNotifications = kShowNotificationsAlways;
}
[self.panel loadConfig:_config forAppearance:defaultAppear];
[self.panel loadConfig:_config forAppearance:darkAppear];
[self.panel loadConfig:_config];
}

- (void)loadSchemaSpecificSettings:(NSString *)schemaId
Expand All @@ -251,12 +250,10 @@ - (void)loadSchemaSpecificSettings:(NSString *)schemaId
[schema hasSection:@"style"]) {
SquirrelOptionSwitcher *optionSwitcher = [schema getOptionSwitcher];
self.panel.optionSwitcher = updateOptionSwitcher(optionSwitcher, sessionId);
[self.panel loadConfig:schema forAppearance:defaultAppear];
[self.panel loadConfig:schema forAppearance:darkAppear];
[self.panel loadConfig:schema];
} else {
self.panel.optionSwitcher = [[SquirrelOptionSwitcher alloc] initWithSchemaId:schemaId];
[self.panel loadConfig:self.config forAppearance:defaultAppear];
[self.panel loadConfig:self.config forAppearance:darkAppear];
[self.panel loadConfig:self.config];
}
[schema close];
}
Expand Down
38 changes: 22 additions & 16 deletions SquirrelConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,31 @@ typedef NSMutableDictionary<NSString *, NSNumber *> SquirrelMutableAppOptions;

- (BOOL)hasSection:(NSString *)section;

- (BOOL)getBool:(NSString *)option;
- (int)getInt:(NSString *)option;
- (double)getDouble:(NSString *)option;
- (double)getDouble:(NSString *)option
applyConstraint:(double(*)(double param))func;
- (NSNumber *)getOptionalBool:(NSString *)option;
- (NSNumber *)getOptionalInt:(NSString *)option;
- (NSNumber *)getOptionalDouble:(NSString *)option;
- (NSNumber *)getOptionalDouble:(NSString *)option
applyConstraint:(double(*)(double param))func;

- (NSString *)getString:(NSString *)option;
- (BOOL)setBool:(bool)value forOption:(NSString *)option;
- (BOOL)setInt:(int)value forOption:(NSString *)option;
- (BOOL)setDouble:(double)value forOption:(NSString *)option;
- (BOOL)setString:(NSString *)value forOption:(NSString *)option;

- (BOOL)getBoolForOption:(NSString *)option;
- (int)getIntForOption:(NSString *)option;
- (double)getDoubleForOption:(NSString *)option;
- (double)getDoubleForOption:(NSString *)option
applyConstraint:(double(*)(double param))func;

- (NSNumber *)getOptionalBoolForOption:(NSString *)option;
- (NSNumber *)getOptionalIntForOption:(NSString *)option;
- (NSNumber *)getOptionalDoubleForOption:(NSString *)option;
- (NSNumber *)getOptionalDoubleForOption:(NSString *)option
applyConstraint:(double(*)(double param))func;

- (NSString *)getStringForOption:(NSString *)option;
// 0xaabbggrr or 0xbbggrr
- (NSColor *)getColor:(NSString *)option;
- (NSColor *)getColorForOption:(NSString *)option;
// file path (absolute or relative to ~/Library/Rime)
- (NSImage *)getImage:(NSString *)option;
- (NSImage *)getImageForOption:(NSString *)option;

- (NSUInteger)getListSize:(NSString *)option;
- (NSArray<NSString *> *)getList:(NSString *)option;
- (NSUInteger)getListSizeForOption:(NSString *)option;
- (NSArray<NSString *> *)getListForOption:(NSString *)option;

- (SquirrelOptionSwitcher *)getOptionSwitcher;
- (SquirrelAppOptions *)getAppOptions:(NSString *)appName;
Expand Down
86 changes: 51 additions & 35 deletions SquirrelConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,41 @@ - (BOOL)hasSection:(NSString *)section {
return NO;
}

- (BOOL)getBool:(NSString *)option {
return [self getOptionalBool:option].boolValue;
- (BOOL)setBool:(bool)value forOption:(NSString *)option {
return (BOOL)(rime_get_api()->config_set_bool(&_config, option.UTF8String, value));
}

- (int)getInt:(NSString *)option {
return [self getOptionalInt:option].intValue;
- (BOOL)setInt:(int)value forOption:(NSString *)option {
return (BOOL)(rime_get_api()->config_set_int(&_config, option.UTF8String, value));
}

- (double)getDouble:(NSString *)option {
return [self getOptionalDouble:option].doubleValue;
- (BOOL)setDouble:(double)value forOption:(NSString *)option {
return (BOOL)(rime_get_api()->config_set_double(&_config, option.UTF8String, value));
}

- (double)getDouble:(NSString *)option
applyConstraint:(double(*)(double param))func {
NSNumber *value = [self getOptionalDouble:option];
- (BOOL)setString:(NSString *)value forOption:(NSString *)option {
return (BOOL)(rime_get_api()->config_set_string(&_config, option.UTF8String, value.UTF8String));
}

- (BOOL)getBoolForOption:(NSString *)option {
return [self getOptionalBoolForOption:option].boolValue;
}

- (int)getIntForOption:(NSString *)option {
return [self getOptionalIntForOption:option].intValue;
}

- (double)getDoubleForOption:(NSString *)option {
return [self getOptionalDoubleForOption:option].doubleValue;
}

- (double)getDoubleForOption:(NSString *)option
applyConstraint:(double(*)(double param))func {
NSNumber *value = [self getOptionalDoubleForOption:option];
return func(value.doubleValue);
}

- (NSNumber *)getOptionalBool:(NSString *)option {
- (NSNumber *)getOptionalBoolForOption:(NSString *)option {
NSNumber *cachedValue = [self cachedValueOfObjCType:@encode(BOOL) forKey:option];
if (cachedValue) {
return cachedValue;
Expand All @@ -166,10 +182,10 @@ - (NSNumber *)getOptionalBool:(NSString *)option {
[_cache setObject:number forKey:option];
return number;
}
return [_baseConfig getOptionalBool:option];
return [_baseConfig getOptionalBoolForOption:option];
}

- (NSNumber *)getOptionalInt:(NSString *)option {
- (NSNumber *)getOptionalIntForOption:(NSString *)option {
NSNumber *cachedValue = [self cachedValueOfObjCType:@encode(int) forKey:option];
if (cachedValue) {
return cachedValue;
Expand All @@ -180,10 +196,10 @@ - (NSNumber *)getOptionalInt:(NSString *)option {
[_cache setObject:number forKey:option];
return number;
}
return [_baseConfig getOptionalInt:option];
return [_baseConfig getOptionalIntForOption:option];
}

- (NSNumber *)getOptionalDouble:(NSString *)option {
- (NSNumber *)getOptionalDoubleForOption:(NSString *)option {
NSNumber *cachedValue = [self cachedValueOfObjCType:@encode(double) forKey:option];
if (cachedValue) {
return cachedValue;
Expand All @@ -194,16 +210,16 @@ - (NSNumber *)getOptionalDouble:(NSString *)option {
[_cache setObject:number forKey:option];
return number;
}
return [_baseConfig getOptionalDouble:option];
return [_baseConfig getOptionalDoubleForOption:option];
}

- (NSNumber *)getOptionalDouble:(NSString *)option
applyConstraint:(double(*)(double param))func {
NSNumber *value = [self getOptionalDouble:option];
- (NSNumber *)getOptionalDoubleForOption:(NSString *)option
applyConstraint:(double(*)(double param))func {
NSNumber *value = [self getOptionalDoubleForOption:option];
return value ? [NSNumber numberWithDouble:func(value.doubleValue)] : nil;
}

- (NSString *)getString:(NSString *)option {
- (NSString *)getStringForOption:(NSString *)option {
NSString *cachedValue = [self cachedValueOfClass:NSString.class forKey:option];
if (cachedValue) {
return cachedValue;
Expand All @@ -216,47 +232,47 @@ - (NSString *)getString:(NSString *)option {
[_cache setObject:string forKey:option];
return string;
}
return [_baseConfig getString:option];
return [_baseConfig getStringForOption:option];
}

- (NSColor *)getColor:(NSString *)option {
- (NSColor *)getColorForOption:(NSString *)option {
NSColor *cachedValue = [self cachedValueOfClass:NSColor.class forKey:option];
if (cachedValue) {
return cachedValue;
}
NSColor *color = [self colorFromString:[self getString:option]];
NSColor *color = [self colorFromString:[self getStringForOption:option]];
if (color) {
[_cache setObject:color forKey:option];
return color;
}
return [_baseConfig getColor:option];
return [_baseConfig getColorForOption:option];
}

- (NSImage *)getImage:(NSString *)option {
- (NSImage *)getImageForOption:(NSString *)option {
NSImage *cachedValue = [self cachedValueOfClass:NSImage.class forKey:option];
if (cachedValue) {
return cachedValue;
}
NSImage *image = [self imageFromFile:[self getString:option]];
NSImage *image = [self imageFromFile:[self getStringForOption:option]];
if (image) {
[_cache setObject:image forKey:option];
return image;
}
return [_baseConfig getImage:option];
return [_baseConfig getImageForOption:option];
}

- (NSUInteger)getListSize:(NSString *)option {
- (NSUInteger)getListSizeForOption:(NSString *)option {
return rime_get_api()->config_list_size(&_config, option.UTF8String);
}

- (NSArray<NSString *> *)getList:(NSString *)option {
- (NSArray<NSString *> *)getListForOption:(NSString *)option {
RimeConfigIterator iterator;
if (!rime_get_api()->config_begin_list(&iterator, &_config, option.UTF8String)) {
return nil;
}
NSMutableArray *strList = [[NSMutableArray alloc] init];
while (rime_get_api()->config_next(&iterator)) {
[strList addObject:[self getString:@(iterator.path)]];
[strList addObject:[self getStringForOption:@(iterator.path)]];
}
rime_get_api()->config_end(&iterator);
return strList;
Expand All @@ -270,8 +286,8 @@ - (SquirrelOptionSwitcher *)getOptionSwitcher {
NSMutableDictionary *switcher = [[NSMutableDictionary alloc] init];
NSMutableDictionary *optionGroups = [[NSMutableDictionary alloc] init];
while (rime_get_api()->config_next(&switchIter)) {
int reset = [self getInt:[@(switchIter.path) stringByAppendingString:@"/reset"]];
NSString *name = [self getString:[@(switchIter.path) stringByAppendingString:@"/name"]];
int reset = [self getIntForOption:[@(switchIter.path) stringByAppendingString:@"/reset"]];
NSString *name = [self getStringForOption:[@(switchIter.path) stringByAppendingString:@"/name"]];
if (name) {
if ([self hasSection:[@"style/!" stringByAppendingString:name]] ||
[self hasSection:[@"style/" stringByAppendingString:name]]) {
Expand All @@ -287,7 +303,7 @@ - (SquirrelOptionSwitcher *)getOptionSwitcher {
NSMutableArray *optionGroup = [[NSMutableArray alloc] init];
BOOL hasStyleSection = NO;
while (rime_get_api()->config_next(&optionIter)) {
NSString *option = [self getString:@(optionIter.path)];
NSString *option = [self getStringForOption:@(optionIter.path)];
[optionGroup addObject:option];
hasStyleSection |= [self hasSection:[@"style/" stringByAppendingString:option]];
}
Expand Down Expand Up @@ -315,9 +331,9 @@ - (SquirrelAppOptions *)getAppOptions:(NSString *)appName {
}
while (rime_get_api()->config_next(&iterator)) {
//NSLog(@"DEBUG option[%d]: %s (%s)", iterator.index, iterator.key, iterator.path);
NSNumber *value = [self getOptionalBool:@(iterator.path)] ? :
[self getOptionalInt:@(iterator.path)] ? :
[self getOptionalDouble:@(iterator.path)];
NSNumber *value = [self getOptionalBoolForOption:@(iterator.path)] ? :
[self getOptionalIntForOption:@(iterator.path)] ? :
[self getOptionalDoubleForOption:@(iterator.path)];
if (value) {
appOptions[@(iterator.key)] = value;
}
Expand Down
37 changes: 23 additions & 14 deletions SquirrelInputController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@

@interface SquirrelInputController : IMKInputController

// kPROCESS accepts miscellaneous / function keys (e.g. XK_Escape)
// The remaining 3 actions accept candidate indices (int), starting from item 0 on page 0
typedef NS_ENUM(NSInteger, SquirrelAction) {
kSELECT = 1, // accepts indices in digits, selection keys, and keycodes (XK_Escape)
kHILITE = 2, // accepts indices in digits and selection keys (char '1' / 'A')
kDELETE = 3 // only accepts indices in digits (int 1)
kPROCESS = 0,
kSELECT = 1,
kHIGHLIGHT = 2,
kDELETE = 3
};

typedef NS_ENUM(NSUInteger, SquirrelIndex) {
// 0 ... 9 are ordinal digits, used as (int) index
// 0x21 ... 0x7e are ASCII chars (as selection keys)
// other rime keycodes (as function keys), for paging etc.
kBackSpace = 0xff08, // XK_BackSpace
kEscape = 0xff1b, // XK_Escape
kCodeInput = 0xff37, // XK_Codeinput
kHome = 0xff50, // XK_Home
kPageUp = 0xff55, // XK_Page_Up
kPageDown = 0xff56, // XK_Page_Down
kEnd = 0xff57, // XK_End
kVoidSymbol = 0xffffff // XK_VoidSymbol
// 0, 1, 2 ... are ordinal digits, used as (int) indices
// 0xFFXX are rime keycodes (as function keys), for paging etc.
kBackSpaceKey = 0xff08, // XK_BackSpace
kEscapeKey = 0xff1b, // XK_Escape
kCodeInputArea = 0xff37, // XK_Codeinput
kHomeKey = 0xff50, // XK_Home
kLeftKey = 0xff51, // XK_Left
kUpKey = 0xff52, // XK_Up
kRightKey = 0xff53, // XK_Right
kDownKey = 0xff54, // XK_Down
kPageUpKey = 0xff55, // XK_Page_Up
kPageDownKey = 0xff56, // XK_Page_Down
kEndKey = 0xff57, // XK_End
kExpandButton = 0xff04,
kCompressButton = 0xff05,
kLockButton = 0xff06,
kVoidSymbol = 0xffffff // XK_VoidSymbol
};

@property(class, weak, readonly) SquirrelInputController *currentController;
Expand Down
Loading

0 comments on commit 55bbde2

Please sign in to comment.