Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatchHeight editor action for bbox #1050

Merged
merged 3 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions assets/js/verovio-toolkit.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/SquareEdit/Contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ export const divLineActionContents =
</div>
</div>`;

/**
* Contents of bbox action menu.
*/
export const bboxActionContents =
`<div class="right-side-panel-btns-container">
<button class="side-panel-btn" id="matchHeight">Match Height</button>
<button class="side-panel-btn" id="delete">Delete</button>
</div>`;

/**
* HTML for grouping selection menu.
*/
Expand Down
38 changes: 38 additions & 0 deletions src/SquareEdit/SelectOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ChangeStaffAction,
DisplaceClefOctaveAction,
EditorAction,
MatchHeightAction,
RemoveAction,
SetAction,
SetClefAction
Expand Down Expand Up @@ -245,6 +246,31 @@ export function moveOutsideSyllableHandler(): void {
});
}

/**
* Function to match bbox height to the selected bbox
*/
export function matchHeightHandler(): void {
const selected = Array.from(document.getElementsByClassName('selected'));
if (selected.length > 1) {
Notification.queueNotification('Cannot match height to multiple bbox', 'error');
}
const toChange: MatchHeightAction = {
action: 'matchHeight',
param: {
elementId: selected[0].id
}
};

neonView.edit(toChange, neonView.view.getCurrentPageURI()).then((result) => {
if (result) {
Notification.queueNotification('Height Match Success', 'success');
} else {
Notification.queueNotification('Height Match Failed XoX', 'error');
}
endOptionsSelection();
neonView.updateForCurrentPage();
});
}

function addDeleteListener(): void {
const del = document.getElementById('delete');
Expand Down Expand Up @@ -940,6 +966,18 @@ export function triggerSplitActions (): void {
});
}

/**
* Trigger bbox option.
*/
export function triggerBBoxActions (): void {
endOptionsSelection();
setEditControls('moreEdit', Contents.bboxActionContents);
addDeleteListener();
document.getElementById('matchHeight').addEventListener('click', () => {
matchHeightHandler();
});
}

/**
* Trigger default actions when selecting by syl
*/
Expand Down
10 changes: 9 additions & 1 deletion src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ export type ChangeGroupAction = {
};
};

export type MatchHeightAction = {
action: 'matchHeight',
param: {
elementId: string;
};
};

/** An editing action sent to verovio as described [here](https://github.com/DDMAL/Neon/wiki/Toolkit-Actions). */
export type EditorAction =
| DragAction
Expand All @@ -224,7 +231,8 @@ export type EditorAction =
| ChangeStaffAction
| ChangeStaffToAction
| ChangeGroupAction
| ChainAction;
| ChainAction
| MatchHeightAction;

export type ChainAction = {
action: 'chain',
Expand Down
3 changes: 2 additions & 1 deletion src/utils/SelectTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ export function selectBBox (el: SVGGraphicsElement, dragHandler: DragHandler, ne
}
}
}
SelectOptions.triggerBBoxActions();
}

/**
Expand Down Expand Up @@ -729,7 +730,7 @@ export async function selectAll (elements: Array<SVGGraphicsElement>, neonView:
switch (groups.length) {
case 1:
selectBBox(groups[0], dragHandler, neonView);
SelectOptions.triggerDefaultActions();
SelectOptions.triggerBBoxActions();
break;
default:
groups.forEach(g => selectBBox(g, dragHandler, undefined));
Expand Down
52 changes: 26 additions & 26 deletions verovio-util/verovio-dev/index.js

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions verovio-util/verovio.js

Large diffs are not rendered by default.