mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-11 15:37:29 +02:00
Add command line completion to :macaction command
This enables the user to cycle through all actions by typing ":maca <Tab>" and then repeatedly hitting <Tab>. The help on :maca was also updated. (Initial patch by Nico Weber with some changes by Bjorn Winckler.)
This commit is contained in:
committed by
Bjorn Winckler
parent
7792c4e8ab
commit
69c366f7ed
@@ -341,16 +341,16 @@ to "~/.gvimrc": >
|
||||
<
|
||||
*:maca* *:macaction*
|
||||
It is typical for menu items in Cocoa applications to bind to Objective-C
|
||||
selectors. To support this, MacVim introduces the ":macaction" command. This
|
||||
selectors. To support this, MacVim introduces the |:macaction| command. This
|
||||
command takes the name of an action message as its only parameter. (An action
|
||||
message is an Objective-C message with "void" return type and a single
|
||||
parameter of type "id".) For example, the "New Window" menu item on the
|
||||
"File" menu is created in the following manner: >
|
||||
:an 10.290 File.New\ Window :macaction newWindow:<CR>
|
||||
|
||||
Note 1: A menu item which is bound to ":macaction" will automatically be bound
|
||||
Note 1: A menu item which is bound to |:macaction| will automatically be bound
|
||||
to that action in all modes (as if ":an" was used). It is not possible to
|
||||
bind to ":macaction" in one mode only.
|
||||
bind to |:macaction| in one mode only.
|
||||
Note 2: The action is "nil-targeted", which means it is passed down the first
|
||||
responder chain.
|
||||
|
||||
@@ -361,8 +361,11 @@ application bundle) which contains all actions that may be called. The key in
|
||||
this dictionary is the name of the action message (case sensitive), the value
|
||||
is not used.
|
||||
|
||||
Note: The |:macaction| command supports tab-completion so to cycle through
|
||||
all available commands type ":maca<Space><Tab>" and keep pressing <Tab>.
|
||||
|
||||
Here is a random assortment of actions from Actions.plist which might be
|
||||
useful.
|
||||
useful.
|
||||
|
||||
Action Description ~
|
||||
findNext: Search forward using the "Find Pasteboard"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
id frontendProxy;
|
||||
NSDictionary *colorDict;
|
||||
NSDictionary *sysColorDict;
|
||||
NSDictionary *actionDict;
|
||||
BOOL inputReceived;
|
||||
BOOL tabBarVisible;
|
||||
unsigned backgroundColor;
|
||||
@@ -54,6 +55,7 @@
|
||||
- (void)setSpecialColor:(int)color;
|
||||
- (void)setDefaultColorsBackground:(int)bg foreground:(int)fg;
|
||||
- (NSConnection *)connection;
|
||||
- (NSDictionary *)actionDict;
|
||||
|
||||
- (BOOL)checkin;
|
||||
- (BOOL)openVimWindow;
|
||||
|
||||
+11
-2
@@ -142,8 +142,12 @@ static NSString *MMSymlinkWarningString =
|
||||
sysColorDict = [[NSDictionary dictionaryWithContentsOfFile:path]
|
||||
retain];
|
||||
|
||||
if (!(colorDict && sysColorDict))
|
||||
NSLog(@"ERROR: Failed to load color dictionaries.%@",
|
||||
path = [mainBundle pathForResource:@"Actions" ofType:@"plist"];
|
||||
if (path)
|
||||
actionDict = [[NSDictionary dictionaryWithContentsOfFile:path] retain];
|
||||
|
||||
if (!(colorDict && sysColorDict && actionDict))
|
||||
NSLog(@"ERROR: Failed to load dictionaries.%@",
|
||||
MMSymlinkWarningString);
|
||||
|
||||
return self;
|
||||
@@ -215,6 +219,11 @@ static NSString *MMSymlinkWarningString =
|
||||
return connection;
|
||||
}
|
||||
|
||||
- (NSDictionary *)actionDict
|
||||
{
|
||||
return actionDict;
|
||||
}
|
||||
|
||||
- (BOOL)checkin
|
||||
{
|
||||
if (![self connection]) {
|
||||
|
||||
+34
-16
@@ -1478,22 +1478,8 @@ gui_mch_toggle_tearoffs(int enable)
|
||||
static BOOL
|
||||
gui_macvim_is_valid_action(NSString *action)
|
||||
{
|
||||
static NSDictionary *actionDict = nil;
|
||||
|
||||
if (!actionDict) {
|
||||
NSBundle *mainBundle = [NSBundle mainBundle];
|
||||
NSString *path = [mainBundle pathForResource:@"Actions"
|
||||
ofType:@"plist"];
|
||||
if (path) {
|
||||
actionDict = [[NSDictionary alloc] initWithContentsOfFile:path];
|
||||
} else {
|
||||
// Allocate bogus dictionary so that error only pops up once.
|
||||
actionDict = [NSDictionary new];
|
||||
EMSG(_("E???: Failed to load action dictionary"));
|
||||
}
|
||||
}
|
||||
|
||||
return [actionDict objectForKey:action] != nil;
|
||||
NSDictionary *actionDict = [[MMBackend sharedInstance] actionDict];
|
||||
return actionDict && [actionDict objectForKey:action] != nil;
|
||||
}
|
||||
|
||||
|
||||
@@ -1834,3 +1820,35 @@ odb_end(void)
|
||||
}
|
||||
|
||||
#endif // FEAT_ODB_EDITOR
|
||||
|
||||
|
||||
char_u *
|
||||
get_macaction_name(expand_T *xp, int idx)
|
||||
{
|
||||
static char_u *str = NULL;
|
||||
NSDictionary *actionDict = [[MMBackend sharedInstance] actionDict];
|
||||
|
||||
if (nil == actionDict || idx < 0 || idx >= [actionDict count])
|
||||
return NULL;
|
||||
|
||||
NSString *string = [[actionDict allKeys] objectAtIndex:idx];
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
char_u *plainStr = (char_u*)[string UTF8String];
|
||||
|
||||
#ifdef FEAT_MBYTE
|
||||
if (str) {
|
||||
vim_free(str);
|
||||
str = NULL;
|
||||
}
|
||||
if (input_conv.vc_type != CONV_NONE) {
|
||||
int len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
||||
str = string_convert(&input_conv, plainStr, &len);
|
||||
plainStr = str;
|
||||
}
|
||||
#endif
|
||||
|
||||
return plainStr;
|
||||
}
|
||||
|
||||
|
||||
@@ -3792,6 +3792,14 @@ set_one_cmd_context(xp, buff)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef FEAT_GUI_MACVIM
|
||||
case CMD_macaction:
|
||||
xp->xp_context = EXPAND_MACACTION;
|
||||
xp->xp_pattern = arg;
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* FEAT_CMDL_COMPL */
|
||||
|
||||
default:
|
||||
|
||||
@@ -4449,6 +4449,9 @@ ExpandFromContext(xp, pat, num_file, file, options)
|
||||
{EXPAND_LANGUAGE, get_lang_arg, TRUE},
|
||||
#endif
|
||||
{EXPAND_ENV_VARS, get_env_name, TRUE},
|
||||
#ifdef FEAT_GUI_MACVIM
|
||||
{EXPAND_MACACTION, get_macaction_name, FALSE},
|
||||
#endif
|
||||
};
|
||||
int i;
|
||||
|
||||
|
||||
@@ -201,3 +201,4 @@ OSErr odb_buffer_close(buf_T *buf);
|
||||
OSErr odb_post_buffer_write(buf_T *buf);
|
||||
void odb_end(void);
|
||||
|
||||
char_u *get_macaction_name(expand_T *xp, int idx);
|
||||
|
||||
Reference in New Issue
Block a user