mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Add "Open file in CotEditor" Service
This commit is contained in:
parent
cac8da3c81
commit
b9be2df841
@ -9,7 +9,7 @@ Change Log
|
||||
|
||||
- New AppleScript property `tab width` for document object.
|
||||
- Now, CotEditor script receives the absolute file path of the frontmost document as an argument if available.
|
||||
- Add “New CotEditor Document with Selection” Services menu.
|
||||
- Add “New CotEditor Document with Selection” and “Open File in CotEditor” Services.
|
||||
|
||||
|
||||
### Additions/Changes
|
||||
|
@ -970,6 +970,27 @@
|
||||
<string>NSStringPboardType</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>NSMenuItem</key>
|
||||
<dict>
|
||||
<key>default</key>
|
||||
<string>Open File in CotEditor</string>
|
||||
</dict>
|
||||
<key>NSMessage</key>
|
||||
<string>openFile</string>
|
||||
<key>NSPortName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>NSSendTypes</key>
|
||||
<array>
|
||||
<string>NSURLPboardType</string>
|
||||
<string>NSStringPboardType</string>
|
||||
</array>
|
||||
<key>NSRequiredContext</key>
|
||||
<dict>
|
||||
<key>NSTextContent</key>
|
||||
<string>FilePath</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</array>
|
||||
<key>OSAScriptingDefinition</key>
|
||||
<string>${PRODUCT_NAME}.sdef</string>
|
||||
|
@ -47,5 +47,6 @@
|
||||
@interface CEAppDelegate (Services)
|
||||
|
||||
- (void)openSelection:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error;
|
||||
- (void)openFile:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error;
|
||||
|
||||
@end
|
||||
|
@ -779,6 +779,47 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
/// open files via Services
|
||||
- (void)openFile:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
for (NSPasteboardItem *item in [pboard pasteboardItems]) {
|
||||
NSString *type = [item availableTypeFromArray:@[(NSString *)kUTTypeFileURL, (NSString *)kUTTypeText]];
|
||||
NSURL *fileURL = [NSURL URLWithString:[item stringForType:type]];
|
||||
|
||||
if (![fileURL checkResourceIsReachableAndReturnError:nil]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get file UTI
|
||||
NSString *uti = nil;
|
||||
[fileURL getResourceValue:&uti forKey:NSURLTypeIdentifierKey error:nil];
|
||||
|
||||
// process only plain-text files
|
||||
if (![[NSWorkspace sharedWorkspace] type:uti conformsToType:(NSString *)kUTTypeText]) {
|
||||
NSError *err = [NSError errorWithDomain:NSCocoaErrorDomain
|
||||
code:NSFileReadCorruptFileError
|
||||
userInfo:@{NSURLErrorKey: fileURL}];
|
||||
[[NSAlert alertWithError:err] runModal];
|
||||
continue;
|
||||
}
|
||||
|
||||
// open file
|
||||
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:fileURL
|
||||
display:YES
|
||||
completionHandler:^(NSDocument *document,
|
||||
BOOL documentWasAlreadyOpen,
|
||||
NSError *error)
|
||||
{
|
||||
if (error) {
|
||||
[[NSAlert alertWithError:error] runModal];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -12,3 +12,4 @@
|
||||
|
||||
|
||||
"New CotEditor Document with Selection" = "選択範囲を含む新規書類を CotEditor で開く";
|
||||
"Open File in CotEditor" = "ファイルを CotEditor で開く";
|
||||
|
@ -12,3 +12,4 @@
|
||||
|
||||
|
||||
"New CotEditor Document with Selection" = "New CotEditor Document with Selection"; // FIXME:
|
||||
"Open File in CotEditor" = "Open File in CotEditor"; // FIXME:
|
||||
|
Loading…
Reference in New Issue
Block a user