mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Add displayNameWithExtension: method to OakDocument
This will also ensure the display name does not contain any slashes (which it can when a custom name is set) so that it is safe to use this as a filename.
This commit is contained in:
@@ -25,6 +25,8 @@ PUBLIC @interface OakDocument : NSObject
|
||||
@property (nonatomic) NSString* diskEncoding;
|
||||
@property (nonatomic) NSString* diskNewlines;
|
||||
|
||||
- (NSString*)displayNameWithExtension:(BOOL)flag;
|
||||
|
||||
- (void)loadModalForWindow:(NSWindow*)aWindow completionHandler:(void(^)(BOOL success, NSString* errorMessage, oak::uuid_t const& filterUUID))block;
|
||||
- (void)close;
|
||||
|
||||
|
||||
@@ -401,6 +401,37 @@ private:
|
||||
return _untitledCount == 1 ? @"untitled" : [NSString stringWithFormat:@"untitled %lu", _untitledCount];
|
||||
}
|
||||
|
||||
- (NSString*)displayNameWithExtension:(BOOL)flag
|
||||
{
|
||||
NSString* res = [self.displayName stringByReplacingOccurrencesOfString:@"/" withString:@":"];
|
||||
if(!flag)
|
||||
return res;
|
||||
|
||||
if(_customName && OakNotEmptyString([res pathExtension]))
|
||||
return res;
|
||||
|
||||
if(_path)
|
||||
return [_path lastPathComponent];
|
||||
|
||||
if(_buffer && _buffer->grammar())
|
||||
{
|
||||
if(bundles::item_ptr item = bundles::lookup(_buffer->grammar()->uuid()))
|
||||
{
|
||||
if(NSString* ext = to_ns(item->value_for_field(bundles::kFieldGrammarExtension)))
|
||||
return [res stringByAppendingPathExtension:ext];
|
||||
}
|
||||
}
|
||||
else if(_fileType)
|
||||
{
|
||||
for(auto const& item : bundles::query(bundles::kFieldGrammarScope, to_s(_fileType)))
|
||||
{
|
||||
if(NSString* ext = to_ns(item->value_for_field(bundles::kFieldGrammarExtension)))
|
||||
return [res stringByAppendingPathExtension:ext];
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
- (void)setPath:(NSString*)newPath
|
||||
{
|
||||
NSString* path = to_ns(path::resolve(to_s(newPath)));
|
||||
|
||||
Reference in New Issue
Block a user