Skip to content

Commit cd517e5

Browse files
committed
Add hidden Copy FIle Path command (close #1853)
1 parent d86cdfe commit cd517e5

File tree

5 files changed

+124
-3
lines changed

5 files changed

+124
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
### New Features
77

88
- Enhance the content of the file preview view for the file browser.
9+
- Add the “Copy File Path” command to the File menu as an alternative to the “Show in Finder” command, which can be shown while pressing the Option key.
910

1011

1112
### Improvements

CotEditor/Sources/Document/DataDocument.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import AppKit
3939
override func validateUserInterfaceItem(_ item: any NSValidatedUserInterfaceItem) -> Bool {
4040

4141
switch item.action {
42-
case #selector(showInFinder):
42+
case #selector(showInFinder),
43+
#selector(copyPath):
4344
return self.fileURL != nil
4445

4546
default: break
@@ -60,6 +61,16 @@ import AppKit
6061
}
6162

6263

64+
/// Copies the file path to the clipboard.
65+
@IBAction func copyPath(_ sender: Any?) {
66+
67+
guard let fileURL else { return }
68+
69+
NSPasteboard.general.clearContents()
70+
NSPasteboard.general.writeObjects([fileURL as NSURL])
71+
}
72+
73+
6374
/// Shows the sharing picker interface.
6475
@IBAction func shareDocument(_ sender: Any?) {
6576

CotEditor/Sources/Document/DirectoryDocument+Actions.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extension DirectoryDocument {
5252
return (self.currentDocument as? Document)?.validateUserInterfaceItem(item) ?? false
5353

5454
case #selector(showInFinder),
55+
#selector(copyPath),
5556
#selector(shareDocument):
5657
return self.currentDocument?.validateUserInterfaceItem(item) ?? false
5758

@@ -125,6 +126,12 @@ extension DirectoryDocument {
125126
}
126127

127128

129+
@objc func copyPath(_ sender: Any?) {
130+
131+
self.currentDocument?.copyPath(sender)
132+
}
133+
134+
128135
@objc func shareDocument(_ sender: NSMenuItem) {
129136

130137
self.currentDocument?.shareDocument(sender)

CotEditor/Storyboards/Base.lproj/Main.storyboard

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="23504" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="23727" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23504"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23727"/>
66
</dependencies>
77
<scenes>
88
<!--Application-->
@@ -124,6 +124,12 @@
124124
<action selector="showInFinder:" target="Ady-hI-5gd" id="c7U-Ai-EpC"/>
125125
</connections>
126126
</menuItem>
127+
<menuItem title="Copy File Path" alternate="YES" id="9sv-l5-xwG">
128+
<modifierMask key="keyEquivalentModifierMask" option="YES"/>
129+
<connections>
130+
<action selector="copyPath:" target="Ady-hI-5gd" id="32y-EP-V8T"/>
131+
</connections>
132+
</menuItem>
127133
<menuItem title="Share…" id="TNF-pL-CAZ">
128134
<modifierMask key="keyEquivalentModifierMask"/>
129135
<connections>

CotEditor/Storyboards/mul.lproj/Main.xcstrings

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,6 +2497,102 @@
24972497
}
24982498
}
24992499
},
2500+
"9sv-l5-xwG.title" : {
2501+
"comment" : "Class = \"NSMenuItem\"; title = \"Copy File Path\"; ObjectID = \"9sv-l5-xwG\";",
2502+
"extractionState" : "extracted_with_value",
2503+
"localizations" : {
2504+
"cs" : {
2505+
"stringUnit" : {
2506+
"state" : "translated",
2507+
"value" : "Zkopírovat cestu k souboru"
2508+
}
2509+
},
2510+
"de" : {
2511+
"stringUnit" : {
2512+
"state" : "translated",
2513+
"value" : "Dateipfad kopieren"
2514+
}
2515+
},
2516+
"en" : {
2517+
"stringUnit" : {
2518+
"state" : "new",
2519+
"value" : "Copy File Path"
2520+
}
2521+
},
2522+
"en-GB" : {
2523+
"stringUnit" : {
2524+
"state" : "translated",
2525+
"value" : "Copy File Path"
2526+
}
2527+
},
2528+
"es" : {
2529+
"stringUnit" : {
2530+
"state" : "translated",
2531+
"value" : "Copiar ruta de archivo"
2532+
}
2533+
},
2534+
"fr" : {
2535+
"stringUnit" : {
2536+
"state" : "translated",
2537+
"value" : "Copier le chemin de fichier"
2538+
}
2539+
},
2540+
"it" : {
2541+
"stringUnit" : {
2542+
"state" : "translated",
2543+
"value" : "Copia percorso file"
2544+
}
2545+
},
2546+
"ja" : {
2547+
"stringUnit" : {
2548+
"state" : "translated",
2549+
"value" : "ファイルパスをコピー"
2550+
}
2551+
},
2552+
"ko" : {
2553+
"stringUnit" : {
2554+
"state" : "translated",
2555+
"value" : "파일 경로 복사"
2556+
}
2557+
},
2558+
"nl" : {
2559+
"stringUnit" : {
2560+
"state" : "translated",
2561+
"value" : "Kopieer bestandspad"
2562+
}
2563+
},
2564+
"pl" : {
2565+
"stringUnit" : {
2566+
"state" : "translated",
2567+
"value" : "Kopiuj ścieżkę do pliku"
2568+
}
2569+
},
2570+
"pt" : {
2571+
"stringUnit" : {
2572+
"state" : "translated",
2573+
"value" : "Copiar Caminho do Arquivo"
2574+
}
2575+
},
2576+
"tr" : {
2577+
"stringUnit" : {
2578+
"state" : "translated",
2579+
"value" : "Dosya Yolunu Kopyala"
2580+
}
2581+
},
2582+
"zh-Hans" : {
2583+
"stringUnit" : {
2584+
"state" : "translated",
2585+
"value" : "拷贝文件路径"
2586+
}
2587+
},
2588+
"zh-Hant" : {
2589+
"stringUnit" : {
2590+
"state" : "translated",
2591+
"value" : "拷貝檔案路徑"
2592+
}
2593+
}
2594+
}
2595+
},
25002596
"10j-rd-fWr.title" : {
25012597
"comment" : "Class = \"NSMenu\"; title = \"Inspector\"; ObjectID = \"10j-rd-fWr\";",
25022598
"extractionState" : "extracted_with_value",

0 commit comments

Comments
 (0)