Skip to content

Commit 196631e

Browse files
committed
use separate textviews
1 parent a1dc0a9 commit 196631e

File tree

14 files changed

+1738
-1660
lines changed

14 files changed

+1738
-1660
lines changed

Assets.xcassets/Symbols/delete.backward.fill.symbolset/delete.backward.fill.svg

Lines changed: 2 additions & 2 deletions
Loading

Assets.xcassets/Symbols/delete.backward.symbolset/delete.backward.svg

Lines changed: 2 additions & 2 deletions
Loading

Squirrel.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@
643643
C01FCF4B08A954540054247B /* Debug */ = {
644644
isa = XCBuildConfiguration;
645645
buildSettings = {
646+
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
647+
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
648+
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
649+
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
650+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
646651
CLANG_CXX_LIBRARY = "libc++";
647652
CLANG_ENABLE_OBJC_ARC = YES;
648653
CODE_SIGN_IDENTITY = "-";
@@ -695,6 +700,11 @@
695700
C01FCF4C08A954540054247B /* Release */ = {
696701
isa = XCBuildConfiguration;
697702
buildSettings = {
703+
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
704+
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
705+
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
706+
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
707+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
698708
CLANG_CXX_LIBRARY = "libc++";
699709
CLANG_ENABLE_OBJC_ARC = YES;
700710
CODE_SIGN_IDENTITY = "-";

SquirrelApplicationDelegate.hh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import <Cocoa/Cocoa.h>
2+
#import "rime_api.h"
23

34
@class SquirrelConfig;
45
@class SquirrelPanel;
@@ -8,14 +9,12 @@
89
// outlet of NSApp's instance
910
@interface SquirrelApplicationDelegate : NSObject <NSApplicationDelegate>
1011

11-
typedef NS_ENUM(NSUInteger, SquirrelNotificationPolicy) {
12+
typedef NS_CLOSED_ENUM(NSUInteger, SquirrelNotificationPolicy) {
1213
kShowNotificationsNever = 0,
1314
kShowNotificationsWhenAppropriate = 1,
1415
kShowNotificationsAlways = 2
1516
};
1617

17-
typedef uintptr_t RimeSessionId;
18-
1918
@property(nonatomic, weak, nullable) IBOutlet NSMenu* menu;
2019
@property(nonatomic, weak, nullable) IBOutlet SquirrelPanel* panel;
2120
@property(nonatomic, weak, nullable) IBOutlet id updater;

SquirrelApplicationDelegate.mm

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#import "SquirrelConfig.hh"
44
#import "SquirrelPanel.hh"
55
#import "macos_keycode.hh"
6-
#import "rime_api.h"
76
#import <UserNotifications/UserNotifications.h>
87

98
static NSString* const kRimeWikiURL = @"https://github.com/rime/home/wiki";
@@ -15,7 +14,7 @@ @implementation SquirrelApplicationDelegate {
1514

1615
- (IBAction)showSwitcher:(id)sender {
1716
NSLog(@"Show Switcher");
18-
if (_switcherKeyEquivalent) {
17+
if (_switcherKeyEquivalent != 0) {
1918
RimeSessionId session = [sender unsignedLongValue];
2019
rime_get_api()->process_key(session, _switcherKeyEquivalent,
2120
_switcherKeyModifierMask);
@@ -45,14 +44,14 @@ - (IBAction)openWiki:(id)sender {
4544
[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:kRimeWikiURL]];
4645
}
4746

48-
void show_notification(const char* msg_text) {
47+
extern void show_notification(const char* msg_text) {
4948
UNUserNotificationCenter* center =
5049
UNUserNotificationCenter.currentNotificationCenter;
5150
[center requestAuthorizationWithOptions:UNAuthorizationOptionAlert |
5251
UNAuthorizationOptionProvisional
5352
completionHandler:^(BOOL granted,
5453
NSError* _Nullable error) {
55-
if (error) {
54+
if (error != nil) {
5655
NSLog(@"User notification authorization error: %@",
5756
error.debugDescription);
5857
}
@@ -63,7 +62,7 @@ void show_notification(const char* msg_text) {
6362
settings.authorizationStatus == UNAuthorizationStatusProvisional) &&
6463
(settings.alertSetting == UNNotificationSettingEnabled)) {
6564
UNMutableNotificationContent* content =
66-
[[UNMutableNotificationContent alloc] init];
65+
UNMutableNotificationContent.alloc.init;
6766
content.title = NSLocalizedString(@"Squirrel", nil);
6867
content.subtitle = NSLocalizedString(@(msg_text), nil);
6968
if (@available(macOS 12.0, *)) {
@@ -75,7 +74,7 @@ void show_notification(const char* msg_text) {
7574
trigger:nil];
7675
[center addNotificationRequest:request
7776
withCompletionHandler:^(NSError* _Nullable error) {
78-
if (error) {
77+
if (error != nil) {
7978
NSLog(@"User notification request error: %@",
8079
error.debugDescription);
8180
}
@@ -85,9 +84,9 @@ void show_notification(const char* msg_text) {
8584
}
8685

8786
static void show_status(const char* msg_text_long, const char* msg_text_short) {
88-
NSString* msgLong = msg_text_long ? @(msg_text_long) : nil;
87+
NSString* msgLong = msg_text_long != NULL ? @(msg_text_long) : nil;
8988
NSString* msgShort =
90-
msg_text_short
89+
msg_text_short != NULL
9190
? @(msg_text_short)
9291
: [msgLong substringWithRange:
9392
[msgLong rangeOfComposedCharacterSequenceAtIndex:0]];
@@ -99,37 +98,34 @@ static void notification_handler(void* context_object,
9998
RimeSessionId session_id,
10099
const char* message_type,
101100
const char* message_value) {
102-
if (!strcmp(message_type, "deploy")) {
103-
if (!strcmp(message_value, "start")) {
101+
if (strcmp(message_type, "deploy") == 0) {
102+
if (strcmp(message_value, "start") == 0) {
104103
show_notification("deploy_start");
105-
} else if (!strcmp(message_value, "success")) {
104+
} else if (strcmp(message_value, "success") == 0) {
106105
show_notification("deploy_success");
107-
} else if (!strcmp(message_value, "failure")) {
106+
} else if (strcmp(message_value, "failure") == 0) {
108107
show_notification("deploy_failure");
109108
}
110109
return;
111110
}
112111
SquirrelApplicationDelegate* app_delegate = (__bridge id)context_object;
113112
// schema change
114-
if (!strcmp(message_type, "schema") &&
113+
if (strcmp(message_type, "schema") == 0 &&
115114
app_delegate.showNotifications != kShowNotificationsNever) {
116115
const char* schema_name = strchr(message_value, '/');
117-
if (schema_name) {
116+
if (schema_name != NULL) {
118117
++schema_name;
119118
show_status(schema_name, schema_name);
120119
}
121120
return;
122121
}
123122
// option change
124-
if (!strcmp(message_type, "option") && app_delegate) {
123+
if (strcmp(message_type, "option") == 0 && app_delegate) {
125124
Bool state = message_value[0] != '!';
126125
const char* option_name = message_value + !state;
126+
BOOL updateScriptVariant = [app_delegate.panel.optionSwitcher
127+
updateCurrentScriptVariant:@(message_value)];
127128
BOOL updateStyleOptions = NO;
128-
BOOL updateScriptVariant = NO;
129-
if ([app_delegate.panel.optionSwitcher
130-
updateCurrentScriptVariant:@(message_value)]) {
131-
updateScriptVariant = YES;
132-
}
133129
if ([app_delegate.panel.optionSwitcher updateGroupState:@(message_value)
134130
ofOption:@(option_name)]) {
135131
updateStyleOptions = YES;
@@ -148,7 +144,7 @@ static void notification_handler(void* context_object,
148144
RimeStringSlice state_label_short =
149145
rime_get_api()->get_state_label_abbreviated(session_id, option_name,
150146
state, True);
151-
if (state_label_long.str || state_label_short.str) {
147+
if (state_label_long.str != NULL || state_label_short.str != NULL) {
152148
const char* short_message =
153149
state_label_short.length < strlen(state_label_short.str)
154150
? NULL
@@ -208,7 +204,7 @@ - (void)loadSettings {
208204
if ([defaultConfig openWithConfigId:@"default"]) {
209205
NSString* hotkey =
210206
[defaultConfig getStringForOption:@"switcher/hotkeys/@0"];
211-
if (hotkey) {
207+
if (hotkey != nil) {
212208
NSArray<NSString*>* keys = [hotkey componentsSeparatedByString:@"+"];
213209
for (NSUInteger i = 0; i < keys.count - 1; ++i) {
214210
_switcherKeyModifierMask |=
@@ -285,7 +281,7 @@ - (BOOL)problematicLaunchDetected {
285281
NSData* archive = [NSData dataWithContentsOfURL:logfile
286282
options:NSDataReadingUncached
287283
error:nil];
288-
if (archive) {
284+
if (archive != nil) {
289285
NSDate* previousLaunch =
290286
[NSKeyedUnarchiver unarchivedObjectOfClass:NSDate.class
291287
fromData:archive
@@ -294,8 +290,7 @@ - (BOOL)problematicLaunchDetected {
294290
detected = YES;
295291
}
296292
}
297-
NSDate* now = [NSDate date];
298-
NSData* record = [NSKeyedArchiver archivedDataWithRootObject:now
293+
NSData* record = [NSKeyedArchiver archivedDataWithRootObject:NSDate.date
299294
requiringSecureCoding:NO
300295
error:nil];
301296
[record writeToURL:logfile atomically:NO];
@@ -328,7 +323,7 @@ - (void)inputSourceChanged:(NSNotification*)aNotification {
328323
CFStringRef inputSource = (CFStringRef)TISGetInputSourceProperty(
329324
TISCopyCurrentKeyboardInputSource(), kTISPropertyInputSourceID);
330325
CFStringRef bundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
331-
if (!CFStringHasPrefix(inputSource, bundleId)) {
326+
if (CFStringHasPrefix(inputSource, bundleId) == kCFCompareEqualTo) {
332327
_isCurrentInputMethod = NO;
333328
}
334329
}
@@ -337,8 +332,7 @@ - (void)inputSourceChanged:(NSNotification*)aNotification {
337332
// any menuItems without an action will be disabled when displayed in the Text
338333
// Input Menu.
339334
- (void)awakeFromNib {
340-
NSNotificationCenter* center =
341-
[NSWorkspace sharedWorkspace].notificationCenter;
335+
NSNotificationCenter* center = NSWorkspace.sharedWorkspace.notificationCenter;
342336
[center addObserver:self
343337
selector:@selector(workspaceWillPowerOff:)
344338
name:NSWorkspaceWillPowerOffNotification
@@ -365,8 +359,8 @@ - (void)awakeFromNib {
365359
}
366360

367361
- (void)dealloc {
368-
[[NSNotificationCenter defaultCenter] removeObserver:self];
369-
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
362+
[NSNotificationCenter.defaultCenter removeObserver:self];
363+
[NSDistributedNotificationCenter.defaultCenter removeObserver:self];
370364
[_panel hide];
371365
}
372366

SquirrelConfig.hh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#import <Cocoa/Cocoa.h>
2-
3-
typedef uintptr_t RimeSessionId;
2+
#import <rime_api.h>
43

54
__attribute__((objc_direct_members))
65
@interface SquirrelOptionSwitcher : NSObject
@@ -101,7 +100,7 @@ typedef NSDictionary<NSString*, NSNumber*> SquirrelAppOptions;
101100
- (NSUInteger)getListSizeForOption:(NSString* _Nonnull)option;
102101
- (NSArray<NSString*>* _Nullable)getListForOption:(NSString* _Nonnull)option;
103102

104-
- (SquirrelOptionSwitcher* _Nullable)getOptionSwitcher;
103+
- (SquirrelOptionSwitcher* _Nonnull)getOptionSwitcher;
105104
- (SquirrelAppOptions* _Nonnull)getAppOptions:(NSString* _Nonnull)appName;
106105

107106
@end // SquirrelConfig

0 commit comments

Comments
 (0)