diff --git a/Easydict/objc/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m b/Easydict/objc/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m index eaed39b17..721ea47c6 100644 --- a/Easydict/objc/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m +++ b/Easydict/objc/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m @@ -148,7 +148,7 @@ - (void)setupData { - (void)setupUI { [self tableView]; - [self updateWindowViewHeight]; + [self updateWindowHeight]; mm_weakify(self); [self setResizeWindowBlock:^{ @@ -174,7 +174,7 @@ - (void)setupUI { } } - [self updateWindowViewHeight]; + [self updateWindowHeight]; }]; }]; @@ -247,7 +247,9 @@ - (void)updateWindowConfiguration:(NSNotification *)notification { } } - [self reloadTableViewData:nil]; + [self reloadTableViewData:^{ +// [self updateTableViewHeight]; + }]; } - (void)modifyLanduage:(NSNotification *)notification { @@ -909,7 +911,7 @@ - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(null self.selectLanguageCell = selectLanguageCell; mm_weakify(self); - [selectLanguageCell setEnterActionBlock:^(EZLanguage _Nonnull from, EZLanguage _Nonnull to) { + [selectLanguageCell setEnterActionBlock:^(EZLanguage from, EZLanguage to) { mm_strongify(self); self.queryModel.userSourceLanguage = from; self.queryModel.userTargetLanguage = to; @@ -996,7 +998,7 @@ - (void)reloadTableViewData:(nullable void (^)(void))completion { - (void)reloadTableViewDataWithLock:(BOOL)lockFlag completion:(nullable void (^)(void))completion { [CATransaction begin]; [CATransaction setCompletionBlock:^{ - [self updateWindowViewHeightWithLock:lockFlag animate:NO display:YES]; + [self updateWindowHeightWithLock:lockFlag]; if (completion) { completion(); } @@ -1081,7 +1083,7 @@ - (void)updateTableViewRowIndexes:(NSIndexSet *)rowIndexes // !!!: Must first notify the update tableView cell height, and then calculate the tableView height. // MMLogInfo(@"noteHeightOfRowsWithIndexesChanged: %@", rowIndexes); [self.tableView noteHeightOfRowsWithIndexesChanged:rowIndexes]; - [self updateWindowViewHeight]; + [self updateWindowHeight]; } completionHandler:^{ // MMLogInfo(@"completionHandler, updateTableViewRowIndexes: %@", rowIndexes); if (completionHandler) { @@ -1566,17 +1568,11 @@ - (CGRect)tableViewContentBounds { #pragma mark - Update Window Height -- (void)updateWindowViewHeight { - [self updateWindowViewHeightWithAnimation:NO display:YES]; -} - -- (void)updateWindowViewHeightWithAnimation:(BOOL)animateFlag display:(BOOL)displayFlag { - [self updateWindowViewHeightWithLock:YES animate:animateFlag display:displayFlag]; +- (void)updateWindowHeight { + [self updateWindowHeightWithLock:YES]; } -- (void)updateWindowViewHeightWithLock:(BOOL)lockFlag - animate:(BOOL)animateFlag - display:(BOOL)displayFlag { +- (void)updateWindowHeightWithLock:(BOOL)lockFlag { if (lockFlag) { self.lockResizeWindow = YES; } @@ -1615,19 +1611,15 @@ - (void)updateWindowViewHeightWithLock:(BOOL)lockFlag // ???: why set window frame will change tableView height? // ???: why this window animation will block cell rendering? // [self.window setFrame:safeFrame display:NO animate:animateFlag]; - [self.baseQueryWindow setFrame:safeFrame display:NO]; + [self.baseQueryWindow setFrame:safeFrame display:YES]; // Restore tableView height. self.tableView.height = tableViewHeight; - if (animateFlag) { - // Animation cost time. - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(EZUpdateTableViewRowHeightAnimationDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - self.lockResizeWindow = NO; - }); - } else { + // Animation cost time. + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(EZUpdateTableViewRowHeightAnimationDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.lockResizeWindow = NO; - } + }); // MMLogInfo(@"window frame: %@", @(window.frame)); } diff --git a/Easydict/objc/ViewController/Window/WindowManager/EZLayoutManager.m b/Easydict/objc/ViewController/Window/WindowManager/EZLayoutManager.m index e58e489fc..45787f0de 100644 --- a/Easydict/objc/ViewController/Window/WindowManager/EZLayoutManager.m +++ b/Easydict/objc/ViewController/Window/WindowManager/EZLayoutManager.m @@ -107,6 +107,10 @@ - (CGSize)maximumWindowSize:(EZWindowType)type { - (CGFloat)inputViewMinHeight:(EZWindowType)type { + if (![self showInputTextField:type]) { + return 0; + } + switch (type) { case EZWindowTypeMain: return 75; // three line @@ -120,6 +124,10 @@ - (CGFloat)inputViewMinHeight:(EZWindowType)type { } - (CGFloat)inputViewMaxHeight:(EZWindowType)type { + if (![self showInputTextField:type]) { + return 0; + } + switch (type) { case EZWindowTypeMain: return NSScreen.mainScreen.frame.size.height * 0.3; @@ -210,4 +218,8 @@ - (void)updateWindowFrame:(EZBaseQueryWindow *)window { [Configuration.shared setWindowFrame:window.frame windowType:windowType]; } +- (BOOL)showInputTextField:(EZWindowType)windowType { + return [Configuration.shared showInputTextFieldWithKey:WindowConfigurationKeyInputFieldCellVisible windowType:windowType]; +} + @end