-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3740] Add keyboard shortcut for object duplication
Bug: #3740 Signed-off-by: Laurent Fasani <[email protected]> Signed-off-by: Florian ROUËNÉ <[email protected]>
- Loading branch information
Showing
6 changed files
with
110 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...es/sirius-web/frontend/sirius-web-application/src/views/edit-project/KeyboardShortcut.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
import { useEffect, useState } from 'react'; | ||
import { Selection, useSelection } from '@eclipse-sirius/sirius-components-core'; | ||
import { DuplicateObjectModal } from '../../modals/duplicate-object/DuplicateObjectModal'; | ||
import { KeyboardShortcutProps } from './KeyboardShortcut.types'; | ||
|
||
export const KeyboardShortcut = ({ editingContextId, readOnly, children }: KeyboardShortcutProps) => { | ||
const [open, setOpen] = useState<boolean>(false); | ||
const { selection, setSelection } = useSelection(); | ||
|
||
const duplicateObjectModalOpen = () => { | ||
if (selection && selection.entries.length === 1) { | ||
const selectionEntryItem = selection.entries[0]; | ||
if (selectionEntryItem && selectionEntryItem.kind.startsWith('siriusComponents://semantic')) { | ||
setOpen(true); | ||
} | ||
} | ||
}; | ||
|
||
const duplicateObjectKeyPressHandler = (e) => { | ||
if ((e.ctrlKey || e.metaKey) && e.key === 'd') { | ||
e.preventDefault(); | ||
duplicateObjectModalOpen(); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (!readOnly) { | ||
window.addEventListener('keydown', duplicateObjectKeyPressHandler); | ||
} | ||
return () => window.removeEventListener('keydown', duplicateObjectKeyPressHandler); | ||
}, [selection, readOnly]); | ||
|
||
const onObjectCreated = (selection: Selection) => { | ||
setSelection(selection); | ||
setOpen(false); | ||
}; | ||
|
||
const onClose = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
{children} | ||
{open ? ( | ||
<DuplicateObjectModal | ||
editingContextId={editingContextId} | ||
objectToDuplicateId={selection.entries[0].id} | ||
objectToDuplicateKind={selection.entries[0].kind} | ||
onObjectDuplicated={onObjectCreated} | ||
onClose={onClose} | ||
/> | ||
) : null} | ||
</> | ||
); | ||
}; |
18 changes: 18 additions & 0 deletions
18
...rius-web/frontend/sirius-web-application/src/views/edit-project/KeyboardShortcut.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
export type KeyboardShortcutProps = { | ||
editingContextId: string; | ||
readOnly: boolean; | ||
children: React.ReactNode; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters