mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Add "File Content" drop file variable (close #967)
This commit is contained in:
parent
3825814b9f
commit
28f14931e6
@ -5,6 +5,11 @@ Change Log
|
||||
3.7.6 (unreleased)
|
||||
--------------------------
|
||||
|
||||
### New Features
|
||||
|
||||
- Add new variable “file content” to FIle Drop feature to insert the file content when the dropped file is a text file.
|
||||
|
||||
|
||||
### Improvements
|
||||
|
||||
- Apply the change of “show other invisible characters” option immediately to the editors.
|
||||
|
@ -32,6 +32,7 @@
|
||||
<tr><td style="white-space: nowrap"><code><<<FILEEXTENSION-LOWER>>></code></td><td>The file extension of the dropped file (lowercase).</td></tr>
|
||||
<tr><td style="white-space: nowrap"><code><<<FILEEXTENSION-UPPER>>></code></td><td>The file extension of the dropped file (uppercase).</td></tr>
|
||||
<tr><td><code><<<DIRECTORY>>></code></td><td>The directory of the dropped file.</td></tr>
|
||||
<tr><td style="white-space: nowrap"><code><<<FILECONTENT>>></code></td><td>The text content of the dropped file (works only when you drop an text file).</td></tr>
|
||||
<tr><td><code><<<IMAGEWIDTH>>></code></td><td>The image width (works only when you drop an image file).</td></tr>
|
||||
<tr><td><code><<<IMAGEHEIGHT>>></code></td><td>The image height (works only when you drop an image file).</td></tr>
|
||||
</tbody>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<tr><td style="white-space: nowrap"><code><<<FILEEXTENSION-LOWER>>></code></td><td>ドロップ元ファイルの拡張子(小文字)</td></tr>
|
||||
<tr><td style="white-space: nowrap"><code><<<FILEEXTENSION-UPPER>>></code></td><td>ドロップ元ファイルの拡張子(大文字)</td></tr>
|
||||
<tr><td><code><<<DIRECTORY>>></code></td><td>ドロップ元ファイルのあるディレクトリ名</td></tr>
|
||||
<tr><td><code><<<FILECONTENT>>></code></td><td>ファイル内容(ドロップ元ファイルがテキストファイルのときのみ有効)</td></tr>
|
||||
<tr><td><code><<<IMAGEWIDTH>>></code></td><td>画像の幅(ドロップ元ファイルが画像ファイルのときのみ有効)</td></tr>
|
||||
<tr><td><code><<<IMAGEHEIGHT>>></code></td><td>画像の高さ(ドロップ元ファイルが画像ファイルのときのみ有効)</td></tr>
|
||||
</tbody>
|
||||
|
@ -8,7 +8,7 @@
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// © 2016-2018 1024jp
|
||||
// © 2016-2019 1024jp
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -51,10 +51,12 @@ final class FileDropComposer {
|
||||
case fileExtensionLowercase = "FILEEXTENSION-LOWER"
|
||||
case fileExtensionUppercase = "FILEEXTENSION-UPPER"
|
||||
case directory = "DIRECTORY"
|
||||
case fileContent = "FILECONTENT"
|
||||
case imageWidth = "IMAGEWIDTH"
|
||||
case imageHeight = "IMAGEHEIGHT"
|
||||
|
||||
static let pathTokens: [Token] = [.absolutePath, .relativePath, .filename, .filenameWithoutExtension, .fileExtension, .fileExtensionLowercase, .fileExtensionUppercase, .directory]
|
||||
static let textTokens: [Token] = [.fileContent]
|
||||
static let imageTokens: [Token] = [.imageWidth, .imageHeight]
|
||||
|
||||
|
||||
@ -85,6 +87,9 @@ final class FileDropComposer {
|
||||
case .directory:
|
||||
return "The parent directory name of dropped file."
|
||||
|
||||
case .fileContent:
|
||||
return "(If the dropped file is a text file) file content."
|
||||
|
||||
case .imageWidth:
|
||||
return "(If the dropped file is an image) image width."
|
||||
|
||||
@ -150,6 +155,13 @@ final class FileDropComposer {
|
||||
}
|
||||
}
|
||||
|
||||
// get text content if needed
|
||||
// -> Replace this at last because the file content can contain other tokens.
|
||||
if template.contains(Token.fileContent.token) {
|
||||
let content = try? String(contentsOf: droppedFileURL)
|
||||
dropText = dropText.replacingOccurrences(of: Token.fileContent.token, with: content ?? "")
|
||||
}
|
||||
|
||||
return dropText
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// © 2004-2007 nakamuxu
|
||||
// © 2014-2018 1024jp
|
||||
// © 2014-2019 1024jp
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -55,6 +55,8 @@ final class FileDropPaneController: NSViewController, NSTableViewDelegate, NSTex
|
||||
if let menu = self.variableInsertionMenu?.menu {
|
||||
menu.addItems(for: FileDropComposer.Token.pathTokens, target: self.formatTextView)
|
||||
menu.addItem(.separator())
|
||||
menu.addItems(for: FileDropComposer.Token.textTokens, target: self.formatTextView)
|
||||
menu.addItem(.separator())
|
||||
menu.addItems(for: FileDropComposer.Token.imageTokens, target: self.formatTextView)
|
||||
}
|
||||
}
|
||||
|
@ -548,6 +548,7 @@
|
||||
"The parent directory name of dropped file." = "Der übergeordnete Ordnername der abgelegten Datei.";
|
||||
"(If the dropped file is an image) image width." = "Die Bildbreite (nur wenn die abgelegte Datei ein Bild ist).";
|
||||
"(If the dropped file is an image) image height." = "Die Bildhöhe (nur wenn die abgelegte Datei ein Bild ist).";
|
||||
"(If the dropped file is a text file) file content." = "(nur wenn die abgelegte Datei eine Textdatai ist) Der Inhalt.";
|
||||
|
||||
|
||||
|
||||
|
@ -548,6 +548,7 @@
|
||||
"The parent directory name of dropped file." = "Le nom du dossier parent du fichier déposé.";
|
||||
"(If the dropped file is an image) image width." = "Largeur de l'image (si le fichier déposé est une image)";
|
||||
"(If the dropped file is an image) image height." = "Hauteur de l'image (si le fichier déposé est une image)";
|
||||
"(If the dropped file is a text file) file content." = "(If the dropped file is a text file) file content."; // FIXME: added
|
||||
|
||||
|
||||
|
||||
|
@ -549,6 +549,7 @@
|
||||
"The parent directory name of dropped file." = "Nome della cartella superiore del file trascinato.";
|
||||
"(If the dropped file is an image) image width." = "Larghezza dell’immagine (se il file trascinato è un’immagine).";
|
||||
"(If the dropped file is an image) image height." = "Altezza dell’immagine (se il file trascinato è un’immagine).";
|
||||
"(If the dropped file is a text file) file content." = "(If the dropped file is a text file) file content."; // FIXME: added
|
||||
|
||||
|
||||
|
||||
|
@ -549,6 +549,7 @@
|
||||
"The parent directory name of dropped file." = "ドロップ元ファイルのあるディレクトリ名";
|
||||
"(If the dropped file is an image) image width." = "イメージの幅(ドロップ元ファイルが画像ファイルのときのみ有効)";
|
||||
"(If the dropped file is an image) image height." = "イメージの高さ(ドロップ元ファイルが画像ファイルのときのみ有効)";
|
||||
"(If the dropped file is a text file) file content." = "ファイル内容(ドロップ元ファイルがテキストファイルのときのみ有効)";
|
||||
|
||||
|
||||
|
||||
|
@ -542,6 +542,7 @@
|
||||
"The parent directory name of dropped file." = "O nome do diretório superior do arquivo solto.";
|
||||
"(If the dropped file is an image) image width." = "Largura da imagem (se o arquivo solto for uma imagem).";
|
||||
"(If the dropped file is an image) image height." = "Altura da imagem (se o arquivo solto for uma imagem).";
|
||||
"(If the dropped file is a text file) file content." = "(If the dropped file is a text file) file content."; // FIXME: added
|
||||
|
||||
|
||||
|
||||
|
@ -549,6 +549,7 @@
|
||||
"The parent directory name of dropped file." = "拖拽的文件的上级目录";
|
||||
"(If the dropped file is an image) image width." = "图片宽度(如果拖拽文件是图像)";
|
||||
"(If the dropped file is an image) image height." = "图片高度(如果拖拽文件是图像)";
|
||||
"(If the dropped file is a text file) file content." = "(If the dropped file is a text file) file content."; // FIXME: added
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user