Enable workflow service menu

This commit is contained in:
Reinhard Pointner 2019-02-21 02:13:54 +07:00
parent 538378a9b0
commit 7dd7908435
4 changed files with 55 additions and 10 deletions

View File

@ -16,8 +16,6 @@ link.app.purchase: @{link.app.purchase}
link.intro: @{link.intro}
link.forums: @{link.forums}
link.twitter: @{link.twitter}
link.facebook: @{link.facebook}
link.faq: @{link.faq}
link.bugs: @{link.bugs}
link.channel: @{link.channel}

View File

@ -14,6 +14,7 @@ import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.UIManager;
@ -109,6 +110,29 @@ public class MacAppUtilities {
openFileHandler.accept(files);
}
});
// add workflow service menu
initializeWorkflowServiceMenu(appMenuBar.getMenu(0));
}
public static void initializeWorkflowServiceMenu(JMenu menu) {
String root = System.getProperty("apple.app.workflows");
String home = System.getProperty("user.home");
if (root == null) {
return;
}
menu.addSeparator();
for (WorkflowType type : WorkflowType.values()) {
File templateFolder = new File(root, type.getFolderName());
File targetFolder = new File(home, type.getLibraryPath());
if (templateFolder.exists()) {
menu.add(new WorkflowMenu(type.getFolderName(), templateFolder, targetFolder));
}
}
}
public static boolean isLockedFolder(File folder) {

View File

@ -29,19 +29,17 @@ public class WorkflowMenu extends DynamicMenu {
@Override
protected void populate() {
for (File workflow : templateFolder.listFiles(WORKFLOW)) {
if (isInstalled(workflow)) {
add(createUninstallMenu(workflow));
for (File template : templateFolder.listFiles(WORKFLOW)) {
File target = new File(targetFolder, template.getName());
if (target.exists()) {
add(createUninstallMenu(target));
} else {
add(createInstallMenu(workflow));
add(createInstallMenu(template));
}
}
}
protected boolean isInstalled(File workflow) {
return new File(targetFolder, workflow.getName()).exists();
}
protected JMenuItem createInstallMenu(File workflow) {
JMenu menu = new JMenu(getNameWithoutExtension(workflow.getName()));

View File

@ -0,0 +1,25 @@
package net.filebot.platform.mac;
public enum WorkflowType {
QuickAction, FolderAction;
public String getFolderName() {
switch (this) {
case QuickAction:
return "Quick Actions";
default:
return "Folder Actions";
}
}
public String getLibraryPath() {
switch (this) {
case QuickAction:
return "Library/Services";
default:
return "Library/Workflows/Applications/Folder Actions";
}
}
}