mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
More code ported to OakDocument
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
#import <bundles/bundles.h>
|
||||
#import <command/parser.h>
|
||||
#import <command/runner.h>
|
||||
#import <document/collection.h>
|
||||
#import <document/OakDocument.h>
|
||||
#import <document/OakDocumentController.h>
|
||||
#import <ns/ns.h>
|
||||
#import <settings/settings.h>
|
||||
#import <OakAppKit/NSAlert Additions.h>
|
||||
@@ -33,13 +34,16 @@ OAK_DEBUG_VAR(AppController_Commands);
|
||||
{
|
||||
case bundles::kItemTypeSnippet:
|
||||
{
|
||||
document::document_ptr doc = document::create();
|
||||
// TODO set language according to snippet’s scope selector
|
||||
doc->sync_load();
|
||||
document::show(doc); // If we call show() with a document that isn’t open then it will be loaded in the background, and show() will return before this has completed, meaning the next line may not target our new document.
|
||||
[[DocumentWindowController controllerForDocument:doc] performBundleItem:item];
|
||||
doc->close();
|
||||
// TODO mark document as “not modified”
|
||||
|
||||
OakDocument* doc = [OakDocumentController.sharedInstance untitledDocument];
|
||||
[doc loadModalForWindow:nil completionHandler:^(OakDocumentIOResult result, NSString* errorMessage, oak::uuid_t const& filterUUID){
|
||||
[OakDocumentController.sharedInstance showDocument:doc];
|
||||
if(DocumentWindowController* controller = [DocumentWindowController controllerForDocument:doc])
|
||||
[controller performBundleItem:item];
|
||||
[doc markDocumentSaved];
|
||||
[doc close];
|
||||
}];
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -53,7 +57,9 @@ OAK_DEBUG_VAR(AppController_Commands);
|
||||
|
||||
case bundles::kItemTypeGrammar:
|
||||
{
|
||||
document::show(document::from_content("", item->value_for_field(bundles::kFieldGrammarScope)));
|
||||
OakDocument* doc = [OakDocumentController.sharedInstance untitledDocument];
|
||||
doc.fileType = to_ns(item->value_for_field(bundles::kFieldGrammarScope));
|
||||
[OakDocumentController.sharedInstance showDocument:doc];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
#import <OakFoundation/NSString Additions.h>
|
||||
#import <ns/ns.h>
|
||||
#import <text/decode.h>
|
||||
#import <document/collection.h>
|
||||
#import <document/OakDocument.h>
|
||||
#import <document/OakDocumentController.h>
|
||||
|
||||
OAK_DEBUG_VAR(AppController_Documents);
|
||||
|
||||
@@ -103,6 +104,7 @@ OAK_DEBUG_VAR(AppController_Documents);
|
||||
if(line != parameters.end())
|
||||
range = text::pos_t(atoi(line->second.c_str())-1, col-1);
|
||||
|
||||
NSUUID* projectUUID = project != parameters.end() ? [[NSUUID alloc] initWithUUIDString:to_ns(project->second)] : nil;
|
||||
if(url != parameters.end())
|
||||
{
|
||||
static std::string const kTildeURLPrefixes[] = { "file://localhost/~/", "file:///~/", "file://~/" };
|
||||
@@ -128,13 +130,13 @@ OAK_DEBUG_VAR(AppController_Documents);
|
||||
|
||||
if(path::is_directory(path))
|
||||
{
|
||||
document::show_browser(path);
|
||||
[OakDocumentController.sharedInstance showFileBrowserAtPath:to_ns(path)];
|
||||
}
|
||||
else if(path::exists(path))
|
||||
{
|
||||
document::document_ptr doc = document::create(path);
|
||||
doc->set_recent_tracking(false);
|
||||
document::show(doc, project != parameters.end() ? oak::uuid_t(project->second) : document::kCollectionAny, range);
|
||||
OakDocument* doc = [OakDocumentController.sharedInstance documentWithPath:to_ns(path)];
|
||||
doc.recentTrackingDisabled = YES;
|
||||
[OakDocumentController.sharedInstance showDocument:doc andSelect:range inProject:projectUUID bringToFront:YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -143,10 +145,10 @@ OAK_DEBUG_VAR(AppController_Documents);
|
||||
}
|
||||
else if(uuid != parameters.end())
|
||||
{
|
||||
if(document::document_ptr doc = document::find(uuid->second))
|
||||
if(OakDocument* doc = [OakDocumentController.sharedInstance findDocumentWithIdentifier:[[NSUUID alloc] initWithUUIDString:to_ns(uuid->second)]])
|
||||
{
|
||||
doc->set_recent_tracking(false);
|
||||
document::show(doc, project != parameters.end() ? oak::uuid_t(project->second) : document::kCollectionAny, range);
|
||||
doc.recentTrackingDisabled = YES;
|
||||
[OakDocumentController.sharedInstance showDocument:doc andSelect:range inProject:projectUUID bringToFront:YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
#import <Preferences/Preferences.h>
|
||||
#import <Preferences/TerminalPreferences.h>
|
||||
#import <SoftwareUpdate/SoftwareUpdate.h>
|
||||
#import <document/collection.h>
|
||||
#import <document/OakDocument.h>
|
||||
#import <document/OakDocumentController.h>
|
||||
#import <bundles/query.h>
|
||||
#import <io/path.h>
|
||||
#import <network/tbz.h>
|
||||
@@ -36,29 +37,31 @@ OAK_DEBUG_VAR(AppController);
|
||||
|
||||
void OakOpenDocuments (NSArray* paths, BOOL treatFilePackageAsFolder)
|
||||
{
|
||||
std::vector<document::document_ptr> documents;
|
||||
NSArray* const bundleExtensions = @[ @"tmbundle", @"tmcommand", @"tmdragcommand", @"tmlanguage", @"tmmacro", @"tmpreferences", @"tmsnippet", @"tmtheme" ];
|
||||
|
||||
NSMutableArray<OakDocument*>* documents = [NSMutableArray array];
|
||||
NSMutableArray* itemsToInstall = [NSMutableArray array];
|
||||
NSMutableArray* plugInsToInstall = [NSMutableArray array];
|
||||
BOOL enableInstallHandler = treatFilePackageAsFolder == NO && ([NSEvent modifierFlags] & NSAlternateKeyMask) == 0;
|
||||
for(NSString* path in paths)
|
||||
{
|
||||
static auto const tmItemExtensions = new std::set<std::string>{ "tmbundle", "tmcommand", "tmdragcommand", "tmlanguage", "tmmacro", "tmpreferences", "tmsnippet", "tmtheme" };
|
||||
std::string const pathExt = to_s([[path pathExtension] lowercaseString]);
|
||||
if(enableInstallHandler && tmItemExtensions->find(pathExt) != tmItemExtensions->end())
|
||||
BOOL isDirectory = NO;
|
||||
NSString* pathExt = [[path pathExtension] lowercaseString];
|
||||
if(enableInstallHandler && [bundleExtensions containsObject:pathExt])
|
||||
{
|
||||
[itemsToInstall addObject:path];
|
||||
}
|
||||
else if(enableInstallHandler && pathExt == "tmplugin")
|
||||
else if(enableInstallHandler && [pathExt isEqualToString:@"tmplugin"])
|
||||
{
|
||||
[plugInsToInstall addObject:path];
|
||||
}
|
||||
else if(path::is_directory(to_s(path)))
|
||||
else if([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory)
|
||||
{
|
||||
document::show_browser(to_s(path));
|
||||
[OakDocumentController.sharedInstance showFileBrowserAtPath:path];
|
||||
}
|
||||
else
|
||||
{
|
||||
documents.push_back(document::create(to_s(path)));
|
||||
[documents addObject:[OakDocumentController.sharedInstance documentWithPath:path]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +71,7 @@ void OakOpenDocuments (NSArray* paths, BOOL treatFilePackageAsFolder)
|
||||
for(NSString* path in plugInsToInstall)
|
||||
[[TMPlugInController sharedInstance] installPlugInAtPath:path];
|
||||
|
||||
document::show(documents);
|
||||
[OakDocumentController.sharedInstance showDocuments:documents];
|
||||
}
|
||||
|
||||
BOOL HasDocumentWindow (NSArray* windows)
|
||||
@@ -436,9 +439,9 @@ BOOL HasDocumentWindow (NSArray* windows)
|
||||
|
||||
if(DocumentWindowController* controller = [NSApp targetForAction:@selector(selectedDocument)])
|
||||
{
|
||||
document::document_ptr doc = controller.selectedDocument;
|
||||
chooser.path = doc ? [NSString stringWithCxxString:doc->path()] : nil;
|
||||
chooser.directory = doc && doc->path() != NULL_STR ? [NSString stringWithCxxString:path::parent(doc->path())] : controller.untitledSavePath;
|
||||
OakDocument* doc = controller.selectedDocument->document();
|
||||
chooser.path = doc.path;
|
||||
chooser.directory = [doc.path stringByDeletingLastPathComponent] ?: doc.directory;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -513,10 +516,9 @@ BOOL HasDocumentWindow (NSArray* windows)
|
||||
}
|
||||
else if(NSString* path = [[[sender selectedItems] lastObject] objectForKey:@"file"])
|
||||
{
|
||||
document::document_ptr doc = document::create(to_s(path));
|
||||
if(NSString* line = [[[sender selectedItems] lastObject] objectForKey:@"line"])
|
||||
doc->set_selection(to_s(line));
|
||||
document::show(doc);
|
||||
OakDocument* doc = [OakDocumentController.sharedInstance documentWithPath:path];
|
||||
NSString* line = [[[sender selectedItems] lastObject] objectForKey:@"line"];
|
||||
[OakDocumentController.sharedInstance showDocument:doc andSelect:(line ? text::pos_t(to_s(line)) : text::pos_t::undefined) inProject:nil bringToFront:YES];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#import <document/document.h>
|
||||
#import <command/runner.h>
|
||||
|
||||
@class OakDocument;
|
||||
|
||||
PUBLIC @interface DocumentWindowController : NSObject
|
||||
@property (nonatomic) NSWindow* window;
|
||||
|
||||
@@ -87,5 +89,5 @@ PUBLIC @interface DocumentWindowController : NSObject
|
||||
- (IBAction)orderFrontGoToFolder:(id)sender;
|
||||
|
||||
// Used by AppController
|
||||
+ (instancetype)controllerForDocument:(document::document_ptr const&)aDocument;
|
||||
+ (instancetype)controllerForDocument:(OakDocument*)aDocument;
|
||||
@end
|
||||
|
||||
@@ -2768,19 +2768,19 @@ static NSUInteger DisableSessionSavingCount = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
+ (instancetype)controllerForDocument:(document::document_ptr const&)aDocument
|
||||
+ (instancetype)controllerForDocument:(OakDocument*)aDocument
|
||||
{
|
||||
if(!aDocument)
|
||||
return nil;
|
||||
|
||||
for(DocumentWindowController* delegate in SortedControllers())
|
||||
{
|
||||
if(delegate.fileBrowserVisible && aDocument->path() != NULL_STR && aDocument->path().find(to_s(delegate.projectPath)) == 0)
|
||||
if(delegate.fileBrowserVisible && aDocument.path && [aDocument.path hasPrefix:delegate.projectPath])
|
||||
return delegate;
|
||||
|
||||
for(auto document : delegate.documents)
|
||||
{
|
||||
if(*document == *aDocument)
|
||||
if([aDocument isEqual:document->document()])
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user