diff --git a/CHANGELOG.md b/CHANGELOG.md index 67d7bb8..212fd26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.4.0] - 2022-11-04 + +### Added +- added class org.adwmainz.da.extensions.askmore.operations.FullySelectElementsOperation.java + ## [1.3.0] - 2020-07-30 ### Added diff --git a/README.md b/README.md index 9607f79..0eab8c3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This software package provides eight Java operations developed at the Digital Ac # Requirements -The AskMoreXtension was developed and tested to be used with the versions 19.1 to 21.0 of the [Oxygen XML Editor](https://www.oxygenxml.com/). +The AskMoreXtension was developed and tested to be used with the versions 19.1 to 24.0 of the [Oxygen XML Editor](https://www.oxygenxml.com/). # Download and Installation diff --git a/src/main/java/org/adwmainz/da/extensions/askmore/operations/FullySelectElementsOperation.java b/src/main/java/org/adwmainz/da/extensions/askmore/operations/FullySelectElementsOperation.java new file mode 100644 index 0000000..f8b8490 --- /dev/null +++ b/src/main/java/org/adwmainz/da/extensions/askmore/operations/FullySelectElementsOperation.java @@ -0,0 +1,77 @@ +package org.adwmainz.da.extensions.askmore.operations; + +import java.util.ArrayList; +import java.util.List; + +import org.adwmainz.da.extensions.askmore.utils.APIAccessUtils; +import org.adwmainz.da.extensions.askmore.utils.ArgumentParser; +import org.adwmainz.da.extensions.askmore.utils.AskMoreArgumentProvider; + +import ro.sync.ecss.extensions.api.ArgumentDescriptor; +import ro.sync.ecss.extensions.api.ArgumentsMap; +import ro.sync.ecss.extensions.api.AuthorAccess; +import ro.sync.ecss.extensions.api.AuthorDocumentController; +import ro.sync.ecss.extensions.api.AuthorOperation; +import ro.sync.ecss.extensions.api.AuthorOperationException; +import ro.sync.ecss.extensions.api.AuthorSelectionModel; +import ro.sync.ecss.extensions.api.ContentInterval; +import ro.sync.ecss.extensions.api.access.AuthorEditorAccess; +import ro.sync.ecss.extensions.api.node.AuthorNode; + +public class FullySelectElementsOperation implements AuthorOperation { + + // field + protected ArgumentDescriptor[] arguments; + + // constructor + public FullySelectElementsOperation() { + arguments = new ArgumentDescriptor[] { + new ArgumentDescriptor( + AskMoreArgumentProvider.ARGUMENT_LOCATION_RESTRICTION, + ArgumentDescriptor.TYPE_XPATH_EXPRESSION, + "An XPath expression that specifies which nodes from the current selection should be used." + + "\n(i.e. this operation selects all (partially) selected nodes with the name NAME and an attribute ATTR if the value " + + "of this param is set to //NAME[@ATTR]." + ) + }; + } + + @Override + public String getDescription() { + return "Fully selects nodes matching a given XPath expression that are only partly selected in the Author Mode."; + } + + @Override + public void doOperation(AuthorAccess authorAccess, ArgumentsMap args) + throws IllegalArgumentException, AuthorOperationException { + String location = ArgumentParser.getValidString(args, AskMoreArgumentProvider.ARGUMENT_LOCATION_RESTRICTION); + + // get the document controller and editor access + AuthorDocumentController documentController = authorAccess.getDocumentController(); + AuthorEditorAccess editorAccess = authorAccess.getEditorAccess(); + + // get all possible insert locations + AuthorNode[] targetNodes = documentController.findNodesByXPath(location, false/*include text nodes*/, true, true); + + // get all selection intervals + AuthorSelectionModel selectionModel = editorAccess.getAuthorSelectionModel(); + List selectionIntervals = selectionModel.getSelectionIntervals(); + List intervals = new ArrayList<>(); + + // iterate over nodes to find the selected ones + for (AuthorNode targetNode: targetNodes) { + for (ContentInterval selectionInterval: selectionIntervals) { + if (APIAccessUtils.containsNode(selectionInterval, targetNode)) { + intervals.add(new ContentInterval(targetNode.getStartOffset(), targetNode.getEndOffset())); + } + } + } + selectionModel.setSelectionIntervals(intervals, true); + } + + @Override + public ArgumentDescriptor[] getArguments() { + return arguments; + } + +} diff --git a/src/main/java/org/adwmainz/da/extensions/askmore/utils/AskMoreArgumentProvider.java b/src/main/java/org/adwmainz/da/extensions/askmore/utils/AskMoreArgumentProvider.java index 93691f5..082f0f7 100644 --- a/src/main/java/org/adwmainz/da/extensions/askmore/utils/AskMoreArgumentProvider.java +++ b/src/main/java/org/adwmainz/da/extensions/askmore/utils/AskMoreArgumentProvider.java @@ -25,6 +25,7 @@ public class AskMoreArgumentProvider { public static final String ARGUMENT_INSERT_LOCATION = "insertLocation"; public static final String ARGUMENT_INSERT_LOCATION_RESTRICTION = "insertLocationRestriction"; public static final String ARGUMENT_INSERT_POSITION = "insertPosition"; + public static final String ARGUMENT_LOCATION_RESTRICTION = "locationRestriction"; public static final String ARGUMENT_MESSAGE = "message"; public static final String ARGUMENT_NO_RESULT_MESSAGE = "noResultMessage"; public static final String ARGUMENT_NOTIFY_USER = "notifyUser";