Skip to content

Commit

Permalink
completed 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Daniel Brookshire authored and Patrick Daniel Brookshire committed Nov 4, 2022
1 parent 1869752 commit a5aeeb3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ContentInterval> selectionIntervals = selectionModel.getSelectionIntervals();
List<ContentInterval> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit a5aeeb3

Please sign in to comment.