feat: new flags inactive and ignore
This commit is contained in:
11
README.md
11
README.md
@@ -43,6 +43,10 @@ And of course, you can always write a script wrapper to call something else.
|
|||||||
|
|
||||||
There are a few ways to modify the menu structure:
|
There are a few ways to modify the menu structure:
|
||||||
|
|
||||||
|
#### Menu Icon
|
||||||
|
|
||||||
|
A subdirectory can have a custom icon if the folder contains an image file named `icon.X` (where `X` is one of: `svg`, `png`, `jpg`, `jpeg`, `gif`, `ico`).
|
||||||
|
|
||||||
#### Sort Order
|
#### Sort Order
|
||||||
|
|
||||||
By default, menu items are sorted in alphabetic order (case-insensitive).
|
By default, menu items are sorted in alphabetic order (case-insensitive).
|
||||||
@@ -60,8 +64,9 @@ Flags are defined by adding a text snippet to the filename.
|
|||||||
These constant strings are defined:
|
These constant strings are defined:
|
||||||
|
|
||||||
- __[txt]__: Execute the script and dump all output in a new `TextEdit` window (useful for reports or log files, etc.)
|
- __[txt]__: Execute the script and dump all output in a new `TextEdit` window (useful for reports or log files, etc.)
|
||||||
- __[verbose]__: Usually, script files are executed in the background. With this flag, a new `Terminal` window will open and show the activley running script (useful for continuous output like `top` or `netstat -w`, etc.)
|
- __[verbose]__: Usually, script files are executed in the background.
|
||||||
|
With this flag, a new `Terminal` window will open and show the activley running script (useful for continuous output like `top` or `netstat -w`, etc.)
|
||||||
|
- __[inactive]__: Make menu item non-clickable (will appear greyed out)
|
||||||
|
- __[ignore]__: Do not show menu item (no menu entry)
|
||||||
|
|
||||||
#### Menu Icon
|
|
||||||
|
|
||||||
A subdirectory can have a custom icon if the folder contains an image file named `icon.X` (where `X` is one of: `svg`, `png`, `jpg`, `jpeg`, `gif`, `ico`).
|
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|||||||
|
|
||||||
func menuNeedsUpdate(_ menu: NSMenu) {
|
func menuNeedsUpdate(_ menu: NSMenu) {
|
||||||
for entry in listDir(menu.title) {
|
for entry in listDir(menu.title) {
|
||||||
|
if entry.action == .Ignore {
|
||||||
|
continue
|
||||||
|
}
|
||||||
let itm = menu.addItem(withTitle: entry.title, action: nil, keyEquivalent: "")
|
let itm = menu.addItem(withTitle: entry.title, action: nil, keyEquivalent: "")
|
||||||
itm.representedObject = entry
|
itm.representedObject = entry
|
||||||
itm.image = entry.icon()
|
itm.image = entry.icon()
|
||||||
@@ -60,7 +63,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|||||||
if entry.isDir {
|
if entry.isDir {
|
||||||
itm.submenu = NSMenu(title: entry.url.path)
|
itm.submenu = NSMenu(title: entry.url.path)
|
||||||
itm.submenu?.delegate = self
|
itm.submenu?.delegate = self
|
||||||
} else {
|
} else if entry.action != .Inactive {
|
||||||
itm.action = #selector(menuItemCallback)
|
itm.action = #selector(menuItemCallback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,11 +251,15 @@ enum ActionFlag {
|
|||||||
case Default
|
case Default
|
||||||
case Text
|
case Text
|
||||||
case Verbose
|
case Verbose
|
||||||
|
case Inactive
|
||||||
|
case Ignore
|
||||||
|
|
||||||
static func from(_ filename: inout String) -> Self {
|
static func from(_ filename: inout String) -> Self {
|
||||||
for (key, flag) in [
|
for (key, flag) in [
|
||||||
"[txt]": ActionFlag.Text,
|
"[txt]": ActionFlag.Text,
|
||||||
"[verbose]": .Verbose,
|
"[verbose]": .Verbose,
|
||||||
|
"[inactive]": .Inactive,
|
||||||
|
"[ignore]": .Ignore,
|
||||||
] {
|
] {
|
||||||
if filename.contains(key) {
|
if filename.contains(key) {
|
||||||
filename = filename
|
filename = filename
|
||||||
|
|||||||
Reference in New Issue
Block a user