mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Add ‘New Document’ to file browser
This create a new file on disk and brings up the “rename” text field.
You can control the type/extension either in Preferences → New document type or by setting it in .tm_properties, e.g.:
[ attr.untitled ]
fileType = 'source.objc++'
New Document can be undone, but it is handled by deleting the file on disk and losing potential edits you have made since creating it.
Closes #161.
This commit is contained in:
@@ -664,6 +664,43 @@ namespace
|
||||
[self takeNewTabIndexFrom:[NSIndexSet indexSetWithIndex:_selectedTabIndex + 1]];
|
||||
}
|
||||
|
||||
- (IBAction)newDocumentInDirectory:(id)sender
|
||||
{
|
||||
if(!self.fileBrowserVisible)
|
||||
return;
|
||||
|
||||
if(NSString* folder = [self.fileBrowser directoryForNewItems])
|
||||
{
|
||||
std::string path = "untitled";
|
||||
for(auto item : bundles::query(bundles::kFieldGrammarScope, settings_for_path(NULL_STR, "attr.untitled", to_s(folder)).get(kSettingsFileTypeKey, "text.plain")))
|
||||
{
|
||||
std::string const& ext = item->value_for_field(bundles::kFieldGrammarExtension);
|
||||
if(ext != NULL_STR)
|
||||
path = "untitled." + ext;
|
||||
}
|
||||
|
||||
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithCxxString:path::unique(path::join([folder fileSystemRepresentation], path))]];
|
||||
if([[OakFileManager sharedInstance] createFileAtURL:url window:self.window])
|
||||
{
|
||||
document::document_ptr doc = document::create(to_s([url path]));
|
||||
doc->open();
|
||||
[self setSelectedDocument:doc];
|
||||
doc->close();
|
||||
|
||||
size_t selectedIndex = _selectedTabIndex;
|
||||
std::vector<document::document_ptr> documents = _documents;
|
||||
if(is_disposable(documents[selectedIndex]))
|
||||
documents[selectedIndex] = doc;
|
||||
else documents.insert(documents.begin() + ++selectedIndex, doc);
|
||||
|
||||
self.documents = documents;
|
||||
self.selectedTabIndex = selectedIndex;
|
||||
|
||||
[self.fileBrowser editURL:url];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)moveDocumentToNewWindow:(id)sender
|
||||
{
|
||||
if(_documents.size() > 1)
|
||||
@@ -1848,6 +1885,8 @@ namespace
|
||||
[menuItem setTitle:self.htmlOutputVisible ? @"Hide HTML Output" : @"Show HTML Output"];
|
||||
active = !self.htmlOutputInWindow || self.htmlOutputWindowController;
|
||||
}
|
||||
else if([menuItem action] == @selector(newDocumentInDirectory:))
|
||||
active = self.fileBrowserVisible && [self.fileBrowser directoryForNewItems] != nil;
|
||||
else if([menuItem action] == @selector(moveDocumentToNewWindow:))
|
||||
active = _documents.size() > 1;
|
||||
else if([menuItem action] == @selector(goBack:))
|
||||
|
||||
@@ -178,7 +178,7 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(folderPopUpButtonWillPopUp:) name:NSPopUpButtonWillPopUpNotification object:_headerView.folderPopUpButton];
|
||||
|
||||
_actionsView = [[OFBActionsView alloc] initWithFrame:NSZeroRect];
|
||||
_actionsView.createButton.action = @selector(newDocumentInTab:);
|
||||
_actionsView.createButton.action = @selector(newDocumentInDirectory:);
|
||||
_actionsView.reloadButton.target = self;
|
||||
_actionsView.reloadButton.action = @selector(reload:);
|
||||
_actionsView.searchButton.action = @selector(orderFrontFindPanelForFileBrowser:);
|
||||
@@ -839,7 +839,7 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
|
||||
if(rootPath)
|
||||
{
|
||||
[aMenu addItem:[NSMenuItem separatorItem]];
|
||||
[aMenu addItemWithTitle:@"New Document" action:@selector(newDocumentInTab:) keyEquivalent:@""];
|
||||
[aMenu addItemWithTitle:@"New Document" action:@selector(newDocumentInDirectory:) keyEquivalent:@""];
|
||||
[aMenu addItemWithTitle:@"New Folder" action:@selector(newFolderInSelectedFolder:) keyEquivalent:@""];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user