Merge pull request #1064 from ichizok/fix/balloon-gui

Fix balloon API on GUI
This commit is contained in:
Yee Cheng Chin
2021-03-07 22:02:03 -08:00
committed by GitHub
6 changed files with 14 additions and 39 deletions
-7
View File
@@ -13,13 +13,6 @@
#import "vim.h"
#ifdef FEAT_BEVAL
// Seconds to delay balloon evaluation after mouse event (subtracted from
// p_bdlay).
extern NSTimeInterval MMBalloonEvalInternalDelay;
#endif
@interface MMBackend : NSObject <MMBackendProtocol, MMVimServerProtocol,
MMVimClientProtocol> {
NSMutableArray *outputQueue;
+4 -10
View File
@@ -46,12 +46,6 @@
static unsigned MMServerMax = 1000;
#ifdef FEAT_BEVAL
// Seconds to delay balloon evaluation after mouse event (subtracted from
// p_bdlay so that this effectively becomes the smallest possible delay).
NSTimeInterval MMBalloonEvalInternalDelay = 0.1;
#endif
// TODO: Move to separate file.
static int eventModifierFlagsToVimModMask(int modifierFlags);
static int eventModifierFlagsToVimMouseModMask(int modifierFlags);
@@ -1919,7 +1913,7 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
object:nil];
[self performSelector:@selector(bevalCallback:)
withObject:nil
afterDelay:MMBalloonEvalInternalDelay];
afterDelay:p_bdlay/1000.0];
}
#endif
} else if (MouseDownMsgID == msgid) {
@@ -1978,7 +1972,7 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
object:nil];
[self performSelector:@selector(bevalCallback:)
withObject:nil
afterDelay:MMBalloonEvalInternalDelay];
afterDelay:p_bdlay/1000.0];
}
#endif
} else if (AddInputMsgID == msgid) {
@@ -3359,14 +3353,14 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
// variable. (The reason we need to know is due to how the Cocoa tool
// tips work: if there is no tool tip we must set it to nil explicitly
// or it might never go away.)
[self setLastToolTip:nil];
(*balloonEval->msgCB)(balloonEval, 0);
[self queueMessage:SetTooltipMsgID properties:
[NSDictionary dictionaryWithObject:(lastToolTip ? lastToolTip : @"")
forKey:@"toolTip"]];
[self flushQueue:YES];
[self setLastToolTip:nil];
}
}
#endif
+5 -11
View File
@@ -161,7 +161,7 @@ static BOOL isUnsafeMessage(int msgid);
- (void)handleBrowseForFile:(NSDictionary *)attr;
- (void)handleShowDialog:(NSDictionary *)attr;
- (void)handleDeleteSign:(NSDictionary *)attr;
- (void)setToolTipDelay:(NSTimeInterval)seconds;
- (void)setToolTipDelay;
@end
@@ -219,6 +219,8 @@ static BOOL isUnsafeMessage(int msgid);
[mainMenu addItem:appMenuItem];
[self setToolTipDelay];
isInitialized = YES;
// After MMVimController's initialization is completed,
@@ -1006,11 +1008,6 @@ static BOOL isUnsafeMessage(int msgid);
[textView setToolTipAtMousePoint:toolTip];
else
[textView setToolTipAtMousePoint:nil];
} else if (SetTooltipDelayMsgID == msgid) {
NSDictionary *dict = [NSDictionary dictionaryWithData:data];
NSNumber *delay = dict ? [dict objectForKey:@"delay"] : nil;
if (delay)
[self setToolTipDelay:[delay floatValue]];
} else if (AddToMRUMsgID == msgid) {
NSDictionary *dict = [NSDictionary dictionaryWithData:data];
NSArray *filenames = dict ? [dict objectForKey:@"filenames"] : nil;
@@ -1906,18 +1903,15 @@ static BOOL isUnsafeMessage(int msgid);
[view deleteSign:[attr objectForKey:@"imgName"]];
}
- (void)setToolTipDelay:(NSTimeInterval)seconds
- (void)setToolTipDelay
{
// HACK! NSToolTipManager is an AppKit private class.
static Class TTM = nil;
if (!TTM)
TTM = NSClassFromString(@"NSToolTipManager");
if (seconds < 0)
seconds = 0;
if (TTM) {
[[TTM sharedToolTipManager] setInitialToolTipDelay:seconds];
[[TTM sharedToolTipManager] setInitialToolTipDelay:1e-6];
} else {
ASLogNotice(@"Failed to get NSToolTipManager");
}
-1
View File
@@ -261,7 +261,6 @@ extern const char * const MMVimMsgIDStrings[];
MSG(SetWindowPositionMsgID) \
MSG(DeleteSignMsgID) \
MSG(SetTooltipMsgID) \
MSG(SetTooltipDelayMsgID) \
MSG(GestureMsgID) \
MSG(AddToMRUMsgID) \
MSG(BackingPropertiesChangedMsgID) \
+5 -7
View File
@@ -2494,12 +2494,7 @@ gui_mch_create_beval_area(
void
gui_mch_enable_beval_area(BalloonEval *beval UNUSED)
{
// Set the balloon delay when enabling balloon eval.
float delay = p_bdlay/1000.0f - MMBalloonEvalInternalDelay;
if (delay < 0) delay = 0;
[[MMBackend sharedInstance] queueMessage:SetTooltipDelayMsgID properties:
[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:delay]
forKey:@"delay"]];
// NOP
}
void
@@ -2514,8 +2509,11 @@ gui_mch_disable_beval_area(BalloonEval *beval UNUSED)
* Show a balloon with "mesg".
*/
void
gui_mch_post_balloon(BalloonEval *beval UNUSED, char_u *mesg)
gui_mch_post_balloon(BalloonEval *beval, char_u *mesg)
{
vim_free(beval->msg);
beval->msg = mesg == NULL ? NULL : vim_strsave(mesg);
NSString *toolTip = [NSString stringWithVimString:mesg];
[[MMBackend sharedInstance] setLastToolTip:toolTip];
}
-3
View File
@@ -4,8 +4,6 @@ source check.vim
CheckGui
CheckFeature balloon_eval
if !has('gui_macvim') " See https://github.com/macvim-dev/macvim/issues/902
func Test_balloon_show_gui()
let msg = 'this this this this'
call balloon_show(msg)
@@ -20,5 +18,4 @@ func Test_balloon_show_gui()
call balloon_show('')
endfunc
endif " !has('gui_macvim')
" vim: shiftwidth=2 sts=2 expandtab