Skip to content

Commit 8ee5fb7

Browse files
committed
Add a ton of new features
1 parent dcc4949 commit 8ee5fb7

20 files changed

+843
-368
lines changed

Sources/OpenKey/engine/Engine.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static bool _isCharKeyCode;
112112
static vector<Uint32> _specialChar;
113113
static bool _useSpellCheckingBefore;
114114
static bool _hasHandleQuickConsonant;
115+
static bool _willTempOffEngine = false;
115116

116117
//function prototype
117118
void findAndCalculateVowel(const bool& forGrammar=false);
@@ -1216,6 +1217,10 @@ void vSetCheckSpelling() {
12161217
_useSpellCheckingBefore = vCheckSpelling;
12171218
}
12181219

1220+
void vTempOffEngine() {
1221+
_willTempOffEngine = true;
1222+
}
1223+
12191224
bool checkQuickConsonant() {
12201225
if (_index <= 1) return false;
12211226
l = 0;
@@ -1267,22 +1272,28 @@ void vEnglishMode(const vKeyEventState& state, const Uint16& data, const bool& i
12671272
hCode = vDoNothing;
12681273
if (state == vKeyEventState::MouseDown || (otherControlKey && !isCaps)) {
12691274
hMacroKey.clear();
1275+
_willTempOffEngine = false;
12701276
} else if (data == KEY_SPACE) {
12711277
if (!_hasHandledMacro && findMacro(hMacroKey, hMacroData)) {
12721278
hCode = vReplaceMaro;
12731279
hBPC = (Byte)hMacroKey.size();
12741280
}
12751281
hMacroKey.clear();
1282+
_willTempOffEngine = false;
12761283
} else if (data == KEY_DELETE) {
12771284
if (hMacroKey.size() > 0) {
12781285
hMacroKey.pop_back();
1286+
} else {
1287+
_willTempOffEngine = false;
12791288
}
12801289
} else {
12811290
if (isWordBreak(vKeyEvent::Keyboard, state, data) &&
12821291
std::find(_charKeyCode.begin(), _charKeyCode.end(), data) == _charKeyCode.end()) {
12831292
hMacroKey.clear();
1293+
_willTempOffEngine = false;
12841294
} else {
1285-
hMacroKey.push_back(data | (isCaps ? CAPS_MASK : 0));
1295+
if (!_willTempOffEngine)
1296+
hMacroKey.push_back(data | (isCaps ? CAPS_MASK : 0));
12861297
}
12871298
}
12881299
}
@@ -1335,6 +1346,7 @@ void vKeyHandleEvent(const vKeyEvent& event,
13351346
if (hCode == vDoNothing) {
13361347
startNewSession();
13371348
vCheckSpelling = _useSpellCheckingBefore;
1349+
_willTempOffEngine = false;
13381350
} else if (hCode == vReplaceMaro || _hasHandleQuickConsonant) {
13391351
_index = 0;
13401352
}
@@ -1391,6 +1403,7 @@ void vKeyHandleEvent(const vKeyEvent& event,
13911403
}
13921404
}
13931405
vCheckSpelling = _useSpellCheckingBefore;
1406+
_willTempOffEngine = false;
13941407
} else if (data == KEY_DELETE) {
13951408
hCode = vDoNothing;
13961409
hExt = 2; //delete
@@ -1438,6 +1451,11 @@ void vKeyHandleEvent(const vKeyEvent& event,
14381451
}
14391452
}
14401453
} else { //START AND CHECK KEY
1454+
if (_willTempOffEngine) {
1455+
hCode = vDoNothing;
1456+
hExt = 3;
1457+
return;
1458+
}
14411459
if (_spaceCount > 0) {
14421460
hBPC = 0;
14431461
hNCC = 0;

Sources/OpenKey/engine/Engine.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,25 @@ extern int vAllowConsonantZFWJ;
161161
*/
162162
extern int vQuickStartConsonant;
163163

164-
/*
164+
/**
165165
* 0: No; 1: Yes
166166
* g -> ng: hag -> hang,...
167167
* h -> nh: vih -> vinh,...
168168
* k -> ch: bak -> bach,...
169169
*/
170170
extern int vQuickEndConsonant;
171171

172+
/**
173+
* 0: No; 1: Yes
174+
* Auto remember table code for each application
175+
*/
176+
extern int vRememberCode;
177+
178+
/**
179+
* 0: No; 1: Yes
180+
* Temporarily turn off OpenKey by hot key (Command on mac, Alt on Windows and Linux)
181+
*/
182+
extern int vTempOffOpenKey;
172183

173184
/**
174185
* Call this function first to receive data pointer
@@ -214,6 +225,11 @@ void vTempOffSpellChecking();
214225
*/
215226
void vSetCheckSpelling();
216227

228+
/**
229+
* temporarily turn off OpenKey engine
230+
*/
231+
void vTempOffEngine();
232+
217233
/**
218234
* some utils function
219235
*/

Sources/OpenKey/macOS/ModernKey/AboutViewController.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ - (IBAction)onLatestReleaseVersion:(id)sender {
4141
}
4242

4343
- (IBAction)onCheckUpdateOnStartup:(NSButton *)sender {
44-
NSInteger val = 0;
45-
if (sender.state == NSControlStateValueOn) {
46-
val = 0;
47-
} else {
48-
val = 1;
49-
}
44+
NSInteger val = sender.state == NSControlStateValueOn ? 0 : 1;
5045
[[NSUserDefaults standardUserDefaults] setInteger:val forKey:@"DontCheckUpdate"];
5146
}
5247

@@ -55,7 +50,7 @@ - (IBAction)onCheckNewVersion:(id)sender {
5550
self.CheckNewVersionButton.title = @"Đang kiểm tra...";
5651
self.CheckNewVersionButton.enabled = false;
5752

58-
[OpenKeyManager checkNewVersion:^{
53+
[OpenKeyManager checkNewVersion: self.view.window callbackFunc:^{
5954
self.CheckNewVersionButton.enabled = true;
6055
self.CheckNewVersionButton.title = @"Kiểm tra bản mới...";
6156
}];

Sources/OpenKey/macOS/ModernKey/AppDelegate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#import <Cocoa/Cocoa.h>
1010
#import "ViewController.h"
1111

12+
#define OPENKEY_BUNDLE @"com.tuyenmai.openkey"
13+
1214
@interface AppDelegate : NSObject <NSApplicationDelegate>
1315

1416
-(void)onImputMethodChanged:(BOOL)willNotify;
@@ -27,5 +29,7 @@
2729
-(void)onMacroSelected;
2830
-(void)onQuickConvert;
2931
-(void)setQuickConvertString;
32+
33+
-(void)showIconOnDock:(BOOL)val;
3034
@end
3135

Sources/OpenKey/macOS/ModernKey/AppDelegate.m

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
int vAllowConsonantZFWJ = 0;
4545
int vQuickStartConsonant = 0;
4646
int vQuickEndConsonant = 0;
47+
int vRememberCode = 1; //new on version 2.0
48+
int vTempOffOpenKey = 0; //new on version 2.0
49+
50+
int vShowIconOnDock = 0; //new on version 2.0
51+
52+
//beta feature
53+
int vFixChromiumBrowser = 0; //new on version 2.0
4754

4855
extern int convertToolHotKey;
4956
extern bool convertToolDontAlertWhenCompleted;
@@ -103,9 +110,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
103110

104111
[self registerSupportedNotification];
105112

113+
//set quick tooltip
114+
[[NSUserDefaults standardUserDefaults] setObject: [NSNumber numberWithInt: 50]
115+
forKey: @"NSInitialToolTipDelay"];
116+
106117
//check whether this app has been launched before that or not
107118
NSArray* runningApp = [[NSWorkspace sharedWorkspace] runningApplications];
108-
if ([runningApp containsObject:@"com.tuyenmai.openkey"]) { //if already running -> exit
119+
if ([runningApp containsObject:OPENKEY_BUNDLE]) { //if already running -> exit
109120
[NSApp terminate:nil];
110121
return;
111122
}
@@ -115,8 +126,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
115126
[self askPermission];
116127
return;
117128
}
118-
119-
//[NSApp setActivationPolicy: NSApplicationActivationPolicyProhibited];
129+
130+
vShowIconOnDock = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"vShowIconOnDock"];
131+
if (vShowIconOnDock)
132+
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
120133

121134
if (vSwitchKeyStatus & 0x8000)
122135
NSBeep();
@@ -145,7 +158,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
145158
//check update if enable
146159
NSInteger dontCheckUpdate = [[NSUserDefaults standardUserDefaults] integerForKey:@"DontCheckUpdate"];
147160
if (!dontCheckUpdate)
148-
[OpenKeyManager checkNewVersion:nil];
161+
[OpenKeyManager checkNewVersion:nil callbackFunc:nil];
162+
163+
//correct run on startup
164+
NSInteger val = [[NSUserDefaults standardUserDefaults] integerForKey:@"RunOnStartup"];
165+
[appDelegate setRunOnStartup:val];
149166
}
150167

151168

@@ -248,7 +265,7 @@ -(void)loadDefaultConfig {
248265
vCodeTable = 0; [[NSUserDefaults standardUserDefaults] setInteger:vCodeTable forKey:@"CodeTable"];
249266
vSwitchKeyStatus = DEFAULT_SWITCH_STATUS; [[NSUserDefaults standardUserDefaults] setInteger:vCodeTable forKey:@"SwitchKeyStatus"];
250267
vQuickTelex = 0; [[NSUserDefaults standardUserDefaults] setInteger:vQuickTelex forKey:@"QuickTelex"];
251-
vUseModernOrthography = 1; [[NSUserDefaults standardUserDefaults] setInteger:vUseModernOrthography forKey:@"ModernOrthography"];
268+
vUseModernOrthography = 0; [[NSUserDefaults standardUserDefaults] setInteger:vUseModernOrthography forKey:@"ModernOrthography"];
252269
vRestoreIfWrongSpelling = 0; [[NSUserDefaults standardUserDefaults] setInteger:vRestoreIfWrongSpelling forKey:@"RestoreIfInvalidWord"];
253270
vFixRecommendBrowser = 1; [[NSUserDefaults standardUserDefaults] setInteger:vFixRecommendBrowser forKey:@"FixRecommendBrowser"];
254271
vUseMacro = 1; [[NSUserDefaults standardUserDefaults] setInteger:vUseMacro forKey:@"UseMacro"];
@@ -260,6 +277,11 @@ -(void)loadDefaultConfig {
260277
vAllowConsonantZFWJ = 0;[[NSUserDefaults standardUserDefaults] setInteger:vAllowConsonantZFWJ forKey:@"vAllowConsonantZFWJ"];
261278
vQuickStartConsonant = 0;[[NSUserDefaults standardUserDefaults] setInteger:vQuickStartConsonant forKey:@"vQuickStartConsonant"];
262279
vQuickEndConsonant = 0;[[NSUserDefaults standardUserDefaults] setInteger:vQuickEndConsonant forKey:@"vQuickEndConsonant"];
280+
vRememberCode = 1;[[NSUserDefaults standardUserDefaults] setInteger:vRememberCode forKey:@"vRememberCode"];
281+
vTempOffOpenKey = 0;[[NSUserDefaults standardUserDefaults] setInteger:vTempOffOpenKey forKey:@"vTempOffOpenKey"];
282+
vShowIconOnDock = 0;[[NSUserDefaults standardUserDefaults] setInteger:vShowIconOnDock forKey:@"vShowIconOnDock"];
283+
vFixChromiumBrowser = 0;[[NSUserDefaults standardUserDefaults] setInteger:vFixChromiumBrowser forKey:@"vFixChromiumBrowser"];
284+
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"RunOnStartup"];
263285

264286
[self fillData];
265287
[viewController fillData];
@@ -273,6 +295,11 @@ -(void)setRunOnStartup:(BOOL)val {
273295
-(void)setGrayIcon:(BOOL)val {
274296
[self fillData];
275297
}
298+
299+
-(void)showIconOnDock:(BOOL)val {
300+
[NSApp setActivationPolicy: val ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyProhibited];
301+
}
302+
276303
#pragma mark -StatusBar menu data
277304

278305
- (void)setInputTypeMenu:(NSMenuItem*) parent {

0 commit comments

Comments
 (0)