Skip to content

Fix balloon API on GUI #1064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/MacVim/MMBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions src/MacVim/MMBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1919,7 +1913,7 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
object:nil];
[self performSelector:@selector(bevalCallback:)
withObject:nil
afterDelay:MMBalloonEvalInternalDelay];
afterDelay:p_bdlay/1000.0];
}
#endif
} else if (MouseDownMsgID == msgid) {
Expand Down Expand Up @@ -1978,7 +1972,7 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
object:nil];
[self performSelector:@selector(bevalCallback:)
withObject:nil
afterDelay:MMBalloonEvalInternalDelay];
afterDelay:p_bdlay/1000.0];
}
#endif
} else if (AddInputMsgID == msgid) {
Expand Down Expand Up @@ -3359,14 +3353,14 @@ - (void)bevalCallback:(id UNUSED)sender
// 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
Expand Down
16 changes: 5 additions & 11 deletions src/MacVim/MMVimController.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ - (void)scheduleClose;
- (void)handleBrowseForFile:(NSDictionary *)attr;
- (void)handleShowDialog:(NSDictionary *)attr;
- (void)handleDeleteSign:(NSDictionary *)attr;
- (void)setToolTipDelay:(NSTimeInterval)seconds;
- (void)setToolTipDelay;
@end


Expand Down Expand Up @@ -221,6 +221,8 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier

[mainMenu addItem:appMenuItem];

[self setToolTipDelay];

isInitialized = YES;

// After MMVimController's initialization is completed,
Expand Down Expand Up @@ -1007,11 +1009,6 @@ - (void)handleMessage:(int)msgid data:(NSData *)data
[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;
Expand Down Expand Up @@ -1907,18 +1904,15 @@ - (void)handleDeleteSign:(NSDictionary *)attr
[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");
}
Expand Down
1 change: 0 additions & 1 deletion src/MacVim/MacVim.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ extern const char * const MMVimMsgIDStrings[];
MSG(SetWindowPositionMsgID) \
MSG(DeleteSignMsgID) \
MSG(SetTooltipMsgID) \
MSG(SetTooltipDelayMsgID) \
MSG(GestureMsgID) \
MSG(AddToMRUMsgID) \
MSG(BackingPropertiesChangedMsgID) \
Expand Down
12 changes: 5 additions & 7 deletions src/MacVim/gui_macvim.m
Original file line number Diff line number Diff line change
Expand Up @@ -2494,12 +2494,7 @@
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
Expand All @@ -2514,8 +2509,11 @@
* 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];
}
Expand Down
3 changes: 0 additions & 3 deletions src/testdir/test_balloon_gui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -20,5 +18,4 @@ func Test_balloon_show_gui()
call balloon_show('')
endfunc

endif " !has('gui_macvim')
" vim: shiftwidth=2 sts=2 expandtab