MOFileCompletionStrategy


Abstract

Implements path completion.

Discussion

MOFileCompletionStrategy implements straight-forward path completion. This class uses the basePath to provide a base to use when interpretting relative paths. There are several options to control the completion behavior including whether to append a "/" after directory completions and whether to append a space after filename completions.



Methods

appendsSpaceOnFileMatch
Returns whether a space should be appended after a non-directory completion.
setAppendsSpaceOnFileMatch:
Sets whether a space should be appended after a non-directory completion.
appendsSlashOnDirectoryMatch
Returns whether a slash should be appended after a directory completion.
setAppendsSlashOnDirectoryMatch:
Sets whether a slash should be appended after a directory completion.
basePathFromProposedBasePath:path:
Calculates the base path to use for the given path.
addFilesMatchingPrefix:forChildrenOfDirectory:toMutableArray:
Collects children of the given directory that start with the given prefix.
matchesForPrefixString:newPrefixString:basePath:
Returns potential completions for a prefix path.
fullStringForPrefixString:completionString:isInitialPrefixMatch:basePath:
Method for composing a prefix path and a completion.

addFilesMatchingPrefix:forChildrenOfDirectory:toMutableArray:

Collects children of the given directory that start with the given prefix.
- ( void ) addFilesMatchingPrefix:
        (NSString *) partialName forChildrenOfDirectory:
        (NSString *) dirPath toMutableArray:
        (NSMutableArray *) matches;

Collects children of the given directory that start with the given prefix. Looking at every file in the given directory, finds any that start with the given prefix. Case-sensitive matches are looked for first, but if none are found, case-insensitive is allowed.

Parameter Descriptions
partialName
The partial name that the children are required to match. If this is nil, then all children are considered to match.
dirPath
The path to the directory to look in.
matches
An NSMutableArray to add any matches to.

appendsSlashOnDirectoryMatch

Returns whether a slash should be appended after a directory completion.
- ( BOOL ) appendsSlashOnDirectoryMatch;

Returns whether a slash should be appended after a directory completion. If YES, then after a complete directory completion, a slash will be appended. Default is YES.

method result
Whether a slash should be appended after a directory completion.

appendsSpaceOnFileMatch

Returns whether a space should be appended after a non-directory completion.
- ( BOOL ) appendsSpaceOnFileMatch;

Returns whether a space should be appended after a non-directory completion. If YES, then after a complete plain filename completion, a space will be appended. Default is NO.

method result
Whether a space should be appended after a non-directory completion.

basePathFromProposedBasePath:path:

Calculates the base path to use for the given path.
- ( NSString *) basePathFromProposedBasePath:
        (NSString *) basePath path:
        (NSString *) path;

Calculates the base path to use for the given path. This returns a standardized copy of basePath if path is not absolute, otherwise it returns nil.

Parameter Descriptions
basePath
The basePath passed into the main entry point methods.
path
The path prefix passed in as the prefix string to the main entry point methods.
method result
The base path to use for the given path.

fullStringForPrefixString:completionString:isInitialPrefixMatch:basePath:

Method for composing a prefix path and a completion.
- ( NSString *) fullStringForPrefixString:
        (NSString *) prefixStr completionString:
        (NSString *) completionStr isInitialPrefixMatch:
        (BOOL ) initialPrefixMatch basePath:
        (NSString *) basePath;

MOFileCompletionStrategy overrides this method to append the prefix and completion together as path components. Also, if initialPrefixMatch is NO then the appendsSpaceOnFileMatch or appendsSlashOnDirectoryMatch setting is taken into account and a space or slash is added if needed.

Parameter Descriptions
prefixStr
The prefix string (directory path).
completionStr
The completion string (last path component).
initialPrefixMatch
If this is NO, then the appendsSpaceOnFileMatch or appendsSlashOnDirectoryMatch settings are taken into account and a space or slash may be appended to the resulting full string.
basePath
MOFileCompletionStrategy uses this as a path that serves as the base for evaluating relative paths.
method result
The composed completion which will be inserted into the NSTextView in place of the prefix.

matchesForPrefixString:newPrefixString:basePath:

Returns potential completions for a prefix path.
- ( NSArray *) matchesForPrefixString:
        (NSString *) path newPrefixString:
        (NSString **) newStr basePath:
        (NSString *) basePath;

This method first splits the prefix string into two pieces. The first is the prefix up to the last path separator character and the second is the last (partial) path component. Then, the first part (the directory path) and the base path are passed to -basePathFromProposedBasePath:path: to find the effective basePath to use. Then, the effective basePath is prepended to the directory path and the result, along with the partial last path component are passed to -addFilesMatchingPrefix:forChildrenOfDirectory:toMutableArray: to generate the actual matches. Finally, the new prefix string (the directory path) is assigned to *newStr.

Parameter Descriptions
str
The prefix string (path) that completions should be done against.
newStr
MOFileCompletionStrategy changes the prefix to remove the last partial path component. Then the results array is returned containing full path components.
basePath
MOFileCompletionStrategy uses this as a path that serves as the base for evaluating relative paths.
method result
An array of path components starting with the given prefix path.

setAppendsSlashOnDirectoryMatch:

Sets whether a slash should be appended after a directory completion.
- ( void ) setAppendsSlashOnDirectoryMatch:
        (BOOL ) flag;

Sets whether a slash should be appended after a directory completion. If YES, then after a complete directory completion, a slash will be appended. Default is YES.

Parameter Descriptions
flag
Whether a slash should be appended after a directory completion.

setAppendsSpaceOnFileMatch:

Sets whether a space should be appended after a non-directory completion.
- ( void ) setAppendsSpaceOnFileMatch:
        (BOOL ) flag;

Sets whether a space should be appended after a non-directory completion. If YES, then after a complete plain filename completion, a space will be appended. Default is NO.

Parameter Descriptions
flag
Whether a space should be appended after a non-directory completion.

(Last Updated 3/20/2005)