Skip to content

Commit

Permalink
Add support for command and line delimited
Browse files Browse the repository at this point in the history
  • Loading branch information
at055612 committed Mar 26, 2024
1 parent 12ad3c6 commit 3f506ea
Showing 1 changed file with 58 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,9 @@ private void fetchPermissions(final List<ExplorerNode> explorerNodes,
.fetchExplorerPermissions(explorerNodes);
}

private void addFavouritesMenuItem(final List<Item> menuItems, final boolean singleSelection, final int priority) {
private boolean addFavouritesMenuItem(final List<Item> menuItems,
final boolean singleSelection,
final int priority) {
final ExplorerNode primarySelection = getPrimarySelection();

// Add the favourites menu item if an item is selected, and it's not a root-level node or a favourite folder
Expand All @@ -789,7 +791,9 @@ private void addFavouritesMenuItem(final List<Item> menuItems, final boolean sin
selectionModel.clear();
})
.build());
return true;
}
return false;
}

private void toggleFavourite(final DocRef docRef, final boolean isFavourite) {
Expand Down Expand Up @@ -931,8 +935,10 @@ private void addModifyMenuItems(final List<Item> menuItems,
// Feeds are a special case so can't be copied, see https://github.com/gchq/stroom/issues/3048
final boolean isCopyEnabled = allowRead && !hasFeed;

addFavouritesMenuItem(menuItems, singleSelection, 10);
menuItems.add(new Separator(12));
final boolean wasAdded = addFavouritesMenuItem(menuItems, singleSelection, 10);
if (wasAdded) {
menuItems.add(new Separator(12));
}

menuItems.add(createInfoMenuItem(singleReadableItem, 20, isInfoEnabled));
menuItems.add(createEditOrAddTagsMenuItem(updatableItems, 21, allowUpdate));
Expand Down Expand Up @@ -1187,28 +1193,55 @@ private MenuItem createCopyAsMenuItem(final List<ExplorerNode> explorerNodes,
}

private List<Item> createCopyAsChildMenuItems(final List<ExplorerNode> explorerNodes) {
List<Item> children = new ArrayList<>();
final List<Item> children = new ArrayList<>();
final int count = explorerNodes.size();
final String plural = count > 1
? "s"
: "";

int priority = 1;
children.add(new IconMenuItem.Builder()
.priority(priority++)
.icon(SvgImage.COPY)
.text("Copy Name" + plural + " to clipboard")
.enabled(true)
.command(() -> copyAs(explorerNodes, ExplorerNode::getName))
.build());
if (count == 1) {
children.add(new IconMenuItem.Builder()
.priority(priority++)
.icon(SvgImage.COPY)
.text("Copy Name to Clipboard")
.enabled(true)
.command(() -> copyAs(explorerNodes, ExplorerNode::getName, "\n"))
.build());

children.add(new IconMenuItem.Builder()
.priority(priority++)
.icon(SvgImage.COPY)
.text("Copy UUID" + plural + " to clipboard")
.enabled(true)
.command(() -> copyAs(explorerNodes, ExplorerNode::getUuid))
.build());
children.add(new IconMenuItem.Builder()
.priority(priority++)
.icon(SvgImage.COPY)
.text("Copy UUID to Clipboard")
.enabled(true)
.command(() -> copyAs(explorerNodes, ExplorerNode::getUuid, "\n"))
.build());
} else if (count > 1) {
children.add(new IconMenuItem.Builder()
.priority(priority++)
.icon(SvgImage.COPY)
.text("Copy Names to Clipboard (lines)")
.enabled(true)
.command(() -> copyAs(explorerNodes, ExplorerNode::getName, "\n"))
.build());
children.add(new IconMenuItem.Builder()
.priority(priority++)
.icon(SvgImage.COPY)
.text("Copy Names to Clipboard (comma delimited)")
.enabled(true)
.command(() -> copyAs(explorerNodes, ExplorerNode::getName, ","))
.build());
children.add(new IconMenuItem.Builder()
.priority(priority++)
.icon(SvgImage.COPY)
.text("Copy UUIDs to Clipboard (lines)")
.enabled(true)
.command(() -> copyAs(explorerNodes, ExplorerNode::getUuid, "\n"))
.build());
children.add(new IconMenuItem.Builder()
.priority(priority++)
.icon(SvgImage.COPY)
.text("Copy UUIDs to Clipboard (comma delimited)")
.enabled(true)
.command(() -> copyAs(explorerNodes, ExplorerNode::getUuid, ","))
.build());
}

if (explorerNodes.size() == 1) {
children.add(createCopyLinkMenuItem(explorerNodes.get(0), priority++));
Expand All @@ -1218,7 +1251,8 @@ private List<Item> createCopyAsChildMenuItems(final List<ExplorerNode> explorerN
}

private void copyAs(final List<ExplorerNode> nodes,
final Function<ExplorerNode, String> extractor) {
final Function<ExplorerNode, String> extractor,
final String delimter) {
final String value;
if (nodes.isEmpty()) {
value = "";
Expand All @@ -1227,7 +1261,7 @@ private void copyAs(final List<ExplorerNode> nodes,
} else {
value = nodes.stream()
.map(extractor)
.collect(Collectors.joining("\n"));
.collect(Collectors.joining(delimter));
}
if (!GwtNullSafe.isBlankString(value)) {
ClipboardUtil.copy(value);
Expand Down

0 comments on commit 3f506ea

Please sign in to comment.