Skip to content

Commit

Permalink
Updating the hooks API
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed May 25, 2021
1 parent d2c218e commit ee64262
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions src/main/java/org/luwrain/app/commander/PanelArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.*;
import java.nio.file.*;
import java.net.*;
import org.luwrain.script.hooks.*;

import org.apache.commons.vfs2.*;

Expand Down Expand Up @@ -85,16 +86,9 @@ boolean runHookOnSelected(String hookPrefix)
if (!(obj instanceof org.apache.commons.vfs2.provider.local.LocalFile))
throw new RuntimeException("The entry is not a local file while the local dir is opened");
final File f = new File(obj.getName().getPath());
try {
if (luwrain.xRunHooks(hookPrefix + ".local.custom", new Object[]{f}, Luwrain.HookStrategy.CHAIN_OF_RESPONSIBILITY))
if (new ChainOfResponsibilityHook(luwrain).runNoExcept(hookPrefix + ".local.custom", new Object[]{f}))
return true;
return luwrain.xRunHooks(hookPrefix + ".local.default", new Object[]{f}, Luwrain.HookStrategy.CHAIN_OF_RESPONSIBILITY);
}
catch(RuntimeException e)
{
luwrain.message(luwrain.i18n().getExceptionDescr(e), Luwrain.MessageType.ERROR);
return true;
}
return new ChainOfResponsibilityHook(luwrain).runNoExcept(hookPrefix + ".local.default", new Object[]{f});
}
//FIXME:remote
return false;
Expand All @@ -118,27 +112,15 @@ boolean runHookOnFilesToProcess(String hookPrefix, boolean background)
} else
return false;
if (!background)
try {
if (luwrain.xRunHooks(hookName + ".custom", new Object[]{arg}, Luwrain.HookStrategy.CHAIN_OF_RESPONSIBILITY))
{
if (new ChainOfResponsibilityHook(luwrain).runNoExcept(hookName + ".custom", new Object[]{arg}))
return true;
return luwrain.xRunHooks(hookName, new Object[]{arg}, Luwrain.HookStrategy.CHAIN_OF_RESPONSIBILITY);
}
catch(RuntimeException e)
{
luwrain.crash(e);
return true;
return new ChainOfResponsibilityHook(luwrain).runNoExcept(hookName, new Object[]{arg});
}
luwrain.executeBkg(new FutureTask(()->{
try {
if (luwrain.xRunHooks(hookName + ".custom", new Object[]{arg}, Luwrain.HookStrategy.CHAIN_OF_RESPONSIBILITY))
if (new ChainOfResponsibilityHook(luwrain).runNoExcept(hookName + ".custom", new Object[]{arg}))
return;
luwrain.xRunHooks(hookName, new Object[]{arg}, Luwrain.HookStrategy.CHAIN_OF_RESPONSIBILITY);
return;
}
catch(RuntimeException e)
{
luwrain.crash(e);
}
new ChainOfResponsibilityHook(luwrain).runNoExcept(hookName, new Object[]{arg});
}, null));
return true;
}
Expand Down

0 comments on commit ee64262

Please sign in to comment.