Class SaveBeforeAction
java.lang.Object
uk.theretiredprogrammer.actionssupport.SaveBeforeAction
Support for saving modified files prior to running an external process which
uses the file.
Two Use Cases are supported:
File is not within a project. In that case the file is saved.
File is within a project. In that case, the project properties file can be
used to obtain a save_before_action setting:
NO - don't save
YES - save the file which is the subject of the action (either file node or
editor)
ALL - save all project source files which are currently in a modified state.
The class supports:
Extracting the required property from the project property file (including
replacement of the instance whenever an update of the property file is made).
Definition of the Source file root folder.
SaveIfModified action Methods: for project and non-project use cases.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe Modes of the Save as set in the project properties file -
Constructor Summary
ConstructorsConstructorDescriptionSaveBeforeAction(Properties properties, String propertyname, SaveBeforeAction.SaveBeforeActionMode defaultmode) Create the instance - defining the basic parameters. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidsaveIfModified(org.openide.loaders.DataObject dataobject) Simple method to save a file if it is modified.voidsaveIfModifiedByMode(org.openide.loaders.DataObject dataobject) Save a project file if it is modified (depending on the Mode set) Use in cases of project files, it follows the Mode instruction and the Source Root where required.voidsetSourceRoot(org.openide.filesystems.FileObject srcroot) Set the root of the Source files (used if mode is ALL)
-
Constructor Details
-
SaveBeforeAction
public SaveBeforeAction(Properties properties, String propertyname, SaveBeforeAction.SaveBeforeActionMode defaultmode) throws IOException Create the instance - defining the basic parameters. Will process the properties to extract the SaveBeforeAction parameter.- Parameters:
properties- the propertiespropertyname- the property key - used to find the Mode valuedefaultmode- the mode value to use if the property is not found in properties- Throws:
IOException- if properties is malformed
-
-
Method Details
-
setSourceRoot
public void setSourceRoot(org.openide.filesystems.FileObject srcroot) Set the root of the Source files (used if mode is ALL)- Parameters:
srcroot- the source root folder
-
saveIfModified
public static void saveIfModified(org.openide.loaders.DataObject dataobject) Simple method to save a file if it is modified. Use in cases of not project files.- Parameters:
dataobject- the dataobject representation of the file
-
saveIfModifiedByMode
public void saveIfModifiedByMode(org.openide.loaders.DataObject dataobject) Save a project file if it is modified (depending on the Mode set) Use in cases of project files, it follows the Mode instruction and the Source Root where required.- Parameters:
dataobject- the dataobject representation of the file (Used when Mode is YES).
-