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.InternalOpener
or 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 interface
Open.InternalOpener
If you wish to add special handling for opening a file type, you may register anInternalOpener
for it.static class
Open.OpenRule
Rules that describe how a file should be opened by the open action.
-
Field Summary
Fields Modifier and Type Field Description protected int
cascade
-
Constructor Summary
Constructors Constructor Description Open()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
appliesTo(Project project, Task task, Member member)
Returnstrue
if this action can be performed on the specified member of a project, project or a task.static void
deleteOpenRule(java.lang.String extension)
Returns the rule that controls handling files with the given file name extension to its default state.java.lang.String
getLabel()
Returns the human-readable name of this action.static Open.OpenRule
getOpenRule(java.lang.String extension)
Returns theOpen.OpenRule
that controls handling for files with the given file name extension.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
.static java.lang.String[]
getRuleExtensions()
Returns an array of the extensions for which anOpen.OpenRule
has been set.boolean
perform(Project project, Task task, Member member)
Perform this action on a member of a project, a project or a task.boolean
performOnSelection(Member[] members)
Applies this action to all of the specified project members.static void
registerOpener(Open.InternalOpener opener)
Registers a new internal opener for handling a custom file type.static boolean
runCommand(java.io.File f, java.lang.String commandString)
Runs a command as if for theOpen.OpenRule.CUSTOM_COMMAND
rule.static void
setOpenRule(java.lang.String extension, Open.OpenRule rule)
Sets the rule used to open files with the given extension.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
.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.boolean
tryDesktopEdit(java.io.File f)
boolean
tryDesktopOpen(java.io.File f)
boolean
tryDesktopPrint(java.io.File f)
boolean
tryInternalOpen(Project project, Member member, java.io.File f)
static void
unregisterOpener(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:TaskAction
Returns the human-readable name of this action.- Specified by:
getLabel
in 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:TaskAction
Applies 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:
performOnSelection
in classTaskAction
- Returns:
true
if 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:TaskAction
Perform this action on a member of a project, a project or a task. If the project itself is the target,task
andmember
will benull
. If a task is the target, thenmember
will be null. If an error occurs while executing the task, then it is the action's responsibility to inform the user. This method can returnfalse
to indicate that if the action is being applied to multiple members, it should stop immediately rather than continue to the next member.- Specified by:
perform
in classTaskAction
- Parameters:
project
- the project that is being acted upontask
- the task within the project that is being acted upon;null
if acting on a projectmember
- the specific member within the task to act upon;null
if 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.IOException
Runs a command as if for theOpen.OpenRule.CUSTOM_COMMAND
rule. 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:
true
if 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:TaskAction
Returnstrue
if this action can be performed on the specified member of a project, project or a task. If the project itself is the target,task
andmember
will benull
. If a task is the target, thenmember
will be null. If an error occurs while executing the task, then it is the action's responsibility to inform the user. This method can returnfalse
to indicate that if the action is being applied to multiple members, it should stop immediately rather than continue to the next member.- Specified by:
appliesTo
in classTaskAction
- Parameters:
project
- the project that is being acted upontask
- the task within the project that is being acted upon;null
if acting on a projectmember
- the specific member within the task to act upon;null
if this is a project or task
-
getRuleExtensions
public static java.lang.String[] getRuleExtensions()
Returns an array of the extensions for which anOpen.OpenRule
has 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 aSpecializedAction
overrides 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.InternalOpener
with 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.OpenRule
that 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 isnull
or is not registered.- Parameters:
opener
- the opener being unregistered- See Also:
registerOpener(ca.cgjennings.apps.arkham.project.Open.InternalOpener)
,Open.InternalOpener
-
-