Add "File Content" drop file variable (close #967)

This commit is contained in:
1024jp 2019-06-08 21:14:14 -07:00
parent 3825814b9f
commit 28f14931e6
11 changed files with 29 additions and 2 deletions

View File

@ -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.

View File

@ -32,6 +32,7 @@
<tr><td style="white-space: nowrap"><code>&lt;&lt;&lt;FILEEXTENSION-LOWER&gt;&gt;&gt;</code></td><td>The file extension of the dropped file (lowercase).</td></tr>
<tr><td style="white-space: nowrap"><code>&lt;&lt;&lt;FILEEXTENSION-UPPER&gt;&gt;&gt;</code></td><td>The file extension of the dropped file (uppercase).</td></tr>
<tr><td><code>&lt;&lt;&lt;DIRECTORY&gt;&gt;&gt;</code></td><td>The directory of the dropped file.</td></tr>
<tr><td style="white-space: nowrap"><code>&lt;&lt;&lt;FILECONTENT&gt;&gt;&gt;</code></td><td>The text content of the dropped file (works only when you drop an text file).</td></tr>
<tr><td><code>&lt;&lt;&lt;IMAGEWIDTH&gt;&gt;&gt;</code></td><td>The image width (works only when you drop an image file).</td></tr>
<tr><td><code>&lt;&lt;&lt;IMAGEHEIGHT&gt;&gt;&gt;</code></td><td>The image height (works only when you drop an image file).</td></tr>
</tbody>

View File

@ -32,6 +32,7 @@
<tr><td style="white-space: nowrap"><code>&lt;&lt;&lt;FILEEXTENSION-LOWER&gt;&gt;&gt;</code></td><td>ドロップ元ファイルの拡張子(小文字)</td></tr>
<tr><td style="white-space: nowrap"><code>&lt;&lt;&lt;FILEEXTENSION-UPPER&gt;&gt;&gt;</code></td><td>ドロップ元ファイルの拡張子(大文字)</td></tr>
<tr><td><code>&lt;&lt;&lt;DIRECTORY&gt;&gt;&gt;</code></td><td>ドロップ元ファイルのあるディレクトリ名</td></tr>
<tr><td><code>&lt;&lt;&lt;FILECONTENT&gt;&gt;&gt;</code></td><td>ファイル内容(ドロップ元ファイルがテキストファイルのときのみ有効)</td></tr>
<tr><td><code>&lt;&lt;&lt;IMAGEWIDTH&gt;&gt;&gt;</code></td><td>画像の幅(ドロップ元ファイルが画像ファイルのときのみ有効)</td></tr>
<tr><td><code>&lt;&lt;&lt;IMAGEHEIGHT&gt;&gt;&gt;</code></td><td>画像の高さ(ドロップ元ファイルが画像ファイルのときのみ有効)</td></tr>
</tbody>

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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.";

View File

@ -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

View File

@ -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 dellimmagine (se il file trascinato è unimmagine).";
"(If the dropped file is an image) image height." = "Altezza dellimmagine (se il file trascinato è unimmagine).";
"(If the dropped file is a text file) file content." = "(If the dropped file is a text file) file content."; // FIXME: added

View File

@ -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." = "ファイル内容(ドロップ元ファイルがテキストファイルのときのみ有効)";

View File

@ -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

View File

@ -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