mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Sync script folder automatically
This commit is contained in:
parent
cb7e93409c
commit
7d408257a9
@ -12,6 +12,8 @@ develop
|
||||
|
||||
### Improvements
|
||||
|
||||
- Auto-sync Script menu with script folder.
|
||||
- Now, you don't need anymore to update script menu after script folder modification.
|
||||
- Display “Not Found” in the find string field in the find panel also when “Find All” failed.
|
||||
- [beta] Add option “Unescape replacement string” to find panel (On by default).
|
||||
- [beta] Improve drawing of font fields in preferences.
|
||||
|
@ -25,14 +25,13 @@
|
||||
<li>>Choose Script > Open Scripts Folder in CotEditor and Finder opens the folder for CotEditor script at:<br/>
|
||||
~/Library/Application Scripts/com.coteditor.CotEditor/</li>
|
||||
<li>Put your script files in this folder, or remove from there.</li>
|
||||
<li>In CotEditor, choose Script > Update Script Menu.</li>
|
||||
<li>The changes you made inside the scripts folder will be automatically reflected.</li>
|
||||
</ol>
|
||||
<ul>
|
||||
<li>CotEditor recognizes scripts only when their file extensions are: .applescript .scpt .sh .pl .php .rb .py .js</li>
|
||||
<li>You can <strong>change the order of appearance</strong> or <strong>assign keyboard shortcuts</strong> by modifying the names of your script files.<br />
|
||||
See <a href="../pgs/about_script_name.html">File naming rules for CotEditor scripts</a> for more details.</li>
|
||||
<li>You can create subfolders in the scripts folder. They will appear as submenus.</li>
|
||||
<li>The changes you made inside the scripts folder will be automatically reflected when CotEditor launches. Thus, you need to perform “Update Script Menu” only when you made modifications during CotEditor is running.</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
@ -25,14 +25,13 @@
|
||||
<li>CotEditor のスクリプトメニューから「スクリプトフォルダを開く」を選択すると、Finder がスクリプト用の次のフォルダを開きます:<br/>
|
||||
~/ライブラリ/Application Scripts/com.coteditor.CotEditor/</li>
|
||||
<li>このフォルダに作成したスクリプトを置くか、また不要なスクリプトを削除します。</li>
|
||||
<li>CotEditor のスクリプトメニューから「スクリプトメニューを更新」を選択します。</li>
|
||||
<li>スクリプトフォルダの変更はスクリプトメニューに自動的に反映されます。</li>
|
||||
</ol>
|
||||
<ul>
|
||||
<li>CotEditor は次の拡張子を持つファイルをスクリプトファイルとして認識します:.applescript .scpt .sh .pl .php .rb .py .js</li>
|
||||
<li>スクリプトのファイル名にある特定の文字列を含めることで、<strong>表示順を変更</strong>したり<strong>キーボードショートカットを設定</strong>できます。<br />
|
||||
詳しくは「<a href="../pgs/about_script_name.html">CotEditor スクリプトのファイル名規則</a>」を参照してください。</li>
|
||||
<li>スクリプトフォルダにはフォルダも置くことができます。フォルダはサブメニューとして表示されます。</li>
|
||||
<li>スクリプトフォルダの変更は起動時に自動的に反映されます。CotEditor が起動していない場合には「スクリプトメニューを更新...」は実行する必要はありません。</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
@ -171,7 +171,7 @@ final class AppDelegate: NSResponder, NSApplicationDelegate {
|
||||
self.buildEncodingMenu()
|
||||
self.buildSyntaxMenu()
|
||||
self.buildThemeMenu()
|
||||
ScriptManager.shared.buildScriptMenu(self)
|
||||
ScriptManager.shared.buildScriptMenu()
|
||||
|
||||
// observe setting list updates
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(buildEncodingMenu), name: .EncodingListDidUpdate, object: nil)
|
||||
|
@ -28,14 +28,13 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
final class ScriptManager: NSObject {
|
||||
final class ScriptManager: NSObject, NSFilePresenter {
|
||||
|
||||
// MARK: Public Properties
|
||||
|
||||
static let shared = ScriptManager()
|
||||
|
||||
|
||||
|
||||
// MARK: Private Properties
|
||||
|
||||
private let scriptsDirectoryURL: URL
|
||||
@ -46,6 +45,8 @@ final class ScriptManager: NSObject {
|
||||
/// file extensions for AppleScript
|
||||
private let AppleScriptExtensions = ["applescript", "scpt"]
|
||||
|
||||
private var didChangeFolder = false
|
||||
|
||||
|
||||
|
||||
// MARK: Private Enum
|
||||
@ -100,7 +101,11 @@ final class ScriptManager: NSObject {
|
||||
|
||||
super.init()
|
||||
|
||||
self.buildScriptMenu(self)
|
||||
self.buildScriptMenu()
|
||||
|
||||
// observe for script folder change
|
||||
NSFileCoordinator.addFilePresenter(self)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive), name: .NSApplicationDidBecomeActive, object: NSApp)
|
||||
|
||||
// run dummy AppleScript once for quick script launch
|
||||
DispatchQueue.main.async {
|
||||
@ -109,6 +114,48 @@ final class ScriptManager: NSObject {
|
||||
}
|
||||
|
||||
|
||||
deinit {
|
||||
NSFileCoordinator.removeFilePresenter(self)
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: File Presenter Protocol
|
||||
|
||||
var presentedItemOperationQueue = OperationQueue()
|
||||
|
||||
|
||||
var presentedItemURL: URL? {
|
||||
|
||||
return self.scriptsDirectoryURL
|
||||
}
|
||||
|
||||
|
||||
/// script folder did change
|
||||
func presentedSubitemDidChange(at url: URL) {
|
||||
|
||||
// [caution] This method can be called from any thread.
|
||||
|
||||
self.didChangeFolder = true
|
||||
|
||||
if NSApp.isActive {
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.buildScriptMenu()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// update script menu if needed
|
||||
func applicationDidBecomeActive(_ notification: Notification) {
|
||||
|
||||
if self.didChangeFolder {
|
||||
self.buildScriptMenu()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: Public Methods
|
||||
|
||||
@ -127,6 +174,27 @@ final class ScriptManager: NSObject {
|
||||
}
|
||||
|
||||
|
||||
/// build Script menu
|
||||
func buildScriptMenu() {
|
||||
|
||||
let menu = MainMenu.script.menu!
|
||||
|
||||
menu.removeAllItems()
|
||||
|
||||
self.addChildFileItem(to: menu, fromDirctory: self.scriptsDirectoryURL)
|
||||
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
|
||||
let openMenuItem = NSMenuItem(title: NSLocalizedString("Open Scripts Folder", comment: ""),
|
||||
action: #selector(openScriptFolder), keyEquivalent: "")
|
||||
openMenuItem.target = self
|
||||
openMenuItem.tag = MenuItemTag.scriptsDefault.rawValue
|
||||
menu.addItem(openMenuItem)
|
||||
|
||||
self.didChangeFolder = false
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: Action Message
|
||||
|
||||
@ -179,31 +247,6 @@ final class ScriptManager: NSObject {
|
||||
}
|
||||
|
||||
|
||||
/// build Script menu
|
||||
@IBAction func buildScriptMenu(_ sender: Any?) {
|
||||
|
||||
let menu = MainMenu.script.menu!
|
||||
|
||||
menu.removeAllItems()
|
||||
|
||||
self.addChildFileItem(to: menu, fromDirctory: self.scriptsDirectoryURL)
|
||||
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
|
||||
let openMenuItem = NSMenuItem(title: NSLocalizedString("Open Scripts Folder", comment: ""),
|
||||
action: #selector(openScriptFolder), keyEquivalent: "")
|
||||
openMenuItem.target = self
|
||||
openMenuItem.tag = MenuItemTag.scriptsDefault.rawValue
|
||||
menu.addItem(openMenuItem)
|
||||
|
||||
let updateMenuItem = NSMenuItem(title: NSLocalizedString("Update Script Menu", comment: ""),
|
||||
action: #selector(buildScriptMenu), keyEquivalent: "")
|
||||
updateMenuItem.target = self
|
||||
updateMenuItem.tag = MenuItemTag.scriptsDefault.rawValue
|
||||
menu.addItem(updateMenuItem)
|
||||
}
|
||||
|
||||
|
||||
/// open Script Menu folder in Finder
|
||||
@IBAction func openScriptFolder(_ sender: Any?) {
|
||||
|
||||
|
@ -470,7 +470,6 @@
|
||||
/* MARK: ScriptManager */
|
||||
// Menu items
|
||||
"Open Scripts Folder" = "Skript-Ordner öffnen";
|
||||
"Update Script Menu" = "Skript-Menü aktualisieren";
|
||||
|
||||
// Script menu item tooltips
|
||||
"“Option + click” to open script in editor." = "„Option + Klicken“, um das Skript im Editor zu öffnen.";
|
||||
|
@ -473,7 +473,6 @@
|
||||
/* MARK: ScriptManager */
|
||||
// Menu items
|
||||
"Open Scripts Folder" = "スクリプトフォルダを開く";
|
||||
"Update Script Menu" = "スクリプトメニューを更新";
|
||||
|
||||
// Script menu item tooltips
|
||||
"“Option + click” to open script in editor." = "スクリプトをエディタで開くには、“Option + クリック”してください。";
|
||||
|
@ -468,7 +468,6 @@
|
||||
/* MARK: ScriptManager */
|
||||
// Menu items
|
||||
"Open Scripts Folder" = "打开脚本文件夹";
|
||||
"Update Script Menu" = "更新脚本菜单";
|
||||
|
||||
// Script menu item tooltips
|
||||
"“Option + click” to open script in editor." = "使用 “Option + 单击” 在编辑器中打开脚本。";
|
||||
|
Loading…
Reference in New Issue
Block a user