Class Open
- java.lang.Object
-
- ca.cgjennings.apps.arkham.project.TaskAction
-
- ca.cgjennings.apps.arkham.project.Open
-
- All Implemented Interfaces:
IconProvider
public class Open extends TaskAction
A task action that opens project files. How a file is handled when it is opened depends on the user's settings, which may specify rules for various file extensions. The default rule has Strange Eons first check if it knows how to open the file (either via a registeredOpen.InternalOpeneror else via a built-in default file handling mechanism). If it does not know how to deal with the file itself, and if the platform supports this capability, the Strange Eons will ask the operating system to open the file if it knows how.- Since:
- 2.1
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceOpen.InternalOpenerIf you wish to add special handling for opening a file type, you may register anInternalOpenerfor it.static classOpen.OpenRuleRules that describe how a file should be opened by the open action.
-
Field Summary
Fields Modifier and Type Field Description protected intcascade
-
Constructor Summary
Constructors Constructor Description Open()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanappliesTo(Project project, Task task, Member member)Returnstrueif this action can be performed on the specified member of a project, project or a task.static voiddeleteOpenRule(java.lang.String extension)Returns the rule that controls handling files with the given file name extension to its default state.java.lang.StringgetLabel()Returns the human-readable name of this action.static Open.OpenRulegetOpenRule(java.lang.String extension)Returns theOpen.OpenRulethat controls handling for files with the given file name extension.static java.lang.StringgetRuleCommand(java.lang.String extension)Returns the command that is executed when opening files with the given file name extension if it uses the open ruleOpen.OpenRule.CUSTOM_COMMAND.static java.lang.String[]getRuleExtensions()Returns an array of the extensions for which anOpen.OpenRulehas been set.booleanperform(Project project, Task task, Member member)Perform this action on a member of a project, a project or a task.booleanperformOnSelection(Member[] members)Applies this action to all of the specified project members.static voidregisterOpener(Open.InternalOpener opener)Registers a new internal opener for handling a custom file type.static booleanrunCommand(java.io.File f, java.lang.String commandString)Runs a command as if for theOpen.OpenRule.CUSTOM_COMMANDrule.static voidsetOpenRule(java.lang.String extension, Open.OpenRule rule)Sets the rule used to open files with the given extension.static voidsetRuleCommand(java.lang.String extension, java.lang.String commandString)Sets the command to execute when opening files with the given file name extension when they use the open ruleOpen.OpenRule.CUSTOM_COMMAND.static java.lang.String[]splitCommand(java.lang.String commandString)Splits a command string into tokens by splitting on spaces unless those spaces are enclosed in a quote sequence.booleantryDesktopEdit(java.io.File f)booleantryDesktopOpen(java.io.File f)booleantryDesktopPrint(java.io.File f)booleantryInternalOpen(Project project, Member member, java.io.File f)static voidunregisterOpener(Open.InternalOpener opener)Unregisters a previously registered internal opener for handling a custom file type.-
Methods inherited from class ca.cgjennings.apps.arkham.project.TaskAction
appliesToSelection, applyToChildren, getActionName, getDescription, getIcon, resolveTarget, toString
-
-
-
-
Method Detail
-
getLabel
public java.lang.String getLabel()
Description copied from class:TaskActionReturns the human-readable name of this action.- Specified by:
getLabelin classTaskAction- Returns:
- the name used to create menu items for this action, localized if possible
-
performOnSelection
public boolean performOnSelection(Member[] members)
Description copied from class:TaskActionApplies this action to all of the specified project members. By overriding this, you can modify what happens when the user tries to initiate this action. For example, you could add a verification dialog and call the super implementation only if the user verifies the action.- Overrides:
performOnSelectionin classTaskAction- Returns:
trueif and only if the action is successfully applied to all of the members
-
perform
public boolean perform(Project project, Task task, Member member)
Description copied from class:TaskActionPerform this action on a member of a project, a project or a task. If the project itself is the target,taskandmemberwill benull. If a task is the target, thenmemberwill be null. If an error occurs while executing the task, then it is the action's responsibility to inform the user. This method can returnfalseto indicate that if the action is being applied to multiple members, it should stop immediately rather than continue to the next member.- Specified by:
performin classTaskAction- Parameters:
project- the project that is being acted upontask- the task within the project that is being acted upon;nullif acting on a projectmember- the specific member within the task to act upon;nullif this is a project or task
-
tryDesktopOpen
public boolean tryDesktopOpen(java.io.File f)
-
tryDesktopEdit
public boolean tryDesktopEdit(java.io.File f)
-
tryDesktopPrint
public boolean tryDesktopPrint(java.io.File f)
-
tryInternalOpen
public boolean tryInternalOpen(Project project, Member member, java.io.File f) throws java.io.IOException
- Throws:
java.io.IOException
-
runCommand
public static boolean runCommand(java.io.File f, java.lang.String commandString) throws java.io.IOExceptionRuns a command as if for theOpen.OpenRule.CUSTOM_COMMANDrule. SeesetRuleCommand(java.lang.String, java.lang.String)for details.- Parameters:
f- the file that the command applies to (used to complete %f variables).commandString- the command string to use- Returns:
trueif the command is successfully started- Throws:
java.io.IOException- if an exception occurs while executing the command
-
splitCommand
public static java.lang.String[] splitCommand(java.lang.String commandString)
Splits a command string into tokens by splitting on spaces unless those spaces are enclosed in a quote sequence. SeesetRuleCommand(java.lang.String, java.lang.String)for details.- Parameters:
commandString-- Returns:
- an array of command line tokens
-
appliesTo
public boolean appliesTo(Project project, Task task, Member member)
Description copied from class:TaskActionReturnstrueif this action can be performed on the specified member of a project, project or a task. If the project itself is the target,taskandmemberwill benull. If a task is the target, thenmemberwill be null. If an error occurs while executing the task, then it is the action's responsibility to inform the user. This method can returnfalseto indicate that if the action is being applied to multiple members, it should stop immediately rather than continue to the next member.- Specified by:
appliesToin classTaskAction- Parameters:
project- the project that is being acted upontask- the task within the project that is being acted upon;nullif acting on a projectmember- the specific member within the task to act upon;nullif this is a project or task
-
getRuleExtensions
public static java.lang.String[] getRuleExtensions()
Returns an array of the extensions for which anOpen.OpenRulehas been set.- Returns:
- an array of file name extensions for which an explicit rule exists
-
setOpenRule
public static void setOpenRule(java.lang.String extension, Open.OpenRule rule)Sets the rule used to open files with the given extension. The rule will be applied to all files with the given extension unless aSpecializedActionoverrides the standard open action. (Note that specializing the open action is not recommended. Instead, if you wish to add custom code to handle opening certain files, you should register anOpen.InternalOpenerwith the standard open action.)- Parameters:
extension- the file extension to set the rule forrule- the rule to set
-
getOpenRule
public static Open.OpenRule getOpenRule(java.lang.String extension)
Returns theOpen.OpenRulethat controls handling for files with the given file name extension. If no rule is explicitly set for an extension, the default rule isOpen.OpenRule.INTERNAL_OPEN.- Parameters:
extension- the file extension to return a rule for- Returns:
- the rule used when opening files with the given extension
-
deleteOpenRule
public static void deleteOpenRule(java.lang.String extension)
Returns the rule that controls handling files with the given file name extension to its default state.- Parameters:
extension- the extension to revert to its default rule
-
setRuleCommand
public static void setRuleCommand(java.lang.String extension, java.lang.String commandString)Sets the command to execute when opening files with the given file name extension when they use the open ruleOpen.OpenRule.CUSTOM_COMMAND.The escape sequence %f will be replaced with the complete path to the file. (The sequence %% may be used to insert a plain percent sign.) Command line tokens that contain spaces must be enclosed in double quotes; to include a double quote within such a sequence it must be escaped as \".
- Parameters:
extension- the file name extension to set the command string forcommandString- the command string to use when opening such files
-
getRuleCommand
public static java.lang.String getRuleCommand(java.lang.String extension)
Returns the command that is executed when opening files with the given file name extension if it uses the open ruleOpen.OpenRule.CUSTOM_COMMAND.- Parameters:
extension- the file name extension to get the command string for- Returns:
- the command string used to open matching files
-
registerOpener
public static void registerOpener(Open.InternalOpener opener)
Registers a new internal opener for handling a custom file type.- Parameters:
opener- the opener being registered- See Also:
unregisterOpener(ca.cgjennings.apps.arkham.project.Open.InternalOpener),Open.InternalOpener
-
unregisterOpener
public static void unregisterOpener(Open.InternalOpener opener)
Unregisters a previously registered internal opener for handling a custom file type. Has no effect if the opener isnullor is not registered.- Parameters:
opener- the opener being unregistered- See Also:
registerOpener(ca.cgjennings.apps.arkham.project.Open.InternalOpener),Open.InternalOpener
-
-